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

Unified Diff: src/objects.cc

Issue 467013003: Add interceptor support for symbols (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Updated to filter out non-symbol keys from for-in enumeration Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.h ('k') | src/objects-debug.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index e3c45c4ac6a5ac90e36da322e086dc0f21b18854..7f2b41db13df3dcc6a44885527751c453d0ab4da 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -2787,22 +2787,23 @@ MaybeHandle<Map> Map::TryUpdateInternal(Handle<Map> old_map) {
MaybeHandle<Object> JSObject::SetPropertyWithInterceptor(LookupIterator* it,
Handle<Object> value) {
- // TODO(rossberg): Support symbols in the API.
- if (it->name()->IsSymbol()) return value;
-
- Handle<String> name_string = Handle<String>::cast(it->name());
+ Handle<Name> name = it->name();
Handle<JSObject> holder = it->GetHolder<JSObject>();
Handle<InterceptorInfo> interceptor(holder->GetNamedInterceptor());
- if (interceptor->setter()->IsUndefined()) return MaybeHandle<Object>();
+ if (interceptor->setter()->IsUndefined() ||
+ (name->IsSymbol() && !interceptor->can_intercept_symbols())) {
+ return MaybeHandle<Object>();
+ }
LOG(it->isolate(),
- ApiNamedPropertyAccess("interceptor-named-set", *holder, *name_string));
+ ApiNamedPropertyAccess("interceptor-named-set", *holder, *name));
PropertyCallbackArguments args(it->isolate(), interceptor->data(), *holder,
*holder);
- v8::NamedPropertySetterCallback setter =
- v8::ToCData<v8::NamedPropertySetterCallback>(interceptor->setter());
+ v8::GenericNamedPropertySetterCallback setter =
+ v8::ToCData<v8::GenericNamedPropertySetterCallback>(
+ interceptor->setter());
v8::Handle<v8::Value> result = args.Call(
- setter, v8::Utils::ToLocal(name_string), v8::Utils::ToLocal(value));
+ setter, v8::Utils::ToLocal(name), v8::Utils::ToLocal(value));
RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(it->isolate(), Object);
if (!result.IsEmpty()) return value;
@@ -3936,9 +3937,6 @@ Maybe<PropertyAttributes> JSObject::GetPropertyAttributesWithInterceptor(
Handle<JSObject> holder,
Handle<Object> receiver,
Handle<Name> name) {
- // TODO(rossberg): Support symbols in the API.
- if (name->IsSymbol()) return maybe(ABSENT);
-
Isolate* isolate = holder->GetIsolate();
HandleScope scope(isolate);
@@ -3947,26 +3945,30 @@ Maybe<PropertyAttributes> JSObject::GetPropertyAttributesWithInterceptor(
AssertNoContextChange ncc(isolate);
Handle<InterceptorInfo> interceptor(holder->GetNamedInterceptor());
+ if (name->IsSymbol() && !interceptor->can_intercept_symbols()) {
+ return maybe(ABSENT);
+ }
PropertyCallbackArguments args(
isolate, interceptor->data(), *receiver, *holder);
if (!interceptor->query()->IsUndefined()) {
- v8::NamedPropertyQueryCallback query =
- v8::ToCData<v8::NamedPropertyQueryCallback>(interceptor->query());
+ v8::GenericNamedPropertyQueryCallback query =
+ v8::ToCData<v8::GenericNamedPropertyQueryCallback>(
+ interceptor->query());
LOG(isolate,
ApiNamedPropertyAccess("interceptor-named-has", *holder, *name));
v8::Handle<v8::Integer> result =
- args.Call(query, v8::Utils::ToLocal(Handle<String>::cast(name)));
+ args.Call(query, v8::Utils::ToLocal(name));
if (!result.IsEmpty()) {
DCHECK(result->IsInt32());
return maybe(static_cast<PropertyAttributes>(result->Int32Value()));
}
} else if (!interceptor->getter()->IsUndefined()) {
- v8::NamedPropertyGetterCallback getter =
- v8::ToCData<v8::NamedPropertyGetterCallback>(interceptor->getter());
+ v8::GenericNamedPropertyGetterCallback getter =
+ v8::ToCData<v8::GenericNamedPropertyGetterCallback>(
+ interceptor->getter());
LOG(isolate,
ApiNamedPropertyAccess("interceptor-named-get-has", *holder, *name));
- v8::Handle<v8::Value> result =
- args.Call(getter, v8::Utils::ToLocal(Handle<String>::cast(name)));
+ v8::Handle<v8::Value> result = args.Call(getter, v8::Utils::ToLocal(name));
if (!result.IsEmpty()) return maybe(DONT_ENUM);
}
@@ -4774,20 +4776,20 @@ MaybeHandle<Object> JSObject::DeletePropertyWithInterceptor(
Handle<JSObject> holder, Handle<JSObject> receiver, Handle<Name> name) {
Isolate* isolate = holder->GetIsolate();
- // TODO(rossberg): Support symbols in the API.
- if (name->IsSymbol()) return MaybeHandle<Object>();
-
Handle<InterceptorInfo> interceptor(holder->GetNamedInterceptor());
- if (interceptor->deleter()->IsUndefined()) return MaybeHandle<Object>();
+ if (interceptor->deleter()->IsUndefined() ||
+ (name->IsSymbol() && !interceptor->can_intercept_symbols())) {
+ return MaybeHandle<Object>();
+ }
- v8::NamedPropertyDeleterCallback deleter =
- v8::ToCData<v8::NamedPropertyDeleterCallback>(interceptor->deleter());
+ v8::GenericNamedPropertyDeleterCallback deleter =
+ v8::ToCData<v8::GenericNamedPropertyDeleterCallback>(
+ interceptor->deleter());
LOG(isolate,
ApiNamedPropertyAccess("interceptor-named-delete", *holder, *name));
PropertyCallbackArguments args(isolate, interceptor->data(), *receiver,
*holder);
- v8::Handle<v8::Boolean> result =
- args.Call(deleter, v8::Utils::ToLocal(Handle<String>::cast(name)));
+ v8::Handle<v8::Boolean> result = args.Call(deleter, v8::Utils::ToLocal(name));
RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object);
if (result.IsEmpty()) return MaybeHandle<Object>();
@@ -5893,14 +5895,15 @@ MaybeHandle<FixedArray> JSReceiver::GetKeys(Handle<JSReceiver> object,
FixedArray);
DCHECK(ContainsOnlyValidKeys(content));
- // Add the property keys from the interceptor.
+ // Add the non-symbol property keys from the interceptor.
if (current->HasNamedInterceptor()) {
Handle<JSObject> result;
if (JSObject::GetKeysForNamedInterceptor(
current, object).ToHandle(&result)) {
ASSIGN_RETURN_ON_EXCEPTION(
isolate, content,
- FixedArray::AddKeysFromArrayLike(content, result),
+ FixedArray::AddKeysFromArrayLike(
+ content, result, FixedArray::NON_SYMBOL_KEYS),
FixedArray);
}
DCHECK(ContainsOnlyValidKeys(content));
@@ -7709,14 +7712,13 @@ void FixedArray::Shrink(int new_length) {
MaybeHandle<FixedArray> FixedArray::AddKeysFromArrayLike(
- Handle<FixedArray> content,
- Handle<JSObject> array) {
+ Handle<FixedArray> content, Handle<JSObject> array, KeyFilter filter) {
DCHECK(array->IsJSArray() || array->HasSloppyArgumentsElements());
ElementsAccessor* accessor = array->GetElementsAccessor();
Handle<FixedArray> result;
ASSIGN_RETURN_ON_EXCEPTION(
array->GetIsolate(), result,
- accessor->AddElementsToFixedArray(array, array, content),
+ accessor->AddElementsToFixedArray(array, array, content, filter),
FixedArray);
#ifdef ENABLE_SLOW_DCHECKS
@@ -7742,7 +7744,8 @@ MaybeHandle<FixedArray> FixedArray::UnionOfKeys(Handle<FixedArray> first,
Handle<Object>::null(), // receiver
Handle<JSObject>::null(), // holder
first,
- Handle<FixedArrayBase>::cast(second)),
+ Handle<FixedArrayBase>::cast(second),
+ ALL_KEYS),
FixedArray);
#ifdef ENABLE_SLOW_DCHECKS
@@ -13161,22 +13164,22 @@ MaybeHandle<Object> JSObject::GetPropertyWithInterceptor(
Handle<Name> name) {
Isolate* isolate = holder->GetIsolate();
- // TODO(rossberg): Support symbols in the API.
- if (name->IsSymbol()) return isolate->factory()->undefined_value();
-
Handle<InterceptorInfo> interceptor(holder->GetNamedInterceptor(), isolate);
- Handle<String> name_string = Handle<String>::cast(name);
-
if (interceptor->getter()->IsUndefined()) return MaybeHandle<Object>();
- v8::NamedPropertyGetterCallback getter =
- v8::ToCData<v8::NamedPropertyGetterCallback>(interceptor->getter());
+ if (name->IsSymbol() && !interceptor->can_intercept_symbols()) {
+ return MaybeHandle<Object>();
+ }
+
+ v8::GenericNamedPropertyGetterCallback getter =
+ v8::ToCData<v8::GenericNamedPropertyGetterCallback>(
+ interceptor->getter());
LOG(isolate,
ApiNamedPropertyAccess("interceptor-named-get", *holder, *name));
PropertyCallbackArguments
args(isolate, interceptor->data(), *receiver, *holder);
v8::Handle<v8::Value> result =
- args.Call(getter, v8::Utils::ToLocal(name_string));
+ args.Call(getter, v8::Utils::ToLocal(name));
RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object);
if (result.IsEmpty()) return MaybeHandle<Object>();
@@ -13188,7 +13191,6 @@ MaybeHandle<Object> JSObject::GetPropertyWithInterceptor(
// Compute the property keys from the interceptor.
-// TODO(rossberg): support symbols in API, and filter here if needed.
MaybeHandle<JSObject> JSObject::GetKeysForNamedInterceptor(
Handle<JSObject> object, Handle<JSReceiver> receiver) {
Isolate* isolate = receiver->GetIsolate();
@@ -13197,8 +13199,8 @@ MaybeHandle<JSObject> JSObject::GetKeysForNamedInterceptor(
args(isolate, interceptor->data(), *receiver, *object);
v8::Handle<v8::Object> result;
if (!interceptor->enumerator()->IsUndefined()) {
- v8::NamedPropertyEnumeratorCallback enum_fun =
- v8::ToCData<v8::NamedPropertyEnumeratorCallback>(
+ v8::GenericNamedPropertyEnumeratorCallback enum_fun =
+ v8::ToCData<v8::GenericNamedPropertyEnumeratorCallback>(
interceptor->enumerator());
LOG(isolate, ApiObjectAccess("interceptor-named-enum", *object));
result = args.Call(enum_fun);
« no previous file with comments | « src/objects.h ('k') | src/objects-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698