Skip to content

Commit 9763cb5

Browse files
committed
assert v8constants are setup properly, initialize constants eagerly now
1 parent 6b9e7da commit 9763cb5

6 files changed

Lines changed: 118 additions & 207 deletions

File tree

runtime/src/main/jni/MetadataNode.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Local<Object> MetadataNode::CreateExtendedJSWrapper(Isolate *isolate, ObjectMana
5757
extInstance = objectManager->GetEmptyObject(isolate);
5858
extInstance->SetInternalField(static_cast<int>(ObjectManager::MetadataNodeKeys::CallSuper), True(isolate));
5959
auto extdCtorFunc = Local<Function>::New(isolate, *cacheData.extendedCtorFunction);
60-
extInstance->SetPrototype(extdCtorFunc->Get(ArgConverter::ConvertToV8String(isolate, "prototype")));
60+
extInstance->SetPrototype(extdCtorFunc->Get(V8StringConstants::GetPrototype(isolate)));
6161

6262
SetInstanceMetadata(isolate, extInstance, cacheData.node);
6363
}
@@ -183,7 +183,7 @@ Local<Object> MetadataNode::CreateJSWrapper(Isolate *isolate, ObjectManager *obj
183183
{
184184
auto ctorFunc = GetConstructorFunction(isolate);
185185
obj->Set(ArgConverter::ConvertToV8String(isolate, "constructor"), ctorFunc);
186-
obj->SetPrototype(ctorFunc->Get(ArgConverter::ConvertToV8String(isolate, "prototype")));
186+
obj->SetPrototype(ctorFunc->Get(V8StringConstants::GetPrototype(isolate)));
187187
SetInstanceMetadata(isolate, obj, this);
188188
}
189189
}
@@ -226,7 +226,7 @@ Local<Object> MetadataNode::CreateArrayWrapper(Isolate *isolate)
226226
arrayObjectTemplate->SetIndexedPropertyHandler(ArrayIndexedPropertyGetterCallback, ArrayIndexedPropertySetterCallback);
227227

228228
auto arr = arrayObjectTemplate->NewInstance();
229-
arr->SetPrototype(objPrototype->Get(ArgConverter::ConvertToV8String(isolate, "prototype")));
229+
arr->SetPrototype(objPrototype->Get(V8StringConstants::GetPrototype(isolate)));
230230
arr->SetAccessor(ArgConverter::ConvertToV8String(isolate, "length"), ArrayLengthGetterCallack, nullptr, Local<Value>(), AccessControl::ALL_CAN_READ, PropertyAttribute::DontDelete);
231231

