Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(904)

Unified Diff: src/api.cc

Issue 2698683003: Make FunctionTemplate::HasInstance checks work with remote contexts. (Closed)
Patch Set: Fix format. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/unittests/api/remote-object-unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 3f73ab78de354ef5611b64e8506d453933267f29..50a488ad33054d183a012cca94dc290525f2d058 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -6541,6 +6541,26 @@ MaybeLocal<v8::Object> FunctionTemplate::NewRemoteInstance() {
return Utils::ToLocal(scope.CloseAndEscape(object));
}
+static bool HasInstanceInGlobalProxy(
+ i::JSGlobalProxy* global_proxy,
+ i::FunctionTemplateInfo* function_template_info) {
+ auto* constructor_object = global_proxy->map()->GetConstructor();
+ if (!constructor_object->IsJSFunction()) return false;
+
+ auto* constructor = i::JSFunction::cast(constructor_object);
+ if (!constructor->shared()->function_data()->IsFunctionTemplateInfo())
+ return false;
+
+ auto* proxy_constructor_template =
+ i::FunctionTemplateInfo::cast(constructor->shared()->function_data());
+ if (!proxy_constructor_template->prototype_template()->IsObjectTemplateInfo())
+ return false;
+
+ auto* global_template = i::ObjectTemplateInfo::cast(
+ proxy_constructor_template->prototype_template());
+ return global_template->constructor() == function_template_info;
+}
+
bool FunctionTemplate::HasInstance(v8::Local<v8::Value> value) {
auto self = Utils::OpenHandle(this);
auto obj = Utils::OpenHandle(*value);
@@ -6548,8 +6568,14 @@ bool FunctionTemplate::HasInstance(v8::Local<v8::Value> value) {
return true;
}
if (obj->IsJSGlobalProxy()) {
- // If it's a global proxy object, then test with the global object.
- i::PrototypeIterator iter(i::JSObject::cast(*obj)->map());
+ auto* global_proxy = i::JSGlobalProxy::cast(*obj);
+ // For global proxies, check the constructor's prototype. Remote global
+ // proxies have no associated global object, so trying to find an instance
+ // of this template in the prototype chain will fail.
+ if (HasInstanceInGlobalProxy(global_proxy, *self)) return true;
+
+ // Otherwise, fallback to testing the prototype chain.
dcheng 2017/02/16 07:12:45 I tried to remove this section, but it makes a bun
+ i::PrototypeIterator iter(global_proxy->map());
if (iter.IsAtEnd()) return false;
return self->IsTemplateFor(iter.GetCurrent<i::JSGlobalObject>());
}
« no previous file with comments | « no previous file | test/unittests/api/remote-object-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698