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 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
853 | 854 |
854 // Install global Function object | 855 // Install global Function object |
855 InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, | 856 InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, |
856 empty_function, Builtins::kIllegal, true); // ECMA native. | 857 empty_function, Builtins::kIllegal, true); // ECMA native. |
857 | 858 |
858 { // --- A r r a y --- | 859 { // --- A r r a y --- |
859 Handle<JSFunction> array_function = | 860 Handle<JSFunction> array_function = |
860 InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize, | 861 InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize, |
861 isolate->initial_object_prototype(), | 862 isolate->initial_object_prototype(), |
862 Builtins::kArrayCode, true); | 863 Builtins::kArrayCode, true); |
863 array_function->shared()->set_construct_stub( | |
864 isolate->builtins()->builtin(Builtins::kArrayConstructCode)); | |
865 array_function->shared()->DontAdaptArguments(); | 864 array_function->shared()->DontAdaptArguments(); |
866 | 865 |
867 // This seems a bit hackish, but we need to make sure Array.length | 866 // This seems a bit hackish, but we need to make sure Array.length |
868 // is 1. | 867 // is 1. |
869 array_function->shared()->set_length(1); | 868 array_function->shared()->set_length(1); |
870 | 869 |
871 Handle<Map> initial_map(array_function->initial_map()); | 870 Handle<Map> initial_map(array_function->initial_map()); |
872 Handle<DescriptorArray> array_descriptors( | 871 Handle<DescriptorArray> array_descriptors( |
873 factory->NewDescriptorArray(0, 1)); | 872 factory->NewDescriptorArray(0, 1)); |
874 DescriptorArray::WhitenessWitness witness(*array_descriptors); | 873 DescriptorArray::WhitenessWitness witness(*array_descriptors); |
875 | 874 |
876 Handle<Foreign> array_length(factory->NewForeign(&Accessors::ArrayLength)); | 875 Handle<Foreign> array_length(factory->NewForeign(&Accessors::ArrayLength)); |
877 PropertyAttributes attribs = static_cast<PropertyAttributes>( | 876 PropertyAttributes attribs = static_cast<PropertyAttributes>( |
878 DONT_ENUM | DONT_DELETE); | 877 DONT_ENUM | DONT_DELETE); |
879 initial_map->set_instance_descriptors(*array_descriptors); | 878 initial_map->set_instance_descriptors(*array_descriptors); |
880 | 879 |
881 { // Add length. | 880 { // Add length. |
882 CallbacksDescriptor d(*factory->length_string(), *array_length, attribs); | 881 CallbacksDescriptor d(*factory->length_string(), *array_length, attribs); |
883 array_function->initial_map()->AppendDescriptor(&d, witness); | 882 array_function->initial_map()->AppendDescriptor(&d, witness); |
884 } | 883 } |
885 | 884 |
886 // array_function is used internally. JS code creating array object should | 885 // array_function is used internally. JS code creating array object should |
887 // search for the 'Array' property on the global object and use that one | 886 // search for the 'Array' property on the global object and use that one |
888 // as the constructor. 'Array' property on a global object can be | 887 // as the constructor. 'Array' property on a global object can be |
889 // overwritten by JS code. | 888 // overwritten by JS code. |
890 native_context()->set_array_function(*array_function); | 889 native_context()->set_array_function(*array_function); |
| 890 |
| 891 // Cache the array maps |
| 892 MaybeObject* cache_result = CacheInitialJSArrayMaps(*native_context(), |
| 893 *initial_map); |
| 894 if (cache_result->IsFailure()) return false; |
| 895 |
| 896 if (FLAG_optimize_constructed_arrays) { |
| 897 ArrayConstructorStub array_constructor_stub(isolate); |
| 898 array_function->shared()->set_construct_stub( |
| 899 *array_constructor_stub.GetCode(isolate)); |
| 900 } else { |
| 901 array_function->shared()->set_construct_stub( |
| 902 isolate->builtins()->builtin(Builtins::kInternalArrayConstructCode)); |
| 903 } |
891 } | 904 } |
892 | 905 |
893 { // --- N u m b e r --- | 906 { // --- N u m b e r --- |
894 Handle<JSFunction> number_fun = | 907 Handle<JSFunction> number_fun = |
895 InstallFunction(global, "Number", JS_VALUE_TYPE, JSValue::kSize, | 908 InstallFunction(global, "Number", JS_VALUE_TYPE, JSValue::kSize, |
896 isolate->initial_object_prototype(), | 909 isolate->initial_object_prototype(), |
897 Builtins::kIllegal, true); | 910 Builtins::kIllegal, true); |
898 native_context()->set_number_function(*number_fun); | 911 native_context()->set_number_function(*number_fun); |
899 } | 912 } |
900 | 913 |
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1505 name, | 1518 name, |
1506 JS_ARRAY_TYPE, | 1519 JS_ARRAY_TYPE, |
1507 JSArray::kSize, | 1520 JSArray::kSize, |
1508 isolate()->initial_object_prototype(), | 1521 isolate()->initial_object_prototype(), |
1509 Builtins::kInternalArrayCode, | 1522 Builtins::kInternalArrayCode, |
1510 true); | 1523 true); |
1511 Handle<JSObject> prototype = | 1524 Handle<JSObject> prototype = |
1512 factory()->NewJSObject(isolate()->object_function(), TENURED); | 1525 factory()->NewJSObject(isolate()->object_function(), TENURED); |
1513 SetPrototype(array_function, prototype); | 1526 SetPrototype(array_function, prototype); |
1514 | 1527 |
1515 // TODO(mvstanton): For performance reasons, this code would have to | |
1516 // be changed to successfully run with FLAG_optimize_constructed_arrays. | |
1517 // The next checkin to enable FLAG_optimize_constructed_arrays by | |
1518 // default will address this. | |
1519 CHECK(!FLAG_optimize_constructed_arrays); | |
1520 array_function->shared()->set_construct_stub( | 1528 array_function->shared()->set_construct_stub( |
1521 isolate()->builtins()->builtin(Builtins::kArrayConstructCode)); | 1529 isolate()->builtins()->builtin(Builtins::kInternalArrayConstructCode)); |
1522 | 1530 |
1523 array_function->shared()->DontAdaptArguments(); | 1531 array_function->shared()->DontAdaptArguments(); |
1524 | 1532 |
1525 MaybeObject* maybe_map = array_function->initial_map()->Copy(); | 1533 MaybeObject* maybe_map = array_function->initial_map()->Copy(); |
1526 Map* new_map; | 1534 Map* new_map; |
1527 if (!maybe_map->To(&new_map)) return Handle<JSFunction>::null(); | 1535 if (!maybe_map->To(&new_map)) return Handle<JSFunction>::null(); |
1528 new_map->set_elements_kind(elements_kind); | 1536 new_map->set_elements_kind(elements_kind); |
1529 array_function->set_initial_map(new_map); | 1537 array_function->set_initial_map(new_map); |
1530 | 1538 |
1531 // Make "length" magic on instances. | 1539 // Make "length" magic on instances. |
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2533 return from + sizeof(NestingCounterType); | 2541 return from + sizeof(NestingCounterType); |
2534 } | 2542 } |
2535 | 2543 |
2536 | 2544 |
2537 // Called when the top-level V8 mutex is destroyed. | 2545 // Called when the top-level V8 mutex is destroyed. |
2538 void Bootstrapper::FreeThreadResources() { | 2546 void Bootstrapper::FreeThreadResources() { |
2539 ASSERT(!IsActive()); | 2547 ASSERT(!IsActive()); |
2540 } | 2548 } |
2541 | 2549 |
2542 } } // namespace v8::internal | 2550 } } // namespace v8::internal |
OLD | NEW |