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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/runtime/runtime.h ('k') | src/x64/builtins-x64.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime/runtime-proxy.cc
diff --git a/src/runtime/runtime-proxy.cc b/src/runtime/runtime-proxy.cc
index c501893db32ec038a4405160c97c225cebed8f33..e9426b7c415fb37422d4cd50282622d83085c8dd 100644
--- a/src/runtime/runtime-proxy.cc
+++ b/src/runtime/runtime-proxy.cc
@@ -73,6 +73,75 @@ RUNTIME_FUNCTION(Runtime_JSProxyCall) {
}
+// 9.5.14 [[Construct]] (argumentsList, newTarget)
+RUNTIME_FUNCTION(Runtime_JSProxyConstruct) {
+ HandleScope scope(isolate);
+ DCHECK_LE(3, args.length());
+ CONVERT_ARG_HANDLE_CHECKED(JSProxy, proxy, args.length() - 2);
+ CONVERT_ARG_HANDLE_CHECKED(Object, new_target, args.length() - 1);
+ Handle<String> trap_name = isolate->factory()->construct_string();
+
+ // 1. Let handler be the value of the [[ProxyHandler]] internal slot of O.
+ Handle<Object> handler(proxy->handler(), isolate);
+ // 2. If handler is null, throw a TypeError exception.
+ if (proxy->IsRevoked()) {
+ THROW_NEW_ERROR_RETURN_FAILURE(
+ isolate, NewTypeError(MessageTemplate::kProxyRevoked, trap_name));
+ }
+ // 3. Assert: Type(handler) is Object.
+ DCHECK(handler->IsJSReceiver());
+ // 4. Let target be the value of the [[ProxyTarget]] internal slot of O.
+ Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate);
+ // 5. Let trap be ? GetMethod(handler, "construct").
+ Handle<Object> trap;
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, trap,
+ Object::GetMethod(Handle<JSReceiver>::cast(handler), trap_name));
+ // 6. If trap is undefined, then
+ int const arguments_length = args.length() - 3;
+ if (trap->IsUndefined()) {
+ // 6.a. Assert: target has a [[Construct]] internal method.
+ DCHECK(target->IsConstructor());
+ // 6.b. Return Construct(target, argumentsList, newTarget).
+ ScopedVector<Handle<Object>> argv(arguments_length);
+ for (int i = 0; i < arguments_length; ++i) {
+ argv[i] = args.at<Object>(i + 1);
+ }
+ Handle<Object> result;
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, result, Execution::New(isolate, target, new_target,
+ arguments_length, argv.start()));
+ return *result;
+ }
+ // 7. Let argArray be CreateArrayFromList(argumentsList).
+ Handle<JSArray> arg_array = isolate->factory()->NewJSArray(
+ FAST_ELEMENTS, arguments_length, arguments_length);
+ ElementsAccessor* accessor = arg_array->GetElementsAccessor();
+ {
+ DisallowHeapAllocation no_gc;
+ FixedArrayBase* elements = arg_array->elements();
+ for (int i = 0; i < arguments_length; i++) {
+ accessor->Set(elements, i, args[i + 1]);
+ }
+ }
+ // 8. Let newObj be ? Call(trap, handler, «target, argArray, newTarget »).
+ Handle<Object> new_object;
+ Handle<Object> trap_args[] = {target, arg_array, new_target};
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, new_object,
+ Execution::Call(isolate, trap, handler, arraysize(trap_args), trap_args));
+ // 9. If Type(newObj) is not Object, throw a TypeError exception.
+ if (!new_object->IsJSReceiver()) {
+ THROW_NEW_ERROR_RETURN_FAILURE(
+ isolate,
+ NewTypeError(MessageTemplate::kProxyTrapConstructMustReturnObject,
+ new_object));
+ }
+ // 10. Return newObj.
+ return *new_object;
+}
+
+
RUNTIME_FUNCTION(Runtime_IsJSProxy) {
SealHandleScope shs(isolate);
DCHECK(args.length() == 1);
« 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