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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 if (str->IsUtf8EqualTo(name)) { | 58 if (str->IsUtf8EqualTo(name)) { |
59 *handle = Handle<SharedFunctionInfo>( | 59 *handle = Handle<SharedFunctionInfo>( |
60 SharedFunctionInfo::cast(cache_->get(i + 1))); | 60 SharedFunctionInfo::cast(cache_->get(i + 1))); |
61 return true; | 61 return true; |
62 } | 62 } |
63 } | 63 } |
64 return false; | 64 return false; |
65 } | 65 } |
66 | 66 |
67 void Add(Vector<const char> name, Handle<SharedFunctionInfo> shared) { | 67 void Add(Vector<const char> name, Handle<SharedFunctionInfo> shared) { |
68 HandleScope scope; | 68 HandleScope scope(shared->GetIsolate()); |
69 int length = cache_->length(); | 69 int length = cache_->length(); |
70 Handle<FixedArray> new_array = | 70 Handle<FixedArray> new_array = |
71 FACTORY->NewFixedArray(length + 2, TENURED); | 71 FACTORY->NewFixedArray(length + 2, TENURED); |
72 cache_->CopyTo(0, *new_array, 0, cache_->length()); | 72 cache_->CopyTo(0, *new_array, 0, cache_->length()); |
73 cache_ = *new_array; | 73 cache_ = *new_array; |
74 Handle<String> str = FACTORY->NewStringFromAscii(name, TENURED); | 74 Handle<String> str = FACTORY->NewStringFromAscii(name, TENURED); |
75 cache_->set(length, *str); | 75 cache_->set(length, *str); |
76 cache_->set(length + 1, *shared); | 76 cache_->set(length + 1, *shared); |
77 Script::cast(shared->script())->set_type(Smi::FromInt(type_)); | 77 Script::cast(shared->script())->set_type(Smi::FromInt(type_)); |
78 } | 78 } |
79 | 79 |
80 private: | 80 private: |
81 Script::Type type_; | 81 Script::Type type_; |
82 FixedArray* cache_; | 82 FixedArray* cache_; |
83 DISALLOW_COPY_AND_ASSIGN(SourceCodeCache); | 83 DISALLOW_COPY_AND_ASSIGN(SourceCodeCache); |
84 }; | 84 }; |
85 | 85 |
86 | 86 |
87 // The Boostrapper is the public interface for creating a JavaScript global | 87 // The Boostrapper is the public interface for creating a JavaScript global |
88 // context. | 88 // context. |
89 class Bootstrapper { | 89 class Bootstrapper { |
90 public: | 90 public: |
91 // Requires: Heap::SetUp has been called. | 91 // Requires: Heap::SetUp has been called. |
92 void Initialize(bool create_heap_objects); | 92 void Initialize(bool create_heap_objects); |
93 void TearDown(); | 93 void TearDown(); |
94 | 94 |
95 // Creates a JavaScript Global Context with initial object graph. | 95 // Creates a JavaScript Global Context with initial object graph. |
96 // The returned value is a global handle casted to V8Environment*. | 96 // The returned value is a global handle casted to V8Environment*. |
97 Handle<Context> CreateEnvironment( | 97 Handle<Context> CreateEnvironment( |
98 Isolate* isolate, | |
99 Handle<Object> global_object, | 98 Handle<Object> global_object, |
100 v8::Handle<v8::ObjectTemplate> global_template, | 99 v8::Handle<v8::ObjectTemplate> global_template, |
101 v8::ExtensionConfiguration* extensions); | 100 v8::ExtensionConfiguration* extensions); |
102 | 101 |
103 // Detach the environment from its outer global object. | 102 // Detach the environment from its outer global object. |
104 void DetachGlobal(Handle<Context> env); | 103 void DetachGlobal(Handle<Context> env); |
105 | 104 |
106 // Reattach an outer global object to an environment. | 105 // Reattach an outer global object to an environment. |
107 void ReattachGlobal(Handle<Context> env, Handle<JSGlobalProxy> global_proxy); | 106 void ReattachGlobal(Handle<Context> env, Handle<JSGlobalProxy> global_proxy); |
108 | 107 |
(...skipping 16 matching lines...) Expand all Loading... |
125 // It should only be used for strictly finite allocations. | 124 // It should only be used for strictly finite allocations. |
126 char* AllocateAutoDeletedArray(int bytes); | 125 char* AllocateAutoDeletedArray(int bytes); |
127 | 126 |
128 // Used for new context creation. | 127 // Used for new context creation. |
129 bool InstallExtensions(Handle<Context> native_context, | 128 bool InstallExtensions(Handle<Context> native_context, |
130 v8::ExtensionConfiguration* extensions); | 129 v8::ExtensionConfiguration* extensions); |
131 | 130 |
132 SourceCodeCache* extensions_cache() { return &extensions_cache_; } | 131 SourceCodeCache* extensions_cache() { return &extensions_cache_; } |
133 | 132 |
134 private: | 133 private: |
| 134 Isolate* isolate_; |
135 typedef int NestingCounterType; | 135 typedef int NestingCounterType; |
136 NestingCounterType nesting_; | 136 NestingCounterType nesting_; |
137 SourceCodeCache extensions_cache_; | 137 SourceCodeCache extensions_cache_; |
138 // This is for delete, not delete[]. | 138 // This is for delete, not delete[]. |
139 List<char*>* delete_these_non_arrays_on_tear_down_; | 139 List<char*>* delete_these_non_arrays_on_tear_down_; |
140 // This is for delete[] | 140 // This is for delete[] |
141 List<char*>* delete_these_arrays_on_tear_down_; | 141 List<char*>* delete_these_arrays_on_tear_down_; |
142 | 142 |
143 friend class BootstrapperActive; | 143 friend class BootstrapperActive; |
144 friend class Isolate; | 144 friend class Isolate; |
145 friend class NativesExternalStringResource; | 145 friend class NativesExternalStringResource; |
146 | 146 |
147 Bootstrapper(); | 147 explicit Bootstrapper(Isolate* isolate); |
148 | 148 |
149 DISALLOW_COPY_AND_ASSIGN(Bootstrapper); | 149 DISALLOW_COPY_AND_ASSIGN(Bootstrapper); |
150 }; | 150 }; |
151 | 151 |
152 | 152 |
153 class BootstrapperActive BASE_EMBEDDED { | 153 class BootstrapperActive BASE_EMBEDDED { |
154 public: | 154 public: |
155 BootstrapperActive() { | 155 explicit BootstrapperActive(Bootstrapper* bootstrapper) |
156 ++Isolate::Current()->bootstrapper()->nesting_; | 156 : bootstrapper_(bootstrapper) { |
| 157 ++bootstrapper_->nesting_; |
157 } | 158 } |
158 | 159 |
159 ~BootstrapperActive() { | 160 ~BootstrapperActive() { |
160 --Isolate::Current()->bootstrapper()->nesting_; | 161 --bootstrapper_->nesting_; |
161 } | 162 } |
162 | 163 |
163 private: | 164 private: |
| 165 Bootstrapper* bootstrapper_; |
| 166 |
164 DISALLOW_COPY_AND_ASSIGN(BootstrapperActive); | 167 DISALLOW_COPY_AND_ASSIGN(BootstrapperActive); |
165 }; | 168 }; |
166 | 169 |
167 | 170 |
168 class NativesExternalStringResource | 171 class NativesExternalStringResource |
169 : public v8::String::ExternalAsciiStringResource { | 172 : public v8::String::ExternalAsciiStringResource { |
170 public: | 173 public: |
171 NativesExternalStringResource(Bootstrapper* bootstrapper, | 174 NativesExternalStringResource(Bootstrapper* bootstrapper, |
172 const char* source, | 175 const char* source, |
173 size_t length); | 176 size_t length); |
174 | 177 |
175 const char* data() const { | 178 const char* data() const { |
176 return data_; | 179 return data_; |
177 } | 180 } |
178 | 181 |
179 size_t length() const { | 182 size_t length() const { |
180 return length_; | 183 return length_; |
181 } | 184 } |
182 private: | 185 private: |
183 const char* data_; | 186 const char* data_; |
184 size_t length_; | 187 size_t length_; |
185 }; | 188 }; |
186 | 189 |
187 }} // namespace v8::internal | 190 }} // namespace v8::internal |
188 | 191 |
189 #endif // V8_BOOTSTRAPPER_H_ | 192 #endif // V8_BOOTSTRAPPER_H_ |
OLD | NEW |