Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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* function_template_info) { | |
| 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 return global_template->constructor() == function_template_info; | |
| 6562 } | |
| 6563 | |
| 6544 bool FunctionTemplate::HasInstance(v8::Local<v8::Value> value) { | 6564 bool FunctionTemplate::HasInstance(v8::Local<v8::Value> value) { |
| 6545 auto self = Utils::OpenHandle(this); | 6565 auto self = Utils::OpenHandle(this); |
| 6546 auto obj = Utils::OpenHandle(*value); | 6566 auto obj = Utils::OpenHandle(*value); |
| 6547 if (obj->IsJSObject() && self->IsTemplateFor(i::JSObject::cast(*obj))) { | 6567 if (obj->IsJSObject() && self->IsTemplateFor(i::JSObject::cast(*obj))) { |
| 6548 return true; | 6568 return true; |
| 6549 } | 6569 } |
| 6550 if (obj->IsJSGlobalProxy()) { | 6570 if (obj->IsJSGlobalProxy()) { |
| 6551 // If it's a global proxy object, then test with the global object. | 6571 auto* global_proxy = i::JSGlobalProxy::cast(*obj); |
| 6552 i::PrototypeIterator iter(i::JSObject::cast(*obj)->map()); | 6572 // For global proxies, check the constructor's prototype. Remote global |
| 6573 // proxies have no associated global object, so trying to find an instance | |
| 6574 // of this template in the prototype chain will fail. | |
| 6575 if (HasInstanceInGlobalProxy(global_proxy, *self)) return true; | |
| 6576 | |
| 6577 // 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
| |
| 6578 i::PrototypeIterator iter(global_proxy->map()); | |
| 6553 if (iter.IsAtEnd()) return false; | 6579 if (iter.IsAtEnd()) return false; |
| 6554 return self->IsTemplateFor(iter.GetCurrent<i::JSGlobalObject>()); | 6580 return self->IsTemplateFor(iter.GetCurrent<i::JSGlobalObject>()); |
| 6555 } | 6581 } |
| 6556 return false; | 6582 return false; |
| 6557 } | 6583 } |
| 6558 | 6584 |
| 6559 | 6585 |
| 6560 Local<External> v8::External::New(Isolate* isolate, void* value) { | 6586 Local<External> v8::External::New(Isolate* isolate, void* value) { |
| 6561 STATIC_ASSERT(sizeof(value) == sizeof(i::Address)); | 6587 STATIC_ASSERT(sizeof(value) == sizeof(i::Address)); |
| 6562 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 6588 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| (...skipping 3605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10168 Address callback_address = | 10194 Address callback_address = |
| 10169 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 10195 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 10170 VMState<EXTERNAL> state(isolate); | 10196 VMState<EXTERNAL> state(isolate); |
| 10171 ExternalCallbackScope call_scope(isolate, callback_address); | 10197 ExternalCallbackScope call_scope(isolate, callback_address); |
| 10172 callback(info); | 10198 callback(info); |
| 10173 } | 10199 } |
| 10174 | 10200 |
| 10175 | 10201 |
| 10176 } // namespace internal | 10202 } // namespace internal |
| 10177 } // namespace v8 | 10203 } // namespace v8 |
| OLD | NEW |