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

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

Issue 2006673002: Reduce boilerplace for common pattern to return MaybeHandle. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase and fix Created 4 years, 6 months 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-operators.cc ('k') | src/runtime/runtime-regexp.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 28 matching lines...) Expand all
39 isolate, trap, 39 isolate, trap,
40 Object::GetMethod(Handle<JSReceiver>::cast(handler), trap_name)); 40 Object::GetMethod(Handle<JSReceiver>::cast(handler), trap_name));
41 // 6. If trap is undefined, then 41 // 6. If trap is undefined, then
42 int const arguments_length = args.length() - 2; 42 int const arguments_length = args.length() - 2;
43 if (trap->IsUndefined()) { 43 if (trap->IsUndefined()) {
44 // 6.a. Return Call(target, thisArgument, argumentsList). 44 // 6.a. Return Call(target, thisArgument, argumentsList).
45 ScopedVector<Handle<Object>> argv(arguments_length); 45 ScopedVector<Handle<Object>> argv(arguments_length);
46 for (int i = 0; i < arguments_length; ++i) { 46 for (int i = 0; i < arguments_length; ++i) {
47 argv[i] = args.at<Object>(i + 1); 47 argv[i] = args.at<Object>(i + 1);
48 } 48 }
49 Handle<Object> result; 49 RETURN_RESULT_OR_FAILURE(
50 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 50 isolate, Execution::Call(isolate, target, receiver, arguments_length,
51 isolate, result, Execution::Call(isolate, target, receiver, 51 argv.start()));
52 arguments_length, argv.start()));
53 return *result;
54 } 52 }
55 // 7. Let argArray be CreateArrayFromList(argumentsList). 53 // 7. Let argArray be CreateArrayFromList(argumentsList).
56 Handle<JSArray> arg_array = isolate->factory()->NewJSArray( 54 Handle<JSArray> arg_array = isolate->factory()->NewJSArray(
57 FAST_ELEMENTS, arguments_length, arguments_length); 55 FAST_ELEMENTS, arguments_length, arguments_length);
58 ElementsAccessor* accessor = arg_array->GetElementsAccessor(); 56 ElementsAccessor* accessor = arg_array->GetElementsAccessor();
59 { 57 {
60 DisallowHeapAllocation no_gc; 58 DisallowHeapAllocation no_gc;
61 for (int i = 0; i < arguments_length; i++) { 59 for (int i = 0; i < arguments_length; i++) {
62 accessor->Set(arg_array, i, args[i + 1]); 60 accessor->Set(arg_array, i, args[i + 1]);
63 } 61 }
64 } 62 }
65 // 8. Return Call(trap, handler, «target, thisArgument, argArray»). 63 // 8. Return Call(trap, handler, «target, thisArgument, argArray»).
66 Handle<Object> trap_result;
67 Handle<Object> trap_args[] = {target, receiver, arg_array}; 64 Handle<Object> trap_args[] = {target, receiver, arg_array};
68 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 65 RETURN_RESULT_OR_FAILURE(
69 isolate, trap_result, 66 isolate,
70 Execution::Call(isolate, trap, handler, arraysize(trap_args), trap_args)); 67 Execution::Call(isolate, trap, handler, arraysize(trap_args), trap_args));
71 return *trap_result;
72 } 68 }
73 69
74 70
75 // 9.5.14 [[Construct]] (argumentsList, newTarget) 71 // 9.5.14 [[Construct]] (argumentsList, newTarget)
76 RUNTIME_FUNCTION(Runtime_JSProxyConstruct) { 72 RUNTIME_FUNCTION(Runtime_JSProxyConstruct) {
77 HandleScope scope(isolate); 73 HandleScope scope(isolate);
78 DCHECK_LE(3, args.length()); 74 DCHECK_LE(3, args.length());
79 CONVERT_ARG_HANDLE_CHECKED(JSProxy, proxy, args.length() - 2); 75 CONVERT_ARG_HANDLE_CHECKED(JSProxy, proxy, args.length() - 2);
80 CONVERT_ARG_HANDLE_CHECKED(Object, new_target, args.length() - 1); 76 CONVERT_ARG_HANDLE_CHECKED(Object, new_target, args.length() - 1);
81 Handle<String> trap_name = isolate->factory()->construct_string(); 77 Handle<String> trap_name = isolate->factory()->construct_string();
(...skipping 17 matching lines...) Expand all
99 // 6. If trap is undefined, then 95 // 6. If trap is undefined, then
100 int const arguments_length = args.length() - 3; 96 int const arguments_length = args.length() - 3;
101 if (trap->IsUndefined()) { 97 if (trap->IsUndefined()) {
102 // 6.a. Assert: target has a [[Construct]] internal method. 98 // 6.a. Assert: target has a [[Construct]] internal method.
103 DCHECK(target->IsConstructor()); 99 DCHECK(target->IsConstructor());
104 // 6.b. Return Construct(target, argumentsList, newTarget). 100 // 6.b. Return Construct(target, argumentsList, newTarget).
105 ScopedVector<Handle<Object>> argv(arguments_length); 101 ScopedVector<Handle<Object>> argv(arguments_length);
106 for (int i = 0; i < arguments_length; ++i) { 102 for (int i = 0; i < arguments_length; ++i) {
107 argv[i] = args.at<Object>(i + 1); 103 argv[i] = args.at<Object>(i + 1);
108 } 104 }
109 Handle<Object> result; 105 RETURN_RESULT_OR_FAILURE(
110 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 106 isolate, Execution::New(isolate, target, new_target, arguments_length,
111 isolate, result, Execution::New(isolate, target, new_target, 107 argv.start()));
112 arguments_length, argv.start()));
113 return *result;
114 } 108 }
115 // 7. Let argArray be CreateArrayFromList(argumentsList). 109 // 7. Let argArray be CreateArrayFromList(argumentsList).
116 Handle<JSArray> arg_array = isolate->factory()->NewJSArray( 110 Handle<JSArray> arg_array = isolate->factory()->NewJSArray(
117 FAST_ELEMENTS, arguments_length, arguments_length); 111 FAST_ELEMENTS, arguments_length, arguments_length);
118 ElementsAccessor* accessor = arg_array->GetElementsAccessor(); 112 ElementsAccessor* accessor = arg_array->GetElementsAccessor();
119 { 113 {
120 DisallowHeapAllocation no_gc; 114 DisallowHeapAllocation no_gc;
121 for (int i = 0; i < arguments_length; i++) { 115 for (int i = 0; i < arguments_length; i++) {
122 accessor->Set(arg_array, i, args[i + 1]); 116 accessor->Set(arg_array, i, args[i + 1]);
123 } 117 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 RUNTIME_FUNCTION(Runtime_JSProxyRevoke) { 160 RUNTIME_FUNCTION(Runtime_JSProxyRevoke) {
167 HandleScope scope(isolate); 161 HandleScope scope(isolate);
168 DCHECK(args.length() == 1); 162 DCHECK(args.length() == 1);
169 CONVERT_ARG_HANDLE_CHECKED(JSProxy, proxy, 0); 163 CONVERT_ARG_HANDLE_CHECKED(JSProxy, proxy, 0);
170 JSProxy::Revoke(proxy); 164 JSProxy::Revoke(proxy);
171 return isolate->heap()->undefined_value(); 165 return isolate->heap()->undefined_value();
172 } 166 }
173 167
174 } // namespace internal 168 } // namespace internal
175 } // namespace v8 169 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime-operators.cc ('k') | src/runtime/runtime-regexp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698