Skip to content

fix: DictionaryAdapter missing handle scopes and locks #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion NativeScript/runtime/DictionaryAdapter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ - (instancetype)initWithMap:(std::shared_ptr<Persistent<Value>>)map isolate:(Iso

- (id)nextObject {
Isolate* isolate = self->isolate_;
v8::Locker locker(isolate);
Isolate::Scope isolate_scope(isolate);
HandleScope handle_scope(isolate);

Local<Context> context = self->cache_->GetContext();
Local<v8::Array> array = self->map_->Get(isolate).As<Map>()->AsArray();

Expand Down Expand Up @@ -82,15 +86,23 @@ - (instancetype)initWithProperties:(std::shared_ptr<Persistent<Value>>)dictionar
}

- (Local<v8::Array>)getProperties {
v8::Locker locker(self->isolate_);
Isolate::Scope isolate_scope(self->isolate_);
EscapableHandleScope handle_scope(self->isolate_);

Local<Context> context = self->cache_->GetContext();
Local<v8::Array> properties;
Local<Object> dictionary = self->dictionary_->Get(self->isolate_).As<Object>();
tns::Assert(dictionary->GetOwnPropertyNames(context).ToLocal(&properties), self->isolate_);
return properties;
return handle_scope.Escape(properties);
}

- (id)nextObject {
Isolate* isolate = self->isolate_;
v8::Locker locker(isolate);
Isolate::Scope isolate_scope(isolate);
HandleScope handle_scope(isolate);

Local<Context> context = self->cache_->GetContext();
Local<v8::Array> properties = [self getProperties];
if (self->index_ < properties->Length()) {
Expand All @@ -107,6 +119,10 @@ - (id)nextObject {

- (NSArray*)allObjects {
Isolate* isolate = self->isolate_;
v8::Locker locker(isolate);
Isolate::Scope isolate_scope(isolate);
HandleScope handle_scope(isolate);

Local<Context> context = self->cache_->GetContext();
NSMutableArray* array = [NSMutableArray array];
Local<v8::Array> properties = [self getProperties];
Expand Down Expand Up @@ -146,6 +162,10 @@ - (instancetype)initWithJSObject:(Local<Object>)jsObject isolate:(Isolate*)isola
}

- (NSUInteger)count {
v8::Locker locker(self->isolate_);
Isolate::Scope isolate_scope(self->isolate_);
HandleScope handle_scope(self->isolate_);

Local<Object> obj = self->object_->Get(self->isolate_).As<Object>();

if (obj->IsMap()) {
Expand All @@ -163,6 +183,10 @@ - (NSUInteger)count {

- (id)objectForKey:(id)aKey {
Isolate* isolate = self->isolate_;
v8::Locker locker(isolate);
Isolate::Scope isolate_scope(isolate);
HandleScope handle_scope(isolate);

Local<Context> context = self->cache_->GetContext();
Local<Object> obj = self->object_->Get(self->isolate_).As<Object>();

Expand Down Expand Up @@ -194,6 +218,10 @@ - (id)objectForKey:(id)aKey {
}

- (NSEnumerator*)keyEnumerator {
v8::Locker locker(self->isolate_);
Isolate::Scope isolate_scope(self->isolate_);
HandleScope handle_scope(self->isolate_);

Local<Value> obj = self->object_->Get(self->isolate_);

if (obj->IsMap()) {
Expand Down
6 changes: 3 additions & 3 deletions NativeScript/runtime/PromiseProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ void PromiseProxy::Init(v8::Local<v8::Context> context) {
return new Proxy(promise, {
get: function(target, name) {
let orig = target[name];
if (name === "then" || name === "catch") {
if (name === "then" || name === "catch" || name === "finally") {
return orig.bind(target);
}
return function(x) {
return typeof orig === 'function' ? function(x) {
CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, orig.bind(target, x));
CFRunLoopWakeUp(runloop);
return target;
};
} : orig;
}
});
}
Expand Down