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 4476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4487 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); | 4487 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
4488 return Just(true); | 4488 return Just(true); |
4489 } | 4489 } |
4490 | 4490 |
4491 | 4491 |
4492 bool v8::Object::SetPrototype(Local<Value> value) { | 4492 bool v8::Object::SetPrototype(Local<Value> value) { |
4493 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); | 4493 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
4494 return SetPrototype(context, value).FromMaybe(false); | 4494 return SetPrototype(context, value).FromMaybe(false); |
4495 } | 4495 } |
4496 | 4496 |
4497 static bool HasInstanceInGlobalProxy(i::JSGlobalProxy* global_proxy, | |
4498 i::FunctionTemplateInfo* target_template) { | |
4499 auto* constructor_object = global_proxy->map()->GetConstructor(); | |
4500 if (!constructor_object->IsJSFunction()) return false; | |
4501 | |
4502 auto* constructor = i::JSFunction::cast(constructor_object); | |
4503 if (!constructor->shared()->function_data()->IsFunctionTemplateInfo()) | |
4504 return false; | |
4505 | |
4506 auto* proxy_constructor_template = | |
4507 i::FunctionTemplateInfo::cast(constructor->shared()->function_data()); | |
4508 if (!proxy_constructor_template->prototype_template()->IsObjectTemplateInfo()) | |
4509 return false; | |
4510 | |
4511 auto* global_template = i::ObjectTemplateInfo::cast( | |
4512 proxy_constructor_template->prototype_template()); | |
4513 // Iterate through the chain of inheriting function templates to | |
4514 // see if the required one occurs. | |
4515 for (i::Object* type = global_template->constructor(); | |
4516 type->IsFunctionTemplateInfo(); | |
4517 type = i::FunctionTemplateInfo::cast(type)->parent_template()) { | |
4518 if (type == target_template) return true; | |
4519 } | |
4520 // Didn't find the required type in the inheritance chain. | |
4521 return false; | |
4522 } | |
4523 | |
4524 Local<Object> v8::Object::FindInstanceInPrototypeChain( | 4497 Local<Object> v8::Object::FindInstanceInPrototypeChain( |
4525 v8::Local<FunctionTemplate> tmpl) { | 4498 v8::Local<FunctionTemplate> tmpl) { |
4526 auto self = Utils::OpenHandle(this); | 4499 auto self = Utils::OpenHandle(this); |
4527 auto isolate = self->GetIsolate(); | 4500 auto isolate = self->GetIsolate(); |
4528 i::PrototypeIterator iter(isolate, *self, i::kStartAtReceiver); | 4501 i::PrototypeIterator iter(isolate, *self, i::kStartAtReceiver); |
4529 auto tmpl_info = *Utils::OpenHandle(*tmpl); | 4502 auto tmpl_info = *Utils::OpenHandle(*tmpl); |
4530 while (!tmpl_info->IsTemplateFor(iter.GetCurrent<i::JSObject>())) { | 4503 while (!tmpl_info->IsTemplateFor(iter.GetCurrent<i::JSObject>())) { |
4531 iter.Advance(); | 4504 iter.Advance(); |
4532 if (iter.IsAtEnd()) { | 4505 if (iter.IsAtEnd()) return Local<Object>(); |
4533 // Normally, a standard prototype walk is sufficient; however, global | |
4534 // proxies aren't directly constructed with the supplied template. | |
4535 // Normally, this is not a problem, because the prototype chain includes | |
4536 // the global object; however, a remote context has no global object. | |
4537 if (self->IsJSGlobalProxy() && | |
4538 HasInstanceInGlobalProxy(i::JSGlobalProxy::cast(*self), tmpl_info)) | |
4539 return Utils::ToLocal(self); | |
4540 return Local<Object>(); | |
4541 } | |
4542 if (!iter.GetCurrent()->IsJSObject()) return Local<Object>(); | 4506 if (!iter.GetCurrent()->IsJSObject()) return Local<Object>(); |
4543 } | 4507 } |
4544 // IsTemplateFor() ensures that iter.GetCurrent() can't be a Proxy here. | 4508 // IsTemplateFor() ensures that iter.GetCurrent() can't be a Proxy here. |
4545 return Utils::ToLocal(i::handle(iter.GetCurrent<i::JSObject>(), isolate)); | 4509 return Utils::ToLocal(i::handle(iter.GetCurrent<i::JSObject>(), isolate)); |
4546 } | 4510 } |
4547 | 4511 |
4548 MaybeLocal<Array> v8::Object::GetPropertyNames(Local<Context> context) { | 4512 MaybeLocal<Array> v8::Object::GetPropertyNames(Local<Context> context) { |
4549 return GetPropertyNames( | 4513 return GetPropertyNames( |
4550 context, v8::KeyCollectionMode::kIncludePrototypes, | 4514 context, v8::KeyCollectionMode::kIncludePrototypes, |
4551 static_cast<v8::PropertyFilter>(ONLY_ENUMERABLE | SKIP_SYMBOLS), | 4515 static_cast<v8::PropertyFilter>(ONLY_ENUMERABLE | SKIP_SYMBOLS), |
(...skipping 2046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6598 return Utils::ToLocal(scope.CloseAndEscape(object)); | 6562 return Utils::ToLocal(scope.CloseAndEscape(object)); |
6599 } | 6563 } |
6600 | 6564 |
6601 bool FunctionTemplate::HasInstance(v8::Local<v8::Value> value) { | 6565 bool FunctionTemplate::HasInstance(v8::Local<v8::Value> value) { |
6602 auto self = Utils::OpenHandle(this); | 6566 auto self = Utils::OpenHandle(this); |
6603 auto obj = Utils::OpenHandle(*value); | 6567 auto obj = Utils::OpenHandle(*value); |
6604 if (obj->IsJSObject() && self->IsTemplateFor(i::JSObject::cast(*obj))) { | 6568 if (obj->IsJSObject() && self->IsTemplateFor(i::JSObject::cast(*obj))) { |
6605 return true; | 6569 return true; |
6606 } | 6570 } |
6607 if (obj->IsJSGlobalProxy()) { | 6571 if (obj->IsJSGlobalProxy()) { |
6608 auto* global_proxy = i::JSGlobalProxy::cast(*obj); | 6572 // If it's a global proxy object, then test with the global object. |
6609 // For global proxies, check the constructor's prototype instead. Remote | 6573 i::PrototypeIterator iter(i::JSObject::cast(*obj)->map()); |
6610 // global proxies have no global object to perform instance checks on, but | 6574 if (iter.IsAtEnd()) return false; |
jochen (gone - plz use gerrit)
2017/02/22 09:03:14
how can this happen? Shouldn't there now always be
dcheng
2017/02/22 09:29:53
I was reverting this to the original version, but
| |
6611 // the constructor's prototype's constructor corresponds to the original | 6575 return self->IsTemplateFor(iter.GetCurrent<i::JSObject>()); |
6612 // template used to create the context. | |
6613 return HasInstanceInGlobalProxy(global_proxy, *self); | |
6614 } | 6576 } |
6615 return false; | 6577 return false; |
6616 } | 6578 } |
6617 | 6579 |
6618 | 6580 |
6619 Local<External> v8::External::New(Isolate* isolate, void* value) { | 6581 Local<External> v8::External::New(Isolate* isolate, void* value) { |
6620 STATIC_ASSERT(sizeof(value) == sizeof(i::Address)); | 6582 STATIC_ASSERT(sizeof(value) == sizeof(i::Address)); |
6621 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 6583 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
6622 LOG_API(i_isolate, External, New); | 6584 LOG_API(i_isolate, External, New); |
6623 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); | 6585 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); |
(...skipping 3656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10280 Address callback_address = | 10242 Address callback_address = |
10281 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 10243 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
10282 VMState<EXTERNAL> state(isolate); | 10244 VMState<EXTERNAL> state(isolate); |
10283 ExternalCallbackScope call_scope(isolate, callback_address); | 10245 ExternalCallbackScope call_scope(isolate, callback_address); |
10284 callback(info); | 10246 callback(info); |
10285 } | 10247 } |
10286 | 10248 |
10287 | 10249 |
10288 } // namespace internal | 10250 } // namespace internal |
10289 } // namespace v8 | 10251 } // namespace v8 |
OLD | NEW |