Chromium Code Reviews| Index: src/prologue.js |
| diff --git a/src/prologue.js b/src/prologue.js |
| index 5defb534d671d6e7c4a26577a82c5d0177e28dce..96da85859f4023120df2b68e1ec3d058f49537ad 100644 |
| --- a/src/prologue.js |
| +++ b/src/prologue.js |
| @@ -2,7 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -(function(global, utils) { |
| +(function(global, utils, extrasUtils) { |
| "use strict"; |
| @@ -267,4 +267,57 @@ utils.PostDebug = PostDebug; |
| %ToFastProperties(utils); |
| +// ----------------------------------------------------------------------- |
| + |
| +%OptimizeObjectForAddingMultipleProperties(extrasUtils, 7); |
| + |
| +extrasUtils.logStackTrace = function logStackTrace() { |
| + %DebugTrace(); |
| +}; |
| + |
| +extrasUtils.log = function log() { |
| + let message = ''; |
| + for (const arg of arguments) { |
| + message += arg; |
| + } |
| + |
| + %GlobalPrint(message); |
| +}; |
| + |
| +// Extras need the ability to store private state on their objects without |
| +// exposing it to the outside world. |
| + |
| +extrasUtils.createPrivateSymbol = function createPrivateSymbol(name) { |
| + return %CreatePrivateSymbol(name); |
| +}; |
| + |
| +// These functions are key for safe meta-programming: |
| +// http://wiki.ecmascript.org/doku.php?id=conventions:safe_meta_programming |
| +// |
| +// Technically they could all be derived from combinations of |
| +// Function.prototype.{bind,call,apply} but that introduces lots of layers of |
| +// indirection and slowness given how un-optimized bind is. |
| + |
| +extrasUtils.call = function call(func, thisArg) { |
| + 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
|
| +}; |
| + |
| +extrasUtils.apply = function apply(func, thisArg, args) { |
| + return %Apply(func, thisArg, args, 0, args.length); |
| +}; |
| + |
| +extrasUtils.simpleBind = function simpleBind(func, thisArg) { |
| + return function() { |
| + return %Apply(func, thisArg, arguments, 0, arguments.length); |
| + }; |
| +}; |
| + |
| +extrasUtils.uncurryThis = function uncurryThis(func) { |
| + return function(thisArg) { |
| + return %Apply(func, thisArg, arguments, 1, arguments.length - 1); |
| + }; |
| +}; |
| + |
| +%ToFastProperties(extrasUtils); |
| + |
| }) |