Permalink
Browse files

check if array-enclosed elements are empty before trying to release t…

…hem during GC
  • Loading branch information...
Pip3r4o committed Apr 19, 2017
1 parent 30bf433 commit 38e894a45082c855caeb46c472849ceda4136edf
Showing with 20 additions and 0 deletions.
  1. +17 −0 runtime/src/main/jni/ObjectManager.cpp
  2. +3 −0 runtime/src/main/jni/ObjectManager.h
@@ -460,6 +460,10 @@ void ObjectManager::MarkReachableObjects(Isolate* isolate, const Local<Object>&
NativeScriptExtension::ReleaseClosureObjects(closureObjects); NativeScriptExtension::ReleaseClosureObjects(closureObjects);
} }
if (o->IsArray()) {
MarkReachableArrayElements(o, s);
}
auto proto = o->GetPrototype(); auto proto = o->GetPrototype();
if (!proto.IsEmpty() && !proto->IsNull() && !proto->IsUndefined() && proto->IsObject()) { if (!proto.IsEmpty() && !proto->IsNull() && !proto->IsUndefined() && proto->IsObject()) {
s.push(proto); s.push(proto);
@@ -518,6 +522,19 @@ void ObjectManager::MarkReachableObjects(Isolate* isolate, const Local<Object>&
} // while } // while
} }
void ObjectManager::MarkReachableArrayElements(Local<Object> &o, stack<Local<Value>> &s) {
auto arr = o.As<Array>();
int arrEnclosedObjectsLength = arr->Length();
for (int i = 0; i < arrEnclosedObjectsLength; i++) {
auto enclosedElement = arr->Get(i);
if (!enclosedElement.IsEmpty() && enclosedElement->IsObject()) {
s.push(enclosedElement);
}
}
}
void ObjectManager::OnGcStartedStatic(Isolate* isolate, GCType type, GCCallbackFlags flags) { void ObjectManager::OnGcStartedStatic(Isolate* isolate, GCType type, GCCallbackFlags flags) {
try { try {
auto runtime = Runtime::GetRuntime(isolate); auto runtime = Runtime::GetRuntime(isolate);
@@ -49,12 +49,15 @@ class ObjectManager {
v8::Local<v8::Object> GetEmptyObject(v8::Isolate* isolate); v8::Local<v8::Object> GetEmptyObject(v8::Isolate* isolate);
static void MarkReachableArrayElements(v8::Local<v8::Object> &o, std::stack<v8::Local<v8::Value>> &s);
enum class MetadataNodeKeys { enum class MetadataNodeKeys {
JsInfo, JsInfo,
CallSuper, CallSuper,
END END
}; };
private: private:
struct JSInstanceInfo { struct JSInstanceInfo {

0 comments on commit 38e894a

Please sign in to comment.