Chromium Code Reviews| 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>()); |
| } |