to-fast-properties
Advanced tools
Comparing version 1.0.3 to 2.0.0
34
index.js
'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) { | ||
function Sub() {} | ||
Sub.prototype = o; | ||
var receiver = new Sub(); // create an instance | ||
function ic() { return typeof receiver.foo; } // perform access | ||
ic(); | ||
ic(); | ||
return o; | ||
eval("o" + o); // ensure no dead code elimination | ||
} | ||
return FastObject(o); | ||
}; |
{ | ||
"name": "to-fast-properties", | ||
"version": "1.0.3", | ||
"version": "2.0.0", | ||
"description": "Force V8 to use fast properties for an object", | ||
@@ -13,3 +13,3 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=4" | ||
}, | ||
@@ -16,0 +16,0 @@ "scripts": { |
@@ -37,2 +37,2 @@ # to-fast-properties [![Build Status](https://travis-ci.org/sindresorhus/to-fast-properties.svg?branch=master)](https://travis-ci.org/sindresorhus/to-fast-properties) | ||
MIT © Petka Antonov, Sindre Sorhus | ||
MIT © Petka Antonov, John-David Dalton, Sindre Sorhus |
Sorry, the diff of this file is not supported yet
3496
23