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

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: using new proxy method 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
« no previous file with comments | « src/objects.h ('k') | src/runtime/runtime-object.cc » ('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 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 14757 matching lines...) Expand 10 before | Expand all | Expand 10 after
14768 TransitionArray::PutPrototypeTransition(map, prototype, new_map); 14768 TransitionArray::PutPrototypeTransition(map, prototype, new_map);
14769 Map::SetPrototype(new_map, prototype, mode); 14769 Map::SetPrototype(new_map, prototype, mode);
14770 } 14770 }
14771 return new_map; 14771 return new_map;
14772 } 14772 }
14773 14773
14774 14774
14775 Maybe<bool> JSReceiver::SetPrototype(Handle<JSReceiver> object, 14775 Maybe<bool> JSReceiver::SetPrototype(Handle<JSReceiver> object,
14776 Handle<Object> value, bool from_javascript, 14776 Handle<Object> value, bool from_javascript,
14777 ShouldThrow should_throw) { 14777 ShouldThrow should_throw) {
14778 if (!object->IsJSObject()) return Just(false); 14778 if (object->IsJSProxy()) {
14779 // TODO(neis): Deal with proxies. 14779 return JSProxy::SetPrototype(Handle<JSProxy>::cast(object), value,
14780 from_javascript, should_throw);
14781 }
14780 return JSObject::SetPrototype(Handle<JSObject>::cast(object), value, 14782 return JSObject::SetPrototype(Handle<JSObject>::cast(object), value,
14781 from_javascript, should_throw); 14783 from_javascript, should_throw);
14782 } 14784 }
14783 14785
14784 14786
14787 // ES6: 9.5.2 [[SetPrototypeOf]] (V)
14788 // static
14789 Maybe<bool> JSProxy::SetPrototype(Handle<JSProxy> proxy, Handle<Object> value,
14790 bool from_javascript,
14791 ShouldThrow should_throw) {
14792 Isolate* isolate = proxy->GetIsolate();
14793 Handle<JSReceiver> handle;
14794 Handle<Name> trap_name = isolate->factory()->setPrototypeOf_string();
14795 // 1. Assert: Either Type(V) is Object or Type(V) is Null.
14796 DCHECK(value->IsJSReceiver() || value->IsNull());
14797 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O.
14798 Handle<Object> raw_handler(proxy->handler(), isolate);
14799 // 3. If handler is null, throw a TypeError exception.
14800 // 4. Assert: Type(handler) is Object.
14801 if (proxy->IsRevoked()) {
14802 DCHECK(raw_handler->IsNull());
14803 DCHECK(proxy->target()->IsNull());
14804 isolate->Throw(
14805 *isolate->factory()->NewTypeError(MessageTemplate::kProxyRevoked));
14806 return Nothing<bool>();
14807 }
14808 Handle<JSReceiver> handler = Handle<JSReceiver>::cast(raw_handler);
14809 // 5. Let target be the value of the [[ProxyTarget]] internal slot.
14810 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate);
14811 // 6. Let trap be ? GetMethod(handler, "getPrototypeOf").
14812 Handle<Object> trap;
14813 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
14814 isolate, trap, Object::GetMethod(handler, trap_name), Nothing<bool>());
14815 // 7. If trap is undefined, then return target.[[SetPrototypeOf]]().
14816 if (trap->IsUndefined()) {
14817 return JSReceiver::SetPrototype(target, value, from_javascript,
14818 should_throw);
14819 }
14820 // 8. Let booleanTrapResult be ToBoolean(? Call(trap, handler, «target, V»)).
14821 Handle<Object> argv[] = {target, value};
14822 Handle<Object> trap_result;
14823 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
14824 isolate, trap_result,
14825 Execution::Call(isolate, trap, handler, arraysize(argv), argv),
14826 Nothing<bool>());
14827 bool bool_trap_result = trap_result->BooleanValue();
14828 // 9. Let extensibleTarget be ? IsExtensible(target).
14829 Maybe<bool> is_extensible = JSReceiver::IsExtensible(target);
14830 if (is_extensible.IsNothing()) return Nothing<bool>();
14831 // 10. If extensibleTarget is true, return booleanTrapResult.
14832 if (is_extensible.FromJust()) return Just(bool_trap_result);
14833 // 11. Let targetProto be ? target.[[GetPrototypeOf]]().
14834 Handle<Object> target_proto;
14835 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, target_proto,
14836 Object::GetPrototype(isolate, target),
14837 Nothing<bool>());
14838 // 12. If booleanTrapResult is true and SameValue(V, targetProto) is false,
14839 // throw a TypeError exception.
14840 if (bool_trap_result && !value->SameValue(*target_proto)) {
14841 isolate->Throw(*isolate->factory()->NewTypeError(
14842 MessageTemplate::kProxyTrapViolatesInvariant, target));
14843 return Nothing<bool>();
14844 }
14845 // 13. Return booleanTrapResult.
14846 return Just(bool_trap_result);
14847 }
14848
14849
14785 Maybe<bool> JSObject::SetPrototype(Handle<JSObject> object, 14850 Maybe<bool> JSObject::SetPrototype(Handle<JSObject> object,
14786 Handle<Object> value, bool from_javascript, 14851 Handle<Object> value, bool from_javascript,
14787 ShouldThrow should_throw) { 14852 ShouldThrow should_throw) {
14788 Isolate* isolate = object->GetIsolate(); 14853 Isolate* isolate = object->GetIsolate();
14789 14854
14790 const bool observed = from_javascript && object->map()->is_observed(); 14855 const bool observed = from_javascript && object->map()->is_observed();
14791 Handle<Object> old_value; 14856 Handle<Object> old_value;
14792 if (observed) { 14857 if (observed) {
14793 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, old_value, 14858 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, old_value,
14794 Object::GetPrototype(isolate, object), 14859 Object::GetPrototype(isolate, object),
(...skipping 4154 matching lines...) Expand 10 before | Expand all | Expand 10 after
18949 if (cell->value() != *new_value) { 19014 if (cell->value() != *new_value) {
18950 cell->set_value(*new_value); 19015 cell->set_value(*new_value);
18951 Isolate* isolate = cell->GetIsolate(); 19016 Isolate* isolate = cell->GetIsolate();
18952 cell->dependent_code()->DeoptimizeDependentCodeGroup( 19017 cell->dependent_code()->DeoptimizeDependentCodeGroup(
18953 isolate, DependentCode::kPropertyCellChangedGroup); 19018 isolate, DependentCode::kPropertyCellChangedGroup);
18954 } 19019 }
18955 } 19020 }
18956 19021
18957 } // namespace internal 19022 } // namespace internal
18958 } // namespace v8 19023 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/runtime/runtime-object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698