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

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

Issue 1499593003: [runtime] [proxy] Implementing [[Call]] (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updating comment 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/factory.h" 9 #include "src/factory.h"
10 #include "src/isolate-inl.h"
9 #include "src/objects-inl.h" 11 #include "src/objects-inl.h"
10 12
11 namespace v8 { 13 namespace v8 {
12 namespace internal { 14 namespace internal {
13 15
14 16
17 // ES6 9.5.13 [[Call]] (thisArgument, argumentsList)
18 RUNTIME_FUNCTION(Runtime_JSProxyCall) {
19 HandleScope scope(isolate);
20 DCHECK_LE(2, args.length());
21 // thisArgument == receiver
22 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0);
23 CONVERT_ARG_HANDLE_CHECKED(JSProxy, proxy, args.length() - 1);
24 Handle<String> trap_name = isolate->factory()->apply_string();
25 // 1. Let handler be the value of the [[ProxyHandler]] internal slot of O.
26 Handle<Object> handler(proxy->handler(), isolate);
27 // 2. If handler is null, throw a TypeError exception.
28 if (proxy->IsRevoked()) {
29 THROW_NEW_ERROR_RETURN_FAILURE(
30 isolate, NewTypeError(MessageTemplate::kProxyRevoked, trap_name));
31 }
32 // 3. Assert: Type(handler) is Object.
33 DCHECK(handler->IsJSReceiver());
34 // 4. Let target be the value of the [[ProxyTarget]] internal slot of O.
35 Handle<JSReceiver> target(proxy->target(), isolate);
36 // 5. Let trap be ? GetMethod(handler, "apply").
37 Handle<Object> trap;
38 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
39 isolate, trap,
40 Object::GetMethod(Handle<JSReceiver>::cast(handler), trap_name));
41 // 6. If trap is undefined, then
42 int const arguments_length = args.length() - 2;
43 if (trap->IsUndefined()) {
44 // 6.a. Return Call(target, thisArgument, argumentsList).
45 ScopedVector<Handle<Object>> argv(arguments_length);
46 for (int i = 0; i < arguments_length; ++i) {
47 argv[i] = args.at<Object>(i + 1);
48 }
49 Handle<Object> result;
50 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
51 isolate, result, Execution::Call(isolate, target, receiver,
52 arguments_length, argv.start()));
53 return *result;
54 }
55 // 7. Let argArray be CreateArrayFromList(argumentsList).
56 Handle<JSArray> arg_array = isolate->factory()->NewJSArray(
57 FAST_ELEMENTS, arguments_length, arguments_length);
58 ElementsAccessor* accessor = arg_array->GetElementsAccessor();
59 {
60 DisallowHeapAllocation no_gc;
61 FixedArrayBase* elements = arg_array->elements();
62 for (int i = 0; i < arguments_length; i++) {
63 accessor->Set(elements, i, args[i + 1]);
64 }
65 }
66 // 8. Return Call(trap, handler, «target, thisArgument, argArray»).
67 Handle<Object> trap_result;
68 Handle<Object> trap_args[] = {target, receiver, arg_array};
69 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
70 isolate, trap_result,
71 Execution::Call(isolate, trap, handler, arraysize(trap_args), trap_args));
72 return *trap_result;
73 }
74
15 75
16 RUNTIME_FUNCTION(Runtime_IsJSProxy) { 76 RUNTIME_FUNCTION(Runtime_IsJSProxy) {
17 SealHandleScope shs(isolate); 77 SealHandleScope shs(isolate);
18 DCHECK(args.length() == 1); 78 DCHECK(args.length() == 1);
19 CONVERT_ARG_CHECKED(Object, obj, 0); 79 CONVERT_ARG_CHECKED(Object, obj, 0);
20 return isolate->heap()->ToBoolean(obj->IsJSProxy()); 80 return isolate->heap()->ToBoolean(obj->IsJSProxy());
21 } 81 }
22 82
23 83
24 RUNTIME_FUNCTION(Runtime_GetHandler) { 84 RUNTIME_FUNCTION(Runtime_GetHandler) {
25 SealHandleScope shs(isolate); 85 SealHandleScope shs(isolate);
26 DCHECK(args.length() == 1); 86 DCHECK(args.length() == 1);
27 CONVERT_ARG_CHECKED(JSProxy, proxy, 0); 87 CONVERT_ARG_CHECKED(JSProxy, proxy, 0);
28 return proxy->handler(); 88 return proxy->handler();
29 } 89 }
30 90
31 91
32 RUNTIME_FUNCTION(Runtime_RevokeProxy) { 92 RUNTIME_FUNCTION(Runtime_RevokeProxy) {
33 HandleScope scope(isolate); 93 HandleScope scope(isolate);
34 DCHECK(args.length() == 1); 94 DCHECK(args.length() == 1);
35 CONVERT_ARG_HANDLE_CHECKED(JSProxy, proxy, 0); 95 CONVERT_ARG_HANDLE_CHECKED(JSProxy, proxy, 0);
36 JSProxy::Revoke(proxy); 96 JSProxy::Revoke(proxy);
37 return isolate->heap()->undefined_value(); 97 return isolate->heap()->undefined_value();
38 } 98 }
39 99
40 } // namespace internal 100 } // namespace internal
41 } // namespace v8 101 } // 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