Skip to content

Commit 22173da

Browse files
author
Ben Delaney
authored
fix: DictionaryAdapter missing handle scopes and locks (#90)
1 parent d56a260 commit 22173da

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

NativeScript/runtime/DictionaryAdapter.mm

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ - (instancetype)initWithMap:(std::shared_ptr<Persistent<Value>>)map isolate:(Iso
3434

3535
- (id)nextObject {
3636
Isolate* isolate = self->isolate_;
37+
v8::Locker locker(isolate);
38+
Isolate::Scope isolate_scope(isolate);
39+
HandleScope handle_scope(isolate);
40+
3741
Local<Context> context = self->cache_->GetContext();
3842
Local<v8::Array> array = self->map_->Get(isolate).As<Map>()->AsArray();
3943

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

8488
- (Local<v8::Array>)getProperties {
89+
v8::Locker locker(self->isolate_);
90+
Isolate::Scope isolate_scope(self->isolate_);
91+
EscapableHandleScope handle_scope(self->isolate_);
92+
8593
Local<Context> context = self->cache_->GetContext();
8694
Local<v8::Array> properties;
8795
Local<Object> dictionary = self->dictionary_->Get(self->isolate_).As<Object>();
8896
tns::Assert(dictionary->GetOwnPropertyNames(context).ToLocal(&properties), self->isolate_);
89-
return properties;
97+
return handle_scope.Escape(properties);
9098
}
9199

92100
- (id)nextObject {
93101
Isolate* isolate = self->isolate_;
102+
v8::Locker locker(isolate);
103+
Isolate::Scope isolate_scope(isolate);
104+
HandleScope handle_scope(isolate);
105+
94106
Local<Context> context = self->cache_->GetContext();
95107
Local<v8::Array> properties = [self getProperties];
96108
if (self->index_ < properties->Length()) {
@@ -107,6 +119,10 @@ - (id)nextObject {
107119

108120
- (NSArray*)allObjects {
109121
Isolate* isolate = self->isolate_;
122+
v8::Locker locker(isolate);
123+
Isolate::Scope isolate_scope(isolate);
124+
HandleScope handle_scope(isolate);
125+
110126
Local<Context> context = self->cache_->GetContext();
111127
NSMutableArray* array = [NSMutableArray array];
112128
Local<v8::Array> properties = [self getProperties];
@@ -146,6 +162,10 @@ - (instancetype)initWithJSObject:(Local<Object>)jsObject isolate:(Isolate*)isola
146162
}
147163

148164
- (NSUInteger)count {
165+
v8::Locker locker(self->isolate_);
166+
Isolate::Scope isolate_scope(self->isolate_);
167+
HandleScope handle_scope(self->isolate_);
168+
149169
Local<Object> obj = self->object_->Get(self->isolate_).As<Object>();
150170

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

164184
- (id)objectForKey:(id)aKey {
165185
Isolate* isolate = self->isolate_;
186+
v8::Locker locker(isolate);
187+
Isolate::Scope isolate_scope(isolate);
188+
HandleScope handle_scope(isolate);
189+
166190
Local<Context> context = self->cache_->GetContext();
167191
Local<Object> obj = self->object_->Get(self->isolate_).As<Object>();
168192

@@ -194,6 +218,10 @@ - (id)objectForKey:(id)aKey {
194218
}
195219

196220
- (NSEnumerator*)keyEnumerator {
221+
v8::Locker locker(self->isolate_);
222+
Isolate::Scope isolate_scope(self->isolate_);
223+
HandleScope handle_scope(self->isolate_);
224+
197225
Local<Value> obj = self->object_->Get(self->isolate_);
198226

199227
if (obj->IsMap()) {

NativeScript/runtime/PromiseProxy.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ void PromiseProxy::Init(v8::Local<v8::Context> context) {
2828
return new Proxy(promise, {
2929
get: function(target, name) {
3030
let orig = target[name];
31-
if (name === "then" || name === "catch") {
31+
if (name === "then" || name === "catch" || name === "finally") {
3232
return orig.bind(target);
3333
}
34-
return function(x) {
34+
return typeof orig === 'function' ? function(x) {
3535
CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, orig.bind(target, x));
3636
CFRunLoopWakeUp(runloop);
3737
return target;
38-
};
38+
} : orig;
3939
}
4040
});
4141
}

0 commit comments

Comments
 (0)