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

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

Issue 2613723002: [runtime] Use DCHECK_EQ instead of DCHECK for number of args. (Closed)
Patch Set: Rebase. Created 3 years, 11 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-error.cc ('k') | src/runtime/runtime-futex.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/accessors.h" 7 #include "src/accessors.h"
8 #include "src/arguments.h" 8 #include "src/arguments.h"
9 #include "src/compiler.h" 9 #include "src/compiler.h"
10 #include "src/frames-inl.h" 10 #include "src/frames-inl.h"
11 #include "src/isolate-inl.h" 11 #include "src/isolate-inl.h"
12 #include "src/messages.h" 12 #include "src/messages.h"
13 #include "src/wasm/wasm-module.h" 13 #include "src/wasm/wasm-module.h"
14 14
15 namespace v8 { 15 namespace v8 {
16 namespace internal { 16 namespace internal {
17 17
18 RUNTIME_FUNCTION(Runtime_FunctionGetName) { 18 RUNTIME_FUNCTION(Runtime_FunctionGetName) {
19 HandleScope scope(isolate); 19 HandleScope scope(isolate);
20 DCHECK(args.length() == 1); 20 DCHECK_EQ(1, args.length());
21 21
22 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, function, 0); 22 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, function, 0);
23 if (function->IsJSBoundFunction()) { 23 if (function->IsJSBoundFunction()) {
24 RETURN_RESULT_OR_FAILURE( 24 RETURN_RESULT_OR_FAILURE(
25 isolate, JSBoundFunction::GetName( 25 isolate, JSBoundFunction::GetName(
26 isolate, Handle<JSBoundFunction>::cast(function))); 26 isolate, Handle<JSBoundFunction>::cast(function)));
27 } else { 27 } else {
28 return *JSFunction::GetName(isolate, Handle<JSFunction>::cast(function)); 28 return *JSFunction::GetName(isolate, Handle<JSFunction>::cast(function));
29 } 29 }
30 } 30 }
31 31
32 32
33 RUNTIME_FUNCTION(Runtime_FunctionSetName) { 33 RUNTIME_FUNCTION(Runtime_FunctionSetName) {
34 HandleScope scope(isolate); 34 HandleScope scope(isolate);
35 DCHECK(args.length() == 2); 35 DCHECK_EQ(2, args.length());
36 36
37 CONVERT_ARG_HANDLE_CHECKED(JSFunction, f, 0); 37 CONVERT_ARG_HANDLE_CHECKED(JSFunction, f, 0);
38 CONVERT_ARG_HANDLE_CHECKED(String, name, 1); 38 CONVERT_ARG_HANDLE_CHECKED(String, name, 1);
39 39
40 name = String::Flatten(name); 40 name = String::Flatten(name);
41 f->shared()->set_name(*name); 41 f->shared()->set_name(*name);
42 return isolate->heap()->undefined_value(); 42 return isolate->heap()->undefined_value();
43 } 43 }
44 44
45 45
46 RUNTIME_FUNCTION(Runtime_FunctionRemovePrototype) { 46 RUNTIME_FUNCTION(Runtime_FunctionRemovePrototype) {
47 SealHandleScope shs(isolate); 47 SealHandleScope shs(isolate);
48 DCHECK(args.length() == 1); 48 DCHECK_EQ(1, args.length());
49 49
50 CONVERT_ARG_CHECKED(JSFunction, f, 0); 50 CONVERT_ARG_CHECKED(JSFunction, f, 0);
51 CHECK(f->RemovePrototype()); 51 CHECK(f->RemovePrototype());
52 f->shared()->SetConstructStub( 52 f->shared()->SetConstructStub(
53 *isolate->builtins()->ConstructedNonConstructable()); 53 *isolate->builtins()->ConstructedNonConstructable());
54 54
55 return isolate->heap()->undefined_value(); 55 return isolate->heap()->undefined_value();
56 } 56 }
57 57
58 // TODO(5530): Remove once uses in debug.js are gone. 58 // TODO(5530): Remove once uses in debug.js are gone.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, function, 0); 92 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, function, 0);
93 if (function->IsJSFunction()) { 93 if (function->IsJSFunction()) {
94 return *Handle<JSFunction>::cast(function)->shared()->GetSourceCode(); 94 return *Handle<JSFunction>::cast(function)->shared()->GetSourceCode();
95 } 95 }
96 return isolate->heap()->undefined_value(); 96 return isolate->heap()->undefined_value();
97 } 97 }
98 98
99 99
100 RUNTIME_FUNCTION(Runtime_FunctionGetScriptSourcePosition) { 100 RUNTIME_FUNCTION(Runtime_FunctionGetScriptSourcePosition) {
101 SealHandleScope shs(isolate); 101 SealHandleScope shs(isolate);
102 DCHECK(args.length() == 1); 102 DCHECK_EQ(1, args.length());
103 103
104 CONVERT_ARG_CHECKED(JSFunction, fun, 0); 104 CONVERT_ARG_CHECKED(JSFunction, fun, 0);
105 int pos = fun->shared()->start_position(); 105 int pos = fun->shared()->start_position();
106 return Smi::FromInt(pos); 106 return Smi::FromInt(pos);
107 } 107 }
108 108
109 RUNTIME_FUNCTION(Runtime_FunctionGetContextData) { 109 RUNTIME_FUNCTION(Runtime_FunctionGetContextData) {
110 SealHandleScope shs(isolate); 110 SealHandleScope shs(isolate);
111 DCHECK(args.length() == 1); 111 DCHECK_EQ(1, args.length());
112 112
113 CONVERT_ARG_CHECKED(JSFunction, fun, 0); 113 CONVERT_ARG_CHECKED(JSFunction, fun, 0);
114 FixedArray* array = fun->native_context()->embedder_data(); 114 FixedArray* array = fun->native_context()->embedder_data();
115 return array->get(v8::Context::kDebugIdIndex); 115 return array->get(v8::Context::kDebugIdIndex);
116 } 116 }
117 117
118 RUNTIME_FUNCTION(Runtime_FunctionSetInstanceClassName) { 118 RUNTIME_FUNCTION(Runtime_FunctionSetInstanceClassName) {
119 SealHandleScope shs(isolate); 119 SealHandleScope shs(isolate);
120 DCHECK(args.length() == 2); 120 DCHECK_EQ(2, args.length());
121 121
122 CONVERT_ARG_CHECKED(JSFunction, fun, 0); 122 CONVERT_ARG_CHECKED(JSFunction, fun, 0);
123 CONVERT_ARG_CHECKED(String, name, 1); 123 CONVERT_ARG_CHECKED(String, name, 1);
124 fun->shared()->set_instance_class_name(name); 124 fun->shared()->set_instance_class_name(name);
125 return isolate->heap()->undefined_value(); 125 return isolate->heap()->undefined_value();
126 } 126 }
127 127
128 128
129 RUNTIME_FUNCTION(Runtime_FunctionSetLength) { 129 RUNTIME_FUNCTION(Runtime_FunctionSetLength) {
130 SealHandleScope shs(isolate); 130 SealHandleScope shs(isolate);
131 DCHECK(args.length() == 2); 131 DCHECK_EQ(2, args.length());
132 132
133 CONVERT_ARG_CHECKED(JSFunction, fun, 0); 133 CONVERT_ARG_CHECKED(JSFunction, fun, 0);
134 CONVERT_SMI_ARG_CHECKED(length, 1); 134 CONVERT_SMI_ARG_CHECKED(length, 1);
135 CHECK((length & 0xC0000000) == 0xC0000000 || (length & 0xC0000000) == 0x0); 135 CHECK((length & 0xC0000000) == 0xC0000000 || (length & 0xC0000000) == 0x0);
136 fun->shared()->set_length(length); 136 fun->shared()->set_length(length);
137 return isolate->heap()->undefined_value(); 137 return isolate->heap()->undefined_value();
138 } 138 }
139 139
140 140
141 RUNTIME_FUNCTION(Runtime_FunctionSetPrototype) { 141 RUNTIME_FUNCTION(Runtime_FunctionSetPrototype) {
142 HandleScope scope(isolate); 142 HandleScope scope(isolate);
143 DCHECK(args.length() == 2); 143 DCHECK_EQ(2, args.length());
144 144
145 CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0); 145 CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0);
146 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); 146 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1);
147 CHECK(fun->IsConstructor()); 147 CHECK(fun->IsConstructor());
148 RETURN_FAILURE_ON_EXCEPTION(isolate, 148 RETURN_FAILURE_ON_EXCEPTION(isolate,
149 Accessors::FunctionSetPrototype(fun, value)); 149 Accessors::FunctionSetPrototype(fun, value));
150 return args[0]; // return TOS 150 return args[0]; // return TOS
151 } 151 }
152 152
153 153
154 RUNTIME_FUNCTION(Runtime_FunctionIsAPIFunction) { 154 RUNTIME_FUNCTION(Runtime_FunctionIsAPIFunction) {
155 SealHandleScope shs(isolate); 155 SealHandleScope shs(isolate);
156 DCHECK(args.length() == 1); 156 DCHECK_EQ(1, args.length());
157 157
158 CONVERT_ARG_CHECKED(JSFunction, f, 0); 158 CONVERT_ARG_CHECKED(JSFunction, f, 0);
159 return isolate->heap()->ToBoolean(f->shared()->IsApiFunction()); 159 return isolate->heap()->ToBoolean(f->shared()->IsApiFunction());
160 } 160 }
161 161
162 162
163 RUNTIME_FUNCTION(Runtime_SetCode) { 163 RUNTIME_FUNCTION(Runtime_SetCode) {
164 HandleScope scope(isolate); 164 HandleScope scope(isolate);
165 DCHECK(args.length() == 2); 165 DCHECK_EQ(2, args.length());
166 166
167 CONVERT_ARG_HANDLE_CHECKED(JSFunction, target, 0); 167 CONVERT_ARG_HANDLE_CHECKED(JSFunction, target, 0);
168 CONVERT_ARG_HANDLE_CHECKED(JSFunction, source, 1); 168 CONVERT_ARG_HANDLE_CHECKED(JSFunction, source, 1);
169 169
170 Handle<SharedFunctionInfo> target_shared(target->shared()); 170 Handle<SharedFunctionInfo> target_shared(target->shared());
171 Handle<SharedFunctionInfo> source_shared(source->shared()); 171 Handle<SharedFunctionInfo> source_shared(source->shared());
172 172
173 if (!Compiler::Compile(source, Compiler::KEEP_EXCEPTION)) { 173 if (!Compiler::Compile(source, Compiler::KEEP_EXCEPTION)) {
174 return isolate->heap()->exception(); 174 return isolate->heap()->exception();
175 } 175 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 argv[i] = args.at(2 + i); 281 argv[i] = args.at(2 + i);
282 } 282 }
283 RETURN_RESULT_OR_FAILURE( 283 RETURN_RESULT_OR_FAILURE(
284 isolate, Execution::Call(isolate, target, receiver, argc, argv.start())); 284 isolate, Execution::Call(isolate, target, receiver, argc, argv.start()));
285 } 285 }
286 286
287 287
288 // ES6 section 9.2.1.2, OrdinaryCallBindThis for sloppy callee. 288 // ES6 section 9.2.1.2, OrdinaryCallBindThis for sloppy callee.
289 RUNTIME_FUNCTION(Runtime_ConvertReceiver) { 289 RUNTIME_FUNCTION(Runtime_ConvertReceiver) {
290 HandleScope scope(isolate); 290 HandleScope scope(isolate);
291 DCHECK(args.length() == 1); 291 DCHECK_EQ(1, args.length());
292 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0); 292 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0);
293 return *Object::ConvertReceiver(isolate, receiver).ToHandleChecked(); 293 return *Object::ConvertReceiver(isolate, receiver).ToHandleChecked();
294 } 294 }
295 295
296 296
297 RUNTIME_FUNCTION(Runtime_IsFunction) { 297 RUNTIME_FUNCTION(Runtime_IsFunction) {
298 SealHandleScope shs(isolate); 298 SealHandleScope shs(isolate);
299 DCHECK_EQ(1, args.length()); 299 DCHECK_EQ(1, args.length());
300 CONVERT_ARG_CHECKED(Object, object, 0); 300 CONVERT_ARG_CHECKED(Object, object, 0);
301 return isolate->heap()->ToBoolean(object->IsFunction()); 301 return isolate->heap()->ToBoolean(object->IsFunction());
302 } 302 }
303 303
304 304
305 RUNTIME_FUNCTION(Runtime_FunctionToString) { 305 RUNTIME_FUNCTION(Runtime_FunctionToString) {
306 HandleScope scope(isolate); 306 HandleScope scope(isolate);
307 DCHECK_EQ(1, args.length()); 307 DCHECK_EQ(1, args.length());
308 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, function, 0); 308 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, function, 0);
309 return function->IsJSBoundFunction() 309 return function->IsJSBoundFunction()
310 ? *JSBoundFunction::ToString( 310 ? *JSBoundFunction::ToString(
311 Handle<JSBoundFunction>::cast(function)) 311 Handle<JSBoundFunction>::cast(function))
312 : *JSFunction::ToString(Handle<JSFunction>::cast(function)); 312 : *JSFunction::ToString(Handle<JSFunction>::cast(function));
313 } 313 }
314 314
315 } // namespace internal 315 } // namespace internal
316 } // namespace v8 316 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime-error.cc ('k') | src/runtime/runtime-futex.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698