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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 } | 74 } |
75 return *name; | 75 return *name; |
76 } | 76 } |
77 | 77 |
78 | 78 |
79 RUNTIME_FUNCTION(Runtime_HomeObjectSymbol) { | 79 RUNTIME_FUNCTION(Runtime_HomeObjectSymbol) { |
80 DCHECK(args.length() == 0); | 80 DCHECK(args.length() == 0); |
81 return isolate->heap()->home_object_symbol(); | 81 return isolate->heap()->home_object_symbol(); |
82 } | 82 } |
83 | 83 |
84 | 84 static MaybeHandle<Object> DefineClass(Isolate* isolate, |
85 static MaybeHandle<Object> DefineClass(Isolate* isolate, Handle<Object> name, | |
86 Handle<Object> super_class, | 85 Handle<Object> super_class, |
87 Handle<JSFunction> constructor, | 86 Handle<JSFunction> constructor, |
88 int start_position, int end_position) { | 87 int start_position, int end_position) { |
89 Handle<Object> prototype_parent; | 88 Handle<Object> prototype_parent; |
90 Handle<Object> constructor_parent; | 89 Handle<Object> constructor_parent; |
91 | 90 |
92 if (super_class->IsTheHole()) { | 91 if (super_class->IsTheHole()) { |
93 prototype_parent = isolate->initial_object_prototype(); | 92 prototype_parent = isolate->initial_object_prototype(); |
94 } else { | 93 } else { |
95 if (super_class->IsNull()) { | 94 if (super_class->IsNull()) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 if (super_class->IsNull()) { | 130 if (super_class->IsNull()) { |
132 // Strong class is not permitted to extend null. | 131 // Strong class is not permitted to extend null. |
133 THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kStrongExtendNull), | 132 THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kStrongExtendNull), |
134 Object); | 133 Object); |
135 } | 134 } |
136 } | 135 } |
137 Map::SetPrototype(map, prototype_parent); | 136 Map::SetPrototype(map, prototype_parent); |
138 map->SetConstructor(*constructor); | 137 map->SetConstructor(*constructor); |
139 Handle<JSObject> prototype = isolate->factory()->NewJSObjectFromMap(map); | 138 Handle<JSObject> prototype = isolate->factory()->NewJSObjectFromMap(map); |
140 | 139 |
141 Handle<String> name_string = name->IsString() | |
142 ? Handle<String>::cast(name) | |
143 : isolate->factory()->empty_string(); | |
144 constructor->shared()->set_name(*name_string); | |
145 | |
146 if (!super_class->IsTheHole()) { | 140 if (!super_class->IsTheHole()) { |
147 // Derived classes, just like builtins, don't create implicit receivers in | 141 // Derived classes, just like builtins, don't create implicit receivers in |
148 // [[construct]]. Instead they just set up new.target and call into the | 142 // [[construct]]. Instead they just set up new.target and call into the |
149 // constructor. Hence we can reuse the builtins construct stub for derived | 143 // constructor. Hence we can reuse the builtins construct stub for derived |
150 // classes. | 144 // classes. |
151 Handle<Code> stub(isolate->builtins()->JSBuiltinsConstructStubForDerived()); | 145 Handle<Code> stub(isolate->builtins()->JSBuiltinsConstructStubForDerived()); |
152 constructor->shared()->set_construct_stub(*stub); | 146 constructor->shared()->set_construct_stub(*stub); |
153 } | 147 } |
154 | 148 |
155 JSFunction::SetPrototype(constructor, prototype); | 149 JSFunction::SetPrototype(constructor, prototype); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 constructor, isolate->factory()->class_end_position_symbol(), | 182 constructor, isolate->factory()->class_end_position_symbol(), |
189 handle(Smi::FromInt(end_position), isolate), STRICT), | 183 handle(Smi::FromInt(end_position), isolate), STRICT), |
190 Object); | 184 Object); |
191 | 185 |
192 return constructor; | 186 return constructor; |
193 } | 187 } |
194 | 188 |
195 | 189 |
196 RUNTIME_FUNCTION(Runtime_DefineClass) { | 190 RUNTIME_FUNCTION(Runtime_DefineClass) { |
197 HandleScope scope(isolate); | 191 HandleScope scope(isolate); |
198 DCHECK(args.length() == 5); | 192 DCHECK(args.length() == 4); |
199 CONVERT_ARG_HANDLE_CHECKED(Object, name, 0); | 193 CONVERT_ARG_HANDLE_CHECKED(Object, super_class, 0); |
200 CONVERT_ARG_HANDLE_CHECKED(Object, super_class, 1); | 194 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 1); |
201 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 2); | 195 CONVERT_SMI_ARG_CHECKED(start_position, 2); |
202 CONVERT_SMI_ARG_CHECKED(start_position, 3); | 196 CONVERT_SMI_ARG_CHECKED(end_position, 3); |
203 CONVERT_SMI_ARG_CHECKED(end_position, 4); | |
204 | 197 |
205 Handle<Object> result; | 198 Handle<Object> result; |
206 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 199 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
207 isolate, result, DefineClass(isolate, name, super_class, constructor, | 200 isolate, result, DefineClass(isolate, super_class, constructor, |
208 start_position, end_position)); | 201 start_position, end_position)); |
209 return *result; | 202 return *result; |
210 } | 203 } |
211 | 204 |
212 | 205 |
213 RUNTIME_FUNCTION(Runtime_DefineClassMethod) { | 206 RUNTIME_FUNCTION(Runtime_DefineClassMethod) { |
214 HandleScope scope(isolate); | 207 HandleScope scope(isolate); |
215 DCHECK(args.length() == 3); | 208 DCHECK(args.length() == 3); |
216 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | 209 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
217 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); | 210 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 | 459 |
467 RUNTIME_FUNCTION(Runtime_GetSuperConstructor) { | 460 RUNTIME_FUNCTION(Runtime_GetSuperConstructor) { |
468 SealHandleScope shs(isolate); | 461 SealHandleScope shs(isolate); |
469 DCHECK_EQ(1, args.length()); | 462 DCHECK_EQ(1, args.length()); |
470 CONVERT_ARG_CHECKED(JSFunction, active_function, 0); | 463 CONVERT_ARG_CHECKED(JSFunction, active_function, 0); |
471 return active_function->map()->prototype(); | 464 return active_function->map()->prototype(); |
472 } | 465 } |
473 | 466 |
474 } // namespace internal | 467 } // namespace internal |
475 } // namespace v8 | 468 } // namespace v8 |
OLD | NEW |