diff --git a/.travis.yml b/.travis.yml index 4ec0908ed..c1d7debc3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ env: global: - NODE_VERSION=6.11.1 - - NDK_VERSION=r17b + - NDK_VERSION=r18b - DATE=$(date +%Y-%m-%d) - PACKAGE_VERSION=next-$DATE-$TRAVIS_BUILD_NUMBER - EMULATOR_API_LEVEL=21 diff --git a/build-artifacts/project-template-gradle/settings.json b/build-artifacts/project-template-gradle/settings.json index 0e44c524d..7c41f2512 100644 --- a/build-artifacts/project-template-gradle/settings.json +++ b/build-artifacts/project-template-gradle/settings.json @@ -1,3 +1,3 @@ { - "v8Version": "6.9.427.23" + "v8Version": "7.1.302.31" } \ No newline at end of file diff --git a/package.json b/package.json index c969e9966..7328c8fba 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "**/*" ], "gradle": { - "version": "4.10.2", - "android": "3.2.1" - } + "version": "4.10.2", + "android": "3.2.1" + }, + "android_ndk_version": "18b" } diff --git a/test-app/app/src/main/assets/app/modules/libCalc-arm.so b/test-app/app/src/main/assets/app/modules/libCalc-arm.so index d5d3a4c5b..bfc3347b5 100755 Binary files a/test-app/app/src/main/assets/app/modules/libCalc-arm.so and b/test-app/app/src/main/assets/app/modules/libCalc-arm.so differ diff --git a/test-app/app/src/main/assets/app/modules/libCalc-arm64.so b/test-app/app/src/main/assets/app/modules/libCalc-arm64.so index 0101abdb7..e1a22f72a 100755 Binary files a/test-app/app/src/main/assets/app/modules/libCalc-arm64.so and b/test-app/app/src/main/assets/app/modules/libCalc-arm64.so differ diff --git a/test-app/app/src/main/assets/app/modules/libCalc-x86.so b/test-app/app/src/main/assets/app/modules/libCalc-x86.so index 078aa7233..eb7a0a7ce 100755 Binary files a/test-app/app/src/main/assets/app/modules/libCalc-x86.so and b/test-app/app/src/main/assets/app/modules/libCalc-x86.so differ diff --git a/test-app/app/src/main/assets/app/tests/exceptionHandlingTests.js b/test-app/app/src/main/assets/app/tests/exceptionHandlingTests.js index 742b8ac4a..5deab7438 100644 --- a/test-app/app/src/main/assets/app/tests/exceptionHandlingTests.js +++ b/test-app/app/src/main/assets/app/tests/exceptionHandlingTests.js @@ -31,12 +31,10 @@ describe("Tests exception handling ", function () { var eh = new EH(); - try - { + try { eh.triggerEvent1("test", 5); } - catch (e) - { + catch (e) { exceptionCaught = true; sameExObject = e === ex; __log("e=" + e); @@ -71,16 +69,13 @@ describe("Tests exception handling ", function () { var eh = new EH(); - try - { + try { eh.triggerEvent1("test", 5); } - catch (e) - { + catch (e) { exceptionCaught = true; nativeExceptionFound = e.nativeException !== undefined; - if (nativeExceptionFound) - { + if (nativeExceptionFound) { exMsg = e.nativeException.getMessage(); } } @@ -111,13 +106,11 @@ describe("Tests exception handling ", function () { var eh = new EH(); - try - { + try { eh.triggerEvent1WithCatchClause("test", 5); exceptionCaught = false; } - catch (e) - { + catch (e) { exceptionCaught = true; } @@ -147,13 +140,11 @@ describe("Tests exception handling ", function () { var eh = new EH(); - try - { + try { eh.triggerEvent1WithCatchClause("test", 5); exceptionCaught = false; } - catch (e) - { + catch (e) { exceptionCaught = true; } @@ -169,12 +160,10 @@ describe("Tests exception handling ", function () { var dummy = new com.tns.tests.DummyClass(); - try - { + try { dummy.methodThatThrowsException(); } - catch (e) - { + catch (e) { exceptionCaught = true; } @@ -190,12 +179,10 @@ describe("Tests exception handling ", function () { var dummy = new com.tns.tests.DummyClass(); - try - { + try { dummy.methodThatThrowsException(); } - catch (e) - { + catch (e) { var nativeException = e.nativeException; } @@ -214,12 +201,10 @@ describe("Tests exception handling ", function () { var exceptionCaught = false; - try - { + try { var dummy = new com.tns.tests.DummyClass(true /* throwsException */); } - catch (e) - { + catch (e) { exceptionCaught = true; } @@ -240,14 +225,12 @@ describe("Tests exception handling ", function () { expect(arrLength).toEqual(1); - try - { + try { var dummy = arr[arrLength]; var name = dummy.getName(); } - catch (e) - { + catch (e) { exceptionCaught = true; } @@ -270,12 +253,10 @@ describe("Tests exception handling ", function () { var last = arr[arrLength - 1]; - try - { + try { arr[arrLength] = last; } - catch (e) - { + catch (e) { exceptionCaught = true; } @@ -335,8 +316,8 @@ describe("Tests exception handling ", function () { } expect(exceptionCaught).toBe(true); expect(errMsg).toContain("Cannot compile /data/data/com.tns.testapplication/files/app/tests/syntaxErrors.js"); - expect(errMsg).toContain("SyntaxError: Unexpected token ="); - expect(errMsg).toContain("File: \"file:///data/data/com.tns.testapplication/files/app/tests/syntaxErrors.js, line: 3, column: 10"); + expect(errMsg).toContain("SyntaxError: Unexpected token class"); + expect(errMsg).toContain("File: \"file:///data/data/com.tns.testapplication/files/app/tests/syntaxErrors.js, line: 3, column: 4"); }); // run this test only for API level bigger than 25 as we have handling there diff --git a/test-app/runtime/src/main/cpp/ArgConverter.cpp b/test-app/runtime/src/main/cpp/ArgConverter.cpp index 3c12f5e97..168d3f068 100644 --- a/test-app/runtime/src/main/cpp/ArgConverter.cpp +++ b/test-app/runtime/src/main/cpp/ArgConverter.cpp @@ -216,7 +216,7 @@ int64_t ArgConverter::ConvertToJavaLong(Isolate* isolate, const Local& va assert(!valueProp.IsEmpty()); - string num = ConvertToString(valueProp->ToString()); + string num = ConvertToString(valueProp->ToString(isolate)); int64_t longValue = atoll(num.c_str()); @@ -241,7 +241,8 @@ string ArgConverter::ConvertToString(const v8::Local& s) { if (s.IsEmpty()) { return string(); } else { - String::Utf8Value str(s); + auto isolate = v8::Isolate::GetCurrent(); + String::Utf8Value str(isolate, s); return string(*str); } } @@ -259,7 +260,8 @@ u16string ArgConverter::ConvertToUtf16String(const v8::Local& s) { jstring ArgConverter::ConvertToJavaString(const Local& value) { JEnv env; - String::Value stringValue(value); + auto isolate = v8::Isolate::GetCurrent(); + String::Value stringValue(isolate, value); return env.NewString((const jchar*) *stringValue, stringValue.length()); } @@ -276,18 +278,8 @@ Local ArgConverter::ConvertToV8String(Isolate* isolate, const char* data return String::NewFromUtf8(isolate, (const char*) data, String::kNormalString, length); } -Local ArgConverter::ConvertToV8UTF16String(Isolate* isolate, const string& string) { - auto utf16str = Util::ConvertFromUtf8ToUtf16(string); - - return ConvertToV8UTF16String(isolate, utf16str); -} - Local ArgConverter::ConvertToV8UTF16String(Isolate* isolate, const u16string& utf16string) { return String::NewFromTwoByte(isolate, ((const uint16_t*) utf16string.data())); } -Local ArgConverter::ConvertToV8UTF16String(v8::Isolate* isolate, const uint16_t* utf16string, int size) { - return String::NewFromTwoByte(isolate, utf16string, NewStringType::kNormal, size).ToLocalChecked(); -} - std::map ArgConverter::s_type_long_operations_cache; \ No newline at end of file diff --git a/test-app/runtime/src/main/cpp/ArgConverter.h b/test-app/runtime/src/main/cpp/ArgConverter.h index a7d439296..6ebbf2a6a 100644 --- a/test-app/runtime/src/main/cpp/ArgConverter.h +++ b/test-app/runtime/src/main/cpp/ArgConverter.h @@ -40,10 +40,6 @@ class ArgConverter { static v8::Local ConvertToV8String(v8::Isolate* isolate, const char* data, int length); - static v8::Local ConvertToV8UTF16String(v8::Isolate* isolate, const std::string& string); - - static v8::Local ConvertToV8UTF16String(v8::Isolate* isolate, const uint16_t* utf16string, int size); - static v8::Local ConvertToV8UTF16String(v8::Isolate* isolate, const std::u16string& utf16string); private: diff --git a/test-app/runtime/src/main/cpp/ArrayElementAccessor.cpp b/test-app/runtime/src/main/cpp/ArrayElementAccessor.cpp index a81957a53..221a29c51 100644 --- a/test-app/runtime/src/main/cpp/ArrayElementAccessor.cpp +++ b/test-app/runtime/src/main/cpp/ArrayElementAccessor.cpp @@ -83,6 +83,7 @@ void ArrayElementAccessor::SetArrayElement(Isolate* isolate, const Local HandleScope handleScope(isolate); auto runtime = Runtime::GetRuntime(isolate); auto objectManager = runtime->GetObjectManager(); + auto context = isolate->GetCurrentContext(); auto arr = objectManager->GetJavaObjectByJsObject(array); @@ -90,15 +91,15 @@ void ArrayElementAccessor::SetArrayElement(Isolate* isolate, const Local jboolean isCopy = false; if (elementSignature == "Z") { //bool - jboolean boolElementValue = (jboolean) value->BooleanValue(); + jboolean boolElementValue = (jboolean) value->BooleanValue(context).ToChecked(); jbooleanArray boolArr = static_cast(arr); env.SetBooleanArrayRegion(boolArr, index, 1, &boolElementValue); } else if (elementSignature == "B") { //byte - jbyte byteElementValue = (jbyte) value->Int32Value(); + jbyte byteElementValue = (jbyte) value->Int32Value(context).ToChecked(); jbyteArray byteArr = static_cast(arr); env.SetByteArrayRegion(byteArr, index, 1, &byteElementValue); } else if (elementSignature == "C") { //char - String::Utf8Value utf8(value->ToString()); + String::Utf8Value utf8(isolate, value->ToString(isolate)); JniLocalRef s(env.NewString((jchar*) *utf8, 1)); const char* singleChar = env.GetStringUTFChars(s, &isCopy); jchar charElementValue = *singleChar; @@ -106,11 +107,11 @@ void ArrayElementAccessor::SetArrayElement(Isolate* isolate, const Local jcharArray charArr = static_cast(arr); env.SetCharArrayRegion(charArr, index, 1, &charElementValue); } else if (elementSignature == "S") { //short - jshort shortElementValue = (jshort) value->Int32Value(); + jshort shortElementValue = (jshort) value->Int32Value(context).ToChecked(); jshortArray shortArr = static_cast(arr); env.SetShortArrayRegion(shortArr, index, 1, &shortElementValue); } else if (elementSignature == "I") { //int - jint intElementValue = value->Int32Value(); + jint intElementValue = value->Int32Value(context).ToChecked(); jintArray intArr = static_cast(arr); env.SetIntArrayRegion(intArr, index, 1, &intElementValue); } else if (elementSignature == "J") { //long @@ -118,16 +119,16 @@ void ArrayElementAccessor::SetArrayElement(Isolate* isolate, const Local if (value->IsObject()) { longElementValue = (jlong) ArgConverter::ConvertToJavaLong(isolate, value); } else { - longElementValue = (jlong) value->IntegerValue(); + longElementValue = (jlong) value->IntegerValue(context).ToChecked(); } jlongArray longArr = static_cast(arr); env.SetLongArrayRegion(longArr, index, 1, &longElementValue); } else if (elementSignature == "F") { //float - jfloat floatElementValue = (jfloat) value->NumberValue(); + jfloat floatElementValue = (jfloat) value->NumberValue(context).ToChecked(); jfloatArray floatArr = static_cast(arr); env.SetFloatArrayRegion(floatArr, index, 1, &floatElementValue); } else if (elementSignature == "D") { //double - jdouble doubleElementValue = (jdouble) value->NumberValue(); + jdouble doubleElementValue = (jdouble) value->NumberValue(context).ToChecked(); jdoubleArray doubleArr = static_cast(arr); env.SetDoubleArrayRegion(doubleArr, index, 1, &doubleElementValue); } else { //string or object diff --git a/test-app/runtime/src/main/cpp/CallbackHandlers.cpp b/test-app/runtime/src/main/cpp/CallbackHandlers.cpp index f1fbb6ffc..dcd0c0ff4 100644 --- a/test-app/runtime/src/main/cpp/CallbackHandlers.cpp +++ b/test-app/runtime/src/main/cpp/CallbackHandlers.cpp @@ -559,6 +559,7 @@ CallbackHandlers::GetImplementedInterfaces(JEnv &env, const Local &imple vector interfacesToImplement; auto propNames = implementationObject->GetOwnPropertyNames(); + auto isolate = implementationObject->GetIsolate(); for (int i = 0; i < propNames->Length(); i++) { auto name = propNames->Get(i).As(); auto prop = implementationObject->Get(name); @@ -566,14 +567,13 @@ CallbackHandlers::GetImplementedInterfaces(JEnv &env, const Local &imple bool arrFound = !prop.IsEmpty() && prop->IsArray(); if (arrFound) { - v8::String::Utf8Value propName(name); + v8::String::Utf8Value propName(isolate, name); std::string arrNameC = std::string(*propName); if (arrNameC == "interfaces") { - auto interfacesArr = prop->ToObject(); + auto interfacesArr = prop->ToObject(isolate); - auto isolate = implementationObject->GetIsolate(); - int length = interfacesArr->Get( - v8::String::NewFromUtf8(isolate, "length"))->ToObject()->Uint32Value(); + auto context = isolate->GetCurrentContext(); + int length = interfacesArr->Get(v8::String::NewFromUtf8(isolate, "length"))->ToObject(isolate)->Uint32Value(context).ToChecked(); if (length > 0) { for (int i = 0; i < length; i++) { @@ -615,6 +615,7 @@ CallbackHandlers::GetMethodOverrides(JEnv &env, const Local &implementat vector methodNames; auto propNames = implementationObject->GetOwnPropertyNames(); + auto isolate = implementationObject->GetIsolate(); for (int i = 0; i < propNames->Length(); i++) { auto name = propNames->Get(i).As(); auto method = implementationObject->Get(name); @@ -622,7 +623,7 @@ CallbackHandlers::GetMethodOverrides(JEnv &env, const Local &implementat bool methodFound = !method.IsEmpty() && method->IsFunction(); if (methodFound) { - String::Utf8Value stringValue(name); + String::Utf8Value stringValue(isolate, name); jstring value = env.NewStringUTF(*stringValue); methodNames.push_back(value); } @@ -645,7 +646,8 @@ CallbackHandlers::GetMethodOverrides(JEnv &env, const Local &implementat void CallbackHandlers::LogMethodCallback(const v8::FunctionCallbackInfo &args) { try { if ((args.Length() > 0) && args[0]->IsString()) { - String::Utf8Value message(args[0]->ToString()); + auto isolate = args.GetIsolate(); + String::Utf8Value message(isolate, args[0]->ToString(isolate)); DEBUG_WRITE("%s", *message); } } catch (NativeScriptException &e) { @@ -885,11 +887,8 @@ void CallbackHandlers::NewThreadCallback(const v8::FunctionCallbackInfoGetIsolate(); - auto currentExecutingScriptName = StackTrace::CurrentStackTrace(isolate, 1, - StackTrace::kScriptName)->GetFrame( - 0)->GetScriptName(); - auto currentExecutingScriptNameStr = ArgConverter::ConvertToString( - currentExecutingScriptName); + auto currentExecutingScriptName = StackTrace::CurrentStackTrace(isolate, 1, StackTrace::kScriptName)->GetFrame(isolate, 0)->GetScriptName(); + auto currentExecutingScriptNameStr = ArgConverter::ConvertToString(currentExecutingScriptName); auto lastForwardSlash = currentExecutingScriptNameStr.find_last_of("/"); auto currentDir = currentExecutingScriptNameStr.substr(0, lastForwardSlash + 1); string fileSchema("file://"); @@ -952,9 +951,10 @@ CallbackHandlers::WorkerObjectPostMessageCallback(const v8::FunctionCallbackInfo ArgConverter::ConvertToV8String(isolate, "workerId"), jsId); - Local msg = tns::JsonStringifyObject(isolate, args[0])->ToString(); + Local msg = tns::JsonStringifyObject(isolate, args[0])->ToString(isolate); + auto context = isolate->GetCurrentContext(); // get worker's ID that is associated on the other side - in Java - auto id = jsId->Int32Value(); + auto id = jsId->Int32Value(context).ToChecked(); JEnv env; auto mId = env.GetStaticMethodID(RUNTIME_CLASS, "sendMessageFromMainToWorker", @@ -1049,7 +1049,7 @@ CallbackHandlers::WorkerGlobalPostMessageCallback(const v8::FunctionCallbackInfo return; } - Local msg = tns::JsonStringifyObject(isolate, args[0])->ToString(); + Local msg = tns::JsonStringifyObject(isolate, args[0])->ToString(isolate); JEnv env; auto mId = env.GetStaticMethodID(RUNTIME_CLASS, "sendMessageFromWorkerToMain", @@ -1145,6 +1145,7 @@ CallbackHandlers::WorkerObjectTerminateCallback(const v8::FunctionCallbackInfoGetCurrentContext(); Local jsId; @@ -1153,13 +1154,13 @@ CallbackHandlers::WorkerObjectTerminateCallback(const v8::FunctionCallbackInfoInt32Value(); + auto id = jsId->Int32Value(context).ToChecked(); Local isTerminated; V8GetPrivateValue(isolate, thiz, ArgConverter::ConvertToV8String(isolate, "isTerminated"), isTerminated); - if (!isTerminated.IsEmpty() && isTerminated->BooleanValue()) { + if (!isTerminated.IsEmpty() && isTerminated->BooleanValue(context).ToChecked()) { DEBUG_WRITE( "Main: WorkerObjectTerminateCallback - Worker(id=%d)'s terminate has already been called.", id); @@ -1204,7 +1205,7 @@ void CallbackHandlers::WorkerGlobalCloseCallback(const v8::FunctionCallbackInfo< auto isTerminating = globalObject->Get( ArgConverter::ConvertToV8String(isolate, "isTerminating")); - if (!isTerminating.IsEmpty() && isTerminating->BooleanValue()) { + if (!isTerminating.IsEmpty() && isTerminating->BooleanValue(context).ToChecked()) { DEBUG_WRITE("WORKER: WorkerThreadCloseCallback - Worker is currently terminating..."); return; } @@ -1273,7 +1274,7 @@ void CallbackHandlers::CallWorkerScopeOnErrorHandle(Isolate *isolate, TryCatch & auto result = func->Call(Undefined(isolate), 1, args1); // return 'true'-like value, don't bubble up to main Worker.onerror - if (!result.IsEmpty() && result->BooleanValue()) { + if (!result.IsEmpty() && result->BooleanValue(context).ToChecked()) { // Do nothing, exception has been handled return; } @@ -1281,7 +1282,7 @@ void CallbackHandlers::CallWorkerScopeOnErrorHandle(Isolate *isolate, TryCatch & // will account for exceptions thrown inside the error handler if (innerTc.HasCaught()) { - auto lno = innerTc.Message()->GetLineNumber(); + auto lno = innerTc.Message()->GetLineNumber(context).ToChecked(); auto msg = innerTc.Message()->Get(); Local outStackTrace = innerTc.StackTrace(context).FromMaybe(Local()); Local stackTrace; @@ -1295,7 +1296,7 @@ void CallbackHandlers::CallWorkerScopeOnErrorHandle(Isolate *isolate, TryCatch & } // throw so that it may bubble up to main - auto lno = tc.Message()->GetLineNumber(); + auto lno = tc.Message()->GetLineNumber(context).ToChecked(); auto msg = tc.Message()->Get(); auto source = tc.Message()->GetScriptResourceName()->ToString(isolate); Local outStackTrace = tc.StackTrace(context).FromMaybe(Local()); @@ -1367,7 +1368,8 @@ CallbackHandlers::CallWorkerObjectOnErrorHandle(Isolate *isolate, jint workerId, // Handle exceptions thrown in onmessage with the worker.onerror handler, if present auto result = func->Call(Undefined(isolate), 1, args1); - if (!result.IsEmpty() && result->BooleanValue()) { + auto context = isolate->GetCurrentContext(); + if (!result.IsEmpty() && result->BooleanValue(context).ToChecked()) { // Do nothing, exception is handled and does not need to be raised to application level return; } diff --git a/test-app/runtime/src/main/cpp/DOMDomainCallbackHandlers.cpp b/test-app/runtime/src/main/cpp/DOMDomainCallbackHandlers.cpp index ec075f30c..f73e2789d 100644 --- a/test-app/runtime/src/main/cpp/DOMDomainCallbackHandlers.cpp +++ b/test-app/runtime/src/main/cpp/DOMDomainCallbackHandlers.cpp @@ -54,7 +54,8 @@ void DOMDomainCallbackHandlers::ChildNodeInsertedCallback(const v8::FunctionCall return; } - domAgentInstance->m_frontend.childNodeInserted(parentId->Int32Value(), lastId->Int32Value(), std::move(domNode)); + auto context = isolate->GetCurrentContext(); + domAgentInstance->m_frontend.childNodeInserted(parentId->Int32Value(context).ToChecked(), lastId->Int32Value(context).ToChecked(), std::move(domNode)); } catch (NativeScriptException& e) { e.ReThrowToV8(); } catch (std::exception e) { @@ -87,7 +88,8 @@ void DOMDomainCallbackHandlers::ChildNodeRemovedCallback(const v8::FunctionCallb auto parentId = args[0]->ToNumber(isolate); auto nodeId = args[1]->ToNumber(isolate); - domAgentInstance->m_frontend.childNodeRemoved(parentId->Int32Value(), nodeId->Int32Value()); + auto context = isolate->GetCurrentContext(); + domAgentInstance->m_frontend.childNodeRemoved(parentId->Int32Value(context).ToChecked(), nodeId->Int32Value(context).ToChecked()); } catch (NativeScriptException& e) { e.ReThrowToV8(); } catch (std::exception e) { @@ -118,12 +120,13 @@ void DOMDomainCallbackHandlers::AttributeModifiedCallback(const v8::FunctionCall } auto nodeId = args[0]->ToNumber(isolate); - auto attributeName = args[1]->ToString(); - auto attributeValue = args[2]->ToString(); + auto attributeName = args[1]->ToString(isolate); + auto attributeValue = args[2]->ToString(isolate); - domAgentInstance->m_frontend.attributeModified(nodeId->Int32Value(), - v8_inspector::toProtocolString(attributeName), - v8_inspector::toProtocolString(attributeValue)); + auto context = isolate->GetCurrentContext(); + domAgentInstance->m_frontend.attributeModified(nodeId->Int32Value(context).ToChecked(), + v8_inspector::toProtocolString(isolate, attributeName), + v8_inspector::toProtocolString(isolate, attributeValue)); } catch (NativeScriptException& e) { e.ReThrowToV8(); } catch (std::exception e) { @@ -153,10 +156,11 @@ void DOMDomainCallbackHandlers::AttributeRemovedCallback(const v8::FunctionCallb } auto nodeId = args[0]->ToNumber(isolate); - auto attributeName = args[1]->ToString(); + auto attributeName = args[1]->ToString(isolate); - domAgentInstance->m_frontend.attributeRemoved(nodeId->Int32Value(), - v8_inspector::toProtocolString(attributeName)); + auto context = isolate->GetCurrentContext(); + domAgentInstance->m_frontend.attributeRemoved(nodeId->Int32Value(context).ToChecked(), + v8_inspector::toProtocolString(isolate, attributeName)); } catch (NativeScriptException& e) { e.ReThrowToV8(); } catch (std::exception e) { diff --git a/test-app/runtime/src/main/cpp/FieldAccessor.cpp b/test-app/runtime/src/main/cpp/FieldAccessor.cpp index 1757ece8e..fb9777d46 100644 --- a/test-app/runtime/src/main/cpp/FieldAccessor.cpp +++ b/test-app/runtime/src/main/cpp/FieldAccessor.cpp @@ -234,28 +234,29 @@ void FieldAccessor::SetJavaField(Isolate* isolate, const Local& target, auto clazz = fieldData->clazz; if (isPrimitiveType) { + auto context = isolate->GetCurrentContext(); switch (fieldTypeName[0]) { case 'Z': { //bool //TODO: validate value is a boolean before calling if (isStatic) { - env.SetStaticBooleanField(clazz, fieldId, value->BooleanValue()); + env.SetStaticBooleanField(clazz, fieldId, value->BooleanValue(context).ToChecked()); } else { - env.SetBooleanField(targetJavaObject, fieldId, value->BooleanValue()); + env.SetBooleanField(targetJavaObject, fieldId, value->BooleanValue(context).ToChecked()); } break; } case 'B': { //byte //TODO: validate value is a byte before calling if (isStatic) { - env.SetStaticByteField(clazz, fieldId, value->Int32Value()); + env.SetStaticByteField(clazz, fieldId, value->Int32Value(context).ToChecked()); } else { - env.SetByteField(targetJavaObject, fieldId, value->Int32Value()); + env.SetByteField(targetJavaObject, fieldId, value->Int32Value(context).ToChecked()); } break; } case 'C': { //char //TODO: validate value is a single char - String::Utf8Value stringValue(value->ToString()); + String::Utf8Value stringValue(isolate, value->ToString(isolate)); JniLocalRef strValue(env.NewStringUTF(*stringValue)); const char* chars = env.GetStringUTFChars(strValue, 0); @@ -270,18 +271,18 @@ void FieldAccessor::SetJavaField(Isolate* isolate, const Local& target, case 'S': { //short //TODO: validate value is a short before calling if (isStatic) { - env.SetStaticShortField(clazz, fieldId, value->Int32Value()); + env.SetStaticShortField(clazz, fieldId, value->Int32Value(context).ToChecked()); } else { - env.SetShortField(targetJavaObject, fieldId, value->Int32Value()); + env.SetShortField(targetJavaObject, fieldId, value->Int32Value(context).ToChecked()); } break; } case 'I': { //int //TODO: validate value is a int before calling if (isStatic) { - env.SetStaticIntField(clazz, fieldId, value->Int32Value()); + env.SetStaticIntField(clazz, fieldId, value->Int32Value(context).ToChecked()); } else { - env.SetIntField(targetJavaObject, fieldId, value->Int32Value()); + env.SetIntField(targetJavaObject, fieldId, value->Int32Value(context).ToChecked()); } break; @@ -297,17 +298,17 @@ void FieldAccessor::SetJavaField(Isolate* isolate, const Local& target, } case 'F': { //float if (isStatic) { - env.SetStaticFloatField(clazz, fieldId, static_cast(value->NumberValue())); + env.SetStaticFloatField(clazz, fieldId, static_cast(value->NumberValue(context).ToChecked())); } else { - env.SetFloatField(targetJavaObject, fieldId, static_cast(value->NumberValue())); + env.SetFloatField(targetJavaObject, fieldId, static_cast(value->NumberValue(context).ToChecked())); } break; } case 'D': { //double if (isStatic) { - env.SetStaticDoubleField(clazz, fieldId, value->NumberValue()); + env.SetStaticDoubleField(clazz, fieldId, value->NumberValue(context).ToChecked()); } else { - env.SetDoubleField(targetJavaObject, fieldId, value->NumberValue()); + env.SetDoubleField(targetJavaObject, fieldId, value->NumberValue(context).ToChecked()); } break; } @@ -326,7 +327,7 @@ void FieldAccessor::SetJavaField(Isolate* isolate, const Local& target, //TODO: validate valie is a string; result = ArgConverter::ConvertToJavaString(value); } else { - auto objectWithHiddenID = value->ToObject(); + auto objectWithHiddenID = value->ToObject(isolate); result = objectManager->GetJavaObjectByJsObject(objectWithHiddenID); } } diff --git a/test-app/runtime/src/main/cpp/JsArgConverter.cpp b/test-app/runtime/src/main/cpp/JsArgConverter.cpp index 56fed5803..5a64a7cc3 100644 --- a/test-app/runtime/src/main/cpp/JsArgConverter.cpp +++ b/test-app/runtime/src/main/cpp/JsArgConverter.cpp @@ -98,7 +98,7 @@ bool JsArgConverter::ConvertArg(const Local& arg, int index) { sprintf(buff, "Cannot convert string to %s at index %d", typeSignature.c_str(), index); } } else if (arg->IsObject()) { - auto jsObject = arg->ToObject(); + auto jsObject = arg->ToObject(m_isolate); auto castType = NumericCasts::GetCastType(m_isolate, jsObject); @@ -107,12 +107,13 @@ bool JsArgConverter::ConvertArg(const Local& arg, int index) { auto runtime = Runtime::GetRuntime(m_isolate); auto objectManager = runtime->GetObjectManager(); + auto context = m_isolate->GetCurrentContext(); switch (castType) { case CastType::Char: castValue = NumericCasts::GetCastValue(jsObject); if (castValue->IsString()) { - string value = ArgConverter::ConvertToString(castValue->ToString()); + string value = ArgConverter::ConvertToString(castValue->ToString(m_isolate)); m_args[index].c = (jchar) value[0]; success = true; } @@ -121,12 +122,12 @@ bool JsArgConverter::ConvertArg(const Local& arg, int index) { case CastType::Byte: castValue = NumericCasts::GetCastValue(jsObject); if (castValue->IsString()) { - string strValue = ArgConverter::ConvertToString(castValue->ToString()); + string strValue = ArgConverter::ConvertToString(castValue->ToString(m_isolate)); int byteArg = atoi(strValue.c_str()); jbyte value = (jbyte) byteArg; success = ConvertFromCastFunctionObject(value, index); } else if (castValue->IsInt32()) { - jbyte value = (jbyte) castValue->ToInt32(m_isolate)->Int32Value(); + jbyte value = (jbyte) castValue->ToInt32(m_isolate)->Int32Value(context).ToChecked(); success = ConvertFromCastFunctionObject(value, index); } break; @@ -134,12 +135,12 @@ bool JsArgConverter::ConvertArg(const Local& arg, int index) { case CastType::Short: castValue = NumericCasts::GetCastValue(jsObject); if (castValue->IsString()) { - string strValue = ArgConverter::ConvertToString(castValue->ToString()); + string strValue = ArgConverter::ConvertToString(castValue->ToString(m_isolate)); int shortArg = atoi(strValue.c_str()); jshort value = (jshort) shortArg; success = ConvertFromCastFunctionObject(value, index); } else if (castValue->IsInt32()) { - jshort value = (jshort) castValue->ToInt32(m_isolate)->Int32Value(); + jshort value = (jshort) castValue->ToInt32(m_isolate)->Int32Value(context).ToChecked(); success = ConvertFromCastFunctionObject(value, index); } break; @@ -147,12 +148,12 @@ bool JsArgConverter::ConvertArg(const Local& arg, int index) { case CastType::Long: castValue = NumericCasts::GetCastValue(jsObject); if (castValue->IsString()) { - string strValue = ArgConverter::ConvertToString(castValue->ToString()); + string strValue = ArgConverter::ConvertToString(castValue->ToString(m_isolate)); int64_t longArg = atoll(strValue.c_str()); jlong value = (jlong) longArg; success = ConvertFromCastFunctionObject(value, index); } else if (castValue->IsInt32()) { - jlong value = (jlong) castValue->ToInt32(m_isolate)->IntegerValue(); + jlong value = (jlong) castValue->ToInt32(m_isolate)->IntegerValue(context).ToChecked(); success = ConvertFromCastFunctionObject(value, index); } break; @@ -160,7 +161,7 @@ bool JsArgConverter::ConvertArg(const Local& arg, int index) { case CastType::Float: castValue = NumericCasts::GetCastValue(jsObject); if (castValue->IsNumber()) { - double floatArg = castValue->ToNumber(m_isolate)->NumberValue(); + double floatArg = castValue->ToNumber(m_isolate)->NumberValue(context).ToChecked(); jfloat value = (jfloat) floatArg; success = ConvertFromCastFunctionObject(value, index); } @@ -169,7 +170,7 @@ bool JsArgConverter::ConvertArg(const Local& arg, int index) { case CastType::Double: castValue = NumericCasts::GetCastValue(jsObject); if (castValue->IsNumber()) { - double doubleArg = castValue->ToNumber(m_isolate)->NumberValue(); + double doubleArg = castValue->ToNumber(m_isolate)->NumberValue(context).ToChecked(); jdouble value = (jdouble) doubleArg; success = ConvertFromCastFunctionObject(value, index); } @@ -230,20 +231,21 @@ bool JsArgConverter::ConvertJavaScriptNumber(const Local& jsValue, int in }; const auto& typeSignature = m_tokens.at(index); + auto context = m_isolate->GetCurrentContext(); const char typePrefix = typeSignature[0]; switch (typePrefix) { case 'B': // byte - value.b = (jbyte) jsValue->Int32Value(); + value.b = (jbyte) jsValue->Int32Value(context).ToChecked(); break; case 'S': // short - value.s = (jshort) jsValue->Int32Value(); + value.s = (jshort) jsValue->Int32Value(context).ToChecked(); break; case 'I': // int - value.i = (jint) jsValue->Int32Value(); + value.i = (jint) jsValue->Int32Value(context).ToChecked(); break; case 'J': // long @@ -252,16 +254,16 @@ bool JsArgConverter::ConvertJavaScriptNumber(const Local& jsValue, int in auto numObj = Local::Cast(jsValue); value.j = (jlong) numObj->ValueOf(); } else { - value.j = (jlong) jsValue->IntegerValue(); + value.j = (jlong) jsValue->IntegerValue(context).ToChecked(); } break; case 'F': // float - value.f = (jfloat) jsValue->NumberValue(); + value.f = (jfloat) jsValue->NumberValue(context).ToChecked(); break; case 'D': // double - value.d = (jdouble) jsValue->NumberValue(); + value.d = (jdouble) jsValue->NumberValue(context).ToChecked(); break; default: @@ -280,16 +282,17 @@ bool JsArgConverter::ConvertJavaScriptBoolean(const Local& jsValue, int i bool success; const auto& typeSignature = m_tokens.at(index); + auto context = m_isolate->GetCurrentContext(); if (typeSignature == "Z") { bool argValue; if (jsValue->IsBoolean()) { - argValue = jsValue->BooleanValue(); + argValue = jsValue->BooleanValue(context).ToChecked(); } else { auto boolObj = Local::Cast(jsValue); auto val = boolObj->Get(V8StringConstants::GetValueOf(m_isolate)); if (!val.IsEmpty() && val->IsFunction()) { - argValue = val.As()->Call(boolObj, 0, nullptr)->BooleanValue(); + argValue = val.As()->Call(boolObj, 0, nullptr)->BooleanValue(context).ToChecked(); } else { argValue = false; } @@ -320,6 +323,7 @@ bool JsArgConverter::ConvertJavaScriptArray(const Local& jsArr, int index jsize arrLength = jsArr->Length(); const auto& arraySignature = m_tokens.at(index); + auto context = m_isolate->GetCurrentContext(); string elementType = arraySignature.substr(1); @@ -332,21 +336,21 @@ bool JsArgConverter::ConvertJavaScriptArray(const Local& jsArr, int index case 'Z': arr = m_env.NewBooleanArray(arrLength); for (jsize i = 0; i < arrLength; i++) { - jboolean value = jsArr->Get(i)->BooleanValue(); + jboolean value = jsArr->Get(i)->BooleanValue(context).ToChecked(); m_env.SetBooleanArrayRegion((jbooleanArray) arr, i, 1, &value); } break; case 'B': arr = m_env.NewByteArray(arrLength); for (jsize i = 0; i < arrLength; i++) { - jbyte value = jsArr->Get(i)->Int32Value(); + jbyte value = jsArr->Get(i)->Int32Value(context).ToChecked(); m_env.SetByteArrayRegion((jbyteArray) arr, i, 1, &value); } break; case 'C': arr = m_env.NewCharArray(arrLength); for (jsize i = 0; i < arrLength; i++) { - String::Utf8Value utf8(jsArr->Get(i)->ToString()); + String::Utf8Value utf8(m_isolate, jsArr->Get(i)->ToString(m_isolate)); JniLocalRef s(m_env.NewString((jchar*) *utf8, 1)); const char* singleChar = m_env.GetStringUTFChars(s, nullptr); jchar value = *singleChar; @@ -357,35 +361,35 @@ bool JsArgConverter::ConvertJavaScriptArray(const Local& jsArr, int index case 'S': arr = m_env.NewShortArray(arrLength); for (jsize i = 0; i < arrLength; i++) { - jshort value = jsArr->Get(i)->Int32Value(); + jshort value = jsArr->Get(i)->Int32Value(context).ToChecked(); m_env.SetShortArrayRegion((jshortArray) arr, i, 1, &value); } break; case 'I': arr = m_env.NewIntArray(arrLength); for (jsize i = 0; i < arrLength; i++) { - jint value = jsArr->Get(i)->Int32Value(); + jint value = jsArr->Get(i)->Int32Value(context).ToChecked(); m_env.SetIntArrayRegion((jintArray) arr, i, 1, &value); } break; case 'J': arr = m_env.NewLongArray(arrLength); for (jsize i = 0; i < arrLength; i++) { - jlong value = jsArr->Get(i)->NumberValue(); + jlong value = jsArr->Get(i)->NumberValue(context).ToChecked(); m_env.SetLongArrayRegion((jlongArray) arr, i, 1, &value); } break; case 'F': arr = m_env.NewFloatArray(arrLength); for (jsize i = 0; i < arrLength; i++) { - jfloat value = jsArr->Get(i)->NumberValue(); + jfloat value = jsArr->Get(i)->NumberValue(context).ToChecked(); m_env.SetFloatArrayRegion((jfloatArray) arr, i, 1, &value); } break; case 'D': arr = m_env.NewDoubleArray(arrLength); for (jsize i = 0; i < arrLength; i++) { - jdouble value = jsArr->Get(i)->NumberValue(); + jdouble value = jsArr->Get(i)->NumberValue(context).ToChecked(); m_env.SetDoubleArrayRegion((jdoubleArray) arr, i, 1, &value); } break; diff --git a/test-app/runtime/src/main/cpp/JsArgToArrayConverter.cpp b/test-app/runtime/src/main/cpp/JsArgToArrayConverter.cpp index 866e724e2..e37ee67dc 100644 --- a/test-app/runtime/src/main/cpp/JsArgToArrayConverter.cpp +++ b/test-app/runtime/src/main/cpp/JsArgToArrayConverter.cpp @@ -59,18 +59,19 @@ bool JsArgToArrayConverter::ConvertArg(const Local& arg, int index) { JEnv env; Type returnType = JType::getClassType(m_return_type); + auto context = m_isolate->GetCurrentContext(); if (arg.IsEmpty()) { s << "Cannot convert empty JavaScript object"; success = false; } else if (arg->IsInt32() && (returnType == Type::Int || returnType == Type::Null)) { - jint value = arg->Int32Value(); + jint value = arg->Int32Value(context).ToChecked(); auto javaObject = JType::NewInt(env, value); SetConvertedObject(env, index, javaObject); success = true; } else if (arg->IsNumber() || arg->IsNumberObject()) { - double d = arg->NumberValue(); + double d = arg->NumberValue(context).ToChecked(); int64_t i = (int64_t) d; //if returnType isNumber and this check is true, the number we'll try to convert is whole(integer) @@ -109,13 +110,13 @@ bool JsArgToArrayConverter::ConvertArg(const Local& arg, int index) { success = true; } } else if (arg->IsBoolean()) { - jboolean value = arg->BooleanValue(); + jboolean value = arg->BooleanValue(context).ToChecked(); auto javaObject = JType::NewBoolean(env, value); SetConvertedObject(env, index, javaObject); success = true; } else if (arg->IsBooleanObject()) { auto boolObj = Local::Cast(arg); - jboolean value = boolObj->BooleanValue() ? JNI_TRUE : JNI_FALSE; + jboolean value = boolObj->BooleanValue(context).ToChecked() ? JNI_TRUE : JNI_FALSE; auto javaObject = JType::NewBoolean(env, value); SetConvertedObject(env, index, javaObject); @@ -126,7 +127,7 @@ bool JsArgToArrayConverter::ConvertArg(const Local& arg, int index) { success = true; } else if (arg->IsObject()) { - auto jsObj = arg->ToObject(); + auto jsObj = arg->ToObject(m_isolate); auto castType = NumericCasts::GetCastType(m_isolate, jsObj); @@ -148,7 +149,7 @@ bool JsArgToArrayConverter::ConvertArg(const Local& arg, int index) { castValue = NumericCasts::GetCastValue(jsObj); charValue = '\0'; if (castValue->IsString()) { - string str = ArgConverter::ConvertToString(castValue->ToString()); + string str = ArgConverter::ConvertToString(castValue->ToString(m_isolate)); charValue = (jchar) str[0]; } javaObject = JType::NewChar(env, charValue); @@ -160,11 +161,11 @@ bool JsArgToArrayConverter::ConvertArg(const Local& arg, int index) { castValue = NumericCasts::GetCastValue(jsObj); byteValue = 0; if (castValue->IsString()) { - string value = ArgConverter::ConvertToString(castValue->ToString()); + string value = ArgConverter::ConvertToString(castValue->ToString(m_isolate)); int byteArg = atoi(value.c_str()); byteValue = (jbyte) byteArg; } else if (castValue->IsInt32()) { - int byteArg = castValue->ToInt32(m_isolate)->Int32Value(); + int byteArg = castValue->ToInt32(m_isolate)->Int32Value(context).ToChecked(); byteValue = (jbyte) byteArg; } javaObject = JType::NewByte(env, byteValue); @@ -176,11 +177,11 @@ bool JsArgToArrayConverter::ConvertArg(const Local& arg, int index) { castValue = NumericCasts::GetCastValue(jsObj); shortValue = 0; if (castValue->IsString()) { - string value = ArgConverter::ConvertToString(castValue->ToString()); + string value = ArgConverter::ConvertToString(castValue->ToString(m_isolate)); int shortArg = atoi(value.c_str()); shortValue = (jshort) shortArg; } else if (castValue->IsInt32()) { - jlong shortArg = castValue->ToInt32(m_isolate)->Int32Value(); + jlong shortArg = castValue->ToInt32(m_isolate)->Int32Value(context).ToChecked(); shortValue = (jshort) shortArg; } javaObject = JType::NewShort(env, shortValue); @@ -192,10 +193,10 @@ bool JsArgToArrayConverter::ConvertArg(const Local& arg, int index) { castValue = NumericCasts::GetCastValue(jsObj); longValue = 0; if (castValue->IsString()) { - auto strValue = ArgConverter::ConvertToString(castValue->ToString()); + auto strValue = ArgConverter::ConvertToString(castValue->ToString(m_isolate)); longValue = atoll(strValue.c_str()); } else if (castValue->IsInt32()) { - longValue = castValue->ToInt32(m_isolate)->Int32Value(); + longValue = castValue->ToInt32(m_isolate)->Int32Value(context).ToChecked(); } javaObject = JType::NewLong(env, longValue); SetConvertedObject(env, index, javaObject); @@ -206,7 +207,7 @@ bool JsArgToArrayConverter::ConvertArg(const Local& arg, int index) { castValue = NumericCasts::GetCastValue(jsObj); floatValue = 0; if (castValue->IsNumber()) { - double floatArg = castValue->ToNumber(m_isolate)->NumberValue(); + double floatArg = castValue->ToNumber(m_isolate)->NumberValue(context).ToChecked(); floatValue = (jfloat) floatArg; } javaObject = JType::NewFloat(env, floatValue); @@ -218,7 +219,7 @@ bool JsArgToArrayConverter::ConvertArg(const Local& arg, int index) { castValue = NumericCasts::GetCastValue(jsObj); doubleValue = 0; if (castValue->IsNumber()) { - double doubleArg = castValue->ToNumber(m_isolate)->NumberValue(); + double doubleArg = castValue->ToNumber(m_isolate)->NumberValue(context).ToChecked(); doubleValue = (jdouble) doubleArg; } javaObject = JType::NewDouble(env, doubleValue); @@ -263,7 +264,7 @@ bool JsArgToArrayConverter::ConvertArg(const Local& arg, int index) { if (success) { SetConvertedObject(env, index, obj.Move(), obj.IsGlobal()); } else { - String::Utf8Value jsObjStr(jsObj); + String::Utf8Value jsObjStr(m_isolate, jsObj); s << "Cannot marshal JavaScript argument " << (*jsObjStr ? *jsObjStr : "") << " at index " << index << " to Java type."; } break; diff --git a/test-app/runtime/src/main/cpp/JsV8InspectorClient.cpp b/test-app/runtime/src/main/cpp/JsV8InspectorClient.cpp index ca5af221a..2be0386a8 100644 --- a/test-app/runtime/src/main/cpp/JsV8InspectorClient.cpp +++ b/test-app/runtime/src/main/cpp/JsV8InspectorClient.cpp @@ -205,12 +205,13 @@ void JsV8InspectorClient::sendToFrontEndCallback(const v8::FunctionCallbackInfo< } try { + auto isolate = args.GetIsolate(); if ((args.Length() > 0) && args[0]->IsString()) { - std::string message = ArgConverter::ConvertToString(args[0]->ToString()); + std::string message = ArgConverter::ConvertToString(args[0]->ToString(isolate)); std::string level = "log"; if (args.Length() > 1 && args[1]->IsString()) { - level = ArgConverter::ConvertToString(args[1]->ToString()); + level = ArgConverter::ConvertToString(args[1]->ToString(isolate)); } JEnv env; @@ -239,7 +240,7 @@ void JsV8InspectorClient::consoleLogCallback(const string& message, const string auto isolate = Runtime::GetRuntime(0)->GetIsolate(); auto stack = v8::StackTrace::CurrentStackTrace(isolate, 1, v8::StackTrace::StackTraceOptions::kDetailed); - auto frame = stack->GetFrame(0); + auto frame = stack->GetFrame(isolate, 0); // will be no-op in non-debuggable builds v8_inspector::V8LogAgentImpl::EntryAdded(message, logLevel, ArgConverter::ConvertToString(frame->GetScriptNameOrSourceURL()), frame->GetLineNumber()); diff --git a/test-app/runtime/src/main/cpp/MetadataNode.cpp b/test-app/runtime/src/main/cpp/MetadataNode.cpp index b29748cb7..d9a245470 100644 --- a/test-app/runtime/src/main/cpp/MetadataNode.cpp +++ b/test-app/runtime/src/main/cpp/MetadataNode.cpp @@ -57,7 +57,7 @@ Local MetadataNode::CreateExtendedJSWrapper(Isolate* isolate, ObjectMana auto extdCtorFunc = Local::New(isolate, *cacheData.extendedCtorFunction); auto context = isolate->GetCurrentContext(); extInstance->SetPrototype(context, extdCtorFunc->Get(V8StringConstants::GetPrototype(isolate))); - extInstance->Set(ConvertToV8String("constructor"), extdCtorFunc); + extInstance->Set(ArgConverter::ConvertToV8String(isolate, "constructor"), extdCtorFunc); SetInstanceMetadata(isolate, extInstance, cacheData.node); } @@ -308,8 +308,8 @@ void MetadataNode::FieldAccessorGetterCallback(Local property, const Prope auto fieldCallbackData = reinterpret_cast(info.Data().As()->Value()); if ((!fieldCallbackData->isStatic && thiz->StrictEquals(info.Holder())) - // check whether there's a declaring type to get the class from it - || (fieldCallbackData->declaringType == "")) { + // check whether there's a declaring type to get the class from it + || (fieldCallbackData->declaringType == "")) { info.GetReturnValue().SetUndefined(); return; } @@ -462,13 +462,13 @@ vector MetadataNode::SetInstanceMethodsFromSt auto funcData = External::New(isolate, callbackData); auto funcTemplate = FunctionTemplate::New(isolate, MethodCallback, funcData); - auto funcName = ConvertToV8String(entry.name); + auto funcName = ArgConverter::ConvertToV8String(isolate, entry.name); if (s_profilerEnabled) { auto func = funcTemplate->GetFunction(); Local wrapperFunc = Wrap(isolate, func, entry.name, origin, false /* isCtorFunc */); Local ctorFunc = ctorFuncTemplate->GetFunction(); - Local protoObject = ctorFunc->Get(ConvertToV8String("prototype")).As(); + Local protoObject = ctorFunc->Get(ArgConverter::ConvertToV8String(isolate, "prototype")).As(); if (!protoObject.IsEmpty() && !protoObject->IsUndefined() && !protoObject->IsNull()) { protoObject->Set(funcName, wrapperFunc); } @@ -516,7 +516,7 @@ void MetadataNode::SetInstanceFieldsFromStaticMetadata(Isolate* isolate, LocaldeclaringType = curType; auto fieldData = External::New(isolate, fieldInfo); @@ -883,7 +883,7 @@ void MetadataNode::InterfaceConstructorCallback(const v8::FunctionCallbackInfoIsObject()) { throw NativeScriptException(string("First argument must be implementation object")); } - implementationObject = info[0]->ToObject(); + implementationObject = info[0]->ToObject(isolate); } else if (info.Length() == 2) { if (!info[0]->IsString()) { throw NativeScriptException(string("First argument must be string")); @@ -892,8 +892,8 @@ void MetadataNode::InterfaceConstructorCallback(const v8::FunctionCallbackInfoToString(); - implementationObject = info[1]->ToObject(); + v8ExtendName = info[0]->ToString(isolate); + implementationObject = info[1]->ToObject(isolate); } else { throw NativeScriptException(string("Invalid number of arguments")); } @@ -1219,6 +1219,7 @@ void MetadataNode::PackageGetterCallback(Local property, const PropertyCal } bool MetadataNode::ValidateExtendArguments(const FunctionCallbackInfo& info, bool extendLocationFound, string& extendLocation, v8::Local& extendName, Local& implementationObject, bool isTypeScriptExtend) { + auto isolate = info.GetIsolate(); if (info.Length() == 1) { if (!extendLocationFound) { @@ -1237,7 +1238,7 @@ bool MetadataNode::ValidateExtendArguments(const FunctionCallbackInfo& in throw NativeScriptException(exceptionMessage); } - implementationObject = info[0]->ToObject(); + implementationObject = info[0]->ToObject(isolate); } else if (info.Length() == 2 || isTypeScriptExtend) { if (!info[0]->IsString()) { stringstream ss; @@ -1256,7 +1257,7 @@ bool MetadataNode::ValidateExtendArguments(const FunctionCallbackInfo& in } DEBUG_WRITE("ExtendsCallMethodHandler: getting extend name"); - extendName = info[0]->ToString(); + extendName = info[0]->ToString(isolate); bool isValidExtendName = IsValidExtendName(extendName); if (!isValidExtendName) { stringstream ss; @@ -1265,7 +1266,7 @@ bool MetadataNode::ValidateExtendArguments(const FunctionCallbackInfo& in throw NativeScriptException(exceptionMessage); } - implementationObject = info[1]->ToObject(); + implementationObject = info[1]->ToObject(isolate); } else { stringstream ss; ss << "Invalid extend() call at location: " << extendLocation.c_str(); @@ -1317,6 +1318,7 @@ void MetadataNode::ExtendMethodCallback(const v8::FunctionCallbackInfoIsString()) { stringstream ss; @@ -1335,7 +1337,8 @@ void MetadataNode::ExtendMethodCallback(const v8::FunctionCallbackInfo()); hasDot = strName.find('.') != string::npos; } else if (info.Length() == 3) { - if (info[2]->IsBoolean() && info[2]->BooleanValue()) { + auto context = isolate->GetCurrentContext(); + if (info[2]->IsBoolean() && info[2]->BooleanValue(context).ToChecked()) { isTypeScriptExtend = true; } } @@ -1344,7 +1347,7 @@ void MetadataNode::ExtendMethodCallback(const v8::FunctionCallbackInfo(); implementationObject = info[1].As(); } else { - auto isValidExtendLocation = GetExtendLocation(extendLocation, isTypeScriptExtend); + auto isValidExtendLocation = GetExtendLocation(isolate, extendLocation, isTypeScriptExtend); auto validArgs = ValidateExtendArguments(info, isValidExtendLocation, extendLocation, extendName, implementationObject, isTypeScriptExtend); if (!validArgs) { @@ -1365,8 +1368,6 @@ void MetadataNode::ExtendMethodCallback(const v8::FunctionCallbackInfo()); } - auto isolate = info.GetIsolate(); - //resolve class (pre-generated or generated runtime from dex generator) uint8_t nodeType = s_metadataReader.GetNodeType(node->m_treeNode); bool isInterface = s_metadataReader.IsNodeTypeInterface(nodeType); @@ -1454,15 +1455,15 @@ bool MetadataNode::IsValidExtendName(const Local& name) { return true; } -bool MetadataNode::GetExtendLocation(string& extendLocation, bool isTypeScriptExtend) { +bool MetadataNode::GetExtendLocation(v8::Isolate* isolate, string& extendLocation, bool isTypeScriptExtend) { stringstream extendLocationStream; auto stackTrace = StackTrace::CurrentStackTrace(Isolate::GetCurrent(), 3, StackTrace::kOverview); if (!stackTrace.IsEmpty()) { Local frame; if (isTypeScriptExtend) { - frame = stackTrace->GetFrame(2); // the _super.apply call to ts_helpers will always be the third call frame + frame = stackTrace->GetFrame(isolate, 2); // the _super.apply call to ts_helpers will always be the third call frame } else { - frame = stackTrace->GetFrame(0); + frame = stackTrace->GetFrame(isolate, 0); } if (!frame.IsEmpty()) { @@ -1646,7 +1647,7 @@ void MetadataNode::CreateTopLevelNamespaces(Isolate* isolate, const LocalCreateWrapper(isolate); string nameSpace = node->m_treeNode->name; // if the namespaces matches a javascript keyword, prefix it with $ to avoid TypeScript and JavaScript errors - if(IsJavascriptKeyword(nameSpace)) { + if (IsJavascriptKeyword(nameSpace)) { nameSpace = "$" + nameSpace; } global->Set(ArgConverter::ConvertToV8String(isolate, nameSpace), packageObj); @@ -1678,7 +1679,7 @@ bool MetadataNode::IsJavascriptKeyword(std::string word) { "double", "else", "enum", "eval", "export", "extends", "false", "final", "finally", "float", "for", "function", "goto", "if", "implements", "import", "in", "instanceof", "int", "interface", "let", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "typeof", "var", "void", "volatile", "while", "with", "yield" - }; + }; keywords = set(kw, kw + sizeof(kw)/sizeof(kw[0])); } @@ -1732,7 +1733,7 @@ Local MetadataNode::Wrap(Isolate* isolate, const Local& func if (!result.IsEmpty()) { ret = result.As(); ret->Set(ArgConverter::ConvertToV8String(isolate, "__func"), function); - ret->SetName(ConvertToV8String(actualName)); + ret->SetName(ArgConverter::ConvertToV8String(isolate, actualName)); auto prototypePropName = V8StringConstants::GetPrototype(isolate); ret->Set(prototypePropName, function->Get(prototypePropName)); @@ -1806,7 +1807,7 @@ void MetadataNode::SetMissingBaseMethods(Isolate* isolate, const vectorSet(funcName, funcTemplate); } @@ -1842,7 +1843,7 @@ void MetadataNode::RegisterSymbolHasInstanceCallback(Isolate* isolate, MetadataE auto hasInstanceFunc = hasInstanceTemplate->GetFunction(); PropertyDescriptor descriptor(hasInstanceFunc, false); auto hasInstanceSymbol = Symbol::GetHasInstance(isolate); - interface->ToObject()->DefineProperty(isolate->GetCurrentContext(), hasInstanceSymbol, descriptor); + interface->ToObject(isolate)->DefineProperty(isolate->GetCurrentContext(), hasInstanceSymbol, descriptor); } void MetadataNode::SymbolHasInstanceCallback(const v8::FunctionCallbackInfo& info) { @@ -1862,7 +1863,7 @@ void MetadataNode::SymbolHasInstanceCallback(const v8::FunctionCallbackInfoGetObjectManager(); - auto obj = objectManager->GetJavaObjectByJsObject(arg->ToObject()); + auto obj = objectManager->GetJavaObjectByJsObject(arg->ToObject(isolate)); if (obj.IsNull()) { // Couldn't find a corresponding java instance counterpart. This could happen diff --git a/test-app/runtime/src/main/cpp/MetadataNode.h b/test-app/runtime/src/main/cpp/MetadataNode.h index 77c36b8a6..c46237ddc 100644 --- a/test-app/runtime/src/main/cpp/MetadataNode.h +++ b/test-app/runtime/src/main/cpp/MetadataNode.h @@ -128,7 +128,7 @@ class MetadataNode { static void ArrayIndexedPropertySetterCallback(uint32_t index, v8::Local value, const v8::PropertyCallbackInfo& info); static bool IsValidExtendName(const v8::Local& name); - static bool GetExtendLocation(std::string& extendLocation, bool isTypeScriptExtend); + static bool GetExtendLocation(v8::Isolate* isolate, std::string& extendLocation, bool isTypeScriptExtend); static ExtendedClassCacheData GetCachedExtendedClassData(v8::Isolate* isolate, const std::string& proxyClassName); static void RegisterSymbolHasInstanceCallback(v8::Isolate* isolate, MetadataEntry entry, v8::Local interface); diff --git a/test-app/runtime/src/main/cpp/MethodCache.cpp b/test-app/runtime/src/main/cpp/MethodCache.cpp index 40506fb61..2eddbb107 100644 --- a/test-app/runtime/src/main/cpp/MethodCache.cpp +++ b/test-app/runtime/src/main/cpp/MethodCache.cpp @@ -118,7 +118,7 @@ string MethodCache::GetType(Isolate* isolate, const v8::Local& value) string type; if (value->IsObject()) { - auto objVal = value->ToObject(); + auto objVal = value->ToObject(isolate); Local nullNode; //out V8GetPrivateValue(isolate, objVal, V8StringConstants::GetNullNodeName(isolate), nullNode); @@ -152,13 +152,14 @@ string MethodCache::GetType(Isolate* isolate, const v8::Local& value) } else if (value->IsString() || value->IsStringObject()) { type = "string"; } else if (value->IsNumber() || value->IsNumberObject()) { - double d = value->NumberValue(); + auto context = isolate->GetCurrentContext(); + double d = value->NumberValue(context).ToChecked(); int64_t i = (int64_t) d; bool isInteger = d == i; type = isInteger ? "intnumber" : "doublenumber"; } else if (value->IsObject()) { - auto object = value->ToObject(); + auto object = value->ToObject(isolate); auto castType = NumericCasts::GetCastType(isolate, object); MetadataNode* node; diff --git a/test-app/runtime/src/main/cpp/ModuleInternal.cpp b/test-app/runtime/src/main/cpp/ModuleInternal.cpp index 4e30fdaf3..15fe292d7 100644 --- a/test-app/runtime/src/main/cpp/ModuleInternal.cpp +++ b/test-app/runtime/src/main/cpp/ModuleInternal.cpp @@ -286,7 +286,8 @@ Local ModuleInternal::LoadModule(Isolate* isolate, const string& moduleP if (Util::EndsWith(modulePath, ".js")) { auto script = LoadScript(isolate, modulePath, fullRequiredModulePath); - moduleFunc = script->Run().As(); + auto context = isolate->GetCurrentContext(); + moduleFunc = script->Run(context).ToLocalChecked().As(); if (tc.HasCaught()) { throw NativeScriptException(tc, "Error running script " + modulePath); } diff --git a/test-app/runtime/src/main/cpp/NativeScriptException.cpp b/test-app/runtime/src/main/cpp/NativeScriptException.cpp index 468fcbdf6..1298b8951 100644 --- a/test-app/runtime/src/main/cpp/NativeScriptException.cpp +++ b/test-app/runtime/src/main/cpp/NativeScriptException.cpp @@ -103,7 +103,7 @@ void NativeScriptException::ReThrowToJava() { env.Throw(ex); } -void NativeScriptException::Init(ObjectManager* objectManager) { +void NativeScriptException::Init() { JEnv env; RUNTIME_CLASS = env.FindClass("com/tns/Runtime"); @@ -303,7 +303,7 @@ string NativeScriptException::GetErrorMessage(const Local& message, Loc } else { ss << "File: \""; } - ss << ", line: " << message->GetLineNumber() << ", column: " << message->GetStartColumn() << endl << endl; + ss << ", line: " << message->GetLineNumber(context).ToChecked() << ", column: " << message->GetStartColumn() << endl << endl; ss << "StackTrace: " << endl << stackTraceMessage << endl; return ss.str(); @@ -318,7 +318,7 @@ string NativeScriptException::GetErrorStackTrace(const Local& stackT int frameCount = stackTrace->GetFrameCount(); for (int i = 0; i < frameCount; i++) { - auto frame = stackTrace->GetFrame(i); + auto frame = stackTrace->GetFrame(isolate, i); auto funcName = ArgConverter::ConvertToString(frame->GetFunctionName()); auto srcName = ArgConverter::ConvertToString(frame->GetScriptName()); auto lineNumber = frame->GetLineNumber(); diff --git a/test-app/runtime/src/main/cpp/NativeScriptException.h b/test-app/runtime/src/main/cpp/NativeScriptException.h index e4dbbf533..8e2b312d7 100644 --- a/test-app/runtime/src/main/cpp/NativeScriptException.h +++ b/test-app/runtime/src/main/cpp/NativeScriptException.h @@ -28,7 +28,7 @@ class NativeScriptException { void ReThrowToV8(); void ReThrowToJava(); - static void Init(ObjectManager* objectManager); + static void Init(); /* * This handler is attached to v8 to handle uncaught javascript exceptions. diff --git a/test-app/runtime/src/main/cpp/NetworkDomainCallbackHandlers.cpp b/test-app/runtime/src/main/cpp/NetworkDomainCallbackHandlers.cpp index 341807c92..48f76439f 100644 --- a/test-app/runtime/src/main/cpp/NetworkDomainCallbackHandlers.cpp +++ b/test-app/runtime/src/main/cpp/NetworkDomainCallbackHandlers.cpp @@ -27,7 +27,7 @@ void NetworkDomainCallbackHandlers::ResponseReceivedCallback(const v8::FunctionC auto context = isolate->GetCurrentContext(); - v8::Local argsObj = args[0]->ToObject(); + v8::Local argsObj = args[0]->ToObject(isolate); if ((!argsObj->Has(context, ArgConverter::ConvertToV8String(isolate, "requestId")).FromMaybe(false) || !argsObj->Has(context, ArgConverter::ConvertToV8String(isolate, "timestamp")).FromMaybe(false) || @@ -36,12 +36,12 @@ void NetworkDomainCallbackHandlers::ResponseReceivedCallback(const v8::FunctionC throw NativeScriptException(wrongParametersError); } - auto requestId = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "requestId")).ToLocalChecked()->ToString(); - auto type = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "type")).ToLocalChecked()->ToString(); + auto requestId = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "requestId")).ToLocalChecked()->ToString(isolate); + auto type = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "type")).ToLocalChecked()->ToString(isolate); auto response = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "response")).ToLocalChecked(); - auto timeStamp = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "timestamp")).ToLocalChecked()->ToNumber(isolate)->IntegerValue(); + auto timeStamp = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "timestamp")).ToLocalChecked()->ToNumber(isolate)->IntegerValue(context).ToChecked(); - auto responseAsObj = response->ToObject(); + auto responseAsObj = response->ToObject(isolate); auto connectionReusedProp = ArgConverter::ConvertToV8String(isolate, "connectionReused"); if (!responseAsObj->Has(context, connectionReusedProp).FromMaybe(false)) { responseAsObj->Set(connectionReusedProp, v8::Boolean::New(isolate, true)); @@ -129,7 +129,7 @@ void NetworkDomainCallbackHandlers::RequestWillBeSentCallback(const v8::Function auto context = isolate->GetCurrentContext(); - v8::Local argsObj = args[0]->ToObject(); + v8::Local argsObj = args[0]->ToObject(isolate); if ((!(argsObj->Has(context, ArgConverter::ConvertToV8String(isolate, "requestId")).FromMaybe(false)) || !(argsObj->Has(context, ArgConverter::ConvertToV8String(isolate, "url")).FromMaybe(false)) || @@ -139,17 +139,17 @@ void NetworkDomainCallbackHandlers::RequestWillBeSentCallback(const v8::Function throw NativeScriptException(wrongParametersError); } - auto requestId = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "requestId")).ToLocalChecked()->ToString(); - auto url = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "url")).ToLocalChecked()->ToString(); + auto requestId = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "requestId")).ToLocalChecked()->ToString(isolate); + auto url = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "url")).ToLocalChecked()->ToString(isolate); auto request = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "request")).ToLocalChecked(); - auto timeStamp = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "timestamp")).ToLocalChecked()->ToNumber(isolate)->IntegerValue(); - auto typeArg = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "type")).ToLocalChecked()->ToString(); + auto timeStamp = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "timestamp")).ToLocalChecked()->ToNumber(isolate)->IntegerValue(context).ToChecked(); + auto typeArg = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "type")).ToLocalChecked()->ToString(isolate); long long int wallTime = 0; if (argsObj->Has(context, ArgConverter::ConvertToV8String(isolate, "wallTime")).FromMaybe(true)) { - wallTime = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "wallTime")).ToLocalChecked()->ToNumber(isolate)->IntegerValue(); + wallTime = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "wallTime")).ToLocalChecked()->ToNumber(isolate)->IntegerValue(context).ToChecked(); } - auto requestAsObj = request->ToObject(); + auto requestAsObj = request->ToObject(isolate); auto initialPriorityProp = ArgConverter::ConvertToV8String(isolate, "initialPriority"); auto referrerPolicyProp = ArgConverter::ConvertToV8String(isolate, "referrerPolicy"); if (!argsObj->Has(context, initialPriorityProp).FromMaybe(false)) { @@ -230,7 +230,7 @@ void NetworkDomainCallbackHandlers::DataForRequestIdCallback(const v8::FunctionC auto context = isolate->GetCurrentContext(); - v8::Local argsObj = args[0]->ToObject(); + v8::Local argsObj = args[0]->ToObject(isolate); if (!argsObj->Has(context, ArgConverter::ConvertToV8String(isolate, "requestId")).FromMaybe(false) || !argsObj->Has(context, ArgConverter::ConvertToV8String(isolate, "data")).FromMaybe(false) || @@ -238,13 +238,13 @@ void NetworkDomainCallbackHandlers::DataForRequestIdCallback(const v8::FunctionC throw NativeScriptException(wrongParametersError); } - auto requestId = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "requestId")).ToLocalChecked()->ToString(); - auto data = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "data")).ToLocalChecked()->ToString(); - auto hasTextContent = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "hasTextContent")).ToLocalChecked()->ToBoolean(); + auto requestId = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "requestId")).ToLocalChecked()->ToString(isolate); + auto data = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "data")).ToLocalChecked()->ToString(context).ToLocalChecked(); + auto hasTextContent = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "hasTextContent")).ToLocalChecked()->ToBoolean(context).ToLocalChecked(); auto requestIdString = ArgConverter::ConvertToString(requestId); auto dataString = ArgConverter::ConvertToUtf16String(data); - auto hasTextContentBool = hasTextContent->BooleanValue(); + auto hasTextContentBool = hasTextContent->BooleanValue(context).ToChecked(); auto responses = networkAgentInstance->m_responses; auto it = responses.find(requestIdString); @@ -290,19 +290,19 @@ void NetworkDomainCallbackHandlers::LoadingFinishedCallback(const v8::FunctionCa auto context = isolate->GetCurrentContext(); - v8::Local argsObj = args[0]->ToObject(); + v8::Local argsObj = args[0]->ToObject(isolate); if (!argsObj->Has(context, ArgConverter::ConvertToV8String(isolate, "requestId")).FromMaybe(false) || !argsObj->Has(context, ArgConverter::ConvertToV8String(isolate, "timestamp")).FromMaybe(false)) { throw NativeScriptException(wrongParametersError); } - auto requestId = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "requestId")).ToLocalChecked()->ToString(); - auto timeStamp = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "timestamp")).ToLocalChecked()->ToNumber(isolate)->IntegerValue(); + auto requestId = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "requestId")).ToLocalChecked()->ToString(isolate); + auto timeStamp = argsObj->Get(context, ArgConverter::ConvertToV8String(isolate, "timestamp")).ToLocalChecked()->ToNumber(isolate)->IntegerValue(context).ToChecked(); long long int encodedDataLength = 0; auto encodedDataLengthProp = ArgConverter::ConvertToV8String(isolate, "encodedDataLength"); if (argsObj->Has(context, encodedDataLengthProp).FromMaybe(true)) { - encodedDataLength = argsObj->Get(context, encodedDataLengthProp).ToLocalChecked()->ToNumber(isolate)->IntegerValue(); + encodedDataLength = argsObj->Get(context, encodedDataLengthProp).ToLocalChecked()->ToNumber(isolate)->IntegerValue(context).ToChecked(); } networkAgentInstance->m_frontend.loadingFinished(ArgConverter::ConvertToString(requestId).c_str(), timeStamp, encodedDataLength); diff --git a/test-app/runtime/src/main/cpp/NumericCasts.cpp b/test-app/runtime/src/main/cpp/NumericCasts.cpp index 4e6a66cc6..c0ae4bc2d 100644 --- a/test-app/runtime/src/main/cpp/NumericCasts.cpp +++ b/test-app/runtime/src/main/cpp/NumericCasts.cpp @@ -28,7 +28,8 @@ CastType NumericCasts::GetCastType(Isolate* isolate, const Local& object Local hidden; V8GetPrivateValue(isolate, object, key, hidden); if (!hidden.IsEmpty()) { - ret = static_cast(hidden->Int32Value()); + auto context = isolate->GetCurrentContext(); + ret = static_cast(hidden->Int32Value(context).ToChecked()); } return ret; @@ -175,7 +176,7 @@ void NumericCasts::MarkAsLongCallback(const v8::FunctionCallbackInfo& arg if (args[0]->IsInt32()) { value = args[0]->ToInt32(isolate); } else { - value = args[0]->ToString(); + value = args[0]->ToString(isolate); } auto cast = Object::New(isolate); @@ -209,7 +210,7 @@ void NumericCasts::MarkAsByteCallback(const v8::FunctionCallbackInfo& arg if (args[0]->IsInt32()) { value = args[0]->ToInt32(isolate); } else { - value = args[0]->ToString(); + value = args[0]->ToString(isolate); } auto cast = Object::New(isolate); @@ -244,7 +245,7 @@ void NumericCasts::MarkAsShortCallback(const v8::FunctionCallbackInfo& ar if (args[0]->IsInt32()) { value = args[0]->ToInt32(isolate); } else { - value = args[0]->ToString(); + value = args[0]->ToString(isolate); } auto cast = Object::New(isolate); @@ -274,7 +275,7 @@ void NumericCasts::MarkAsCharCallback(const v8::FunctionCallbackInfo& arg throw NativeScriptException(string("char(x) should be called with single parameter containing a char representation")); } - auto value = args[0]->ToString(); + auto value = args[0]->ToString(isolate); if (value->Length() != 1) { throw NativeScriptException(string("char(x) should be called with single parameter containing a single char")); } diff --git a/test-app/runtime/src/main/cpp/ObjectManager.cpp b/test-app/runtime/src/main/cpp/ObjectManager.cpp index 0c91445a1..5a6bbe99c 100644 --- a/test-app/runtime/src/main/cpp/ObjectManager.cpp +++ b/test-app/runtime/src/main/cpp/ObjectManager.cpp @@ -420,7 +420,8 @@ void ObjectManager::ReleaseRegularObjects() { bool isReachableFromImplementationObject = false; if (!gcNum.IsEmpty()) { - int objGcNum = gcNum->Int32Value(); + auto context = m_isolate->GetCurrentContext(); + int objGcNum = gcNum->Int32Value(context).ToChecked(); // done so we can release only java objects from this GC stack and pass all objects that will be released in parent GC stacks isReachableFromImplementationObject = objGcNum >= numberOfGC; diff --git a/test-app/runtime/src/main/cpp/Profiler.cpp b/test-app/runtime/src/main/cpp/Profiler.cpp index b71883eb2..e92ab0142 100644 --- a/test-app/runtime/src/main/cpp/Profiler.cpp +++ b/test-app/runtime/src/main/cpp/Profiler.cpp @@ -45,7 +45,7 @@ void Profiler::StartCPUProfilerCallbackImpl(const v8::FunctionCallbackInfoIsString())) { - auto name = args[0]->ToString(); + auto name = args[0]->ToString(isolate); StartCPUProfiler(isolate, name); started = true; } @@ -75,7 +75,7 @@ void Profiler::StopCPUProfilerCallbackImpl(const v8::FunctionCallbackInfoIsString())) { - auto name = args[0]->ToString(); + auto name = args[0]->ToString(isolate); stopped = StopCPUProfiler(isolate, name); } args.GetReturnValue().Set(stopped); diff --git a/test-app/runtime/src/main/cpp/Runtime.cpp b/test-app/runtime/src/main/cpp/Runtime.cpp index 286215dfa..07f558734 100644 --- a/test-app/runtime/src/main/cpp/Runtime.cpp +++ b/test-app/runtime/src/main/cpp/Runtime.cpp @@ -31,6 +31,7 @@ #ifdef APPLICATION_IN_DEBUG #include "JsV8InspectorClient.h" +#include "v8_inspector/src/inspector/v8-inspector-platform.h" #endif using namespace v8; @@ -183,7 +184,7 @@ void Runtime::Init(jstring filesPath, jstring nativeLibDir, bool verboseLoggingE auto profilerOutputDirStr = ArgConverter::jstringToString(profilerOutputDir); - NativeScriptException::Init(m_objectManager); + NativeScriptException::Init(); m_isolate = PrepareV8Runtime(filesRoot, nativeLibDirStr, packageNameStr, isDebuggable, callingDirStr, profilerOutputDirStr, maxLogcatObjectSize, forceLog); s_isolate2RuntimesCache.insert(make_pair(m_isolate, this)); @@ -425,7 +426,18 @@ void Runtime::ClearStartupData(JNIEnv* env, jobject obj) { } static void InitializeV8() { - Runtime::platform = v8::platform::CreateDefaultPlatform(); + Runtime::platform = +#ifdef APPLICATION_IN_DEBUG + // The default V8 platform isn't Chrome DevTools compatible. The frontend uses the + // Runtime.evaluate protocol command with timeout flag for every execution in the console. + // The default platform doesn't implement executing delayed javascript code from a background + // thread. To avoid implementing a full blown scheduler, we use the default platform with a + // timeout=0 flag. + V8InspectorPlatform::CreateDefaultPlatform(); +#else + v8::platform::CreateDefaultPlatform(); +#endif + V8::InitializePlatform(Runtime::platform); V8::Initialize(); } @@ -465,6 +477,7 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, const string& native if (snapshotPtr) { m_startupData->data = static_cast(dlsym(snapshotPtr, "TNSSnapshot_blob")); m_startupData->raw_size = *static_cast(dlsym(snapshotPtr, "TNSSnapshot_blob_len")); + create_params.snapshot_blob = m_startupData; DEBUG_WRITE_FORCE("Snapshot library read %p (%dB).", m_startupData->data, m_startupData->raw_size); } else if (!Constants::V8_HEAP_SNAPSHOT_BLOB.empty() || !Constants::V8_HEAP_SNAPSHOT_SCRIPT.empty()) { DEBUG_WRITE_FORCE("Snapshot enabled."); @@ -502,7 +515,7 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, const string& native } DEBUG_WRITE_FORCE("Creating heap snapshot"); - *m_startupData = V8::CreateSnapshotDataBlob(customScript.c_str()); + *m_startupData = Runtime::CreateSnapshotDataBlob(customScript.c_str()); if (m_startupData->raw_size == 0) { DEBUG_WRITE_FORCE("Failed to create heap snapshot."); @@ -618,7 +631,7 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, const string& native auto global = context->Global(); - auto gcFunc = global->Get(ConvertToV8String("gc")); + auto gcFunc = global->Get(ArgConverter::ConvertToV8String(isolate, "gc")); if (!gcFunc.IsEmpty() && gcFunc->IsFunction()) { m_gcFunc = new Persistent(isolate, gcFunc.As()); } @@ -685,6 +698,60 @@ void Runtime::SetManualInstrumentationMode(jstring mode) { } } +StartupData Runtime::CreateSnapshotDataBlob(const char* embedded_source) { + // Create a new isolate and a new context from scratch, optionally run + // a script to embed, and serialize to create a snapshot blob. + StartupData result = {nullptr, 0}; + { + SnapshotCreator snapshot_creator; + Isolate* isolate = snapshot_creator.GetIsolate(); + { + HandleScope scope(isolate); + Local context = Context::New(isolate); + if (embedded_source != nullptr && + !Runtime::RunExtraCode(isolate, context, embedded_source, "")) { + return result; + } + snapshot_creator.SetDefaultContext(context); + } + result = snapshot_creator.CreateBlob( + SnapshotCreator::FunctionCodeHandling::kClear); + } + + return result; +} + +bool Runtime::RunExtraCode(Isolate* isolate, Local context, const char* utf8_source, const char* name) { + Context::Scope context_scope(context); + TryCatch try_catch(isolate); + Local source_string; + if (!v8::String::NewFromUtf8(isolate, utf8_source, NewStringType::kNormal).ToLocal(&source_string)) { + return false; + } + Local resource_name = v8::String::NewFromUtf8(isolate, name, NewStringType::kNormal).ToLocalChecked(); + ScriptOrigin origin(resource_name); + ScriptCompiler::Source source(source_string, origin); + Local