OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 29 matching lines...) Expand all Loading... |
40 namespace v8 { | 40 namespace v8 { |
41 namespace internal { | 41 namespace internal { |
42 | 42 |
43 // A SourceCodeCache uses a FixedArray to store pairs of | 43 // A SourceCodeCache uses a FixedArray to store pairs of |
44 // (AsciiString*, JSFunction*), mapping names of native code files | 44 // (AsciiString*, JSFunction*), mapping names of native code files |
45 // (runtime.js, etc.) to precompiled functions. Instead of mapping | 45 // (runtime.js, etc.) to precompiled functions. Instead of mapping |
46 // names to functions it might make sense to let the JS2C tool | 46 // names to functions it might make sense to let the JS2C tool |
47 // generate an index for each native JS file. | 47 // generate an index for each native JS file. |
48 class SourceCodeCache BASE_EMBEDDED { | 48 class SourceCodeCache BASE_EMBEDDED { |
49 public: | 49 public: |
50 explicit SourceCodeCache(ScriptType type): type_(type) { } | 50 explicit SourceCodeCache(Script::Type type): type_(type) { } |
51 | 51 |
52 void Initialize(bool create_heap_objects) { | 52 void Initialize(bool create_heap_objects) { |
53 if (create_heap_objects) { | 53 if (create_heap_objects) { |
54 cache_ = Heap::empty_fixed_array(); | 54 cache_ = Heap::empty_fixed_array(); |
55 } else { | 55 } else { |
56 cache_ = NULL; | 56 cache_ = NULL; |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
60 void Iterate(ObjectVisitor* v) { | 60 void Iterate(ObjectVisitor* v) { |
(...skipping 21 matching lines...) Expand all Loading... |
82 Factory::NewFixedArray(length + 2, TENURED); | 82 Factory::NewFixedArray(length + 2, TENURED); |
83 cache_->CopyTo(0, *new_array, 0, cache_->length()); | 83 cache_->CopyTo(0, *new_array, 0, cache_->length()); |
84 cache_ = *new_array; | 84 cache_ = *new_array; |
85 Handle<String> str = Factory::NewStringFromAscii(name, TENURED); | 85 Handle<String> str = Factory::NewStringFromAscii(name, TENURED); |
86 cache_->set(length, *str); | 86 cache_->set(length, *str); |
87 cache_->set(length + 1, *fun); | 87 cache_->set(length + 1, *fun); |
88 Script::cast(fun->shared()->script())->set_type(Smi::FromInt(type_)); | 88 Script::cast(fun->shared()->script())->set_type(Smi::FromInt(type_)); |
89 } | 89 } |
90 | 90 |
91 private: | 91 private: |
92 ScriptType type_; | 92 Script::Type type_; |
93 FixedArray* cache_; | 93 FixedArray* cache_; |
94 DISALLOW_COPY_AND_ASSIGN(SourceCodeCache); | 94 DISALLOW_COPY_AND_ASSIGN(SourceCodeCache); |
95 }; | 95 }; |
96 | 96 |
97 static SourceCodeCache natives_cache(SCRIPT_TYPE_NATIVE); | 97 static SourceCodeCache natives_cache(Script::TYPE_NATIVE); |
98 static SourceCodeCache extensions_cache(SCRIPT_TYPE_EXTENSION); | 98 static SourceCodeCache extensions_cache(Script::TYPE_EXTENSION); |
99 | 99 |
100 | 100 |
101 Handle<String> Bootstrapper::NativesSourceLookup(int index) { | 101 Handle<String> Bootstrapper::NativesSourceLookup(int index) { |
102 ASSERT(0 <= index && index < Natives::GetBuiltinsCount()); | 102 ASSERT(0 <= index && index < Natives::GetBuiltinsCount()); |
103 if (Heap::natives_source_cache()->get(index)->IsUndefined()) { | 103 if (Heap::natives_source_cache()->get(index)->IsUndefined()) { |
104 Handle<String> source_code = | 104 Handle<String> source_code = |
105 Factory::NewStringFromAscii(Natives::GetScriptSource(index)); | 105 Factory::NewStringFromAscii(Natives::GetScriptSource(index)); |
106 Heap::natives_source_cache()->set(index, *source_code); | 106 Heap::natives_source_cache()->set(index, *source_code); |
107 } | 107 } |
108 Handle<Object> cached_source(Heap::natives_source_cache()->get(index)); | 108 Handle<Object> cached_source(Heap::natives_source_cache()->get(index)); |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 Handle<String> symbol = Factory::LookupAsciiSymbol("Empty"); | 515 Handle<String> symbol = Factory::LookupAsciiSymbol("Empty"); |
516 Handle<JSFunction> empty_function = | 516 Handle<JSFunction> empty_function = |
517 Factory::NewFunction(symbol, Factory::null_value()); | 517 Factory::NewFunction(symbol, Factory::null_value()); |
518 | 518 |
519 { // --- E m p t y --- | 519 { // --- E m p t y --- |
520 Handle<Code> code = | 520 Handle<Code> code = |
521 Handle<Code>(Builtins::builtin(Builtins::EmptyFunction)); | 521 Handle<Code>(Builtins::builtin(Builtins::EmptyFunction)); |
522 empty_function->set_code(*code); | 522 empty_function->set_code(*code); |
523 Handle<String> source = Factory::NewStringFromAscii(CStrVector("() {}")); | 523 Handle<String> source = Factory::NewStringFromAscii(CStrVector("() {}")); |
524 Handle<Script> script = Factory::NewScript(source); | 524 Handle<Script> script = Factory::NewScript(source); |
525 script->set_type(Smi::FromInt(SCRIPT_TYPE_NATIVE)); | 525 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); |
526 empty_function->shared()->set_script(*script); | 526 empty_function->shared()->set_script(*script); |
527 empty_function->shared()->set_start_position(0); | 527 empty_function->shared()->set_start_position(0); |
528 empty_function->shared()->set_end_position(source->length()); | 528 empty_function->shared()->set_end_position(source->length()); |
529 empty_function->shared()->DontAdaptArguments(); | 529 empty_function->shared()->DontAdaptArguments(); |
530 global_context()->function_map()->set_prototype(*empty_function); | 530 global_context()->function_map()->set_prototype(*empty_function); |
531 global_context()->function_instance_map()->set_prototype(*empty_function); | 531 global_context()->function_instance_map()->set_prototype(*empty_function); |
532 | 532 |
533 // Allocate the function map first and then patch the prototype later | 533 // Allocate the function map first and then patch the prototype later |
534 Handle<Map> empty_fm = Factory::CopyMapDropDescriptors(fm); | 534 Handle<Map> empty_fm = Factory::CopyMapDropDescriptors(fm); |
535 empty_fm->set_instance_descriptors(*function_map_descriptors); | 535 empty_fm->set_instance_descriptors(*function_map_descriptors); |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1055 Factory::LookupAsciiSymbol("data"), | 1055 Factory::LookupAsciiSymbol("data"), |
1056 proxy_data, | 1056 proxy_data, |
1057 common_attributes); | 1057 common_attributes); |
1058 Handle<Proxy> proxy_type = Factory::NewProxy(&Accessors::ScriptType); | 1058 Handle<Proxy> proxy_type = Factory::NewProxy(&Accessors::ScriptType); |
1059 script_descriptors = | 1059 script_descriptors = |
1060 Factory::CopyAppendProxyDescriptor( | 1060 Factory::CopyAppendProxyDescriptor( |
1061 script_descriptors, | 1061 script_descriptors, |
1062 Factory::LookupAsciiSymbol("type"), | 1062 Factory::LookupAsciiSymbol("type"), |
1063 proxy_type, | 1063 proxy_type, |
1064 common_attributes); | 1064 common_attributes); |
| 1065 Handle<Proxy> proxy_compilation_type = |
| 1066 Factory::NewProxy(&Accessors::ScriptCompilationType); |
| 1067 script_descriptors = |
| 1068 Factory::CopyAppendProxyDescriptor( |
| 1069 script_descriptors, |
| 1070 Factory::LookupAsciiSymbol("compilation_type"), |
| 1071 proxy_compilation_type, |
| 1072 common_attributes); |
1065 Handle<Proxy> proxy_line_ends = | 1073 Handle<Proxy> proxy_line_ends = |
1066 Factory::NewProxy(&Accessors::ScriptLineEnds); | 1074 Factory::NewProxy(&Accessors::ScriptLineEnds); |
1067 script_descriptors = | 1075 script_descriptors = |
1068 Factory::CopyAppendProxyDescriptor( | 1076 Factory::CopyAppendProxyDescriptor( |
1069 script_descriptors, | 1077 script_descriptors, |
1070 Factory::LookupAsciiSymbol("line_ends"), | 1078 Factory::LookupAsciiSymbol("line_ends"), |
1071 proxy_line_ends, | 1079 proxy_line_ends, |
1072 common_attributes); | 1080 common_attributes); |
1073 Handle<Proxy> proxy_context_data = | 1081 Handle<Proxy> proxy_context_data = |
1074 Factory::NewProxy(&Accessors::ScriptContextData); | 1082 Factory::NewProxy(&Accessors::ScriptContextData); |
1075 script_descriptors = | 1083 script_descriptors = |
1076 Factory::CopyAppendProxyDescriptor( | 1084 Factory::CopyAppendProxyDescriptor( |
1077 script_descriptors, | 1085 script_descriptors, |
1078 Factory::LookupAsciiSymbol("context_data"), | 1086 Factory::LookupAsciiSymbol("context_data"), |
1079 proxy_context_data, | 1087 proxy_context_data, |
1080 common_attributes); | 1088 common_attributes); |
| 1089 Handle<Proxy> proxy_eval_from_function = |
| 1090 Factory::NewProxy(&Accessors::ScriptEvalFromFunction); |
| 1091 script_descriptors = |
| 1092 Factory::CopyAppendProxyDescriptor( |
| 1093 script_descriptors, |
| 1094 Factory::LookupAsciiSymbol("eval_from_function"), |
| 1095 proxy_eval_from_function, |
| 1096 common_attributes); |
| 1097 Handle<Proxy> proxy_eval_from_position = |
| 1098 Factory::NewProxy(&Accessors::ScriptEvalFromPosition); |
| 1099 script_descriptors = |
| 1100 Factory::CopyAppendProxyDescriptor( |
| 1101 script_descriptors, |
| 1102 Factory::LookupAsciiSymbol("eval_from_position"), |
| 1103 proxy_eval_from_position, |
| 1104 common_attributes); |
1081 | 1105 |
1082 Handle<Map> script_map = Handle<Map>(script_fun->initial_map()); | 1106 Handle<Map> script_map = Handle<Map>(script_fun->initial_map()); |
1083 script_map->set_instance_descriptors(*script_descriptors); | 1107 script_map->set_instance_descriptors(*script_descriptors); |
1084 | 1108 |
1085 // Allocate the empty script. | 1109 // Allocate the empty script. |
1086 Handle<Script> script = Factory::NewScript(Factory::empty_string()); | 1110 Handle<Script> script = Factory::NewScript(Factory::empty_string()); |
1087 script->set_type(Smi::FromInt(SCRIPT_TYPE_NATIVE)); | 1111 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); |
1088 global_context()->set_empty_script(*script); | 1112 global_context()->set_empty_script(*script); |
1089 } | 1113 } |
1090 | 1114 |
1091 #ifdef V8_HOST_ARCH_64_BIT | 1115 #ifdef V8_HOST_ARCH_64_BIT |
1092 // TODO(X64): Reenable remaining initialization when code generation works. | 1116 // TODO(X64): Reenable remaining initialization when code generation works. |
1093 return true; | 1117 return true; |
1094 #endif // V8_HOST_ARCH_64_BIT | 1118 #endif // V8_HOST_ARCH_64_BIT |
1095 | 1119 |
1096 | 1120 |
1097 if (FLAG_natives_file == NULL) { | 1121 if (FLAG_natives_file == NULL) { |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1589 } | 1613 } |
1590 | 1614 |
1591 | 1615 |
1592 // Restore statics that are thread local. | 1616 // Restore statics that are thread local. |
1593 char* Genesis::RestoreState(char* from) { | 1617 char* Genesis::RestoreState(char* from) { |
1594 current_ = *reinterpret_cast<Genesis**>(from); | 1618 current_ = *reinterpret_cast<Genesis**>(from); |
1595 return from + sizeof(current_); | 1619 return from + sizeof(current_); |
1596 } | 1620 } |
1597 | 1621 |
1598 } } // namespace v8::internal | 1622 } } // namespace v8::internal |
OLD | NEW |