Ensure we are nearly always in fast mode on V8
See: https://stackoverflow.com/a/24989927/1518408
This commit is contained in:
parent
7a19d46e8a
commit
27ec5ed9b1
|
@ -18,8 +18,9 @@ class ASTVisitor {
|
|||
// Simple AST node visitor builder for PEG.js
|
||||
static build( functions ) {
|
||||
|
||||
const visitor = new ASTVisitor();
|
||||
let visitor = new ASTVisitor();
|
||||
util.extend( visitor, functions );
|
||||
visitor = util.enforceFastProperties( visitor );
|
||||
return visitor.visit.bind( visitor );
|
||||
|
||||
}
|
||||
|
|
|
@ -109,6 +109,27 @@ const objects = {
|
|||
|
||||
},
|
||||
|
||||
// Will ensure on V8 that that property access is always in fast mode
|
||||
// See: https://stackoverflow.com/a/24989927/1518408
|
||||
enforceFastProperties( o ) {
|
||||
|
||||
/* eslint no-unreachable: 0 */
|
||||
|
||||
function Sub() { }
|
||||
Sub.prototype = o;
|
||||
const receiver = new Sub();
|
||||
function ic() {
|
||||
|
||||
return typeof receiver.foo;
|
||||
|
||||
}
|
||||
ic();
|
||||
ic();
|
||||
return o;
|
||||
eval( "o" + o );
|
||||
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
module.exports = objects;
|
||||
|
|
|
@ -93,7 +93,7 @@
|
|||
function createNode( type, details ) {
|
||||
const node = new ast.Node( type, location() );
|
||||
util.extend( node, details );
|
||||
return node;
|
||||
return util.enforceFastProperties( node );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue