OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/api-natives.h" | 5 #include "src/api-natives.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/isolate-inl.h" | 8 #include "src/isolate-inl.h" |
9 #include "src/lookup.h" | 9 #include "src/lookup.h" |
10 #include "src/messages.h" | 10 #include "src/messages.h" |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 Handle<JSReceiver> new_target, | 297 Handle<JSReceiver> new_target, |
298 bool is_hidden_prototype) { | 298 bool is_hidden_prototype) { |
299 Handle<JSFunction> constructor; | 299 Handle<JSFunction> constructor; |
300 uint32_t serial_number = | 300 uint32_t serial_number = |
301 static_cast<uint32_t>(Smi::cast(info->serial_number())->value()); | 301 static_cast<uint32_t>(Smi::cast(info->serial_number())->value()); |
302 if (!new_target.is_null()) { | 302 if (!new_target.is_null()) { |
303 if (new_target->IsJSFunction() && | 303 if (new_target->IsJSFunction() && |
304 JSFunction::cast(*new_target)->shared()->function_data() == | 304 JSFunction::cast(*new_target)->shared()->function_data() == |
305 info->constructor() && | 305 info->constructor() && |
306 JSFunction::cast(*new_target)->context()->native_context() == | 306 JSFunction::cast(*new_target)->context()->native_context() == |
307 isolate->context()->native_context()) { | 307 isolate->context()->native_context() && |
| 308 !info->immutable_proto()) { |
308 constructor = Handle<JSFunction>::cast(new_target); | 309 constructor = Handle<JSFunction>::cast(new_target); |
309 } else { | 310 } else { |
310 // Disable caching for subclass instantiation. | 311 // Disable caching for subclass instantiation. |
311 serial_number = 0; | 312 serial_number = 0; |
312 } | 313 } |
313 } | 314 } |
314 // Fast path. | 315 // Fast path. |
315 Handle<JSObject> result; | 316 Handle<JSObject> result; |
316 if (serial_number) { | 317 if (serial_number) { |
317 // Probe cache. | 318 // Probe cache. |
(...skipping 21 matching lines...) Expand all Loading... |
339 | 340 |
340 if (new_target.is_null()) new_target = constructor; | 341 if (new_target.is_null()) new_target = constructor; |
341 } | 342 } |
342 | 343 |
343 Handle<JSObject> object; | 344 Handle<JSObject> object; |
344 ASSIGN_RETURN_ON_EXCEPTION(isolate, object, | 345 ASSIGN_RETURN_ON_EXCEPTION(isolate, object, |
345 JSObject::New(constructor, new_target), JSObject); | 346 JSObject::New(constructor, new_target), JSObject); |
346 ASSIGN_RETURN_ON_EXCEPTION( | 347 ASSIGN_RETURN_ON_EXCEPTION( |
347 isolate, result, | 348 isolate, result, |
348 ConfigureInstance(isolate, object, info, is_hidden_prototype), JSObject); | 349 ConfigureInstance(isolate, object, info, is_hidden_prototype), JSObject); |
| 350 if (info->immutable_proto()) { |
| 351 JSObject::SetImmutableProto(object); |
| 352 } |
349 // TODO(dcarney): is this necessary? | 353 // TODO(dcarney): is this necessary? |
350 JSObject::MigrateSlowToFast(result, 0, "ApiNatives::InstantiateObject"); | 354 JSObject::MigrateSlowToFast(result, 0, "ApiNatives::InstantiateObject"); |
351 | 355 |
352 if (serial_number) { | 356 if (serial_number) { |
353 CacheTemplateInstantiation(isolate, serial_number, result); | 357 CacheTemplateInstantiation(isolate, serial_number, result); |
354 result = isolate->factory()->CopyJSObject(result); | 358 result = isolate->factory()->CopyJSObject(result); |
355 } | 359 } |
356 return scope.CloseAndEscape(result); | 360 return scope.CloseAndEscape(result); |
357 } | 361 } |
358 | 362 |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 } else { | 569 } else { |
566 JSObject::AddProperty(Handle<JSObject>::cast(prototype), | 570 JSObject::AddProperty(Handle<JSObject>::cast(prototype), |
567 isolate->factory()->constructor_string(), result, | 571 isolate->factory()->constructor_string(), result, |
568 DONT_ENUM); | 572 DONT_ENUM); |
569 } | 573 } |
570 | 574 |
571 int internal_field_count = 0; | 575 int internal_field_count = 0; |
572 if (!obj->instance_template()->IsUndefined(isolate)) { | 576 if (!obj->instance_template()->IsUndefined(isolate)) { |
573 Handle<ObjectTemplateInfo> instance_template = Handle<ObjectTemplateInfo>( | 577 Handle<ObjectTemplateInfo> instance_template = Handle<ObjectTemplateInfo>( |
574 ObjectTemplateInfo::cast(obj->instance_template())); | 578 ObjectTemplateInfo::cast(obj->instance_template())); |
575 internal_field_count = | 579 internal_field_count = instance_template->internal_field_count(); |
576 Smi::cast(instance_template->internal_field_count())->value(); | |
577 } | 580 } |
578 | 581 |
579 // TODO(svenpanne) Kill ApiInstanceType and refactor things by generalizing | 582 // TODO(svenpanne) Kill ApiInstanceType and refactor things by generalizing |
580 // JSObject::GetHeaderSize. | 583 // JSObject::GetHeaderSize. |
581 int instance_size = kPointerSize * internal_field_count; | 584 int instance_size = kPointerSize * internal_field_count; |
582 InstanceType type; | 585 InstanceType type; |
583 switch (instance_type) { | 586 switch (instance_type) { |
584 case JavaScriptObjectType: | 587 case JavaScriptObjectType: |
585 if (!obj->needs_access_check() && | 588 if (!obj->needs_access_check() && |
586 obj->named_property_handler()->IsUndefined(isolate) && | 589 obj->named_property_handler()->IsUndefined(isolate) && |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 if (!obj->instance_call_handler()->IsUndefined(isolate)) { | 634 if (!obj->instance_call_handler()->IsUndefined(isolate)) { |
632 map->set_is_callable(); | 635 map->set_is_callable(); |
633 map->set_is_constructor(true); | 636 map->set_is_constructor(true); |
634 } | 637 } |
635 | 638 |
636 return result; | 639 return result; |
637 } | 640 } |
638 | 641 |
639 } // namespace internal | 642 } // namespace internal |
640 } // namespace v8 | 643 } // namespace v8 |
OLD | NEW |