Chromium Code Reviews| Index: src/runtime/runtime-proxy.cc |
| diff --git a/src/runtime/runtime-proxy.cc b/src/runtime/runtime-proxy.cc |
| index 52441e9d660553a94cc0d8209ab6f2d83c8a7773..83085997caae1f3e8bdab15b15f730eb5e5a86a4 100644 |
| --- a/src/runtime/runtime-proxy.cc |
| +++ b/src/runtime/runtime-proxy.cc |
| @@ -5,13 +5,73 @@ |
| #include "src/runtime/runtime-utils.h" |
| #include "src/arguments.h" |
| +#include "src/elements.h" |
| #include "src/factory.h" |
| +#include "src/isolate-inl.h" |
| #include "src/objects-inl.h" |
| namespace v8 { |
| namespace internal { |
| +// 9.5.13 [[Call]] (thisArgument, argumentsList) |
|
Jakob Kummerow
2015/12/07 15:55:08
nit: include "ES6" please
|
| +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.
|
| + HandleScope scope(isolate); |
| + int const arguments_length = args.length() - 2; |
| + 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
|
| + // thisArgument == receiver |
| + CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0); |
| + CONVERT_ARG_HANDLE_CHECKED(JSProxy, proxy, args.length() - 1); |
| + Handle<String> trap_name = isolate->factory()->apply_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); |
|
Jakob Kummerow
2015/12/07 15:55:08
nit: cast is unnecessary, proxy->target() returns
Camillo Bruni
2015/12/07 16:54:10
right.
|
| + // 5. Let trap be ? GetMethod(handler, "apply"). |
| + Handle<Object> trap; |
| + ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| + isolate, trap, |
| + Object::GetMethod(Handle<JSReceiver>::cast(handler), trap_name)); |
| + // 6. If trap is undefined, then |
| + if (trap->IsUndefined()) { |
| + // 6.a. Return Call(target, thisArgument, argumentsList). |
| + 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::Call(isolate, target, receiver, |
| + 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. Return Call(trap, handler, «target, thisArgument, argArray»). |
| + Handle<Object> trap_result; |
| + Handle<Object> trap_args[] = {target, receiver, arg_array}; |
| + ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| + isolate, trap_result, |
| + Execution::Call(isolate, trap, handler, arraysize(trap_args), trap_args)); |
| + return *trap_result; |
| +} |
| + |
| RUNTIME_FUNCTION(Runtime_IsJSProxy) { |
| SealHandleScope shs(isolate); |