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

Side by Side Diff: src/runtime/runtime-classes.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-atomics.cc ('k') | src/runtime/runtime-collections.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 <stdlib.h> 7 #include <stdlib.h>
8 #include <limits> 8 #include <limits>
9 9
10 #include "src/accessors.h" 10 #include "src/accessors.h"
11 #include "src/arguments.h" 11 #include "src/arguments.h"
12 #include "src/debug/debug.h" 12 #include "src/debug/debug.h"
13 #include "src/elements.h" 13 #include "src/elements.h"
14 #include "src/frames-inl.h" 14 #include "src/frames-inl.h"
15 #include "src/isolate-inl.h" 15 #include "src/isolate-inl.h"
16 #include "src/messages.h" 16 #include "src/messages.h"
17 #include "src/runtime/runtime.h" 17 #include "src/runtime/runtime.h"
18 18
19 namespace v8 { 19 namespace v8 {
20 namespace internal { 20 namespace internal {
21 21
22 22
23 RUNTIME_FUNCTION(Runtime_ThrowNonMethodError) { 23 RUNTIME_FUNCTION(Runtime_ThrowNonMethodError) {
24 HandleScope scope(isolate); 24 HandleScope scope(isolate);
25 DCHECK(args.length() == 0); 25 DCHECK_EQ(0, args.length());
26 THROW_NEW_ERROR_RETURN_FAILURE( 26 THROW_NEW_ERROR_RETURN_FAILURE(
27 isolate, NewReferenceError(MessageTemplate::kNonMethod)); 27 isolate, NewReferenceError(MessageTemplate::kNonMethod));
28 } 28 }
29 29
30 RUNTIME_FUNCTION(Runtime_ThrowUnsupportedSuperError) { 30 RUNTIME_FUNCTION(Runtime_ThrowUnsupportedSuperError) {
31 HandleScope scope(isolate); 31 HandleScope scope(isolate);
32 DCHECK(args.length() == 0); 32 DCHECK_EQ(0, args.length());
33 THROW_NEW_ERROR_RETURN_FAILURE( 33 THROW_NEW_ERROR_RETURN_FAILURE(
34 isolate, NewReferenceError(MessageTemplate::kUnsupportedSuper)); 34 isolate, NewReferenceError(MessageTemplate::kUnsupportedSuper));
35 } 35 }
36 36
37 37
38 RUNTIME_FUNCTION(Runtime_ThrowConstructorNonCallableError) { 38 RUNTIME_FUNCTION(Runtime_ThrowConstructorNonCallableError) {
39 HandleScope scope(isolate); 39 HandleScope scope(isolate);
40 DCHECK(args.length() == 1); 40 DCHECK_EQ(1, args.length());
41 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 0); 41 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 0);
42 Handle<Object> name(constructor->shared()->name(), isolate); 42 Handle<Object> name(constructor->shared()->name(), isolate);
43 THROW_NEW_ERROR_RETURN_FAILURE( 43 THROW_NEW_ERROR_RETURN_FAILURE(
44 isolate, NewTypeError(MessageTemplate::kConstructorNonCallable, name)); 44 isolate, NewTypeError(MessageTemplate::kConstructorNonCallable, name));
45 } 45 }
46 46
47 47
48 RUNTIME_FUNCTION(Runtime_ThrowArrayNotSubclassableError) { 48 RUNTIME_FUNCTION(Runtime_ThrowArrayNotSubclassableError) {
49 HandleScope scope(isolate); 49 HandleScope scope(isolate);
50 DCHECK(args.length() == 0); 50 DCHECK_EQ(0, args.length());
51 THROW_NEW_ERROR_RETURN_FAILURE( 51 THROW_NEW_ERROR_RETURN_FAILURE(
52 isolate, NewTypeError(MessageTemplate::kArrayNotSubclassable)); 52 isolate, NewTypeError(MessageTemplate::kArrayNotSubclassable));
53 } 53 }
54 54
55 RUNTIME_FUNCTION(Runtime_ThrowStaticPrototypeError) { 55 RUNTIME_FUNCTION(Runtime_ThrowStaticPrototypeError) {
56 HandleScope scope(isolate); 56 HandleScope scope(isolate);
57 DCHECK(args.length() == 0); 57 DCHECK_EQ(0, args.length());
58 THROW_NEW_ERROR_RETURN_FAILURE( 58 THROW_NEW_ERROR_RETURN_FAILURE(
59 isolate, NewTypeError(MessageTemplate::kStaticPrototype)); 59 isolate, NewTypeError(MessageTemplate::kStaticPrototype));
60 } 60 }
61 61
62 namespace { 62 namespace {
63 63
64 Object* ThrowNotSuperConstructor(Isolate* isolate, Handle<Object> constructor, 64 Object* ThrowNotSuperConstructor(Isolate* isolate, Handle<Object> constructor,
65 Handle<JSFunction> function) { 65 Handle<JSFunction> function) {
66 Handle<Object> super_name; 66 Handle<Object> super_name;
67 if (constructor->IsJSFunction()) { 67 if (constructor->IsJSFunction()) {
(...skipping 19 matching lines...) Expand all
87 } 87 }
88 THROW_NEW_ERROR_RETURN_FAILURE( 88 THROW_NEW_ERROR_RETURN_FAILURE(
89 isolate, NewTypeError(MessageTemplate::kNotSuperConstructor, super_name, 89 isolate, NewTypeError(MessageTemplate::kNotSuperConstructor, super_name,
90 function_name)); 90 function_name));
91 } 91 }
92 92
93 } // namespace 93 } // namespace
94 94
95 RUNTIME_FUNCTION(Runtime_ThrowNotSuperConstructor) { 95 RUNTIME_FUNCTION(Runtime_ThrowNotSuperConstructor) {
96 HandleScope scope(isolate); 96 HandleScope scope(isolate);
97 DCHECK(args.length() == 2); 97 DCHECK_EQ(2, args.length());
98 CONVERT_ARG_HANDLE_CHECKED(Object, constructor, 0); 98 CONVERT_ARG_HANDLE_CHECKED(Object, constructor, 0);
99 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 1); 99 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 1);
100 return ThrowNotSuperConstructor(isolate, constructor, function); 100 return ThrowNotSuperConstructor(isolate, constructor, function);
101 } 101 }
102 102
103 RUNTIME_FUNCTION(Runtime_HomeObjectSymbol) { 103 RUNTIME_FUNCTION(Runtime_HomeObjectSymbol) {
104 DCHECK(args.length() == 0); 104 DCHECK_EQ(0, args.length());
105 return isolate->heap()->home_object_symbol(); 105 return isolate->heap()->home_object_symbol();
106 } 106 }
107 107
108 static MaybeHandle<Object> DefineClass(Isolate* isolate, 108 static MaybeHandle<Object> DefineClass(Isolate* isolate,
109 Handle<Object> super_class, 109 Handle<Object> super_class,
110 Handle<JSFunction> constructor, 110 Handle<JSFunction> constructor,
111 int start_position, int end_position) { 111 int start_position, int end_position) {
112 Handle<Object> prototype_parent; 112 Handle<Object> prototype_parent;
113 Handle<Object> constructor_parent; 113 Handle<Object> constructor_parent;
114 114
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 handle(Smi::FromInt(end_position), isolate), STRICT), 188 handle(Smi::FromInt(end_position), isolate), STRICT),
189 Object); 189 Object);
190 190
191 // Caller already has access to constructor, so return the prototype. 191 // Caller already has access to constructor, so return the prototype.
192 return prototype; 192 return prototype;
193 } 193 }
194 194
195 195
196 RUNTIME_FUNCTION(Runtime_DefineClass) { 196 RUNTIME_FUNCTION(Runtime_DefineClass) {
197 HandleScope scope(isolate); 197 HandleScope scope(isolate);
198 DCHECK(args.length() == 4); 198 DCHECK_EQ(4, args.length());
199 CONVERT_ARG_HANDLE_CHECKED(Object, super_class, 0); 199 CONVERT_ARG_HANDLE_CHECKED(Object, super_class, 0);
200 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 1); 200 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 1);
201 CONVERT_SMI_ARG_CHECKED(start_position, 2); 201 CONVERT_SMI_ARG_CHECKED(start_position, 2);
202 CONVERT_SMI_ARG_CHECKED(end_position, 3); 202 CONVERT_SMI_ARG_CHECKED(end_position, 3);
203 203
204 RETURN_RESULT_OR_FAILURE( 204 RETURN_RESULT_OR_FAILURE(
205 isolate, DefineClass(isolate, super_class, constructor, start_position, 205 isolate, DefineClass(isolate, super_class, constructor, start_position,
206 end_position)); 206 end_position));
207 } 207 }
208 208
209 namespace { 209 namespace {
210 void InstallClassNameAccessor(Isolate* isolate, Handle<JSObject> object) { 210 void InstallClassNameAccessor(Isolate* isolate, Handle<JSObject> object) {
211 PropertyAttributes attrs = 211 PropertyAttributes attrs =
212 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); 212 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY);
213 // Cannot fail since this should only be called when creating an object 213 // Cannot fail since this should only be called when creating an object
214 // literal. 214 // literal.
215 CHECK(!JSObject::SetAccessor( 215 CHECK(!JSObject::SetAccessor(
216 object, Accessors::FunctionNameInfo(object->GetIsolate(), attrs)) 216 object, Accessors::FunctionNameInfo(object->GetIsolate(), attrs))
217 .is_null()); 217 .is_null());
218 } 218 }
219 } // anonymous namespace 219 } // anonymous namespace
220 220
221 RUNTIME_FUNCTION(Runtime_InstallClassNameAccessor) { 221 RUNTIME_FUNCTION(Runtime_InstallClassNameAccessor) {
222 HandleScope scope(isolate); 222 HandleScope scope(isolate);
223 DCHECK(args.length() == 1); 223 DCHECK_EQ(1, args.length());
224 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); 224 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0);
225 InstallClassNameAccessor(isolate, object); 225 InstallClassNameAccessor(isolate, object);
226 return *object; 226 return *object;
227 } 227 }
228 228
229 RUNTIME_FUNCTION(Runtime_InstallClassNameAccessorWithCheck) { 229 RUNTIME_FUNCTION(Runtime_InstallClassNameAccessorWithCheck) {
230 HandleScope scope(isolate); 230 HandleScope scope(isolate);
231 DCHECK(args.length() == 1); 231 DCHECK_EQ(1, args.length());
232 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); 232 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0);
233 233
234 // If a property named "name" is already defined, exit. 234 // If a property named "name" is already defined, exit.
235 Handle<Name> key = isolate->factory()->name_string(); 235 Handle<Name> key = isolate->factory()->name_string();
236 if (JSObject::HasRealNamedProperty(object, key).FromMaybe(false)) { 236 if (JSObject::HasRealNamedProperty(object, key).FromMaybe(false)) {
237 return *object; 237 return *object;
238 } 238 }
239 239
240 // Define the "name" accessor. 240 // Define the "name" accessor.
241 InstallClassNameAccessor(isolate, object); 241 InstallClassNameAccessor(isolate, object);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 MAYBE_RETURN(Object::SetSuperProperty(&it, value, language_mode, 373 MAYBE_RETURN(Object::SetSuperProperty(&it, value, language_mode,
374 Object::MAY_BE_STORE_FROM_KEYED), 374 Object::MAY_BE_STORE_FROM_KEYED),
375 MaybeHandle<Object>()); 375 MaybeHandle<Object>());
376 return value; 376 return value;
377 } 377 }
378 378
379 } // anonymous namespace 379 } // anonymous namespace
380 380
381 RUNTIME_FUNCTION(Runtime_StoreToSuper_Strict) { 381 RUNTIME_FUNCTION(Runtime_StoreToSuper_Strict) {
382 HandleScope scope(isolate); 382 HandleScope scope(isolate);
383 DCHECK(args.length() == 4); 383 DCHECK_EQ(4, args.length());
384 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0); 384 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0);
385 CONVERT_ARG_HANDLE_CHECKED(JSObject, home_object, 1); 385 CONVERT_ARG_HANDLE_CHECKED(JSObject, home_object, 1);
386 CONVERT_ARG_HANDLE_CHECKED(Name, name, 2); 386 CONVERT_ARG_HANDLE_CHECKED(Name, name, 2);
387 CONVERT_ARG_HANDLE_CHECKED(Object, value, 3); 387 CONVERT_ARG_HANDLE_CHECKED(Object, value, 3);
388 388
389 RETURN_RESULT_OR_FAILURE(isolate, StoreToSuper(isolate, home_object, receiver, 389 RETURN_RESULT_OR_FAILURE(isolate, StoreToSuper(isolate, home_object, receiver,
390 name, value, STRICT)); 390 name, value, STRICT));
391 } 391 }
392 392
393 393
394 RUNTIME_FUNCTION(Runtime_StoreToSuper_Sloppy) { 394 RUNTIME_FUNCTION(Runtime_StoreToSuper_Sloppy) {
395 HandleScope scope(isolate); 395 HandleScope scope(isolate);
396 DCHECK(args.length() == 4); 396 DCHECK_EQ(4, args.length());
397 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0); 397 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0);
398 CONVERT_ARG_HANDLE_CHECKED(JSObject, home_object, 1); 398 CONVERT_ARG_HANDLE_CHECKED(JSObject, home_object, 1);
399 CONVERT_ARG_HANDLE_CHECKED(Name, name, 2); 399 CONVERT_ARG_HANDLE_CHECKED(Name, name, 2);
400 CONVERT_ARG_HANDLE_CHECKED(Object, value, 3); 400 CONVERT_ARG_HANDLE_CHECKED(Object, value, 3);
401 401
402 RETURN_RESULT_OR_FAILURE(isolate, StoreToSuper(isolate, home_object, receiver, 402 RETURN_RESULT_OR_FAILURE(isolate, StoreToSuper(isolate, home_object, receiver,
403 name, value, SLOPPY)); 403 name, value, SLOPPY));
404 } 404 }
405 405
406 static MaybeHandle<Object> StoreKeyedToSuper( 406 static MaybeHandle<Object> StoreKeyedToSuper(
(...skipping 13 matching lines...) Expand all
420 return StoreElementToSuper(isolate, home_object, receiver, index, value, 420 return StoreElementToSuper(isolate, home_object, receiver, index, value,
421 language_mode); 421 language_mode);
422 } 422 }
423 return StoreToSuper(isolate, home_object, receiver, name, value, 423 return StoreToSuper(isolate, home_object, receiver, name, value,
424 language_mode); 424 language_mode);
425 } 425 }
426 426
427 427
428 RUNTIME_FUNCTION(Runtime_StoreKeyedToSuper_Strict) { 428 RUNTIME_FUNCTION(Runtime_StoreKeyedToSuper_Strict) {
429 HandleScope scope(isolate); 429 HandleScope scope(isolate);
430 DCHECK(args.length() == 4); 430 DCHECK_EQ(4, args.length());
431 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0); 431 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0);
432 CONVERT_ARG_HANDLE_CHECKED(JSObject, home_object, 1); 432 CONVERT_ARG_HANDLE_CHECKED(JSObject, home_object, 1);
433 CONVERT_ARG_HANDLE_CHECKED(Object, key, 2); 433 CONVERT_ARG_HANDLE_CHECKED(Object, key, 2);
434 CONVERT_ARG_HANDLE_CHECKED(Object, value, 3); 434 CONVERT_ARG_HANDLE_CHECKED(Object, value, 3);
435 435
436 RETURN_RESULT_OR_FAILURE( 436 RETURN_RESULT_OR_FAILURE(
437 isolate, 437 isolate,
438 StoreKeyedToSuper(isolate, home_object, receiver, key, value, STRICT)); 438 StoreKeyedToSuper(isolate, home_object, receiver, key, value, STRICT));
439 } 439 }
440 440
441 441
442 RUNTIME_FUNCTION(Runtime_StoreKeyedToSuper_Sloppy) { 442 RUNTIME_FUNCTION(Runtime_StoreKeyedToSuper_Sloppy) {
443 HandleScope scope(isolate); 443 HandleScope scope(isolate);
444 DCHECK(args.length() == 4); 444 DCHECK_EQ(4, args.length());
445 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0); 445 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0);
446 CONVERT_ARG_HANDLE_CHECKED(JSObject, home_object, 1); 446 CONVERT_ARG_HANDLE_CHECKED(JSObject, home_object, 1);
447 CONVERT_ARG_HANDLE_CHECKED(Object, key, 2); 447 CONVERT_ARG_HANDLE_CHECKED(Object, key, 2);
448 CONVERT_ARG_HANDLE_CHECKED(Object, value, 3); 448 CONVERT_ARG_HANDLE_CHECKED(Object, value, 3);
449 449
450 RETURN_RESULT_OR_FAILURE( 450 RETURN_RESULT_OR_FAILURE(
451 isolate, 451 isolate,
452 StoreKeyedToSuper(isolate, home_object, receiver, key, value, SLOPPY)); 452 StoreKeyedToSuper(isolate, home_object, receiver, key, value, SLOPPY));
453 } 453 }
454 454
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 } 504 }
505 505
506 // Call the constructor. 506 // Call the constructor.
507 RETURN_RESULT_OR_FAILURE( 507 RETURN_RESULT_OR_FAILURE(
508 isolate, Execution::New(isolate, constructor, new_target, result_length, 508 isolate, Execution::New(isolate, constructor, new_target, result_length,
509 construct_args.start())); 509 construct_args.start()));
510 } 510 }
511 511
512 } // namespace internal 512 } // namespace internal
513 } // namespace v8 513 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime-atomics.cc ('k') | src/runtime/runtime-collections.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698