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

Side by Side Diff: src/objects.cc

Issue 2311873002: [api] Add interceptor for getOwnPropertyDescriptor(). (Closed)
Patch Set: Crash instead of exception on invalid descriptor. Created 4 years, 3 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 | « src/objects.h ('k') | src/objects-inl.h » ('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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/objects.h" 5 #include "src/objects.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <iomanip> 8 #include <iomanip>
9 #include <memory> 9 #include <memory>
10 #include <sstream> 10 #include <sstream>
(...skipping 7329 matching lines...) Expand 10 before | Expand all | Expand 10 after
7340 Handle<Object> key, 7340 Handle<Object> key,
7341 PropertyDescriptor* desc) { 7341 PropertyDescriptor* desc) {
7342 bool success = false; 7342 bool success = false;
7343 DCHECK(key->IsName() || key->IsNumber()); // |key| is a PropertyKey... 7343 DCHECK(key->IsName() || key->IsNumber()); // |key| is a PropertyKey...
7344 LookupIterator it = LookupIterator::PropertyOrElement( 7344 LookupIterator it = LookupIterator::PropertyOrElement(
7345 isolate, object, key, &success, LookupIterator::OWN); 7345 isolate, object, key, &success, LookupIterator::OWN);
7346 DCHECK(success); // ...so creating a LookupIterator can't fail. 7346 DCHECK(success); // ...so creating a LookupIterator can't fail.
7347 return GetOwnPropertyDescriptor(&it, desc); 7347 return GetOwnPropertyDescriptor(&it, desc);
7348 } 7348 }
7349 7349
7350 namespace {
7351
7352 Maybe<bool> GetPropertyDescriptorWithInterceptor(LookupIterator* it,
7353 PropertyDescriptor* desc) {
7354 if (it->state() == LookupIterator::INTERCEPTOR) {
7355 Isolate* isolate = it->isolate();
7356 Handle<InterceptorInfo> interceptor = it->GetInterceptor();
7357 if (!interceptor->descriptor()->IsUndefined(isolate)) {
7358 Handle<Object> result;
7359 Handle<JSObject> holder = it->GetHolder<JSObject>();
7360
7361 Handle<Object> receiver = it->GetReceiver();
7362 if (!receiver->IsJSReceiver()) {
7363 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
7364 isolate, receiver, Object::ConvertReceiver(isolate, receiver),
7365 Nothing<bool>());
7366 }
7367
7368 PropertyCallbackArguments args(isolate, interceptor->data(), *receiver,
7369 *holder, Object::DONT_THROW);
7370 if (it->IsElement()) {
7371 uint32_t index = it->index();
7372 v8::IndexedPropertyDescriptorCallback descriptorCallback =
7373 v8::ToCData<v8::IndexedPropertyDescriptorCallback>(
7374 interceptor->descriptor());
7375
7376 result = args.Call(descriptorCallback, index);
7377 } else {
7378 Handle<Name> name = it->name();
7379 DCHECK(!name->IsPrivate());
7380 v8::GenericNamedPropertyDescriptorCallback descriptorCallback =
7381 v8::ToCData<v8::GenericNamedPropertyDescriptorCallback>(
7382 interceptor->descriptor());
7383 result = args.Call(descriptorCallback, name);
7384 }
7385 if (!result.is_null()) {
7386 // Request successfully intercepted, try to set the property
7387 // descriptor.
7388 Utils::ApiCheck(
7389 PropertyDescriptor::ToPropertyDescriptor(isolate, result, desc),
7390 it->IsElement() ? "v8::IndexedPropertyDescriptorCallback"
7391 : "v8::NamedPropertyDescriptorCallback",
7392 "Invalid property descriptor.");
7393
7394 return Just(true);
7395 }
7396 }
7397 }
7398 return Just(false);
7399 }
7400 } // namespace
7350 7401
7351 // ES6 9.1.5.1 7402 // ES6 9.1.5.1
7352 // Returns true on success, false if the property didn't exist, nothing if 7403 // Returns true on success, false if the property didn't exist, nothing if
7353 // an exception was thrown. 7404 // an exception was thrown.
7354 // static 7405 // static
7355 Maybe<bool> JSReceiver::GetOwnPropertyDescriptor(LookupIterator* it, 7406 Maybe<bool> JSReceiver::GetOwnPropertyDescriptor(LookupIterator* it,
7356 PropertyDescriptor* desc) { 7407 PropertyDescriptor* desc) {
7357 Isolate* isolate = it->isolate(); 7408 Isolate* isolate = it->isolate();
7358 // "Virtual" dispatch. 7409 // "Virtual" dispatch.
7359 if (it->IsFound() && it->GetHolder<JSReceiver>()->IsJSProxy()) { 7410 if (it->IsFound() && it->GetHolder<JSReceiver>()->IsJSProxy()) {
7360 return JSProxy::GetOwnPropertyDescriptor(isolate, it->GetHolder<JSProxy>(), 7411 return JSProxy::GetOwnPropertyDescriptor(isolate, it->GetHolder<JSProxy>(),
7361 it->GetName(), desc); 7412 it->GetName(), desc);
7362 } 7413 }
7363 7414
7415 Maybe<bool> intercepted = GetPropertyDescriptorWithInterceptor(it, desc);
7416 MAYBE_RETURN(intercepted, Nothing<bool>());
7417 if (intercepted.FromJust()) {
7418 return Just(true);
7419 }
7420
7421 // Request was not intercepted, continue as normal.
7364 // 1. (Assert) 7422 // 1. (Assert)
7365 // 2. If O does not have an own property with key P, return undefined. 7423 // 2. If O does not have an own property with key P, return undefined.
7366 Maybe<PropertyAttributes> maybe = JSObject::GetPropertyAttributes(it); 7424 Maybe<PropertyAttributes> maybe = JSObject::GetPropertyAttributes(it);
7367 MAYBE_RETURN(maybe, Nothing<bool>()); 7425 MAYBE_RETURN(maybe, Nothing<bool>());
7368 PropertyAttributes attrs = maybe.FromJust(); 7426 PropertyAttributes attrs = maybe.FromJust();
7369 if (attrs == ABSENT) return Just(false); 7427 if (attrs == ABSENT) return Just(false);
7370 DCHECK(!isolate->has_pending_exception()); 7428 DCHECK(!isolate->has_pending_exception());
7371 7429
7372 // 3. Let D be a newly created Property Descriptor with no fields. 7430 // 3. Let D be a newly created Property Descriptor with no fields.
7373 DCHECK(desc->is_empty()); 7431 DCHECK(desc->is_empty());
(...skipping 12043 matching lines...) Expand 10 before | Expand all | Expand 10 after
19417 for (PrototypeIterator iter(isolate, this, kStartAtReceiver, 19475 for (PrototypeIterator iter(isolate, this, kStartAtReceiver,
19418 PrototypeIterator::END_AT_NULL); 19476 PrototypeIterator::END_AT_NULL);
19419 !iter.IsAtEnd(); iter.AdvanceIgnoringProxies()) { 19477 !iter.IsAtEnd(); iter.AdvanceIgnoringProxies()) {
19420 if (iter.GetCurrent<Object>()->IsJSProxy()) return true; 19478 if (iter.GetCurrent<Object>()->IsJSProxy()) return true;
19421 } 19479 }
19422 return false; 19480 return false;
19423 } 19481 }
19424 19482
19425 } // namespace internal 19483 } // namespace internal
19426 } // namespace v8 19484 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698