CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) : m_pApp(pApp), m_pDocument(nullptr), m_bBlocking(FALSE), m_isolate(nullptr), m_isolateManaged(false) { #ifndef PDF_ENABLE_XFA IPDF_JSPLATFORM* pPlatform = m_pApp->GetFormFillInfo()->m_pJsPlatform; if (pPlatform->version <= 2) { unsigned int embedderDataSlot = 0; v8::Isolate* pExternalIsolate = nullptr; if (pPlatform->version == 2) { pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate); embedderDataSlot = pPlatform->m_v8EmbedderSlot; } FXJS_Initialize(embedderDataSlot, pExternalIsolate); } m_isolateManaged = FXJS_GetIsolate(&m_isolate); #else if (CPDFXFA_App::GetInstance()->GetJSERuntime()) { // TODO(tsepez): CPDFXFA_App should also use the embedder provided isolate. m_isolate = (v8::Isolate*)CPDFXFA_App::GetInstance()->GetJSERuntime(); } else { IPDF_JSPLATFORM* pPlatform = m_pApp->GetFormFillInfo()->m_pJsPlatform; if (pPlatform->version <= 2) { unsigned int embedderDataSlot = 0; v8::Isolate* pExternalIsolate = nullptr; if (pPlatform->version == 2) { pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate); embedderDataSlot = pPlatform->m_v8EmbedderSlot; } FXJS_Initialize(embedderDataSlot, pExternalIsolate); } m_isolateManaged = FXJS_GetIsolate(&m_isolate); } v8::Isolate* isolate = m_isolate; v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); if (CPDFXFA_App::GetInstance()->IsJavaScriptInitialized()) { CJS_Context* pContext = (CJS_Context*)NewContext(); FXJS_InitializeRuntime(GetIsolate(), this, &m_context, &m_StaticObjects); ReleaseContext(pContext); return; } #endif if (m_isolateManaged || FXJS_GlobalIsolateRefCount() == 0) DefineJSObjects(); #ifdef PDF_ENABLE_XFA CPDFXFA_App::GetInstance()->SetJavaScriptInitialized(TRUE); #endif CJS_Context* pContext = (CJS_Context*)NewContext(); FXJS_InitializeRuntime(GetIsolate(), this, &m_context, &m_StaticObjects); ReleaseContext(pContext); }
JNIEXPORT jint JNICALL Java_com_apple_dnssd_AppleRecordRegistrar_CreateConnection( JNIEnv *pEnv, jobject pThis) { jclass cls = (*pEnv)->GetObjectClass( pEnv, pThis); jfieldID contextField = (*pEnv)->GetFieldID( pEnv, cls, "fNativeContext", "J"); OpContext *pContext = NULL; DNSServiceErrorType err = kDNSServiceErr_NoError; if ( contextField != 0) pContext = NewContext( pEnv, pThis, "recordRegistered", "(Lcom/apple/dnssd/DNSRecord;I)V"); else err = kDNSServiceErr_BadParam; if ( pContext != NULL) { err = DNSServiceCreateConnection( &pContext->ServiceRef); if ( err == kDNSServiceErr_NoError) { (*pEnv)->SetLongField(pEnv, pThis, contextField, (long) pContext); } } else err = kDNSServiceErr_NoMemory; return err; }
JNIEXPORT jint JNICALL Java_com_apple_dnssd_AppleQuery_CreateQuery( JNIEnv *pEnv, jobject pThis, jint flags, jint ifIndex, jstring serviceName, jint rrtype, jint rrclass) { jclass cls = (*pEnv)->GetObjectClass( pEnv, pThis); jfieldID contextField = (*pEnv)->GetFieldID( pEnv, cls, "fNativeContext", "J"); OpContext *pContext = NULL; DNSServiceErrorType err = kDNSServiceErr_NoError; if ( contextField != 0) pContext = NewContext( pEnv, pThis, "queryAnswered", "(Lcom/apple/dnssd/DNSSDService;IILjava/lang/String;II[BI)V"); else err = kDNSServiceErr_BadParam; if ( pContext != NULL) { const char *servStr = SafeGetUTFChars( pEnv, serviceName); err = DNSServiceQueryRecord( &pContext->ServiceRef, flags, ifIndex, servStr, rrtype, rrclass, ServiceQueryReply, pContext); if ( err == kDNSServiceErr_NoError) { (*pEnv)->SetLongField(pEnv, pThis, contextField, (long) pContext); } SafeReleaseUTFChars( pEnv, serviceName, servStr); } else err = kDNSServiceErr_NoMemory; return err; }
JNIEXPORT jint JNICALL Java_com_apple_dnssd_AppleDomainEnum_BeginEnum( JNIEnv *pEnv, jobject pThis, jint flags, jint ifIndex) { jclass cls = (*pEnv)->GetObjectClass( pEnv, pThis); jfieldID contextField = (*pEnv)->GetFieldID( pEnv, cls, "fNativeContext", "J"); OpContext *pContext = NULL; DNSServiceErrorType err = kDNSServiceErr_NoError; if ( contextField != 0) pContext = NewContext( pEnv, pThis, "domainFound", "(Lcom/apple/dnssd/DNSSDService;IILjava/lang/String;)V"); else err = kDNSServiceErr_BadParam; if ( pContext != NULL) { pContext->Callback2 = (*pEnv)->GetMethodID( pEnv, (*pEnv)->GetObjectClass( pEnv, pContext->ClientObj), "domainLost", "(Lcom/apple/dnssd/DNSSDService;IILjava/lang/String;)V"); err = DNSServiceEnumerateDomains( &pContext->ServiceRef, flags, ifIndex, DomainEnumReply, pContext); if ( err == kDNSServiceErr_NoError) { (*pEnv)->SetLongField(pEnv, pThis, contextField, (long) pContext); } } else err = kDNSServiceErr_NoMemory; return err; }
/* HandleTypeParam: make a type parameter instance from a parameter KCT tree and some other info. Used to expand specified procedures. */ tTree HandleTypeParam (tTree formalParameters, PtrContext * callingContext, PtrIdentList * remainingIdents, PtrTypeList * types, PtrComponentParameterList * params, PtrType type, tPosition position) { tTree ret = formalParameters; tTree parameter = formalParameters; PtrType newType; tIdent ident; parameter = GetNextBalsaParam (&ret, &ident, remainingIdents, position); if (parameter == NoTree) return ret; /* Right sort of parameter? */ if (parameter->Kind != kTypeParamPort) { LOG_ERROR (ExpectingAnExprParam, NoIdent, position); return ret; } if (type == NoType) return ret; newType = AliasType (type, ident); *types = NewTypeList (newType, *types); { PtrComponentParameter param = NewComponentParameter (TypeComponentParameter, newType, ident, NULL); if (params) *params = NewComponentParameterList (param, *params); } *callingContext = NewContext ((*callingContext)->depth, NewTypeList (newType, (*callingContext)->types), (*callingContext)->instances, (*callingContext)->procedures); return ret; }
CJS_Runtime::CJS_Runtime(CPDFSDK_FormFillEnvironment* pFormFillEnv) : m_pFormFillEnv(pFormFillEnv), m_bBlocking(false), m_isolateManaged(false) { v8::Isolate* pIsolate = nullptr; IPDF_JSPLATFORM* pPlatform = m_pFormFillEnv->GetFormFillInfo()->m_pJsPlatform; if (pPlatform->version <= 2) { unsigned int embedderDataSlot = 0; v8::Isolate* pExternalIsolate = nullptr; if (pPlatform->version == 2) { pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate); embedderDataSlot = pPlatform->m_v8EmbedderSlot; } FXJS_Initialize(embedderDataSlot, pExternalIsolate); } m_isolateManaged = FXJS_GetIsolate(&pIsolate); SetIsolate(pIsolate); #ifdef PDF_ENABLE_XFA v8::Isolate::Scope isolate_scope(pIsolate); v8::HandleScope handle_scope(pIsolate); #endif if (m_isolateManaged || FXJS_GlobalIsolateRefCount() == 0) DefineJSObjects(); CJS_Context* pContext = (CJS_Context*)NewContext(); InitializeEngine(); ReleaseContext(pContext); SetFormFillEnvToDocument(); }
CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) : m_pApp(pApp), m_pDocument(NULL), m_bBlocking(FALSE), m_isolate(NULL), m_isolateManaged(false) { unsigned int embedderDataSlot = 0; if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { m_isolate = reinterpret_cast<v8::Isolate*>( m_pApp->GetFormFillInfo()->m_pJsPlatform->m_isolate); embedderDataSlot = pApp->GetFormFillInfo()->m_pJsPlatform->m_v8EmbedderSlot; } if (!m_isolate) { m_pArrayBufferAllocator.reset(new FXJS_ArrayBufferAllocator()); v8::Isolate::CreateParams params; params.array_buffer_allocator = m_pArrayBufferAllocator.get(); m_isolate = v8::Isolate::New(params); m_isolateManaged = true; } FXJS_Initialize(embedderDataSlot); DefineJSObjects(); CJS_Context* pContext = (CJS_Context*)NewContext(); FXJS_InitializeRuntime(GetIsolate(), this, pContext, m_context); ReleaseContext(pContext); }
JNIEXPORT jint JNICALL Java_com_apple_dnssd_AppleRegistration_BeginRegister( JNIEnv *pEnv, jobject pThis, jint ifIndex, jint flags, jstring serviceName, jstring regType, jstring domain, jstring host, jint port, jbyteArray txtRecord) { //syslog(LOG_ERR, "BR"); jclass cls = (*pEnv)->GetObjectClass( pEnv, pThis); jfieldID contextField = (*pEnv)->GetFieldID( pEnv, cls, "fNativeContext", "J"); OpContext *pContext = NULL; DNSServiceErrorType err = kDNSServiceErr_NoError; jbyte *pBytes; jsize numBytes; //syslog(LOG_ERR, "BR: contextField %d", contextField); if ( contextField != 0) pContext = NewContext( pEnv, pThis, "serviceRegistered", "(Lcom/apple/dnssd/DNSSDRegistration;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); else err = kDNSServiceErr_BadParam; if ( pContext != NULL) { const char *servStr = SafeGetUTFChars( pEnv, serviceName); const char *regStr = SafeGetUTFChars( pEnv, regType); const char *domainStr = SafeGetUTFChars( pEnv, domain); const char *hostStr = SafeGetUTFChars( pEnv, host); //syslog(LOG_ERR, "BR: regStr %s", regStr); // Since Java ints are defined to be big-endian, we de-canonicalize 'port' from a // big-endian number into a 16-bit pattern here. uint16_t portBits = port; portBits = ( ((unsigned char*) &portBits)[0] << 8) | ((unsigned char*) &portBits)[1]; pBytes = txtRecord ? (*pEnv)->GetByteArrayElements( pEnv, txtRecord, NULL) : NULL; numBytes = txtRecord ? (*pEnv)->GetArrayLength( pEnv, txtRecord) : 0; err = DNSServiceRegister( &pContext->ServiceRef, flags, ifIndex, servStr, regStr, domainStr, hostStr, portBits, numBytes, pBytes, ServiceRegisterReply, pContext); if ( err == kDNSServiceErr_NoError) { (*pEnv)->SetLongField(pEnv, pThis, contextField, (long) pContext); } if ( pBytes != NULL) (*pEnv)->ReleaseByteArrayElements( pEnv, txtRecord, pBytes, 0); SafeReleaseUTFChars( pEnv, serviceName, servStr); SafeReleaseUTFChars( pEnv, regType, regStr); SafeReleaseUTFChars( pEnv, domain, domainStr); SafeReleaseUTFChars( pEnv, host, hostStr); } else err = kDNSServiceErr_NoMemory; return err; }
//----------------------------------------------------------------------------- // CreateGlobalContext - create the basis of the global context //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- void CreateGlobalContext(void) { if (GlobalContext) { CodeOutput(VERBOSE_ALL, "Serious warning: re-create global context\n"); } GlobalContext = NewContext(NULL); assert(GlobalContext != NULL); GlobalContext->IsGlobal = 1; // set global flag in struct }
/* HandleExprParam: make an expression parameter instance from a parameter KCT tree and some other info. Used to expand specified procedures. */ tTree HandleExprParam (tTree formalParameters, PtrContext * callingContext, PtrIdentList * remainingIdents, PtrInstanceList * constants, PtrComponentParameterList * params, TypedValue val, tPosition position) { tTree ret = formalParameters; tTree parameter = formalParameters; PtrInstance constant; tIdent ident; parameter = GetNextBalsaParam (&ret, &ident, remainingIdents, position); if (parameter == NoTree) return ret; /* Right sort of parameter? */ if (parameter->Kind != kParamPort) { LOG_ERROR (ExpectingATypeParam, NoIdent, position); return ret; } /* The right type? */ if (!TypeEquivalence (val.type, parameter->ParamPort.AType->AType.type)) { LOG_ERROR (TypeIsNotValid, NoIdent, position); return ret; } else if (!val.value.baseValue) /* Constant? */ { LOG_ERROR (ExpressionMustBeConstant, NoIdent, position); return ret; } constant = NewConstantInstance (ident, val); *constants = NewInstanceList (constant, *constants); { PtrComponentParameter param; if (TypeEquivalence (val.type, StringTypeObj)) { param = NewComponentParameter (StringComponentParameter, GetBuiltinValuePointer (val.value.baseValue), ident, NULL); } else { param = NewComponentParameter (NumberComponentParameter, val.value.baseValue, ident, val.type); } if (params) *params = NewComponentParameterList (param, *params); } *callingContext = NewContext ((*callingContext)->depth, (*callingContext)->types, NewInstanceList (constant, (*callingContext)->instances), (*callingContext)->procedures); return ret; }
CJS_Runtime::CJS_Runtime(CPDFDoc_Environment * pApp) : m_pApp(pApp), m_pDocument(NULL), m_pFieldEventPath(NULL), m_bBlocking(FALSE), m_bRegistered(FALSE) { m_isolate = v8::Isolate::New(); //m_isolate->Enter(); InitJSObjects(); CJS_Context * pContext = (CJS_Context*)NewContext(); JS_InitialRuntime(*this, this, pContext, m_context); ReleaseContext(pContext); }
CJS_Runtime::CJS_Runtime(CPDFDoc_Environment * pApp) : m_pApp(pApp), m_pDocument(NULL), m_bBlocking(FALSE), m_bRegistered(FALSE), m_pFieldEventPath(NULL) { m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator()); v8::Isolate::CreateParams params; params.array_buffer_allocator = m_pArrayBufferAllocator.get(); m_isolate = v8::Isolate::New(params); InitJSObjects(); CJS_Context * pContext = (CJS_Context*)NewContext(); JS_InitialRuntime(*this, this, pContext, m_context); ReleaseContext(pContext); }
JNIEXPORT jint JNICALL Java_com_apple_dnssd_AppleBrowser_CreateBrowser( JNIEnv *pEnv, jobject pThis, jint flags, jint ifIndex, jstring regType, jstring domain) { jclass cls = (*pEnv)->GetObjectClass( pEnv, pThis); jfieldID contextField = (*pEnv)->GetFieldID( pEnv, cls, "fNativeContext", "J"); OpContext *pContext = NULL; DNSServiceErrorType err = kDNSServiceErr_NoError; if ( contextField != 0) pContext = NewContext( pEnv, pThis, "serviceFound", "(Lcom/apple/dnssd/DNSSDService;IILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); else err = kDNSServiceErr_BadParam; if ( pContext != NULL) { const char *regStr = SafeGetUTFChars( pEnv, regType); const char *domainStr = SafeGetUTFChars( pEnv, domain); pContext->Callback2 = (*pEnv)->GetMethodID( pEnv, (*pEnv)->GetObjectClass( pEnv, pContext->ClientObj), "serviceLost", "(Lcom/apple/dnssd/DNSSDService;IILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); err = DNSServiceBrowse( &pContext->ServiceRef, flags, ifIndex, regStr, domainStr, ServiceBrowseReply, pContext); if ( err == kDNSServiceErr_NoError) { (*pEnv)->SetLongField(pEnv, pThis, contextField, (long) pContext); } SafeReleaseUTFChars( pEnv, regType, regStr); SafeReleaseUTFChars( pEnv, domain, domainStr); } else err = kDNSServiceErr_NoMemory; return err; }
JNIEXPORT jint JNICALL Java_com_apple_dnssd_AppleResolver_CreateResolver( JNIEnv *pEnv, jobject pThis, jint flags, jint ifIndex, jstring serviceName, jstring regType, jstring domain) { jclass cls = (*pEnv)->GetObjectClass( pEnv, pThis); jfieldID contextField = (*pEnv)->GetFieldID( pEnv, cls, "fNativeContext", "J"); OpContext *pContext = NULL; DNSServiceErrorType err = kDNSServiceErr_NoError; if ( contextField != 0) pContext = NewContext( pEnv, pThis, "serviceResolved", "(Lcom/apple/dnssd/DNSSDService;II[B[BILcom/apple/dnssd/TXTRecord;)V"); else err = kDNSServiceErr_BadParam; if ( pContext != NULL) { const char *servStr = SafeGetUTFChars( pEnv, serviceName); const char *regStr = SafeGetUTFChars( pEnv, regType); const char *domainStr = SafeGetUTFChars( pEnv, domain); err = DNSServiceResolve( &pContext->ServiceRef, flags, ifIndex, servStr, regStr, domainStr, ServiceResolveReply, pContext); if ( err == kDNSServiceErr_NoError) { (*pEnv)->SetLongField(pEnv, pThis, contextField, (long) pContext); } SafeReleaseUTFChars( pEnv, serviceName, servStr); SafeReleaseUTFChars( pEnv, regType, regStr); SafeReleaseUTFChars( pEnv, domain, domainStr); } else err = kDNSServiceErr_NoMemory; return err; }
CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) : m_pApp(pApp), m_pDocument(NULL), m_bBlocking(FALSE), m_isolate(NULL), m_isolateManaged(false) { IPDF_JSPLATFORM* pPlatform = m_pApp->GetFormFillInfo()->m_pJsPlatform; if (pPlatform->version <= 2) { unsigned int embedderDataSlot = 0; v8::Isolate* pExternalIsolate = nullptr; if (pPlatform->version == 2) { pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate); embedderDataSlot = pPlatform->m_v8EmbedderSlot; } FXJS_Initialize(embedderDataSlot, pExternalIsolate); } m_isolateManaged = FXJS_GetIsolate(&m_isolate); if (m_isolateManaged || FXJS_GlobalIsolateRefCount() == 0) DefineJSObjects(); CJS_Context* pContext = (CJS_Context*)NewContext(); FXJS_InitializeRuntime(GetIsolate(), this, &m_context, &m_StaticObjects); ReleaseContext(pContext); }
void ScheduleTask(task* Task) { _SimPrintString("Context switch\n"); NewContext(Task->SP); }
OTSocket::OTSocket() : m_pContext(NULL), m_pSocket(NULL) { NewContext(); }