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

Side by Side Diff: src/api.cc

Issue 2698683003: Make FunctionTemplate::HasInstance checks work with remote contexts. (Closed)
Patch Set: Handle parent templates 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 unified diff | Download patch
« no previous file with comments | « no previous file | test/unittests/api/remote-object-unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/api.h" 5 #include "src/api.h"
6 6
7 #include <string.h> // For memcpy, strlen. 7 #include <string.h> // For memcpy, strlen.
8 #ifdef V8_USE_ADDRESS_SANITIZER 8 #ifdef V8_USE_ADDRESS_SANITIZER
9 #include <sanitizer/asan_interface.h> 9 #include <sanitizer/asan_interface.h>
10 #endif // V8_USE_ADDRESS_SANITIZER 10 #endif // V8_USE_ADDRESS_SANITIZER
(...skipping 6523 matching lines...) Expand 10 before | Expand all | Expand 10 after
6534 Utils::OpenHandle(*InstanceTemplate())) 6534 Utils::OpenHandle(*InstanceTemplate()))
6535 .ToHandle(&object)) { 6535 .ToHandle(&object)) {
6536 if (isolate->has_pending_exception()) { 6536 if (isolate->has_pending_exception()) {
6537 isolate->OptionalRescheduleException(true); 6537 isolate->OptionalRescheduleException(true);
6538 } 6538 }
6539 return MaybeLocal<Object>(); 6539 return MaybeLocal<Object>();
6540 } 6540 }
6541 return Utils::ToLocal(scope.CloseAndEscape(object)); 6541 return Utils::ToLocal(scope.CloseAndEscape(object));
6542 } 6542 }
6543 6543
6544 static bool HasInstanceInGlobalProxy(
6545 i::JSGlobalProxy* global_proxy,
6546 i::FunctionTemplateInfo* target_template) {
6547 auto* constructor_object = global_proxy->map()->GetConstructor();
6548 if (!constructor_object->IsJSFunction()) return false;
6549
6550 auto* constructor = i::JSFunction::cast(constructor_object);
6551 if (!constructor->shared()->function_data()->IsFunctionTemplateInfo())
6552 return false;
6553
6554 auto* proxy_constructor_template =
6555 i::FunctionTemplateInfo::cast(constructor->shared()->function_data());
6556 if (!proxy_constructor_template->prototype_template()->IsObjectTemplateInfo())
6557 return false;
6558
6559 auto* global_template = i::ObjectTemplateInfo::cast(
6560 proxy_constructor_template->prototype_template());
6561 // Iterate through the chain of inheriting function templates to
6562 // see if the required one occurs.
6563 for (i::Object* type = global_template->constructor();
6564 type->IsFunctionTemplateInfo();
6565 type = i::FunctionTemplateInfo::cast(type)->parent_template()) {
6566 if (type == target_template) return true;
6567 }
6568 // Didn't find the required type in the inheritance chain.
6569 return false;
6570 }
6571
6544 bool FunctionTemplate::HasInstance(v8::Local<v8::Value> value) { 6572 bool FunctionTemplate::HasInstance(v8::Local<v8::Value> value) {
6545 auto self = Utils::OpenHandle(this); 6573 auto self = Utils::OpenHandle(this);
6546 auto obj = Utils::OpenHandle(*value); 6574 auto obj = Utils::OpenHandle(*value);
6547 if (obj->IsJSObject() && self->IsTemplateFor(i::JSObject::cast(*obj))) { 6575 if (obj->IsJSObject() && self->IsTemplateFor(i::JSObject::cast(*obj))) {
6548 return true; 6576 return true;
6549 } 6577 }
6550 if (obj->IsJSGlobalProxy()) { 6578 if (obj->IsJSGlobalProxy()) {
6551 // If it's a global proxy object, then test with the global object. 6579 auto* global_proxy = i::JSGlobalProxy::cast(*obj);
6552 i::PrototypeIterator iter(i::JSObject::cast(*obj)->map()); 6580 // For global proxies, check the constructor's prototype instead. Remote
6553 if (iter.IsAtEnd()) return false; 6581 // global proxies have no global object to perform instance checks on, but
6554 return self->IsTemplateFor(iter.GetCurrent<i::JSGlobalObject>()); 6582 // the constructor's prototype's constructor corresponds to the original
dcheng 2017/02/16 08:00:12 I was forgetting to walk the parent templates; aft
6583 // template used to create the context.
6584 return HasInstanceInGlobalProxy(global_proxy, *self);
6555 } 6585 }
6556 return false; 6586 return false;
6557 } 6587 }
6558 6588
6559 6589
6560 Local<External> v8::External::New(Isolate* isolate, void* value) { 6590 Local<External> v8::External::New(Isolate* isolate, void* value) {
6561 STATIC_ASSERT(sizeof(value) == sizeof(i::Address)); 6591 STATIC_ASSERT(sizeof(value) == sizeof(i::Address));
6562 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 6592 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6563 LOG_API(i_isolate, External, New); 6593 LOG_API(i_isolate, External, New);
6564 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); 6594 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
(...skipping 3603 matching lines...) Expand 10 before | Expand all | Expand 10 after
10168 Address callback_address = 10198 Address callback_address =
10169 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 10199 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
10170 VMState<EXTERNAL> state(isolate); 10200 VMState<EXTERNAL> state(isolate);
10171 ExternalCallbackScope call_scope(isolate, callback_address); 10201 ExternalCallbackScope call_scope(isolate, callback_address);
10172 callback(info); 10202 callback(info);
10173 } 10203 }
10174 10204
10175 10205
10176 } // namespace internal 10206 } // namespace internal
10177 } // namespace v8 10207 } // namespace v8
OLDNEW
« 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