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/bootstrapper.h" | 5 #include "src/bootstrapper.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
9 #include "src/extensions/externalize-string-extension.h" | 9 #include "src/extensions/externalize-string-extension.h" |
10 #include "src/extensions/free-buffer-extension.h" | 10 #include "src/extensions/free-buffer-extension.h" |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
372 ? factory->NewFunction(internalized_name, call_code, prototype, | 372 ? factory->NewFunction(internalized_name, call_code, prototype, |
373 type, instance_size) | 373 type, instance_size) |
374 : factory->NewFunctionWithoutPrototype(internalized_name, call_code); | 374 : factory->NewFunctionWithoutPrototype(internalized_name, call_code); |
375 PropertyAttributes attributes; | 375 PropertyAttributes attributes; |
376 if (target->IsJSBuiltinsObject()) { | 376 if (target->IsJSBuiltinsObject()) { |
377 attributes = | 377 attributes = |
378 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); | 378 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
379 } else { | 379 } else { |
380 attributes = DONT_ENUM; | 380 attributes = DONT_ENUM; |
381 } | 381 } |
382 JSObject::SetOwnPropertyIgnoreAttributes( | 382 JSObject::InitializeProperty(target, internalized_name, function, attributes); |
383 target, internalized_name, function, attributes).Check(); | |
384 if (target->IsJSGlobalObject()) { | 383 if (target->IsJSGlobalObject()) { |
385 function->shared()->set_instance_class_name(*internalized_name); | 384 function->shared()->set_instance_class_name(*internalized_name); |
386 } | 385 } |
387 function->shared()->set_native(true); | 386 function->shared()->set_native(true); |
388 return function; | 387 return function; |
389 } | 388 } |
390 | 389 |
391 | 390 |
392 void Genesis::SetFunctionInstanceDescriptor( | 391 void Genesis::SetFunctionInstanceDescriptor( |
393 Handle<Map> map, FunctionMode function_mode) { | 392 Handle<Map> map, FunctionMode function_mode) { |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
882 // its the inner global. This makes the security check between two | 881 // its the inner global. This makes the security check between two |
883 // different contexts fail by default even in case of global | 882 // different contexts fail by default even in case of global |
884 // object reinitialization. | 883 // object reinitialization. |
885 native_context()->set_security_token(*inner_global); | 884 native_context()->set_security_token(*inner_global); |
886 | 885 |
887 Isolate* isolate = inner_global->GetIsolate(); | 886 Isolate* isolate = inner_global->GetIsolate(); |
888 Factory* factory = isolate->factory(); | 887 Factory* factory = isolate->factory(); |
889 Heap* heap = isolate->heap(); | 888 Heap* heap = isolate->heap(); |
890 | 889 |
891 Handle<String> object_name = factory->Object_string(); | 890 Handle<String> object_name = factory->Object_string(); |
892 JSObject::SetOwnPropertyIgnoreAttributes( | 891 JSObject::InitializeProperty( |
893 inner_global, object_name, | 892 inner_global, object_name, isolate->object_function(), DONT_ENUM); |
894 isolate->object_function(), DONT_ENUM).Check(); | |
895 | 893 |
896 Handle<JSObject> global(native_context()->global_object()); | 894 Handle<JSObject> global(native_context()->global_object()); |
897 | 895 |
898 // Install global Function object | 896 // Install global Function object |
899 InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, | 897 InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, |
900 empty_function, Builtins::kIllegal); | 898 empty_function, Builtins::kIllegal); |
901 | 899 |
902 { // --- A r r a y --- | 900 { // --- A r r a y --- |
903 Handle<JSFunction> array_function = | 901 Handle<JSFunction> array_function = |
904 InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize, | 902 InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize, |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1083 } | 1081 } |
1084 | 1082 |
1085 { // -- J S O N | 1083 { // -- J S O N |
1086 Handle<String> name = factory->InternalizeUtf8String("JSON"); | 1084 Handle<String> name = factory->InternalizeUtf8String("JSON"); |
1087 Handle<JSFunction> cons = factory->NewFunction(name); | 1085 Handle<JSFunction> cons = factory->NewFunction(name); |
1088 JSFunction::SetInstancePrototype(cons, | 1086 JSFunction::SetInstancePrototype(cons, |
1089 Handle<Object>(native_context()->initial_object_prototype(), isolate)); | 1087 Handle<Object>(native_context()->initial_object_prototype(), isolate)); |
1090 cons->SetInstanceClassName(*name); | 1088 cons->SetInstanceClassName(*name); |
1091 Handle<JSObject> json_object = factory->NewJSObject(cons, TENURED); | 1089 Handle<JSObject> json_object = factory->NewJSObject(cons, TENURED); |
1092 ASSERT(json_object->IsJSObject()); | 1090 ASSERT(json_object->IsJSObject()); |
1093 JSObject::SetOwnPropertyIgnoreAttributes( | 1091 JSObject::InitializeProperty(global, name, json_object, DONT_ENUM); |
1094 global, name, json_object, DONT_ENUM).Check(); | |
1095 native_context()->set_json_object(*json_object); | 1092 native_context()->set_json_object(*json_object); |
1096 } | 1093 } |
1097 | 1094 |
1098 { // -- A r r a y B u f f e r | 1095 { // -- A r r a y B u f f e r |
1099 Handle<JSFunction> array_buffer_fun = | 1096 Handle<JSFunction> array_buffer_fun = |
1100 InstallFunction( | 1097 InstallFunction( |
1101 global, "ArrayBuffer", JS_ARRAY_BUFFER_TYPE, | 1098 global, "ArrayBuffer", JS_ARRAY_BUFFER_TYPE, |
1102 JSArrayBuffer::kSizeWithInternalFields, | 1099 JSArrayBuffer::kSizeWithInternalFields, |
1103 isolate->initial_object_prototype(), | 1100 isolate->initial_object_prototype(), |
1104 Builtins::kIllegal); | 1101 Builtins::kIllegal); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1149 ASSERT(!function->has_initial_map()); | 1146 ASSERT(!function->has_initial_map()); |
1150 function->shared()->set_instance_class_name(*arguments_string); | 1147 function->shared()->set_instance_class_name(*arguments_string); |
1151 function->shared()->set_expected_nof_properties(2); | 1148 function->shared()->set_expected_nof_properties(2); |
1152 function->set_prototype_or_initial_map( | 1149 function->set_prototype_or_initial_map( |
1153 native_context()->object_function()->prototype()); | 1150 native_context()->object_function()->prototype()); |
1154 Handle<JSObject> result = factory->NewJSObject(function); | 1151 Handle<JSObject> result = factory->NewJSObject(function); |
1155 | 1152 |
1156 native_context()->set_sloppy_arguments_boilerplate(*result); | 1153 native_context()->set_sloppy_arguments_boilerplate(*result); |
1157 // Note: length must be added as the first property and | 1154 // Note: length must be added as the first property and |
1158 // callee must be added as the second property. | 1155 // callee must be added as the second property. |
1159 JSObject::SetOwnPropertyIgnoreAttributes( | 1156 JSObject::InitializeProperty( |
1160 result, factory->length_string(), | 1157 result, factory->length_string(), |
1161 factory->undefined_value(), DONT_ENUM, | 1158 factory->undefined_value(), DONT_ENUM, |
1162 Object::FORCE_TAGGED, FORCE_FIELD).Check(); | 1159 Object::FORCE_TAGGED, FORCE_FIELD); |
1163 JSObject::SetOwnPropertyIgnoreAttributes( | 1160 JSObject::InitializeProperty( |
1164 result, factory->callee_string(), | 1161 result, factory->callee_string(), |
1165 factory->undefined_value(), DONT_ENUM, | 1162 factory->undefined_value(), DONT_ENUM, |
1166 Object::FORCE_TAGGED, FORCE_FIELD).Check(); | 1163 Object::FORCE_TAGGED, FORCE_FIELD); |
1167 | 1164 |
1168 #ifdef DEBUG | 1165 #ifdef DEBUG |
1169 LookupResult lookup(isolate); | 1166 LookupResult lookup(isolate); |
1170 result->LookupOwn(factory->callee_string(), &lookup); | 1167 result->LookupOwn(factory->callee_string(), &lookup); |
1171 ASSERT(lookup.IsField()); | 1168 ASSERT(lookup.IsField()); |
1172 ASSERT(lookup.GetFieldIndex().property_index() == | 1169 ASSERT(lookup.GetFieldIndex().property_index() == |
1173 Heap::kArgumentsCalleeIndex); | 1170 Heap::kArgumentsCalleeIndex); |
1174 | 1171 |
1175 result->LookupOwn(factory->length_string(), &lookup); | 1172 result->LookupOwn(factory->length_string(), &lookup); |
1176 ASSERT(lookup.IsField()); | 1173 ASSERT(lookup.IsField()); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1255 map->set_inobject_properties(1); | 1252 map->set_inobject_properties(1); |
1256 | 1253 |
1257 // Copy constructor from the sloppy arguments boilerplate. | 1254 // Copy constructor from the sloppy arguments boilerplate. |
1258 map->set_constructor( | 1255 map->set_constructor( |
1259 native_context()->sloppy_arguments_boilerplate()->map()->constructor()); | 1256 native_context()->sloppy_arguments_boilerplate()->map()->constructor()); |
1260 | 1257 |
1261 // Allocate the arguments boilerplate object. | 1258 // Allocate the arguments boilerplate object. |
1262 Handle<JSObject> result = factory->NewJSObjectFromMap(map); | 1259 Handle<JSObject> result = factory->NewJSObjectFromMap(map); |
1263 native_context()->set_strict_arguments_boilerplate(*result); | 1260 native_context()->set_strict_arguments_boilerplate(*result); |
1264 | 1261 |
1265 // Add length property only for strict mode boilerplate. | |
1266 JSObject::SetOwnPropertyIgnoreAttributes( | |
rossberg
2014/06/27 10:51:02
Hm, why can this call just be dropped?
Toon Verwaest
2014/06/30 11:39:38
Because NewJSObjectFromMap properly initializes al
| |
1267 result, factory->length_string(), | |
1268 factory->undefined_value(), DONT_ENUM).Check(); | |
1269 | |
1270 #ifdef DEBUG | 1262 #ifdef DEBUG |
1271 LookupResult lookup(isolate); | 1263 LookupResult lookup(isolate); |
1272 result->LookupOwn(factory->length_string(), &lookup); | 1264 result->LookupOwn(factory->length_string(), &lookup); |
1273 ASSERT(lookup.IsField()); | 1265 ASSERT(lookup.IsField()); |
1274 ASSERT(lookup.GetFieldIndex().property_index() == | 1266 ASSERT(lookup.GetFieldIndex().property_index() == |
1275 Heap::kArgumentsLengthIndex); | 1267 Heap::kArgumentsLengthIndex); |
1276 | 1268 |
1277 ASSERT(result->map()->inobject_properties() > Heap::kArgumentsLengthIndex); | 1269 ASSERT(result->map()->inobject_properties() > Heap::kArgumentsLengthIndex); |
1278 | 1270 |
1279 // Check the state of the object. | 1271 // Check the state of the object. |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1729 | 1721 |
1730 // Set up the 'global' properties of the builtins object. The | 1722 // Set up the 'global' properties of the builtins object. The |
1731 // 'global' property that refers to the global object is the only | 1723 // 'global' property that refers to the global object is the only |
1732 // way to get from code running in the builtins context to the | 1724 // way to get from code running in the builtins context to the |
1733 // global object. | 1725 // global object. |
1734 static const PropertyAttributes attributes = | 1726 static const PropertyAttributes attributes = |
1735 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); | 1727 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); |
1736 Handle<String> global_string = | 1728 Handle<String> global_string = |
1737 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("global")); | 1729 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("global")); |
1738 Handle<Object> global_obj(native_context()->global_object(), isolate()); | 1730 Handle<Object> global_obj(native_context()->global_object(), isolate()); |
1739 JSObject::SetOwnPropertyIgnoreAttributes( | 1731 JSObject::InitializeProperty(builtins, global_string, global_obj, attributes); |
1740 builtins, global_string, global_obj, attributes).Check(); | |
1741 Handle<String> builtins_string = | 1732 Handle<String> builtins_string = |
1742 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("builtins")); | 1733 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("builtins")); |
1743 JSObject::SetOwnPropertyIgnoreAttributes( | 1734 JSObject::InitializeProperty(builtins, builtins_string, builtins, attributes); |
1744 builtins, builtins_string, builtins, attributes).Check(); | |
1745 | 1735 |
1746 // Set up the reference from the global object to the builtins object. | 1736 // Set up the reference from the global object to the builtins object. |
1747 JSGlobalObject::cast(native_context()->global_object())-> | 1737 JSGlobalObject::cast(native_context()->global_object())-> |
1748 set_builtins(*builtins); | 1738 set_builtins(*builtins); |
1749 | 1739 |
1750 // Create a bridge function that has context in the native context. | 1740 // Create a bridge function that has context in the native context. |
1751 Handle<JSFunction> bridge = factory()->NewFunction(factory()->empty_string()); | 1741 Handle<JSFunction> bridge = factory()->NewFunction(factory()->empty_string()); |
1752 ASSERT(bridge->context() == *isolate()->native_context()); | 1742 ASSERT(bridge->context() == *isolate()->native_context()); |
1753 | 1743 |
1754 // Allocate the builtins context. | 1744 // Allocate the builtins context. |
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2446 for (int i = 0; i < from->map()->NumberOfOwnDescriptors(); i++) { | 2436 for (int i = 0; i < from->map()->NumberOfOwnDescriptors(); i++) { |
2447 PropertyDetails details = descs->GetDetails(i); | 2437 PropertyDetails details = descs->GetDetails(i); |
2448 switch (details.type()) { | 2438 switch (details.type()) { |
2449 case FIELD: { | 2439 case FIELD: { |
2450 HandleScope inner(isolate()); | 2440 HandleScope inner(isolate()); |
2451 Handle<Name> key = Handle<Name>(descs->GetKey(i)); | 2441 Handle<Name> key = Handle<Name>(descs->GetKey(i)); |
2452 FieldIndex index = FieldIndex::ForDescriptor(from->map(), i); | 2442 FieldIndex index = FieldIndex::ForDescriptor(from->map(), i); |
2453 ASSERT(!descs->GetDetails(i).representation().IsDouble()); | 2443 ASSERT(!descs->GetDetails(i).representation().IsDouble()); |
2454 Handle<Object> value = Handle<Object>(from->RawFastPropertyAt(index), | 2444 Handle<Object> value = Handle<Object>(from->RawFastPropertyAt(index), |
2455 isolate()); | 2445 isolate()); |
2456 JSObject::SetOwnPropertyIgnoreAttributes( | 2446 JSObject::InitializeProperty(to, key, value, details.attributes()); |
2457 to, key, value, details.attributes()).Check(); | |
2458 break; | 2447 break; |
2459 } | 2448 } |
2460 case CONSTANT: { | 2449 case CONSTANT: { |
2461 HandleScope inner(isolate()); | 2450 HandleScope inner(isolate()); |
2462 Handle<Name> key = Handle<Name>(descs->GetKey(i)); | 2451 Handle<Name> key = Handle<Name>(descs->GetKey(i)); |
2463 Handle<Object> constant(descs->GetConstant(i), isolate()); | 2452 Handle<Object> constant(descs->GetConstant(i), isolate()); |
2464 JSObject::SetOwnPropertyIgnoreAttributes( | 2453 JSObject::InitializeProperty(to, key, constant, details.attributes()); |
2465 to, key, constant, details.attributes()).Check(); | |
2466 break; | 2454 break; |
2467 } | 2455 } |
2468 case CALLBACKS: { | 2456 case CALLBACKS: { |
2469 LookupResult result(isolate()); | 2457 LookupResult result(isolate()); |
2470 Handle<Name> key(Name::cast(descs->GetKey(i)), isolate()); | 2458 Handle<Name> key(Name::cast(descs->GetKey(i)), isolate()); |
2471 to->LookupOwn(key, &result); | 2459 to->LookupOwn(key, &result); |
2472 // If the property is already there we skip it | 2460 // If the property is already there we skip it |
2473 if (result.IsFound()) continue; | 2461 if (result.IsFound()) continue; |
2474 HandleScope inner(isolate()); | 2462 HandleScope inner(isolate()); |
2475 ASSERT(!to->HasFastProperties()); | 2463 ASSERT(!to->HasFastProperties()); |
(...skipping 29 matching lines...) Expand all Loading... | |
2505 if (result.IsFound()) continue; | 2493 if (result.IsFound()) continue; |
2506 // Set the property. | 2494 // Set the property. |
2507 Handle<Object> value = Handle<Object>(properties->ValueAt(i), | 2495 Handle<Object> value = Handle<Object>(properties->ValueAt(i), |
2508 isolate()); | 2496 isolate()); |
2509 ASSERT(!value->IsCell()); | 2497 ASSERT(!value->IsCell()); |
2510 if (value->IsPropertyCell()) { | 2498 if (value->IsPropertyCell()) { |
2511 value = Handle<Object>(PropertyCell::cast(*value)->value(), | 2499 value = Handle<Object>(PropertyCell::cast(*value)->value(), |
2512 isolate()); | 2500 isolate()); |
2513 } | 2501 } |
2514 PropertyDetails details = properties->DetailsAt(i); | 2502 PropertyDetails details = properties->DetailsAt(i); |
2515 JSObject::SetOwnPropertyIgnoreAttributes( | 2503 JSObject::InitializeProperty(to, key, value, details.attributes()); |
2516 to, key, value, details.attributes()).Check(); | |
2517 } | 2504 } |
2518 } | 2505 } |
2519 } | 2506 } |
2520 } | 2507 } |
2521 | 2508 |
2522 | 2509 |
2523 void Genesis::TransferIndexedProperties(Handle<JSObject> from, | 2510 void Genesis::TransferIndexedProperties(Handle<JSObject> from, |
2524 Handle<JSObject> to) { | 2511 Handle<JSObject> to) { |
2525 // Cloning the elements array is sufficient. | 2512 // Cloning the elements array is sufficient. |
2526 Handle<FixedArray> from_elements = | 2513 Handle<FixedArray> from_elements = |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2742 return from + sizeof(NestingCounterType); | 2729 return from + sizeof(NestingCounterType); |
2743 } | 2730 } |
2744 | 2731 |
2745 | 2732 |
2746 // Called when the top-level V8 mutex is destroyed. | 2733 // Called when the top-level V8 mutex is destroyed. |
2747 void Bootstrapper::FreeThreadResources() { | 2734 void Bootstrapper::FreeThreadResources() { |
2748 ASSERT(!IsActive()); | 2735 ASSERT(!IsActive()); |
2749 } | 2736 } |
2750 | 2737 |
2751 } } // namespace v8::internal | 2738 } } // namespace v8::internal |
OLD | NEW |