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

Side by Side Diff: src/objects.cc

Issue 1481383003: [runtime] [proxy] Adding [[SetPrototypeOf]] trap. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years 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
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 <sstream> 9 #include <sstream>
10 10
(...skipping 14796 matching lines...) Expand 10 before | Expand all | Expand 10 after
14807 TransitionArray::PutPrototypeTransition(map, prototype, new_map); 14807 TransitionArray::PutPrototypeTransition(map, prototype, new_map);
14808 Map::SetPrototype(new_map, prototype, mode); 14808 Map::SetPrototype(new_map, prototype, mode);
14809 } 14809 }
14810 return new_map; 14810 return new_map;
14811 } 14811 }
14812 14812
14813 14813
14814 Maybe<bool> JSReceiver::SetPrototype(Handle<JSReceiver> object, 14814 Maybe<bool> JSReceiver::SetPrototype(Handle<JSReceiver> object,
14815 Handle<Object> value, bool from_javascript, 14815 Handle<Object> value, bool from_javascript,
14816 ShouldThrow should_throw) { 14816 ShouldThrow should_throw) {
14817 if (!object->IsJSObject()) return Just(false); 14817 if (object->IsJSProxy()) {
14818 // TODO(neis): Deal with proxies. 14818 return JSProxy::SetPrototype(Handle<JSProxy>::cast(object), value,
14819 from_javascript, should_throw);
14820 }
14819 return JSObject::SetPrototype(Handle<JSObject>::cast(object), value, 14821 return JSObject::SetPrototype(Handle<JSObject>::cast(object), value,
14820 from_javascript, should_throw); 14822 from_javascript, should_throw);
14821 } 14823 }
14822 14824
14823 14825
14826 // ES6: 9.5.2 [[SetPrototypeOf]] (V)
14827 // static
14828 Maybe<bool> JSProxy::SetPrototype(Handle<JSProxy> proxy, Handle<Object> value,
14829 bool from_javascript,
14830 Object::ShouldThrow should_throw) {
Jakob Kummerow 2015/11/30 16:29:18 I don't think you need "Object::" here (but you ca
Camillo Bruni 2015/12/01 13:26:40 cleaner without.
14831 Isolate* isolate = proxy->GetIsolate();
14832 Handle<JSReceiver> handle;
14833 Handle<Name> trap_name = isolate->factory()->setPrototypeOf_string();
14834 // 1. Assert: Either Type(V) is Object or Type(V) is Null.
14835 DCHECK(value->IsJSReceiver() || value->IsNull());
14836 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O.
14837 Handle<Object> raw_handler(proxy->handler(), isolate);
14838 // 3. If handler is null, throw a TypeError exception.
14839 // 4. Assert: Type(handler) is Object.
14840 if (!raw_handler->IsJSReceiver()) {
Jakob Kummerow 2015/11/30 16:29:18 if (proxy->IsRevoked())
Camillo Bruni 2015/12/01 13:26:40 right :D
14841 DCHECK(raw_handler->IsNull());
14842 DCHECK(proxy->target()->IsNull());
14843 isolate->Throw(*isolate->factory()->NewTypeError(
14844 MessageTemplate::kProxyHandlerNonObject));
14845 return Nothing<bool>();
14846 }
14847 Handle<JSReceiver> handler = Handle<JSReceiver>::cast(raw_handler);
14848 // 5. Let target be the value of the [[ProxyTarget]] internal slot.
14849 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate);
14850 // 6. Let trap be ? GetMethod(handler, "getPrototypeOf").
14851 Handle<Object> trap;
14852 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
14853 isolate, trap, Object::GetMethod(handler, trap_name), Nothing<bool>());
14854 // 7. If trap is undefined, then return target.[[SetPrototypeOf]]().
14855 if (trap->IsUndefined()) {
14856 return JSReceiver::SetPrototype(target, value, from_javascript,
14857 should_throw);
14858 }
14859 // 8. Let booleanTrapResult be ToBoolean(? Call(trap, handler, «target, V»)).
14860 Handle<Object> argv[] = {target, value};
14861 Handle<Object> trap_result;
14862 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
14863 isolate, trap_result,
14864 Execution::Call(isolate, trap, handler, arraysize(argv), argv),
14865 Nothing<bool>());
14866 bool bool_trap_result = trap_result->BooleanValue();
14867 // 9. Let extensibleTarget be ? IsExtensible(target).
14868 Maybe<bool> is_extensible = JSReceiver::IsExtensible(target);
14869 if (is_extensible.IsNothing()) return Nothing<bool>();
14870 // 10. If extensibleTarget is true, return booleanTrapResult.
14871 if (is_extensible.FromJust()) return Just(bool_trap_result);
14872 // 11. Let targetProto be ? target.[[GetPrototypeOf]]().
14873 Handle<Object> target_proto;
14874 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, target_proto,
14875 Object::GetPrototype(isolate, target),
14876 Nothing<bool>());
14877 // 12. If booleanTrapResult is true and SameValue(V, targetProto) is false,
14878 // throw a TypeError exception.
14879 if (bool_trap_result && !value->SameValue(*target_proto)) {
14880 isolate->Throw(*isolate->factory()->NewTypeError(
14881 MessageTemplate::kProxySetPrototypeVioloatesInvariant, value, target));
14882 }
14883 // 13. Return booleanTrapResult.
14884 return Just(bool_trap_result);
14885 }
14886
14887
14824 Maybe<bool> JSObject::SetPrototype(Handle<JSObject> object, 14888 Maybe<bool> JSObject::SetPrototype(Handle<JSObject> object,
14825 Handle<Object> value, bool from_javascript, 14889 Handle<Object> value, bool from_javascript,
14826 ShouldThrow should_throw) { 14890 ShouldThrow should_throw) {
14827 Isolate* isolate = object->GetIsolate(); 14891 Isolate* isolate = object->GetIsolate();
14828 14892
14829 const bool observed = from_javascript && object->map()->is_observed(); 14893 const bool observed = from_javascript && object->map()->is_observed();
14830 Handle<Object> old_value; 14894 Handle<Object> old_value;
14831 if (observed) { 14895 if (observed) {
14832 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, old_value, 14896 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, old_value,
14833 Object::GetPrototype(isolate, object), 14897 Object::GetPrototype(isolate, object),
(...skipping 4154 matching lines...) Expand 10 before | Expand all | Expand 10 after
18988 if (cell->value() != *new_value) { 19052 if (cell->value() != *new_value) {
18989 cell->set_value(*new_value); 19053 cell->set_value(*new_value);
18990 Isolate* isolate = cell->GetIsolate(); 19054 Isolate* isolate = cell->GetIsolate();
18991 cell->dependent_code()->DeoptimizeDependentCodeGroup( 19055 cell->dependent_code()->DeoptimizeDependentCodeGroup(
18992 isolate, DependentCode::kPropertyCellChangedGroup); 19056 isolate, DependentCode::kPropertyCellChangedGroup);
18993 } 19057 }
18994 } 19058 }
18995 19059
18996 } // namespace internal 19060 } // namespace internal
18997 } // namespace v8 19061 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698