232232
SetInstanceMetadata(isolate, arr, this);
@@ -707,7 +707,7 @@ void MetadataNode::SetInnerTypes(Isolate *isolate, Local<Function>& ctorFunction
707707
const auto& children = *treeNode->children;
708708

709709
// prototype of outer class
710-
auto prototypeTemplate2 = ctorFunction->Get(ArgConverter::ConvertToV8String(isolate, "prototype")).As<Object>();
710+
auto prototypeTemplate2 = ctorFunction->Get(V8StringConstants::GetPrototype(isolate)).As<Object>();
711711

712712
for (auto curChild : children)
713713
{
@@ -857,7 +857,7 @@ void MetadataNode::ExtendedClassConstructorCallback(const v8::FunctionCallbackIn
857857

858858
SetInstanceMetadata(isolate, thiz, extData->node);
859859
thiz->SetInternalField(static_cast<int>(ObjectManager::MetadataNodeKeys::CallSuper), True(isolate));
860-
thiz->SetHiddenValue(ArgConverter::ConvertToV8String(isolate, "t::implObj"), implementationObject);
860+
thiz->SetHiddenValue(V8StringConstants::GetImplementationObject(isolate), implementationObject);
861861

862862
ArgsWrapper argWrapper(info, ArgType::Class);
863863

@@ -929,7 +929,7 @@ void MetadataNode::InterfaceConstructorCallback(const v8::FunctionCallbackInfo<v
929929

930930
implementationObject->SetPrototype(thiz->GetPrototype());
931931
thiz->SetPrototype(implementationObject);
932-
thiz->SetHiddenValue(ArgConverter::ConvertToV8String(isolate, "t::implObj"), implementationObject);
932+
thiz->SetHiddenValue(V8StringConstants::GetImplementationObject(isolate), implementationObject);
933933

934934
ArgsWrapper argWrapper(info, ArgType::Interface);
935935

@@ -1134,7 +1134,7 @@ Local<Object> MetadataNode::GetImplementationObject(const Local<Object>& object)
11341134

11351135
Local<Object> implementationObject;
11361136

1137-
implementationObject = object->GetHiddenValue(ArgConverter::ConvertToV8String(isolate, "t::implObj")).As<Object>();
1137+
implementationObject = object->GetHiddenValue(V8StringConstants::GetImplementationObject(isolate)).As<Object>();
11381138
if (!implementationObject.IsEmpty())
11391139
{
11401140
return implementationObject;
@@ -1460,9 +1460,9 @@ void MetadataNode::ExtendMethodCallback(const v8::FunctionCallbackInfo<v8::Value
14601460
extendFuncTemplate->InstanceTemplate()->SetInternalFieldCount(static_cast<int>(ObjectManager::MetadataNodeKeys::END));
14611461

14621462
auto extendFunc = extendFuncTemplate->GetFunction();
1463-
auto prototypeName = ArgConverter::ConvertToV8String(isolate, "prototype");
1463+
auto prototypeName = V8StringConstants::GetPrototype(isolate);
14641464
implementationObject->SetPrototype(baseClassCtorFunc->Get(prototypeName));
1465-
implementationObject->SetAccessor(ArgConverter::ConvertToV8String(isolate, "super"), SuperAccessorGetterCallback, nullptr, implementationObject);
1465+
implementationObject->SetAccessor(V8StringConstants::GetSuper(isolate), SuperAccessorGetterCallback, nullptr, implementationObject);
14661466

14671467
auto extendFuncPrototype = extendFunc->Get(prototypeName).As<Object>();
14681468
auto p = extendFuncPrototype->GetPrototype();
@@ -1797,7 +1797,7 @@ Local<Function> MetadataNode::Wrap(Isolate* isolate, const Local<Function>& f, c
17971797
ret = result.As<Function>();
17981798
ret->Set(ArgConverter::ConvertToV8String(isolate, "__func"), f);
17991799

1800-
auto prototypePropName = ArgConverter::ConvertToV8String(isolate, "prototype");
1800+
auto prototypePropName = V8StringConstants::GetPrototype(isolate);
18011801
ret->Set(prototypePropName, f->Get(prototypePropName));
18021802
}
18031803
else

runtime/src/main/jni/NumericCasts.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ CastType NumericCasts::GetCastType(const Local<Object>& object)
4242
Local<Value> NumericCasts::GetCastValue(const Local<Object>& object)
4343
{
4444
auto isolate = object->GetIsolate();
45-
auto value = object->Get(ArgConverter::ConvertToV8String(isolate, "value"));
45+
auto value = object->Get(V8StringConstants::GetValue(isolate));
4646
return value;
4747
}
4848

@@ -208,7 +208,7 @@ void NumericCasts::MarkAsLongCallback(const v8::FunctionCallbackInfo<Value>& arg
208208
{
209209
try
210210
{
211-
auto isolate = Isolate::GetCurrent();
211+
auto isolate = args.GetIsolate();
212212

213213
if (args.Length() != 1)
214214
{
@@ -253,7 +253,7 @@ void NumericCasts::MarkAsByteCallback(const v8::FunctionCallbackInfo<Value>& arg
253253
{
254254
try
255255
{
256-
auto isolate = Isolate::GetCurrent();
256+
auto isolate = args.GetIsolate();
257257

258258
if (args.Length() != 1)
259259
{
@@ -298,7 +298,7 @@ void NumericCasts::MarkAsShortCallback(const v8::FunctionCallbackInfo<Value>& ar
298298
{
299299
try
300300
{
301-
auto isolate = Isolate::GetCurrent();
301+
auto isolate = args.GetIsolate();
302302

303303
if (args.Length() != 1)
304304
{
@@ -344,7 +344,7 @@ void NumericCasts::MarkAsCharCallback(const v8::FunctionCallbackInfo<Value>& arg
344344
{
345345
try
346346
{
347-
auto isolate = Isolate::GetCurrent();
347+
auto isolate = args.GetIsolate();
348348

349349
if (args.Length() != 1)
350350
{
@@ -385,7 +385,7 @@ void NumericCasts::MarkAsFloatCallback(const v8::FunctionCallbackInfo<Value>& ar
385385
{
386386
try
387387
{
388-
auto isolate = Isolate::GetCurrent();
388+
auto isolate = args.GetIsolate();
389389

390390
if (args.Length() != 1)
391391
{
@@ -460,7 +460,7 @@ void NumericCasts::MarkJsObject(const Local<Object>& object, CastType castType,
460460
auto type = Integer::New(isolate, static_cast<int>(castType));
461461

462462
object->SetHiddenValue(key, type);
463-
object->Set(ArgConverter::ConvertToV8String(isolate, "value"), value);
463+
object->Set(V8StringConstants::GetValue(isolate), value);
464464
DEBUG_WRITE("MarkJsObject: Marking js object: %d with cast type: %d", object->GetIdentityHash(), castType);
465465
}
466466

runtime/src/main/jni/Runtime.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,9 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring packageName,
430430

431431
m_objectManager->SetInstanceIsolate(isolate);
432432

433-
// TODO: Pete: Will set a structure with constants on the isolate object at slot 1
434-
V8StringConstants::PerIsolateV8Constants* consts = new V8StringConstants::PerIsolateV8Constants();
435-
zip_uint32_t slot = 1;
436-
isolate->SetData(slot, consts);
433+
// Sets a structure with v8 String constants on the isolate object at slot 1
434+
V8StringConstants::PerIsolateV8Constants* consts = new V8StringConstants::PerIsolateV8Constants(isolate);
435+
isolate->SetData((uint32_t)Runtime::IsolateData::CONSTANTS, consts);
437436

438437
V8::SetFlagsFromString(Constants::V8_STARTUP_FLAGS.c_str(), Constants::V8_STARTUP_FLAGS.size());
439438
V8::SetCaptureStackTraceForUncaughtExceptions(true, 100, StackTrace::kOverview);

runtime/src/main/jni/Runtime.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ namespace tns
1818
class Runtime
1919
{
2020
public:
21+
enum IsolateData {
22+
RUNTIME = 0,
23+
CONSTANTS = 1
24+
};
25+
2126
static Runtime *GetRuntime(int runtimeId);
2227

2328
static Runtime *GetRuntime(v8::Isolate *isolate);

0 commit comments

Comments
 (0)