summaryrefslogtreecommitdiff
path: root/tools/node_modules/babel-eslint/node_modules/to-fast-properties/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/node_modules/babel-eslint/node_modules/to-fast-properties/index.js')
-rw-r--r--tools/node_modules/babel-eslint/node_modules/to-fast-properties/index.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/tools/node_modules/babel-eslint/node_modules/to-fast-properties/index.js b/tools/node_modules/babel-eslint/node_modules/to-fast-properties/index.js
new file mode 100644
index 0000000000..028c88af01
--- /dev/null
+++ b/tools/node_modules/babel-eslint/node_modules/to-fast-properties/index.js
@@ -0,0 +1,27 @@
+'use strict';
+
+let fastProto = null;
+
+// Creates an object with permanently fast properties in V8. See Toon Verwaest's
+// post https://medium.com/@tverwaes/setting-up-prototypes-in-v8-ec9c9491dfe2#5f62
+// for more details. Use %HasFastProperties(object) and the Node.js flag
+// --allow-natives-syntax to check whether an object has fast properties.
+function FastObject(o) {
+ // A prototype object will have "fast properties" enabled once it is checked
+ // against the inline property cache of a function, e.g. fastProto.property:
+ // https://github.com/v8/v8/blob/6.0.122/test/mjsunit/fast-prototype.js#L48-L63
+ if (fastProto !== null && typeof fastProto.property) {
+ const result = fastProto;
+ fastProto = FastObject.prototype = null;
+ return result;
+ }
+ fastProto = FastObject.prototype = o == null ? Object.create(null) : o;
+ return new FastObject;
+}
+
+// Initialize the inline property cache of FastObject
+FastObject();
+
+module.exports = function toFastproperties(o) {
+ return FastObject(o);
+};