Index: src/objects.cc |
diff --git a/src/objects.cc b/src/objects.cc |
index cc6ae919a8a37927b840575a8ed9235b571bbdfb..6e874a6618342a4b6992a29aa2991a79708fd5f1 100644 |
--- a/src/objects.cc |
+++ b/src/objects.cc |
@@ -845,6 +845,62 @@ Handle<FixedArray> JSObject::EnsureWritableFastElements( |
} |
+// static |
Jakob Kummerow
2015/11/12 12:04:24
Please also mention the spec chapter:
// ES6 9.5.1
|
+MaybeHandle<Object> JSProxy::GetPrototype(Handle<JSProxy> proxy) { |
+ Isolate* isolate = proxy->GetIsolate(); |
+ // 1. Let handler be the value of the [[ProxyHandler]] internal slot. |
+ Handle<Object> raw_handler(proxy->handler(), isolate); |
+ // 2. If handler is null, throw a TypeError exception. |
Jakob Kummerow
2015/11/12 12:04:24
nit: drop a space before "If"
|
+ // 3. Assert: Type(handler) is Object. |
+ if (!raw_handler->IsSpecObject()) { |
+ // TODO(cbruni): throw correct error message |
Jakob Kummerow
2015/11/12 12:04:24
nit: comments, including TODOs, should begin capit
|
+ THROW_NEW_ERROR( |
+ isolate, NewTypeError(MessageTemplate::kProxyHandlerNonObject), Object); |
+ } |
+ Handle<JSReceiver> handler = Handle<JSReceiver>::cast(raw_handler); |
+ // 4. Let target be the value of the [[ProxyTarget]] internal slot. |
+ // TODO(cbruni): Probably change the type of target to JSObject directly |
Jakob Kummerow
2015/11/12 12:04:24
Can a target not be another Proxy? :-)
Camillo Bruni
2015/11/12 20:20:55
changed to JSReceiver
|
+ Handle<JSObject> target(JSObject::cast(proxy->target()), isolate); |
+ // 5. Let trap be ? GetMethod(handler, "getPrototypeOf"). |
+ Handle<Object> trap; |
+ Handle<String> trap_name = isolate->factory()->getPrototypeOf_string(); |
+ ASSIGN_RETURN_ON_EXCEPTION(isolate, trap, GetMethod(handler, trap_name), |
+ Object); |
+ // 6. If trap is undefined, then return target.[[GetPrototypeOf]](). |
+ if (trap->IsUndefined()) { |
+ return Object::GetPrototype(isolate, target); |
+ } |
+ // 7. Let handlerProto be ? Call(trap, handler, «target»). |
+ Handle<Object> argv[] = {target}; |
+ Handle<Object> handler_proto; |
+ ASSIGN_RETURN_ON_EXCEPTION( |
+ isolate, handler_proto, |
+ Execution::Call(isolate, trap, handler, arraysize(argv), argv), Object); |
+ // 8. If Type(handlerProto) is either Object nor Null, throw a TypeError. |
Jakob Kummerow
2015/11/12 12:04:24
s/either/neither/
|
+ if (!handler_proto->IsSpecObject() || !handler_proto->IsNull()) { |
Jakob Kummerow
2015/11/12 12:04:24
s/||/&&/
|
+ THROW_NEW_ERROR(isolate, |
+ NewTypeError(MessageTemplate::kProxyHandlerTrapMissing, |
+ handler, trap_name), |
+ Object); |
+ } |
+ // 9. Let extensibleTarget be ? IsExtensible(target). |
+ // 10. If extensibleTarget is true, return handlerProto. |
+ if (JSObject::IsExtensible(target)) return handler_proto; |
+ // 11. Let targetProto be ? target.[[GetPrototypeOf]](). |
+ Handle<Object> target_proto; |
+ ASSIGN_RETURN_ON_EXCEPTION(isolate, handler_proto, |
+ Object::GetPrototype(isolate, target), Object); |
+ // 12. If SameValue(handlerProto, targetProto) is false, throw a TypeError. |
+ if (!handler_proto->SameValue(*target_proto)) { |
+ THROW_NEW_ERROR(isolate, |
+ NewTypeError(MessageTemplate::kProxyHandlerTrapMissing, |
+ handler, trap_name), |
+ Object); |
+ } |
+ // 13. Return handlerProto. |
+ return handler_proto; |
+} |
+ |
Jakob Kummerow
2015/11/12 12:04:24
nit: two blank lines
|
MaybeHandle<Object> JSProxy::GetPropertyWithHandler(Handle<JSProxy> proxy, |
Handle<Object> receiver, |
Handle<Name> name) { |
@@ -8061,9 +8117,10 @@ Handle<Map> Map::CopyDropDescriptors(Handle<Map> map) { |
Handle<Map> result = RawCopy(map, map->instance_size()); |
// Please note instance_type and instance_size are set when allocated. |
- result->SetInObjectProperties(map->GetInObjectProperties()); |
- result->set_unused_property_fields(map->unused_property_fields()); |
- |
+ if (map->IsJSObjectMap()) { |
+ result->SetInObjectProperties(map->GetInObjectProperties()); |
+ result->set_unused_property_fields(map->unused_property_fields()); |
+ } |
result->ClearCodeCache(map->GetHeap()); |
map->NotifyLeafMapLayoutChange(); |
return result; |
@@ -13922,7 +13979,9 @@ Maybe<bool> JSObject::SetPrototype(Handle<JSObject> object, |
const bool observed = from_javascript && object->map()->is_observed(); |
Handle<Object> old_value; |
if (observed) { |
- old_value = Object::GetPrototype(isolate, object); |
+ ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, old_value, |
+ Object::GetPrototype(isolate, object), |
+ Nothing<bool>()); |
} |
Maybe<bool> result = |
@@ -13930,7 +13989,10 @@ Maybe<bool> JSObject::SetPrototype(Handle<JSObject> object, |
MAYBE_RETURN(result, Nothing<bool>()); |
if (result.FromJust() && observed) { |
- Handle<Object> new_value = Object::GetPrototype(isolate, object); |
+ Handle<Object> new_value; |
+ ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, new_value, |
+ Object::GetPrototype(isolate, object), |
+ Nothing<bool>()); |
if (!new_value->SameValue(*old_value)) { |
RETURN_ON_EXCEPTION_VALUE( |
isolate, JSObject::EnqueueChangeRecord( |