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 <stdlib.h> | 5 #include <stdlib.h> |
6 #include <limits> | 6 #include <limits> |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 isolate->factory()->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 109 isolate->factory()->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
110 map->SetPrototype(prototype_parent); | 110 map->SetPrototype(prototype_parent); |
111 map->set_constructor(*constructor); | 111 map->set_constructor(*constructor); |
112 Handle<JSObject> prototype = isolate->factory()->NewJSObjectFromMap(map); | 112 Handle<JSObject> prototype = isolate->factory()->NewJSObjectFromMap(map); |
113 | 113 |
114 Handle<String> name_string = name->IsString() | 114 Handle<String> name_string = name->IsString() |
115 ? Handle<String>::cast(name) | 115 ? Handle<String>::cast(name) |
116 : isolate->factory()->empty_string(); | 116 : isolate->factory()->empty_string(); |
117 constructor->shared()->set_name(*name_string); | 117 constructor->shared()->set_name(*name_string); |
118 | 118 |
119 if (FLAG_experimental_classes) { | 119 if (!super_class->IsTheHole()) { |
120 if (!super_class->IsTheHole()) { | 120 Handle<Code> stub(isolate->builtins()->JSConstructStubForDerived()); |
121 Handle<Code> stub(isolate->builtins()->JSConstructStubForDerived()); | 121 constructor->shared()->set_construct_stub(*stub); |
122 constructor->shared()->set_construct_stub(*stub); | |
123 } | |
124 } | 122 } |
125 | 123 |
126 JSFunction::SetPrototype(constructor, prototype); | 124 JSFunction::SetPrototype(constructor, prototype); |
127 PropertyAttributes attribs = | 125 PropertyAttributes attribs = |
128 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); | 126 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
129 RETURN_FAILURE_ON_EXCEPTION( | 127 RETURN_FAILURE_ON_EXCEPTION( |
130 isolate, JSObject::SetOwnPropertyIgnoreAttributes( | 128 isolate, JSObject::SetOwnPropertyIgnoreAttributes( |
131 constructor, isolate->factory()->prototype_string(), | 129 constructor, isolate->factory()->prototype_string(), |
132 prototype, attribs)); | 130 prototype, attribs)); |
133 | 131 |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 debug->HandleStepIn(function, Handle<Object>::null(), 0, true); | 422 debug->HandleStepIn(function, Handle<Object>::null(), 0, true); |
425 } | 423 } |
426 return *isolate->factory()->undefined_value(); | 424 return *isolate->factory()->undefined_value(); |
427 } | 425 } |
428 | 426 |
429 | 427 |
430 RUNTIME_FUNCTION(RuntimeReference_DefaultConstructorCallSuper) { | 428 RUNTIME_FUNCTION(RuntimeReference_DefaultConstructorCallSuper) { |
431 UNREACHABLE(); | 429 UNREACHABLE(); |
432 return nullptr; | 430 return nullptr; |
433 } | 431 } |
434 | |
435 | |
436 // TODO(dslomov): deprecated, will remove when experimenal classes is default. | |
437 RUNTIME_FUNCTION(Runtime_DefaultConstructorSuperCall) { | |
438 CHECK(!FLAG_experimental_classes); | |
439 HandleScope scope(isolate); | |
440 DCHECK(args.length() == 0); | |
441 | |
442 // Compute the frame holding the arguments. | |
443 JavaScriptFrameIterator it(isolate); | |
444 it.AdvanceToArgumentsFrame(); | |
445 JavaScriptFrame* frame = it.frame(); | |
446 | |
447 Handle<JSFunction> function(frame->function(), isolate); | |
448 Handle<Object> receiver(frame->receiver(), isolate); | |
449 | |
450 Handle<Object> proto_function; | |
451 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, proto_function, | |
452 Runtime::GetPrototype(isolate, function)); | |
453 | |
454 // Get the actual number of provided arguments. | |
455 const int argc = frame->ComputeParametersCount(); | |
456 | |
457 // Loose upper bound to allow fuzzing. We'll most likely run out of | |
458 // stack space before hitting this limit. | |
459 static int kMaxArgc = 1000000; | |
460 RUNTIME_ASSERT(argc >= 0 && argc <= kMaxArgc); | |
461 | |
462 // If there are too many arguments, allocate argv via malloc. | |
463 const int argv_small_size = 10; | |
464 Handle<Object> argv_small_buffer[argv_small_size]; | |
465 SmartArrayPointer<Handle<Object> > argv_large_buffer; | |
466 Handle<Object>* argv = argv_small_buffer; | |
467 if (argc > argv_small_size) { | |
468 argv = new Handle<Object>[argc]; | |
469 if (argv == NULL) return isolate->StackOverflow(); | |
470 argv_large_buffer = SmartArrayPointer<Handle<Object> >(argv); | |
471 } | |
472 | |
473 for (int i = 0; i < argc; ++i) { | |
474 argv[i] = handle(frame->GetParameter(i), isolate); | |
475 } | |
476 | |
477 Handle<Object> result; | |
478 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
479 isolate, result, | |
480 Execution::Call(isolate, proto_function, receiver, argc, argv, false)); | |
481 return *result; | |
482 } | |
483 } | 432 } |
484 } // namespace v8::internal | 433 } // namespace v8::internal |
OLD | NEW |