UNPKG

950 BJavaScriptView Raw
1"use strict";
2
3let fastProto = null;
4
5// Creates an object with permanently fast properties in V8. See Toon Verwaest's
6// post https://medium.com/@tverwaes/setting-up-prototypes-in-v8-ec9c9491dfe2#5f62
7// for more details. Use %HasFastProperties(object) and the Node flag
8// --allow-natives-syntax to check whether an object has fast properties.
9function FastObject() {
10 // A prototype object will have "fast properties" enabled once it is checked
11 // against the inline property cache of a function, e.g. fastProto.property:
12 // https://github.com/v8/v8/blob/6.0.122/test/mjsunit/fast-prototype.js#L48-L63
13 if (fastProto !== null && typeof fastProto.property) {
14 const result = fastProto;
15 fastProto = FastObject.prototype = null;
16 return result;
17 }
18 fastProto = FastObject.prototype = Object.create(null);
19 return new FastObject;
20}
21
22// Initialize the inline property cache of FastObject.
23FastObject();
24
25module.exports = FastObject;