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/frames-inl.h" | 13 #include "src/frames-inl.h" |
14 #include "src/isolate-inl.h" | 14 #include "src/isolate-inl.h" |
15 #include "src/messages.h" | 15 #include "src/messages.h" |
16 #include "src/runtime/runtime.h" | 16 #include "src/runtime/runtime.h" |
17 | 17 |
18 namespace v8 { | 18 namespace v8 { |
19 namespace internal { | 19 namespace internal { |
20 | 20 |
21 | 21 |
22 RUNTIME_FUNCTION(Runtime_ThrowNonMethodError) { | 22 RUNTIME_FUNCTION(Runtime_ThrowNonMethodError) { |
23 HandleScope scope(isolate); | 23 HandleScope scope(isolate); |
24 DCHECK(args.length() == 0); | 24 DCHECK(args.length() == 0); |
25 THROW_NEW_ERROR_RETURN_FAILURE( | 25 THROW_NEW_ERROR_RETURN_FAILURE( |
26 isolate, NewReferenceError(MessageTemplate::kNonMethod)); | 26 isolate, NewReferenceError(MessageTemplate::kNonMethod)); |
27 } | 27 } |
28 | 28 |
29 | |
30 RUNTIME_FUNCTION(Runtime_ThrowUnsupportedSuperError) { | 29 RUNTIME_FUNCTION(Runtime_ThrowUnsupportedSuperError) { |
31 HandleScope scope(isolate); | 30 HandleScope scope(isolate); |
32 DCHECK(args.length() == 0); | 31 DCHECK(args.length() == 0); |
33 THROW_NEW_ERROR_RETURN_FAILURE( | 32 THROW_NEW_ERROR_RETURN_FAILURE( |
34 isolate, NewReferenceError(MessageTemplate::kUnsupportedSuper)); | 33 isolate, NewReferenceError(MessageTemplate::kUnsupportedSuper)); |
35 } | 34 } |
36 | 35 |
37 | 36 |
38 RUNTIME_FUNCTION(Runtime_ThrowConstructorNonCallableError) { | 37 RUNTIME_FUNCTION(Runtime_ThrowConstructorNonCallableError) { |
39 HandleScope scope(isolate); | 38 HandleScope scope(isolate); |
(...skipping 12 matching lines...) Expand all Loading... | |
52 isolate, NewTypeError(MessageTemplate::kArrayNotSubclassable)); | 51 isolate, NewTypeError(MessageTemplate::kArrayNotSubclassable)); |
53 } | 52 } |
54 | 53 |
55 RUNTIME_FUNCTION(Runtime_ThrowStaticPrototypeError) { | 54 RUNTIME_FUNCTION(Runtime_ThrowStaticPrototypeError) { |
56 HandleScope scope(isolate); | 55 HandleScope scope(isolate); |
57 DCHECK(args.length() == 0); | 56 DCHECK(args.length() == 0); |
58 THROW_NEW_ERROR_RETURN_FAILURE( | 57 THROW_NEW_ERROR_RETURN_FAILURE( |
59 isolate, NewTypeError(MessageTemplate::kStaticPrototype)); | 58 isolate, NewTypeError(MessageTemplate::kStaticPrototype)); |
60 } | 59 } |
61 | 60 |
61 namespace { | |
Benedikt Meurer
2016/12/08 18:42:24
Nit: empty line after { and before } below.
| |
62 Object* ThrowNotSuperConstructor(Isolate* isolate, | |
63 Handle<JSFunction> constructor, | |
64 Handle<JSFunction> function) { | |
65 Handle<Object> super_name(constructor->shared()->name(), isolate); | |
66 Handle<Object> function_name(function->shared()->name(), isolate); | |
67 THROW_NEW_ERROR_RETURN_FAILURE( | |
68 isolate, NewTypeError(MessageTemplate::kNotSuperConstructor, super_name, | |
69 function_name)); | |
70 } | |
71 } // anonymous namespace | |
72 | |
73 RUNTIME_FUNCTION(Runtime_ThrowNotSuperConstructor) { | |
74 HandleScope scope(isolate); | |
75 DCHECK(args.length() == 2); | |
76 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 0); | |
77 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 1); | |
78 return ThrowNotSuperConstructor(isolate, constructor, function); | |
79 } | |
80 | |
62 RUNTIME_FUNCTION(Runtime_HomeObjectSymbol) { | 81 RUNTIME_FUNCTION(Runtime_HomeObjectSymbol) { |
63 DCHECK(args.length() == 0); | 82 DCHECK(args.length() == 0); |
64 return isolate->heap()->home_object_symbol(); | 83 return isolate->heap()->home_object_symbol(); |
65 } | 84 } |
66 | 85 |
67 static MaybeHandle<Object> DefineClass(Isolate* isolate, | 86 static MaybeHandle<Object> DefineClass(Isolate* isolate, |
68 Handle<Object> super_class, | 87 Handle<Object> super_class, |
69 Handle<JSFunction> constructor, | 88 Handle<JSFunction> constructor, |
70 int start_position, int end_position) { | 89 int start_position, int end_position) { |
71 Handle<Object> prototype_parent; | 90 Handle<Object> prototype_parent; |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
414 | 433 |
415 RETURN_RESULT_OR_FAILURE( | 434 RETURN_RESULT_OR_FAILURE( |
416 isolate, | 435 isolate, |
417 StoreKeyedToSuper(isolate, home_object, receiver, key, value, SLOPPY)); | 436 StoreKeyedToSuper(isolate, home_object, receiver, key, value, SLOPPY)); |
418 } | 437 } |
419 | 438 |
420 | 439 |
421 RUNTIME_FUNCTION(Runtime_GetSuperConstructor) { | 440 RUNTIME_FUNCTION(Runtime_GetSuperConstructor) { |
422 SealHandleScope shs(isolate); | 441 SealHandleScope shs(isolate); |
423 DCHECK_EQ(1, args.length()); | 442 DCHECK_EQ(1, args.length()); |
424 CONVERT_ARG_CHECKED(JSFunction, active_function, 0); | 443 CONVERT_ARG_HANDLE_CHECKED(JSFunction, active_function, 0); |
425 return active_function->map()->prototype(); | 444 Object* prototype = active_function->map()->prototype(); |
445 if (!prototype->IsConstructor()) { | |
446 return ThrowNotSuperConstructor( | |
447 isolate, Handle<JSFunction>::cast(handle(prototype, isolate)), | |
448 active_function); | |
449 } | |
450 return prototype; | |
426 } | 451 } |
427 | 452 |
428 RUNTIME_FUNCTION(Runtime_NewWithSpread) { | 453 RUNTIME_FUNCTION(Runtime_NewWithSpread) { |
429 HandleScope scope(isolate); | 454 HandleScope scope(isolate); |
430 DCHECK_LE(3, args.length()); | 455 DCHECK_LE(3, args.length()); |
431 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, constructor, 0); | 456 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, constructor, 0); |
432 CONVERT_ARG_HANDLE_CHECKED(Object, new_target, 1); | 457 CONVERT_ARG_HANDLE_CHECKED(Object, new_target, 1); |
433 | 458 |
434 int constructor_argc = args.length() - 2; | 459 int constructor_argc = args.length() - 2; |
435 CONVERT_ARG_HANDLE_CHECKED(Object, spread, args.length() - 1); | 460 CONVERT_ARG_HANDLE_CHECKED(Object, spread, args.length() - 1); |
(...skipping 27 matching lines...) Expand all Loading... | |
463 } | 488 } |
464 | 489 |
465 // Call the constructor. | 490 // Call the constructor. |
466 RETURN_RESULT_OR_FAILURE( | 491 RETURN_RESULT_OR_FAILURE( |
467 isolate, Execution::New(isolate, constructor, new_target, result_length, | 492 isolate, Execution::New(isolate, constructor, new_target, result_length, |
468 construct_args.start())); | 493 construct_args.start())); |
469 } | 494 } |
470 | 495 |
471 } // namespace internal | 496 } // namespace internal |
472 } // namespace v8 | 497 } // namespace v8 |
OLD | NEW |