Skip to content

Commit

Permalink
Bound functions must not leak global object into strict functions
Browse files Browse the repository at this point in the history
  • Loading branch information
szegedi committed May 20, 2018
1 parent cd19d61 commit 1cc1698
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/org/mozilla/javascript/BoundFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public BoundFunction(Context cx, Scriptable scope, Callable targetFunction, Scri
@Override
public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] extraArgs)
{
Scriptable callThis = boundThis != null ? boundThis : ScriptRuntime.getTopCallScope(cx);
return targetFunction.call(cx, scope, callThis, concat(boundArgs, extraArgs));
return targetFunction.call(cx, scope, boundThis, concat(boundArgs, extraArgs));
}

@Override
Expand Down
14 changes: 14 additions & 0 deletions testsrc/org/mozilla/javascript/tests/StrictBindThisTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.mozilla.javascript.tests;

import junit.framework.TestCase;

public class StrictBindThisTest extends TestCase {
public void testStrictBindThis() {
Utils.runWithAllOptimizationLevels(cx -> {
assertTrue((Boolean)cx.evaluateString(cx.initSafeStandardObjects(),
"((function() { 'use strict'; return this == null }).bind(null))()",
"testBindScope.js", 1, null));
return null;
});
}
}

0 comments on commit 1cc1698

Please sign in to comment.