Chromium Code Reviews| 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 { | |
| 62 | |
| 63 Object* ThrowNotSuperConstructor(Isolate* isolate, Handle<Object> constructor, | |
| 64 Handle<JSFunction> function) { | |
| 65 Handle<Object> super_name; | |
| 66 if (constructor->IsJSFunction()) { | |
| 67 super_name = handle(Handle<JSFunction>::cast(constructor)->shared()->name(), | |
| 68 isolate); | |
| 69 } else if (constructor->IsOddball()) { | |
|
Benedikt Meurer
2016/12/09 18:30:28
As far as I can tell, this should always be null i
| |
| 70 super_name = | |
| 71 handle(Handle<Oddball>::cast(constructor)->to_string(), isolate); | |
| 72 } else { | |
| 73 super_name = Object::NoSideEffectsToString(isolate, constructor); | |
| 74 } | |
| 75 Handle<Object> function_name(function->shared()->name(), isolate); | |
| 76 THROW_NEW_ERROR_RETURN_FAILURE( | |
| 77 isolate, NewTypeError(MessageTemplate::kNotSuperConstructor, super_name, | |
| 78 function_name)); | |
| 79 } | |
| 80 | |
| 81 } // anonymous namespace | |
|
Benedikt Meurer
2016/12/09 18:30:28
Nit: just namespace here.
| |
| 82 | |
| 83 RUNTIME_FUNCTION(Runtime_ThrowNotSuperConstructor) { | |
| 84 HandleScope scope(isolate); | |
| 85 DCHECK(args.length() == 2); | |
| 86 CONVERT_ARG_HANDLE_CHECKED(Object, constructor, 0); | |
| 87 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 1); | |
| 88 return ThrowNotSuperConstructor(isolate, constructor, function); | |
| 89 } | |
| 90 | |
| 62 RUNTIME_FUNCTION(Runtime_HomeObjectSymbol) { | 91 RUNTIME_FUNCTION(Runtime_HomeObjectSymbol) { |
| 63 DCHECK(args.length() == 0); | 92 DCHECK(args.length() == 0); |
| 64 return isolate->heap()->home_object_symbol(); | 93 return isolate->heap()->home_object_symbol(); |
| 65 } | 94 } |
| 66 | 95 |
| 67 static MaybeHandle<Object> DefineClass(Isolate* isolate, | 96 static MaybeHandle<Object> DefineClass(Isolate* isolate, |
| 68 Handle<Object> super_class, | 97 Handle<Object> super_class, |
| 69 Handle<JSFunction> constructor, | 98 Handle<JSFunction> constructor, |
| 70 int start_position, int end_position) { | 99 int start_position, int end_position) { |
| 71 Handle<Object> prototype_parent; | 100 Handle<Object> prototype_parent; |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 414 | 443 |
| 415 RETURN_RESULT_OR_FAILURE( | 444 RETURN_RESULT_OR_FAILURE( |
| 416 isolate, | 445 isolate, |
| 417 StoreKeyedToSuper(isolate, home_object, receiver, key, value, SLOPPY)); | 446 StoreKeyedToSuper(isolate, home_object, receiver, key, value, SLOPPY)); |
| 418 } | 447 } |
| 419 | 448 |
| 420 | 449 |
| 421 RUNTIME_FUNCTION(Runtime_GetSuperConstructor) { | 450 RUNTIME_FUNCTION(Runtime_GetSuperConstructor) { |
| 422 SealHandleScope shs(isolate); | 451 SealHandleScope shs(isolate); |
| 423 DCHECK_EQ(1, args.length()); | 452 DCHECK_EQ(1, args.length()); |
| 424 CONVERT_ARG_CHECKED(JSFunction, active_function, 0); | 453 CONVERT_ARG_HANDLE_CHECKED(JSFunction, active_function, 0); |
| 425 return active_function->map()->prototype(); | 454 Object* prototype = active_function->map()->prototype(); |
| 455 if (!prototype->IsConstructor()) { | |
| 456 return ThrowNotSuperConstructor( | |
| 457 isolate, Handle<JSFunction>::cast(handle(prototype, isolate)), | |
| 458 active_function); | |
| 459 } | |
| 460 return prototype; | |
| 426 } | 461 } |
| 427 | 462 |
| 428 RUNTIME_FUNCTION(Runtime_NewWithSpread) { | 463 RUNTIME_FUNCTION(Runtime_NewWithSpread) { |
| 429 HandleScope scope(isolate); | 464 HandleScope scope(isolate); |
| 430 DCHECK_LE(3, args.length()); | 465 DCHECK_LE(3, args.length()); |
| 431 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, constructor, 0); | 466 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, constructor, 0); |
| 432 CONVERT_ARG_HANDLE_CHECKED(Object, new_target, 1); | 467 CONVERT_ARG_HANDLE_CHECKED(Object, new_target, 1); |
| 433 | 468 |
| 434 int constructor_argc = args.length() - 2; | 469 int constructor_argc = args.length() - 2; |
| 435 CONVERT_ARG_HANDLE_CHECKED(Object, spread, args.length() - 1); | 470 CONVERT_ARG_HANDLE_CHECKED(Object, spread, args.length() - 1); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 463 } | 498 } |
| 464 | 499 |
| 465 // Call the constructor. | 500 // Call the constructor. |
| 466 RETURN_RESULT_OR_FAILURE( | 501 RETURN_RESULT_OR_FAILURE( |
| 467 isolate, Execution::New(isolate, constructor, new_target, result_length, | 502 isolate, Execution::New(isolate, constructor, new_target, result_length, |
| 468 construct_args.start())); | 503 construct_args.start())); |
| 469 } | 504 } |
| 470 | 505 |
| 471 } // namespace internal | 506 } // namespace internal |
| 472 } // namespace v8 | 507 } // namespace v8 |
| OLD | NEW |