| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 THROW_NEW_ERROR( | 117 THROW_NEW_ERROR( |
| 118 isolate, | 118 isolate, |
| 119 NewTypeError(MessageTemplate::kExtendsValueNotFunction, super_class), | 119 NewTypeError(MessageTemplate::kExtendsValueNotFunction, super_class), |
| 120 Object); | 120 Object); |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 | 123 |
| 124 Handle<Map> map = | 124 Handle<Map> map = |
| 125 isolate->factory()->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 125 isolate->factory()->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
| 126 map->set_is_prototype_map(true); | 126 map->set_is_prototype_map(true); |
| 127 if (constructor->map()->is_strong()) { | |
| 128 map->set_is_strong(); | |
| 129 if (super_class->IsNull()) { | |
| 130 // Strong class is not permitted to extend null. | |
| 131 THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kStrongExtendNull), | |
| 132 Object); | |
| 133 } | |
| 134 } | |
| 135 Map::SetPrototype(map, prototype_parent); | 127 Map::SetPrototype(map, prototype_parent); |
| 136 map->SetConstructor(*constructor); | 128 map->SetConstructor(*constructor); |
| 137 Handle<JSObject> prototype = isolate->factory()->NewJSObjectFromMap(map); | 129 Handle<JSObject> prototype = isolate->factory()->NewJSObjectFromMap(map); |
| 138 | 130 |
| 139 if (!super_class->IsTheHole()) { | 131 if (!super_class->IsTheHole()) { |
| 140 // Derived classes, just like builtins, don't create implicit receivers in | 132 // Derived classes, just like builtins, don't create implicit receivers in |
| 141 // [[construct]]. Instead they just set up new.target and call into the | 133 // [[construct]]. Instead they just set up new.target and call into the |
| 142 // constructor. Hence we can reuse the builtins construct stub for derived | 134 // constructor. Hence we can reuse the builtins construct stub for derived |
| 143 // classes. | 135 // classes. |
| 144 Handle<Code> stub(isolate->builtins()->JSBuiltinsConstructStubForDerived()); | 136 Handle<Code> stub(isolate->builtins()->JSBuiltinsConstructStubForDerived()); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 isolate, result, DefineClass(isolate, super_class, constructor, | 191 isolate, result, DefineClass(isolate, super_class, constructor, |
| 200 start_position, end_position)); | 192 start_position, end_position)); |
| 201 return *result; | 193 return *result; |
| 202 } | 194 } |
| 203 | 195 |
| 204 | 196 |
| 205 RUNTIME_FUNCTION(Runtime_FinalizeClassDefinition) { | 197 RUNTIME_FUNCTION(Runtime_FinalizeClassDefinition) { |
| 206 HandleScope scope(isolate); | 198 HandleScope scope(isolate); |
| 207 DCHECK(args.length() == 2); | 199 DCHECK(args.length() == 2); |
| 208 CONVERT_ARG_HANDLE_CHECKED(JSObject, constructor, 0); | 200 CONVERT_ARG_HANDLE_CHECKED(JSObject, constructor, 0); |
| 209 CONVERT_ARG_HANDLE_CHECKED(JSObject, prototype, 1); | |
| 210 | |
| 211 JSObject::MigrateSlowToFast(constructor, 0, "RuntimeToFastProperties"); | 201 JSObject::MigrateSlowToFast(constructor, 0, "RuntimeToFastProperties"); |
| 212 | |
| 213 if (constructor->map()->is_strong()) { | |
| 214 DCHECK(prototype->map()->is_strong()); | |
| 215 MAYBE_RETURN(JSReceiver::SetIntegrityLevel(prototype, FROZEN, | |
| 216 Object::THROW_ON_ERROR), | |
| 217 isolate->heap()->exception()); | |
| 218 MAYBE_RETURN(JSReceiver::SetIntegrityLevel(constructor, FROZEN, | |
| 219 Object::THROW_ON_ERROR), | |
| 220 isolate->heap()->exception()); | |
| 221 } | |
| 222 return *constructor; | 202 return *constructor; |
| 223 } | 203 } |
| 224 | 204 |
| 225 static MaybeHandle<Object> LoadFromSuper(Isolate* isolate, | 205 static MaybeHandle<Object> LoadFromSuper(Isolate* isolate, |
| 226 Handle<Object> receiver, | 206 Handle<Object> receiver, |
| 227 Handle<JSObject> home_object, | 207 Handle<JSObject> home_object, |
| 228 Handle<Name> name) { | 208 Handle<Name> name) { |
| 229 if (home_object->IsAccessCheckNeeded() && | 209 if (home_object->IsAccessCheckNeeded() && |
| 230 !isolate->MayAccess(handle(isolate->context()), home_object)) { | 210 !isolate->MayAccess(handle(isolate->context()), home_object)) { |
| 231 isolate->ReportFailedAccessCheck(home_object); | 211 isolate->ReportFailedAccessCheck(home_object); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 | 412 |
| 433 RUNTIME_FUNCTION(Runtime_GetSuperConstructor) { | 413 RUNTIME_FUNCTION(Runtime_GetSuperConstructor) { |
| 434 SealHandleScope shs(isolate); | 414 SealHandleScope shs(isolate); |
| 435 DCHECK_EQ(1, args.length()); | 415 DCHECK_EQ(1, args.length()); |
| 436 CONVERT_ARG_CHECKED(JSFunction, active_function, 0); | 416 CONVERT_ARG_CHECKED(JSFunction, active_function, 0); |
| 437 return active_function->map()->prototype(); | 417 return active_function->map()->prototype(); |
| 438 } | 418 } |
| 439 | 419 |
| 440 } // namespace internal | 420 } // namespace internal |
| 441 } // namespace v8 | 421 } // namespace v8 |
| OLD | NEW |