| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "global-handles.h" | 36 #include "global-handles.h" |
| 37 #include "isolate-inl.h" | 37 #include "isolate-inl.h" |
| 38 #include "macro-assembler.h" | 38 #include "macro-assembler.h" |
| 39 #include "natives.h" | 39 #include "natives.h" |
| 40 #include "objects-visiting.h" | 40 #include "objects-visiting.h" |
| 41 #include "platform.h" | 41 #include "platform.h" |
| 42 #include "snapshot.h" | 42 #include "snapshot.h" |
| 43 #include "extensions/externalize-string-extension.h" | 43 #include "extensions/externalize-string-extension.h" |
| 44 #include "extensions/gc-extension.h" | 44 #include "extensions/gc-extension.h" |
| 45 #include "extensions/statistics-extension.h" | 45 #include "extensions/statistics-extension.h" |
| 46 #include "code-stubs.h" |
| 46 | 47 |
| 47 namespace v8 { | 48 namespace v8 { |
| 48 namespace internal { | 49 namespace internal { |
| 49 | 50 |
| 50 | 51 |
| 51 NativesExternalStringResource::NativesExternalStringResource( | 52 NativesExternalStringResource::NativesExternalStringResource( |
| 52 Bootstrapper* bootstrapper, | 53 Bootstrapper* bootstrapper, |
| 53 const char* source, | 54 const char* source, |
| 54 size_t length) | 55 size_t length) |
| 55 : data_(source), length_(length) { | 56 : data_(source), length_(length) { |
| (...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 | 856 |
| 856 // Install global Function object | 857 // Install global Function object |
| 857 InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, | 858 InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, |
| 858 empty_function, Builtins::kIllegal, true); // ECMA native. | 859 empty_function, Builtins::kIllegal, true); // ECMA native. |
| 859 | 860 |
| 860 { // --- A r r a y --- | 861 { // --- A r r a y --- |
| 861 Handle<JSFunction> array_function = | 862 Handle<JSFunction> array_function = |
| 862 InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize, | 863 InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize, |
| 863 isolate->initial_object_prototype(), | 864 isolate->initial_object_prototype(), |
| 864 Builtins::kArrayCode, true); | 865 Builtins::kArrayCode, true); |
| 865 array_function->shared()->set_construct_stub( | |
| 866 isolate->builtins()->builtin(Builtins::kArrayConstructCode)); | |
| 867 array_function->shared()->DontAdaptArguments(); | 866 array_function->shared()->DontAdaptArguments(); |
| 868 | 867 |
| 869 // This seems a bit hackish, but we need to make sure Array.length | 868 // This seems a bit hackish, but we need to make sure Array.length |
| 870 // is 1. | 869 // is 1. |
| 871 array_function->shared()->set_length(1); | 870 array_function->shared()->set_length(1); |
| 872 | 871 |
| 873 Handle<Map> initial_map(array_function->initial_map()); | 872 Handle<Map> initial_map(array_function->initial_map()); |
| 874 Handle<DescriptorArray> array_descriptors( | 873 Handle<DescriptorArray> array_descriptors( |
| 875 factory->NewDescriptorArray(0, 1)); | 874 factory->NewDescriptorArray(0, 1)); |
| 876 DescriptorArray::WhitenessWitness witness(*array_descriptors); | 875 DescriptorArray::WhitenessWitness witness(*array_descriptors); |
| 877 | 876 |
| 878 Handle<Foreign> array_length(factory->NewForeign(&Accessors::ArrayLength)); | 877 Handle<Foreign> array_length(factory->NewForeign(&Accessors::ArrayLength)); |
| 879 PropertyAttributes attribs = static_cast<PropertyAttributes>( | 878 PropertyAttributes attribs = static_cast<PropertyAttributes>( |
| 880 DONT_ENUM | DONT_DELETE); | 879 DONT_ENUM | DONT_DELETE); |
| 881 initial_map->set_instance_descriptors(*array_descriptors); | 880 initial_map->set_instance_descriptors(*array_descriptors); |
| 882 | 881 |
| 883 { // Add length. | 882 { // Add length. |
| 884 CallbacksDescriptor d(*factory->length_string(), *array_length, attribs); | 883 CallbacksDescriptor d(*factory->length_string(), *array_length, attribs); |
| 885 array_function->initial_map()->AppendDescriptor(&d, witness); | 884 array_function->initial_map()->AppendDescriptor(&d, witness); |
| 886 } | 885 } |
| 887 | 886 |
| 888 // array_function is used internally. JS code creating array object should | 887 // array_function is used internally. JS code creating array object should |
| 889 // search for the 'Array' property on the global object and use that one | 888 // search for the 'Array' property on the global object and use that one |
| 890 // as the constructor. 'Array' property on a global object can be | 889 // as the constructor. 'Array' property on a global object can be |
| 891 // overwritten by JS code. | 890 // overwritten by JS code. |
| 892 native_context()->set_array_function(*array_function); | 891 native_context()->set_array_function(*array_function); |
| 892 |
| 893 // Cache the array maps |
| 894 MaybeObject* cache_result = CacheInitialJSArrayMaps(*native_context(), |
| 895 *initial_map); |
| 896 if (cache_result->IsFailure()) return false; |
| 897 |
| 898 if (FLAG_optimize_constructed_arrays) { |
| 899 ArrayConstructorStub array_constructor_stub(isolate); |
| 900 array_function->shared()->set_construct_stub( |
| 901 *array_constructor_stub.GetCode(isolate)); |
| 902 } else { |
| 903 array_function->shared()->set_construct_stub( |
| 904 isolate->builtins()->builtin(Builtins::kCommonArrayConstructCode)); |
| 905 } |
| 893 } | 906 } |
| 894 | 907 |
| 895 { // --- N u m b e r --- | 908 { // --- N u m b e r --- |
| 896 Handle<JSFunction> number_fun = | 909 Handle<JSFunction> number_fun = |
| 897 InstallFunction(global, "Number", JS_VALUE_TYPE, JSValue::kSize, | 910 InstallFunction(global, "Number", JS_VALUE_TYPE, JSValue::kSize, |
| 898 isolate->initial_object_prototype(), | 911 isolate->initial_object_prototype(), |
| 899 Builtins::kIllegal, true); | 912 Builtins::kIllegal, true); |
| 900 native_context()->set_number_function(*number_fun); | 913 native_context()->set_number_function(*number_fun); |
| 901 } | 914 } |
| 902 | 915 |
| (...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1526 name, | 1539 name, |
| 1527 JS_ARRAY_TYPE, | 1540 JS_ARRAY_TYPE, |
| 1528 JSArray::kSize, | 1541 JSArray::kSize, |
| 1529 isolate()->initial_object_prototype(), | 1542 isolate()->initial_object_prototype(), |
| 1530 Builtins::kInternalArrayCode, | 1543 Builtins::kInternalArrayCode, |
| 1531 true); | 1544 true); |
| 1532 Handle<JSObject> prototype = | 1545 Handle<JSObject> prototype = |
| 1533 factory()->NewJSObject(isolate()->object_function(), TENURED); | 1546 factory()->NewJSObject(isolate()->object_function(), TENURED); |
| 1534 SetPrototype(array_function, prototype); | 1547 SetPrototype(array_function, prototype); |
| 1535 | 1548 |
| 1536 // TODO(mvstanton): For performance reasons, this code would have to | |
| 1537 // be changed to successfully run with FLAG_optimize_constructed_arrays. | |
| 1538 // The next checkin to enable FLAG_optimize_constructed_arrays by | |
| 1539 // default will address this. | |
| 1540 CHECK(!FLAG_optimize_constructed_arrays); | |
| 1541 array_function->shared()->set_construct_stub( | 1549 array_function->shared()->set_construct_stub( |
| 1542 isolate()->builtins()->builtin(Builtins::kArrayConstructCode)); | 1550 isolate()->builtins()->builtin(Builtins::kCommonArrayConstructCode)); |
| 1543 | 1551 |
| 1544 array_function->shared()->DontAdaptArguments(); | 1552 array_function->shared()->DontAdaptArguments(); |
| 1545 | 1553 |
| 1546 MaybeObject* maybe_map = array_function->initial_map()->Copy(); | 1554 MaybeObject* maybe_map = array_function->initial_map()->Copy(); |
| 1547 Map* new_map; | 1555 Map* new_map; |
| 1548 if (!maybe_map->To(&new_map)) return Handle<JSFunction>::null(); | 1556 if (!maybe_map->To(&new_map)) return Handle<JSFunction>::null(); |
| 1549 new_map->set_elements_kind(elements_kind); | 1557 new_map->set_elements_kind(elements_kind); |
| 1550 array_function->set_initial_map(new_map); | 1558 array_function->set_initial_map(new_map); |
| 1551 | 1559 |
| 1552 // Make "length" magic on instances. | 1560 // Make "length" magic on instances. |
| (...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2554 return from + sizeof(NestingCounterType); | 2562 return from + sizeof(NestingCounterType); |
| 2555 } | 2563 } |
| 2556 | 2564 |
| 2557 | 2565 |
| 2558 // Called when the top-level V8 mutex is destroyed. | 2566 // Called when the top-level V8 mutex is destroyed. |
| 2559 void Bootstrapper::FreeThreadResources() { | 2567 void Bootstrapper::FreeThreadResources() { |
| 2560 ASSERT(!IsActive()); | 2568 ASSERT(!IsActive()); |
| 2561 } | 2569 } |
| 2562 | 2570 |
| 2563 } } // namespace v8::internal | 2571 } } // namespace v8::internal |
| OLD | NEW |