OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 (function(global, utils) { | 5 (function(global, utils) { |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
11 // ----------------------------------------------------------------------- | 11 // ----------------------------------------------------------------------- |
12 // Utils | 12 // Utils |
13 | 13 |
14 var imports = UNDEFINED; | 14 var imports = UNDEFINED; |
15 var exports = UNDEFINED; | |
16 var imports_from_experimental = UNDEFINED; | 15 var imports_from_experimental = UNDEFINED; |
17 var exports_to_runtime = UNDEFINED; | 16 var exports_to_runtime = UNDEFINED; |
| 17 var exports_container = {}; |
18 | 18 |
19 // Export to other scripts. | 19 // Export to other scripts. |
20 // In normal natives, this exports functions to other normal natives. | 20 // In normal natives, this exports functions to other normal natives. |
21 // In experimental natives, this exports to other experimental natives and | 21 // In experimental natives, this exports to other experimental natives and |
22 // to normal natives that import using utils.ImportFromExperimental. | 22 // to normal natives that import using utils.ImportFromExperimental. |
23 function Export(f) { | 23 function Export(f) { |
24 f.next = exports; | 24 f(exports_container); |
25 exports = f; | |
26 } | 25 } |
27 | 26 |
28 | 27 |
29 // Export to the native context for calls from the runtime. | 28 // Export to the native context for calls from the runtime. |
30 function ExportToRuntime(f) { | 29 function ExportToRuntime(f) { |
31 f.next = exports_to_runtime; | 30 f.next = exports_to_runtime; |
32 exports_to_runtime = f; | 31 exports_to_runtime = f; |
33 } | 32 } |
34 | 33 |
35 // Import from other scripts. | 34 |
| 35 // Import from other scripts. The actual importing happens in PostNatives and |
| 36 // PostExperimental so that we can import from scripts executed later. However, |
| 37 // that means that the import is not available until the very end. If the |
| 38 // import needs to be available immediate, use ImportNow. |
36 // In normal natives, this imports from other normal natives. | 39 // In normal natives, this imports from other normal natives. |
37 // In experimental natives, this imports from other experimental natives and | 40 // In experimental natives, this imports from other experimental natives and |
38 // whitelisted exports from normal natives. | 41 // whitelisted exports from normal natives. |
39 function Import(f) { | 42 function Import(f) { |
40 f.next = imports; | 43 f.next = imports; |
41 imports = f; | 44 imports = f; |
42 } | 45 } |
43 | 46 |
| 47 // Import immediately from exports of previous scripts. We need this for |
| 48 // functions called during bootstrapping. Hooking up imports in PostNatives |
| 49 // would be too late. |
| 50 function ImportNow(f) { |
| 51 f(exports_container); |
| 52 } |
| 53 |
44 | 54 |
45 // In normal natives, import from experimental natives. | 55 // In normal natives, import from experimental natives. |
46 // Not callable from experimental natives. | 56 // Not callable from experimental natives. |
47 function ImportFromExperimental(f) { | 57 function ImportFromExperimental(f) { |
48 f.next = imports_from_experimental; | 58 f.next = imports_from_experimental; |
49 imports_from_experimental = f; | 59 imports_from_experimental = f; |
50 } | 60 } |
51 | 61 |
52 | 62 |
53 function SetFunctionName(f, name, prefix) { | 63 function SetFunctionName(f, name, prefix) { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 %AddNamedProperty(prototype, key, f, DONT_ENUM | DONT_DELETE | READ_ONLY); | 152 %AddNamedProperty(prototype, key, f, DONT_ENUM | DONT_DELETE | READ_ONLY); |
143 %SetNativeFlag(f); | 153 %SetNativeFlag(f); |
144 } | 154 } |
145 %InternalSetPrototype(prototype, null); | 155 %InternalSetPrototype(prototype, null); |
146 %ToFastProperties(prototype); | 156 %ToFastProperties(prototype); |
147 } | 157 } |
148 | 158 |
149 // ----------------------------------------------------------------------- | 159 // ----------------------------------------------------------------------- |
150 // To be called by bootstrapper | 160 // To be called by bootstrapper |
151 | 161 |
152 var experimental_exports = UNDEFINED; | |
153 | |
154 function PostNatives(utils) { | 162 function PostNatives(utils) { |
155 %CheckIsBootstrapping(); | 163 %CheckIsBootstrapping(); |
156 | 164 |
157 var container = {}; | 165 for ( ; !IS_UNDEFINED(imports); imports = imports.next) { |
158 for ( ; !IS_UNDEFINED(exports); exports = exports.next) exports(container); | 166 imports(exports_container); |
159 for ( ; !IS_UNDEFINED(imports); imports = imports.next) imports(container); | 167 } |
160 | 168 |
161 var runtime_container = {}; | 169 var runtime_container = {}; |
162 for ( ; !IS_UNDEFINED(exports_to_runtime); | 170 for ( ; !IS_UNDEFINED(exports_to_runtime); |
163 exports_to_runtime = exports_to_runtime.next) { | 171 exports_to_runtime = exports_to_runtime.next) { |
164 exports_to_runtime(runtime_container); | 172 exports_to_runtime(runtime_container); |
165 } | 173 } |
166 %ImportToRuntime(runtime_container); | 174 %ImportToRuntime(runtime_container); |
167 | 175 |
168 // Whitelist of exports from normal natives to experimental natives. | 176 // Whitelist of exports from normal natives to experimental natives and debug. |
169 var expose_to_experimental = [ | 177 var expose_list = [ |
170 "ArrayToString", | 178 "ArrayToString", |
| 179 "FunctionSourceString", |
171 "GetIterator", | 180 "GetIterator", |
172 "GetMethod", | 181 "GetMethod", |
173 "InnerArrayEvery", | 182 "InnerArrayEvery", |
174 "InnerArrayFilter", | 183 "InnerArrayFilter", |
175 "InnerArrayForEach", | 184 "InnerArrayForEach", |
176 "InnerArrayIndexOf", | 185 "InnerArrayIndexOf", |
177 "InnerArrayJoin", | 186 "InnerArrayJoin", |
178 "InnerArrayLastIndexOf", | 187 "InnerArrayLastIndexOf", |
179 "InnerArrayMap", | 188 "InnerArrayMap", |
180 "InnerArrayReduce", | 189 "InnerArrayReduce", |
181 "InnerArrayReduceRight", | 190 "InnerArrayReduceRight", |
182 "InnerArrayReverse", | 191 "InnerArrayReverse", |
183 "InnerArraySome", | 192 "InnerArraySome", |
184 "InnerArraySort", | 193 "InnerArraySort", |
185 "InnerArrayToLocaleString", | 194 "InnerArrayToLocaleString", |
186 "IsNaN", | 195 "IsNaN", |
187 "MathMax", | 196 "MathMax", |
188 "MathMin", | 197 "MathMin", |
189 "ObjectIsFrozen", | 198 "ObjectIsFrozen", |
190 "ObjectDefineProperty", | 199 "ObjectDefineProperty", |
191 "OwnPropertyKeys", | 200 "OwnPropertyKeys", |
192 "ToNameArray", | 201 "ToNameArray", |
| 202 "ToBoolean", |
| 203 "ToNumber", |
| 204 "ToString", |
193 ]; | 205 ]; |
194 experimental_exports = {}; | 206 |
| 207 var filtered_exports = {}; |
195 %OptimizeObjectForAddingMultipleProperties( | 208 %OptimizeObjectForAddingMultipleProperties( |
196 experimental_exports, expose_to_experimental.length); | 209 filtered_exports, expose_list.length); |
197 for (var key of expose_to_experimental) { | 210 for (var key of expose_list) { |
198 experimental_exports[key] = container[key]; | 211 filtered_exports[key] = exports_container[key]; |
199 } | 212 } |
200 %ToFastProperties(experimental_exports); | 213 %ToFastProperties(filtered_exports); |
201 container = UNDEFINED; | 214 exports_container = filtered_exports; |
202 | 215 |
203 utils.PostNatives = UNDEFINED; | 216 utils.PostNatives = UNDEFINED; |
204 utils.ImportFromExperimental = UNDEFINED; | 217 utils.ImportFromExperimental = UNDEFINED; |
205 } | 218 } |
206 | 219 |
207 | 220 |
208 function PostExperimentals(utils) { | 221 function PostExperimentals(utils) { |
209 %CheckIsBootstrapping(); | 222 %CheckIsBootstrapping(); |
210 | 223 |
211 for ( ; !IS_UNDEFINED(exports); exports = exports.next) { | |
212 exports(experimental_exports); | |
213 } | |
214 for ( ; !IS_UNDEFINED(imports); imports = imports.next) { | 224 for ( ; !IS_UNDEFINED(imports); imports = imports.next) { |
215 imports(experimental_exports); | 225 imports(exports_container); |
216 } | 226 } |
217 for ( ; !IS_UNDEFINED(imports_from_experimental); | 227 for ( ; !IS_UNDEFINED(imports_from_experimental); |
218 imports_from_experimental = imports_from_experimental.next) { | 228 imports_from_experimental = imports_from_experimental.next) { |
219 imports_from_experimental(experimental_exports); | 229 imports_from_experimental(exports_container); |
220 } | 230 } |
221 var runtime_container = {}; | 231 var runtime_container = {}; |
222 for ( ; !IS_UNDEFINED(exports_to_runtime); | 232 for ( ; !IS_UNDEFINED(exports_to_runtime); |
223 exports_to_runtime = exports_to_runtime.next) { | 233 exports_to_runtime = exports_to_runtime.next) { |
224 exports_to_runtime(runtime_container); | 234 exports_to_runtime(runtime_container); |
225 } | 235 } |
226 %ImportExperimentalToRuntime(runtime_container); | 236 %ImportExperimentalToRuntime(runtime_container); |
227 | 237 |
228 experimental_exports = UNDEFINED; | 238 exports_container = UNDEFINED; |
229 | 239 |
230 utils.PostExperimentals = UNDEFINED; | 240 utils.PostExperimentals = UNDEFINED; |
231 utils.PostDebug = UNDEFINED; | 241 utils.PostDebug = UNDEFINED; |
232 utils.Import = UNDEFINED; | 242 utils.Import = UNDEFINED; |
233 utils.Export = UNDEFINED; | 243 utils.Export = UNDEFINED; |
234 } | 244 } |
235 | 245 |
236 | 246 |
237 function PostDebug(utils) { | 247 function PostDebug(utils) { |
238 for ( ; !IS_UNDEFINED(exports); exports = exports.next) { | 248 for ( ; !IS_UNDEFINED(imports); imports = imports.next) { |
239 exports(experimental_exports); | 249 imports(exports_container); |
240 } | 250 } |
241 for ( ; !IS_UNDEFINED(imports); imports = imports.next) { | 251 |
242 imports(experimental_exports); | 252 exports_container = UNDEFINED; |
243 } | |
244 | 253 |
245 utils.PostDebug = UNDEFINED; | 254 utils.PostDebug = UNDEFINED; |
246 utils.PostExperimentals = UNDEFINED; | 255 utils.PostExperimentals = UNDEFINED; |
247 utils.Import = UNDEFINED; | 256 utils.Import = UNDEFINED; |
248 utils.Export = UNDEFINED; | 257 utils.Export = UNDEFINED; |
249 } | 258 } |
250 | 259 |
251 // ----------------------------------------------------------------------- | 260 // ----------------------------------------------------------------------- |
252 | 261 |
253 %OptimizeObjectForAddingMultipleProperties(utils, 13); | 262 %OptimizeObjectForAddingMultipleProperties(utils, 14); |
254 | 263 |
255 utils.Import = Import; | 264 utils.Import = Import; |
| 265 utils.ImportNow = ImportNow; |
256 utils.Export = Export; | 266 utils.Export = Export; |
257 utils.ExportToRuntime = ExportToRuntime; | 267 utils.ExportToRuntime = ExportToRuntime; |
258 utils.ImportFromExperimental = ImportFromExperimental; | 268 utils.ImportFromExperimental = ImportFromExperimental; |
259 utils.SetFunctionName = SetFunctionName; | 269 utils.SetFunctionName = SetFunctionName; |
260 utils.InstallConstants = InstallConstants; | 270 utils.InstallConstants = InstallConstants; |
261 utils.InstallFunctions = InstallFunctions; | 271 utils.InstallFunctions = InstallFunctions; |
262 utils.InstallGetter = InstallGetter; | 272 utils.InstallGetter = InstallGetter; |
263 utils.InstallGetterSetter = InstallGetterSetter; | 273 utils.InstallGetterSetter = InstallGetterSetter; |
264 utils.SetUpLockedPrototype = SetUpLockedPrototype; | 274 utils.SetUpLockedPrototype = SetUpLockedPrototype; |
265 utils.PostNatives = PostNatives; | 275 utils.PostNatives = PostNatives; |
266 utils.PostExperimentals = PostExperimentals; | 276 utils.PostExperimentals = PostExperimentals; |
267 utils.PostDebug = PostDebug; | 277 utils.PostDebug = PostDebug; |
268 | 278 |
269 %ToFastProperties(utils); | 279 %ToFastProperties(utils); |
270 | 280 |
271 }) | 281 }) |
OLD | NEW |