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 <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(args.length() == 0); |
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 | |
31 RUNTIME_FUNCTION(Runtime_ThrowUnsupportedSuperError) { | 30 RUNTIME_FUNCTION(Runtime_ThrowUnsupportedSuperError) { |
32 HandleScope scope(isolate); | 31 HandleScope scope(isolate); |
33 DCHECK(args.length() == 0); | 32 DCHECK(args.length() == 0); |
34 THROW_NEW_ERROR_RETURN_FAILURE( | 33 THROW_NEW_ERROR_RETURN_FAILURE( |
35 isolate, NewReferenceError(MessageTemplate::kUnsupportedSuper)); | 34 isolate, NewReferenceError(MessageTemplate::kUnsupportedSuper)); |
36 } | 35 } |
37 | 36 |
38 | 37 |
39 RUNTIME_FUNCTION(Runtime_ThrowConstructorNonCallableError) { | 38 RUNTIME_FUNCTION(Runtime_ThrowConstructorNonCallableError) { |
40 HandleScope scope(isolate); | 39 HandleScope scope(isolate); |
(...skipping 12 matching lines...) Expand all Loading... |
53 isolate, NewTypeError(MessageTemplate::kArrayNotSubclassable)); | 52 isolate, NewTypeError(MessageTemplate::kArrayNotSubclassable)); |
54 } | 53 } |
55 | 54 |
56 RUNTIME_FUNCTION(Runtime_ThrowStaticPrototypeError) { | 55 RUNTIME_FUNCTION(Runtime_ThrowStaticPrototypeError) { |
57 HandleScope scope(isolate); | 56 HandleScope scope(isolate); |
58 DCHECK(args.length() == 0); | 57 DCHECK(args.length() == 0); |
59 THROW_NEW_ERROR_RETURN_FAILURE( | 58 THROW_NEW_ERROR_RETURN_FAILURE( |
60 isolate, NewTypeError(MessageTemplate::kStaticPrototype)); | 59 isolate, NewTypeError(MessageTemplate::kStaticPrototype)); |
61 } | 60 } |
62 | 61 |
| 62 namespace { |
| 63 |
| 64 Object* ThrowNotSuperConstructor(Isolate* isolate, Handle<Object> constructor, |
| 65 Handle<JSFunction> function) { |
| 66 Handle<Object> super_name; |
| 67 if (constructor->IsJSFunction()) { |
| 68 super_name = handle(Handle<JSFunction>::cast(constructor)->shared()->name(), |
| 69 isolate); |
| 70 } else if (constructor->IsOddball()) { |
| 71 DCHECK(constructor->IsNull(isolate)); |
| 72 super_name = isolate->factory()->null_string(); |
| 73 } else { |
| 74 super_name = Object::NoSideEffectsToString(isolate, constructor); |
| 75 } |
| 76 // null constructor |
| 77 if (Handle<String>::cast(super_name)->length() == 0) { |
| 78 super_name = isolate->factory()->null_string(); |
| 79 } |
| 80 Handle<Object> function_name(function->shared()->name(), isolate); |
| 81 // anonymous class |
| 82 if (Handle<String>::cast(function_name)->length() == 0) { |
| 83 THROW_NEW_ERROR_RETURN_FAILURE( |
| 84 isolate, |
| 85 NewTypeError(MessageTemplate::kNotSuperConstructorAnonymousClass, |
| 86 super_name)); |
| 87 } |
| 88 THROW_NEW_ERROR_RETURN_FAILURE( |
| 89 isolate, NewTypeError(MessageTemplate::kNotSuperConstructor, super_name, |
| 90 function_name)); |
| 91 } |
| 92 |
| 93 } // namespace |
| 94 |
| 95 RUNTIME_FUNCTION(Runtime_ThrowNotSuperConstructor) { |
| 96 HandleScope scope(isolate); |
| 97 DCHECK(args.length() == 2); |
| 98 CONVERT_ARG_HANDLE_CHECKED(Object, constructor, 0); |
| 99 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 1); |
| 100 return ThrowNotSuperConstructor(isolate, constructor, function); |
| 101 } |
| 102 |
63 RUNTIME_FUNCTION(Runtime_HomeObjectSymbol) { | 103 RUNTIME_FUNCTION(Runtime_HomeObjectSymbol) { |
64 DCHECK(args.length() == 0); | 104 DCHECK(args.length() == 0); |
65 return isolate->heap()->home_object_symbol(); | 105 return isolate->heap()->home_object_symbol(); |
66 } | 106 } |
67 | 107 |
68 static MaybeHandle<Object> DefineClass(Isolate* isolate, | 108 static MaybeHandle<Object> DefineClass(Isolate* isolate, |
69 Handle<Object> super_class, | 109 Handle<Object> super_class, |
70 Handle<JSFunction> constructor, | 110 Handle<JSFunction> constructor, |
71 int start_position, int end_position) { | 111 int start_position, int end_position) { |
72 Handle<Object> prototype_parent; | 112 Handle<Object> prototype_parent; |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 | 455 |
416 RETURN_RESULT_OR_FAILURE( | 456 RETURN_RESULT_OR_FAILURE( |
417 isolate, | 457 isolate, |
418 StoreKeyedToSuper(isolate, home_object, receiver, key, value, SLOPPY)); | 458 StoreKeyedToSuper(isolate, home_object, receiver, key, value, SLOPPY)); |
419 } | 459 } |
420 | 460 |
421 | 461 |
422 RUNTIME_FUNCTION(Runtime_GetSuperConstructor) { | 462 RUNTIME_FUNCTION(Runtime_GetSuperConstructor) { |
423 SealHandleScope shs(isolate); | 463 SealHandleScope shs(isolate); |
424 DCHECK_EQ(1, args.length()); | 464 DCHECK_EQ(1, args.length()); |
425 CONVERT_ARG_CHECKED(JSFunction, active_function, 0); | 465 CONVERT_ARG_HANDLE_CHECKED(JSFunction, active_function, 0); |
426 return active_function->map()->prototype(); | 466 Object* prototype = active_function->map()->prototype(); |
| 467 if (!prototype->IsConstructor()) { |
| 468 return ThrowNotSuperConstructor( |
| 469 isolate, Handle<JSFunction>::cast(handle(prototype, isolate)), |
| 470 active_function); |
| 471 } |
| 472 return prototype; |
427 } | 473 } |
428 | 474 |
429 RUNTIME_FUNCTION(Runtime_NewWithSpread) { | 475 RUNTIME_FUNCTION(Runtime_NewWithSpread) { |
430 HandleScope scope(isolate); | 476 HandleScope scope(isolate); |
431 DCHECK_LE(3, args.length()); | 477 DCHECK_LE(3, args.length()); |
432 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, constructor, 0); | 478 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, constructor, 0); |
433 CONVERT_ARG_HANDLE_CHECKED(Object, new_target, 1); | 479 CONVERT_ARG_HANDLE_CHECKED(Object, new_target, 1); |
434 | 480 |
435 int constructor_argc = args.length() - 2; | 481 int constructor_argc = args.length() - 2; |
436 CONVERT_ARG_HANDLE_CHECKED(Object, spread, args.length() - 1); | 482 CONVERT_ARG_HANDLE_CHECKED(Object, spread, args.length() - 1); |
(...skipping 27 matching lines...) Expand all Loading... |
464 } | 510 } |
465 | 511 |
466 // Call the constructor. | 512 // Call the constructor. |
467 RETURN_RESULT_OR_FAILURE( | 513 RETURN_RESULT_OR_FAILURE( |
468 isolate, Execution::New(isolate, constructor, new_target, result_length, | 514 isolate, Execution::New(isolate, constructor, new_target, result_length, |
469 construct_args.start())); | 515 construct_args.start())); |
470 } | 516 } |
471 | 517 |
472 } // namespace internal | 518 } // namespace internal |
473 } // namespace v8 | 519 } // namespace v8 |
OLD | NEW |