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

Side by Side Diff: src/api.cc

Issue 2677653002: Fix receiver checks for v8::Function on a remote context. (Closed)
Patch Set: Fix comments 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 | src/bootstrapper.cc » ('j') | src/bootstrapper.cc » ('J')
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 4454 matching lines...) Expand 10 before | Expand all | Expand 10 after
4465 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); 4465 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
4466 return Just(true); 4466 return Just(true);
4467 } 4467 }
4468 4468
4469 4469
4470 bool v8::Object::SetPrototype(Local<Value> value) { 4470 bool v8::Object::SetPrototype(Local<Value> value) {
4471 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); 4471 auto context = ContextFromHeapObject(Utils::OpenHandle(this));
4472 return SetPrototype(context, value).FromMaybe(false); 4472 return SetPrototype(context, value).FromMaybe(false);
4473 } 4473 }
4474 4474
4475 static bool HasInstanceInGlobalProxy(i::JSGlobalProxy* global_proxy,
4476 i::FunctionTemplateInfo* target_template) {
4477 auto* constructor_object = global_proxy->map()->GetConstructor();
4478 if (!constructor_object->IsJSFunction()) return false;
4479
4480 auto* constructor = i::JSFunction::cast(constructor_object);
4481 if (!constructor->shared()->function_data()->IsFunctionTemplateInfo())
4482 return false;
4483
4484 auto* proxy_constructor_template =
4485 i::FunctionTemplateInfo::cast(constructor->shared()->function_data());
4486 if (!proxy_constructor_template->prototype_template()->IsObjectTemplateInfo())
4487 return false;
4488
4489 auto* global_template = i::ObjectTemplateInfo::cast(
4490 proxy_constructor_template->prototype_template());
4491 // Iterate through the chain of inheriting function templates to
4492 // see if the required one occurs.
4493 for (i::Object* type = global_template->constructor();
4494 type->IsFunctionTemplateInfo();
4495 type = i::FunctionTemplateInfo::cast(type)->parent_template()) {
4496 if (type == target_template) return true;
4497 }
4498 // Didn't find the required type in the inheritance chain.
4499 return false;
4500 }
4501
4502 Local<Object> v8::Object::FindInstanceInPrototypeChain( 4475 Local<Object> v8::Object::FindInstanceInPrototypeChain(
4503 v8::Local<FunctionTemplate> tmpl) { 4476 v8::Local<FunctionTemplate> tmpl) {
4504 auto self = Utils::OpenHandle(this); 4477 auto self = Utils::OpenHandle(this);
4505 auto isolate = self->GetIsolate(); 4478 auto isolate = self->GetIsolate();
4506 i::PrototypeIterator iter(isolate, *self, i::kStartAtReceiver); 4479 i::PrototypeIterator iter(isolate, *self, i::kStartAtReceiver);
4507 auto tmpl_info = *Utils::OpenHandle(*tmpl); 4480 auto tmpl_info = *Utils::OpenHandle(*tmpl);
4508 while (!tmpl_info->IsTemplateFor(iter.GetCurrent<i::JSObject>())) { 4481 while (!tmpl_info->IsTemplateFor(iter.GetCurrent<i::JSObject>())) {
4509 iter.Advance(); 4482 iter.Advance();
4510 if (iter.IsAtEnd()) { 4483 if (iter.IsAtEnd()) return Local<Object>();
4511 // Normally, a standard prototype walk is sufficient; however, global
4512 // proxies aren't directly constructed with the supplied template.
4513 // Normally, this is not a problem, because the prototype chain includes
4514 // the global object; however, a remote context has no global object.
4515 if (self->IsJSGlobalProxy() &&
4516 HasInstanceInGlobalProxy(i::JSGlobalProxy::cast(*self), tmpl_info))
4517 return Utils::ToLocal(self);
4518 return Local<Object>();
4519 }
4520 if (!iter.GetCurrent()->IsJSObject()) return Local<Object>(); 4484 if (!iter.GetCurrent()->IsJSObject()) return Local<Object>();
4521 } 4485 }
4522 // IsTemplateFor() ensures that iter.GetCurrent() can't be a Proxy here. 4486 // IsTemplateFor() ensures that iter.GetCurrent() can't be a Proxy here.
4523 return Utils::ToLocal(i::handle(iter.GetCurrent<i::JSObject>(), isolate)); 4487 return Utils::ToLocal(i::handle(iter.GetCurrent<i::JSObject>(), isolate));
4524 } 4488 }
4525 4489
4526 MaybeLocal<Array> v8::Object::GetPropertyNames(Local<Context> context) { 4490 MaybeLocal<Array> v8::Object::GetPropertyNames(Local<Context> context) {
4527 return GetPropertyNames( 4491 return GetPropertyNames(
4528 context, v8::KeyCollectionMode::kIncludePrototypes, 4492 context, v8::KeyCollectionMode::kIncludePrototypes,
4529 static_cast<v8::PropertyFilter>(ONLY_ENUMERABLE | SKIP_SYMBOLS), 4493 static_cast<v8::PropertyFilter>(ONLY_ENUMERABLE | SKIP_SYMBOLS),
(...skipping 2046 matching lines...) Expand 10 before | Expand all | Expand 10 after
6576 return Utils::ToLocal(scope.CloseAndEscape(object)); 6540 return Utils::ToLocal(scope.CloseAndEscape(object));
6577 } 6541 }
6578 6542
6579 bool FunctionTemplate::HasInstance(v8::Local<v8::Value> value) { 6543 bool FunctionTemplate::HasInstance(v8::Local<v8::Value> value) {
6580 auto self = Utils::OpenHandle(this); 6544 auto self = Utils::OpenHandle(this);
6581 auto obj = Utils::OpenHandle(*value); 6545 auto obj = Utils::OpenHandle(*value);
6582 if (obj->IsJSObject() && self->IsTemplateFor(i::JSObject::cast(*obj))) { 6546 if (obj->IsJSObject() && self->IsTemplateFor(i::JSObject::cast(*obj))) {
6583 return true; 6547 return true;
6584 } 6548 }
6585 if (obj->IsJSGlobalProxy()) { 6549 if (obj->IsJSGlobalProxy()) {
6586 auto* global_proxy = i::JSGlobalProxy::cast(*obj); 6550 // If it's a global proxy object, then test with the global object.
6587 // For global proxies, check the constructor's prototype instead. Remote 6551 i::PrototypeIterator iter(i::JSObject::cast(*obj)->map());
6588 // global proxies have no global object to perform instance checks on, but 6552 if (iter.IsAtEnd()) return false;
6589 // the constructor's prototype's constructor corresponds to the original 6553 return self->IsTemplateFor(iter.GetCurrent<i::JSGlobalObject>());
6590 // template used to create the context.
6591 return HasInstanceInGlobalProxy(global_proxy, *self);
6592 } 6554 }
6593 return false; 6555 return false;
6594 } 6556 }
6595 6557
6596 6558
6597 Local<External> v8::External::New(Isolate* isolate, void* value) { 6559 Local<External> v8::External::New(Isolate* isolate, void* value) {
6598 STATIC_ASSERT(sizeof(value) == sizeof(i::Address)); 6560 STATIC_ASSERT(sizeof(value) == sizeof(i::Address));
6599 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 6561 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6600 LOG_API(i_isolate, External, New); 6562 LOG_API(i_isolate, External, New);
6601 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); 6563 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
(...skipping 3603 matching lines...) Expand 10 before | Expand all | Expand 10 after
10205 Address callback_address = 10167 Address callback_address =
10206 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 10168 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
10207 VMState<EXTERNAL> state(isolate); 10169 VMState<EXTERNAL> state(isolate);
10208 ExternalCallbackScope call_scope(isolate, callback_address); 10170 ExternalCallbackScope call_scope(isolate, callback_address);
10209 callback(info); 10171 callback(info);
10210 } 10172 }
10211 10173
10212 10174
10213 } // namespace internal 10175 } // namespace internal
10214 } // namespace v8 10176 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/bootstrapper.cc » ('j') | src/bootstrapper.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698