augment evaluate to extract within objects (#1425)
- gated by `unsafe` - replaces previous optimisation specific to String.length - "123"[0] => 1 - [1, 2, 3][0] => 1 - [1, 2, 3].length => 3 - does not apply to objects with overridden prototype functions
This commit is contained in:
committed by
Richard van Velzen
parent
48284844a4
commit
0d7d4918eb
17
lib/scope.js
17
lib/scope.js
@@ -184,6 +184,17 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
||||
var func = null;
|
||||
var globals = self.globals = new Dictionary();
|
||||
var tw = new TreeWalker(function(node, descend){
|
||||
function isModified(node, level) {
|
||||
var parent = tw.parent(level);
|
||||
if (parent instanceof AST_Unary && (parent.operator === "++" || parent.operator === "--")
|
||||
|| parent instanceof AST_Assign && parent.left === node
|
||||
|| parent instanceof AST_Call && parent.expression === node) {
|
||||
return true;
|
||||
} else if (parent instanceof AST_PropAccess && parent.expression === node) {
|
||||
return isModified(parent, level + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (node instanceof AST_Lambda) {
|
||||
var prev_func = func;
|
||||
func = node;
|
||||
@@ -197,8 +208,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
||||
}
|
||||
if (node instanceof AST_SymbolRef) {
|
||||
var name = node.name;
|
||||
var parent = tw.parent();
|
||||
if (name == "eval" && parent instanceof AST_Call) {
|
||||
if (name == "eval" && tw.parent() instanceof AST_Call) {
|
||||
for (var s = node.scope; s && !s.uses_eval; s = s.parent_scope) {
|
||||
s.uses_eval = true;
|
||||
}
|
||||
@@ -220,8 +230,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
||||
sym = g;
|
||||
}
|
||||
node.thedef = sym;
|
||||
if (parent instanceof AST_Unary && (parent.operator === "++" || parent.operator === "--")
|
||||
|| parent instanceof AST_Assign && parent.left === node) {
|
||||
if (isModified(node, 0)) {
|
||||
sym.modified = true;
|
||||
}
|
||||
node.reference();
|
||||
|
||||
Reference in New Issue
Block a user