@@ -82,19 +82,17 @@ JniLocalRef ObjectManager::GetJavaObjectByJsObject(const Local<Object>& object)
82
82
return JniLocalRef ();
83
83
}
84
84
85
- JSInstanceInfo* ObjectManager::GetJSInstanceInfo (const Local<Object>& object)
85
+ ObjectManager:: JSInstanceInfo* ObjectManager::GetJSInstanceInfo (const Local<Object>& object)
86
86
{
87
87
DEBUG_WRITE (" ObjectManager::GetJSInstanceInfo: called" );
88
88
JSInstanceInfo *jsInstanceInfo = nullptr ;
89
89
90
90
auto isolate = Isolate::GetCurrent ();
91
91
HandleScope handleScope (isolate);
92
92
93
- int internalFieldCound = NativeScriptExtension::GetInternalFieldCount (object);
94
- const int count = static_cast <int >(MetadataNodeKeys::END);
95
- const int jsInfoIdx = static_cast <int >(MetadataNodeKeys::JsInfo);
96
- if (internalFieldCound == count)
93
+ if (IsJsRuntimeObject (object))
97
94
{
95
+ const int jsInfoIdx = static_cast <int >(MetadataNodeKeys::JsInfo);
98
96
auto jsInfo = object->GetInternalField (jsInfoIdx);
99
97
if (jsInfo->IsUndefined ())
100
98
{
@@ -104,8 +102,7 @@ JSInstanceInfo* ObjectManager::GetJSInstanceInfo(const Local<Object>& object)
104
102
if (!prototypeObject.IsEmpty () && prototypeObject->IsObject ())
105
103
{
106
104
DEBUG_WRITE (" GetJSInstanceInfo: need to check prototype :%d" , prototypeObject->GetIdentityHash ());
107
- internalFieldCound = NativeScriptExtension::GetInternalFieldCount (prototypeObject);
108
- if (internalFieldCound == count)
105
+ if (IsJsRuntimeObject (prototypeObject))
109
106
{
110
107
jsInfo = prototypeObject->GetInternalField (jsInfoIdx);
111
108
}
@@ -122,6 +119,12 @@ JSInstanceInfo* ObjectManager::GetJSInstanceInfo(const Local<Object>& object)
122
119
return jsInstanceInfo;
123
120
}
124
121
122
+ bool ObjectManager::IsJsRuntimeObject (const v8::Local<v8::Object>& object) {
123
+ int internalFieldCount = NativeScriptExtension::GetInternalFieldCount (object);
124
+ const int count = static_cast <int >(MetadataNodeKeys::END);
125
+ return internalFieldCount == count;
126
+ }
127
+
125
128
jweak ObjectManager::GetJavaObjectByID (uint32_t javaObjectID)
126
129
{
127
130
jweak obj = m_cache (javaObjectID);
@@ -145,7 +148,7 @@ jclass ObjectManager::GetJavaClass(const Local<Object>& instance)
145
148
DEBUG_WRITE (" GetClass called" );
146
149
147
150
JSInstanceInfo *jsInfo = GetJSInstanceInfo (instance);
148
- jclass clazz = jsInfo->clazz ;
151
+ jclass clazz = jsInfo->ObjectClazz ;
149
152
150
153
return clazz;
151
154
}
@@ -155,7 +158,7 @@ void ObjectManager::SetJavaClass(const Local<Object>& instance, jclass clazz)
155
158
DEBUG_WRITE (" SetClass called" );
156
159
157
160
JSInstanceInfo *jsInfo = GetJSInstanceInfo (instance);
158
- jsInfo->clazz = clazz;
161
+ jsInfo->ObjectClazz = clazz;
159
162
}
160
163
161
164
int ObjectManager::GetOrCreateObjectId (jobject object)
@@ -215,9 +218,7 @@ Local<Object> ObjectManager::CreateJSWrapperHelper(jint javaObjectID, const stri
215
218
216
219
void ObjectManager::Link (const Local<Object>& object, uint32_t javaObjectID, jclass clazz)
217
220
{
218
- int internalFieldCound = NativeScriptExtension::GetInternalFieldCount (object);
219
- const int count = static_cast <int >(MetadataNodeKeys::END);
220
- if (internalFieldCound != count)
221
+ if (!IsJsRuntimeObject (object))
221
222
{
222
223
string errMsg (" Trying to link invalid 'this' to a Java object" );
223
224
throw NativeScriptException (errMsg);
@@ -227,9 +228,7 @@ void ObjectManager::Link(const Local<Object>& object, uint32_t javaObjectID, jcl
227
228
228
229
DEBUG_WRITE (" Linking js object: %d and java instance id: %d" , object->GetIdentityHash (), javaObjectID);
229
230
230
- auto jsInstanceInfo = new JSInstanceInfo ();
231
- jsInstanceInfo->JavaObjectID = javaObjectID;
232
- jsInstanceInfo->clazz = clazz;
231
+ auto jsInstanceInfo = new JSInstanceInfo (false , javaObjectID, clazz);
233
232
234
233
auto objectHandle = new Persistent<Object>(isolate, object);
235
234
auto state = new ObjectWeakCallbackState (this , jsInstanceInfo, objectHandle);
0 commit comments