 Chromium Code Reviews
 Chromium Code Reviews Issue 1499593003:
  [runtime] [proxy] Implementing [[Call]]  (Closed) 
  Base URL: https://chromium.googlesource.com/v8/v8.git@master
    
  
    Issue 1499593003:
  [runtime] [proxy] Implementing [[Call]]  (Closed) 
  Base URL: https://chromium.googlesource.com/v8/v8.git@master| OLD | NEW | 
|---|---|
| 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 // 9.5.13 [[Call]] (thisArgument, argumentsList) | |
| 
Jakob Kummerow
2015/12/07 15:55:08
nit: include "ES6" please
 | |
| 18 RUNTIME_FUNCTION(Runtime_JSProxyCall) { | |
| 
Camillo Bruni
2015/12/07 13:26:23
Would it make sense to create a builtin instead? W
 
Jakob Kummerow
2015/12/07 15:55:08
A runtime function is fine, I think.
 | |
| 19 HandleScope scope(isolate); | |
| 20 int const arguments_length = args.length() - 2; | |
| 21 DCHECK_LE(1, args.length()); | |
| 
Jakob Kummerow
2015/12/07 15:55:08
s/1/2/, judging from the "- 2" above.
 
Camillo Bruni
2015/12/07 16:54:10
this is actually the size of the wrapper arguments
 | |
| 22 // thisArgument == receiver | |
| 23 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0); | |
| 24 CONVERT_ARG_HANDLE_CHECKED(JSProxy, proxy, args.length() - 1); | |
| 25 Handle<String> trap_name = isolate->factory()->apply_string(); | |
| 26 // 1. Let handler be the value of the [[ProxyHandler]] internal slot of O. | |
| 27 Handle<Object> handler(proxy->handler(), isolate); | |
| 28 // 2. If handler is null, throw a TypeError exception. | |
| 29 if (proxy->IsRevoked()) { | |
| 30 THROW_NEW_ERROR_RETURN_FAILURE( | |
| 31 isolate, NewTypeError(MessageTemplate::kProxyRevoked, trap_name)); | |
| 32 } | |
| 33 // 3. Assert: Type(handler) is Object. | |
| 34 DCHECK(handler->IsJSReceiver()); | |
| 35 // 4. Let target be the value of the [[ProxyTarget]] internal slot of O. | |
| 36 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate); | |
| 
Jakob Kummerow
2015/12/07 15:55:08
nit: cast is unnecessary, proxy->target() returns
 
Camillo Bruni
2015/12/07 16:54:10
right.
 | |
| 37 // 5. Let trap be ? GetMethod(handler, "apply"). | |
| 38 Handle<Object> trap; | |
| 39 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
| 40 isolate, trap, | |
| 41 Object::GetMethod(Handle<JSReceiver>::cast(handler), trap_name)); | |
| 42 // 6. If trap is undefined, then | |
| 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 | 
| OLD | NEW |