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

Side by Side Diff: src/runtime/runtime-proxy.cc

Issue 1509603005: [runtime] [proxy] implement [[Construct]] (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@2015-12-03_JSProxy_Call_1499593003
Patch Set: fimpsing 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/runtime/runtime.h ('k') | src/x64/builtins-x64.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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/elements.h" 8 #include "src/elements.h"
9 #include "src/factory.h" 9 #include "src/factory.h"
10 #include "src/isolate-inl.h" 10 #include "src/isolate-inl.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 // 8. Return Call(trap, handler, «target, thisArgument, argArray»). 66 // 8. Return Call(trap, handler, «target, thisArgument, argArray»).
67 Handle<Object> trap_result; 67 Handle<Object> trap_result;
68 Handle<Object> trap_args[] = {target, receiver, arg_array}; 68 Handle<Object> trap_args[] = {target, receiver, arg_array};
69 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 69 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
70 isolate, trap_result, 70 isolate, trap_result,
71 Execution::Call(isolate, trap, handler, arraysize(trap_args), trap_args)); 71 Execution::Call(isolate, trap, handler, arraysize(trap_args), trap_args));
72 return *trap_result; 72 return *trap_result;
73 } 73 }
74 74
75 75
76 // 9.5.14 [[Construct]] (argumentsList, newTarget)
77 RUNTIME_FUNCTION(Runtime_JSProxyConstruct) {
78 HandleScope scope(isolate);
79 DCHECK_LE(3, args.length());
80 CONVERT_ARG_HANDLE_CHECKED(JSProxy, proxy, args.length() - 2);
81 CONVERT_ARG_HANDLE_CHECKED(Object, new_target, args.length() - 1);
82 Handle<String> trap_name = isolate->factory()->construct_string();
83
84 // 1. Let handler be the value of the [[ProxyHandler]] internal slot of O.
85 Handle<Object> handler(proxy->handler(), isolate);
86 // 2. If handler is null, throw a TypeError exception.
87 if (proxy->IsRevoked()) {
88 THROW_NEW_ERROR_RETURN_FAILURE(
89 isolate, NewTypeError(MessageTemplate::kProxyRevoked, trap_name));
90 }
91 // 3. Assert: Type(handler) is Object.
92 DCHECK(handler->IsJSReceiver());
93 // 4. Let target be the value of the [[ProxyTarget]] internal slot of O.
94 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate);
95 // 5. Let trap be ? GetMethod(handler, "construct").
96 Handle<Object> trap;
97 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
98 isolate, trap,
99 Object::GetMethod(Handle<JSReceiver>::cast(handler), trap_name));
100 // 6. If trap is undefined, then
101 int const arguments_length = args.length() - 3;
102 if (trap->IsUndefined()) {
103 // 6.a. Assert: target has a [[Construct]] internal method.
104 DCHECK(target->IsConstructor());
105 // 6.b. Return Construct(target, argumentsList, newTarget).
106 ScopedVector<Handle<Object>> argv(arguments_length);
107 for (int i = 0; i < arguments_length; ++i) {
108 argv[i] = args.at<Object>(i + 1);
109 }
110 Handle<Object> result;
111 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
112 isolate, result, Execution::New(isolate, target, new_target,
113 arguments_length, argv.start()));
114 return *result;
115 }
116 // 7. Let argArray be CreateArrayFromList(argumentsList).
117 Handle<JSArray> arg_array = isolate->factory()->NewJSArray(
118 FAST_ELEMENTS, arguments_length, arguments_length);
119 ElementsAccessor* accessor = arg_array->GetElementsAccessor();
120 {
121 DisallowHeapAllocation no_gc;
122 FixedArrayBase* elements = arg_array->elements();
123 for (int i = 0; i < arguments_length; i++) {
124 accessor->Set(elements, i, args[i + 1]);
125 }
126 }
127 // 8. Let newObj be ? Call(trap, handler, «target, argArray, newTarget »).
128 Handle<Object> new_object;
129 Handle<Object> trap_args[] = {target, arg_array, new_target};
130 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
131 isolate, new_object,
132 Execution::Call(isolate, trap, handler, arraysize(trap_args), trap_args));
133 // 9. If Type(newObj) is not Object, throw a TypeError exception.
134 if (!new_object->IsJSReceiver()) {
135 THROW_NEW_ERROR_RETURN_FAILURE(
136 isolate,
137 NewTypeError(MessageTemplate::kProxyTrapConstructMustReturnObject,
138 new_object));
139 }
140 // 10. Return newObj.
141 return *new_object;
142 }
143
144
76 RUNTIME_FUNCTION(Runtime_IsJSProxy) { 145 RUNTIME_FUNCTION(Runtime_IsJSProxy) {
77 SealHandleScope shs(isolate); 146 SealHandleScope shs(isolate);
78 DCHECK(args.length() == 1); 147 DCHECK(args.length() == 1);
79 CONVERT_ARG_CHECKED(Object, obj, 0); 148 CONVERT_ARG_CHECKED(Object, obj, 0);
80 return isolate->heap()->ToBoolean(obj->IsJSProxy()); 149 return isolate->heap()->ToBoolean(obj->IsJSProxy());
81 } 150 }
82 151
83 152
84 RUNTIME_FUNCTION(Runtime_GetHandler) { 153 RUNTIME_FUNCTION(Runtime_GetHandler) {
85 SealHandleScope shs(isolate); 154 SealHandleScope shs(isolate);
86 DCHECK(args.length() == 1); 155 DCHECK(args.length() == 1);
87 CONVERT_ARG_CHECKED(JSProxy, proxy, 0); 156 CONVERT_ARG_CHECKED(JSProxy, proxy, 0);
88 return proxy->handler(); 157 return proxy->handler();
89 } 158 }
90 159
91 160
92 RUNTIME_FUNCTION(Runtime_RevokeProxy) { 161 RUNTIME_FUNCTION(Runtime_RevokeProxy) {
93 HandleScope scope(isolate); 162 HandleScope scope(isolate);
94 DCHECK(args.length() == 1); 163 DCHECK(args.length() == 1);
95 CONVERT_ARG_HANDLE_CHECKED(JSProxy, proxy, 0); 164 CONVERT_ARG_HANDLE_CHECKED(JSProxy, proxy, 0);
96 JSProxy::Revoke(proxy); 165 JSProxy::Revoke(proxy);
97 return isolate->heap()->undefined_value(); 166 return isolate->heap()->undefined_value();
98 } 167 }
99 168
100 } // namespace internal 169 } // namespace internal
101 } // namespace v8 170 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | src/x64/builtins-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698