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/arguments.h" | 10 #include "src/arguments.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 Map::SetPrototype(map, prototype_parent); | 135 Map::SetPrototype(map, prototype_parent); |
136 map->SetConstructor(*constructor); | 136 map->SetConstructor(*constructor); |
137 Handle<JSObject> prototype = isolate->factory()->NewJSObjectFromMap(map); | 137 Handle<JSObject> prototype = isolate->factory()->NewJSObjectFromMap(map); |
138 | 138 |
139 Handle<String> name_string = name->IsString() | 139 Handle<String> name_string = name->IsString() |
140 ? Handle<String>::cast(name) | 140 ? Handle<String>::cast(name) |
141 : isolate->factory()->empty_string(); | 141 : isolate->factory()->empty_string(); |
142 constructor->shared()->set_name(*name_string); | 142 constructor->shared()->set_name(*name_string); |
143 | 143 |
144 if (!super_class->IsTheHole()) { | 144 if (!super_class->IsTheHole()) { |
145 Handle<Code> stub(isolate->builtins()->JSConstructStubForDerived()); | 145 // Derived classes, just like builtins, don't create implicit receivers in |
| 146 // [[construct]]. Instead they just set up new.target and call into the |
| 147 // constructor. Hence we can reuse the builtins construct stub for derived |
| 148 // classes. |
| 149 Handle<Code> stub(isolate->builtins()->JSBuiltinsConstructStub()); |
146 constructor->shared()->set_construct_stub(*stub); | 150 constructor->shared()->set_construct_stub(*stub); |
147 } | 151 } |
148 | 152 |
149 JSFunction::SetPrototype(constructor, prototype); | 153 JSFunction::SetPrototype(constructor, prototype); |
150 PropertyAttributes attribs = | 154 PropertyAttributes attribs = |
151 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); | 155 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
152 RETURN_ON_EXCEPTION(isolate, | 156 RETURN_ON_EXCEPTION(isolate, |
153 JSObject::SetOwnPropertyIgnoreAttributes( | 157 JSObject::SetOwnPropertyIgnoreAttributes( |
154 constructor, isolate->factory()->prototype_string(), | 158 constructor, isolate->factory()->prototype_string(), |
155 prototype, attribs), | 159 prototype, attribs), |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 Handle<Object> result; | 501 Handle<Object> result; |
498 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 502 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
499 isolate, result, Execution::New(isolate, super_constructor, new_target, | 503 isolate, result, Execution::New(isolate, super_constructor, new_target, |
500 argument_count, arguments.get())); | 504 argument_count, arguments.get())); |
501 | 505 |
502 return *result; | 506 return *result; |
503 } | 507 } |
504 | 508 |
505 } // namespace internal | 509 } // namespace internal |
506 } // namespace v8 | 510 } // namespace v8 |
OLD | NEW |