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, extrasUtils) { |
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 imports_from_experimental = UNDEFINED; | 15 var imports_from_experimental = UNDEFINED; |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 utils.InstallFunctions = InstallFunctions; | 260 utils.InstallFunctions = InstallFunctions; |
261 utils.InstallGetter = InstallGetter; | 261 utils.InstallGetter = InstallGetter; |
262 utils.InstallGetterSetter = InstallGetterSetter; | 262 utils.InstallGetterSetter = InstallGetterSetter; |
263 utils.SetUpLockedPrototype = SetUpLockedPrototype; | 263 utils.SetUpLockedPrototype = SetUpLockedPrototype; |
264 utils.PostNatives = PostNatives; | 264 utils.PostNatives = PostNatives; |
265 utils.PostExperimentals = PostExperimentals; | 265 utils.PostExperimentals = PostExperimentals; |
266 utils.PostDebug = PostDebug; | 266 utils.PostDebug = PostDebug; |
267 | 267 |
268 %ToFastProperties(utils); | 268 %ToFastProperties(utils); |
269 | 269 |
270 // ----------------------------------------------------------------------- | |
271 | |
272 %OptimizeObjectForAddingMultipleProperties(extrasUtils, 7); | |
273 | |
274 extrasUtils.logStackTrace = function logStackTrace() { | |
275 %DebugTrace(); | |
276 }; | |
277 | |
278 extrasUtils.log = function log() { | |
279 let message = ''; | |
280 for (const arg of arguments) { | |
281 message += arg; | |
282 } | |
283 | |
284 %GlobalPrint(message); | |
285 }; | |
286 | |
287 // Extras need the ability to store private state on their objects without | |
288 // exposing it to the outside world. | |
289 | |
290 extrasUtils.createPrivateSymbol = function createPrivateSymbol(name) { | |
291 return %CreatePrivateSymbol(name); | |
292 }; | |
293 | |
294 // These functions are key for safe meta-programming: | |
295 // http://wiki.ecmascript.org/doku.php?id=conventions:safe_meta_programming | |
296 // | |
297 // Technically they could all be derived from combinations of | |
298 // Function.prototype.{bind,call,apply} but that introduces lots of layers of | |
299 // indirection and slowness given how un-optimized bind is. | |
300 | |
301 extrasUtils.call = function call(func, thisArg) { | |
302 return %Apply(func, thisArg, arguments, 2, arguments.length - 2); | |
Yang
2015/09/16 18:41:34
%Apply should not be any faster than Function.prot
| |
303 }; | |
304 | |
305 extrasUtils.apply = function apply(func, thisArg, args) { | |
306 return %Apply(func, thisArg, args, 0, args.length); | |
307 }; | |
308 | |
309 extrasUtils.simpleBind = function simpleBind(func, thisArg) { | |
310 return function() { | |
311 return %Apply(func, thisArg, arguments, 0, arguments.length); | |
312 }; | |
313 }; | |
314 | |
315 extrasUtils.uncurryThis = function uncurryThis(func) { | |
316 return function(thisArg) { | |
317 return %Apply(func, thisArg, arguments, 1, arguments.length - 1); | |
318 }; | |
319 }; | |
320 | |
321 %ToFastProperties(extrasUtils); | |
322 | |
270 }) | 323 }) |
OLD | NEW |