diff --git a/js/src/builtin/Eval.cpp b/js/src/builtin/Eval.cpp index 95179b20ce47..03b8c7045048 100644 --- a/js/src/builtin/Eval.cpp +++ b/js/src/builtin/Eval.cpp @@ -428,7 +428,19 @@ js::DirectEvalStringFromIon(JSContext *cx, // the calling frame cannot be updated to store the new object. MOZ_ASSERT(thisValue.isObject() || thisValue.isUndefined() || thisValue.isNull()); - return ExecuteKernel(cx, esg.script(), *scopeobj, thisValue, ExecuteType(DIRECT_EVAL), + // When eval'ing strict code in a non-strict context, compute the 'this' + // value to use from what the caller passed in. This isn't necessary if + // the callee is not strict, as it will compute the non-strict 'this' + // value as necessary while it executes. + RootedValue nthisValue(cx, thisValue); + if (!callerScript->strict() && esg.script()->strict() && !thisValue.isObject()) { + JSObject *obj = BoxNonStrictThis(cx, thisValue); + if (!obj) + return false; + nthisValue = ObjectValue(*obj); + } + + return ExecuteKernel(cx, esg.script(), *scopeobj, nthisValue, ExecuteType(DIRECT_EVAL), NullFramePtr() /* evalInFrame */, vp.address()); } diff --git a/js/src/jit-test/tests/ion/bug1123011.js b/js/src/jit-test/tests/ion/bug1123011.js new file mode 100644 index 000000000000..a1ced3f5ec44 --- /dev/null +++ b/js/src/jit-test/tests/ion/bug1123011.js @@ -0,0 +1,8 @@ + +var global = this; +function f() { + return eval("'use strict'; this;"); +} +for (var j = 0; j < 5; ++j) { + assertEq(f(), global); +} diff --git a/js/src/jit/IonBuilder.cpp b/js/src/jit/IonBuilder.cpp index e6e6adbd3eb8..79df7cc016cd 100644 --- a/js/src/jit/IonBuilder.cpp +++ b/js/src/jit/IonBuilder.cpp @@ -5943,6 +5943,9 @@ IonBuilder::jsop_eval(uint32_t argc) if (!info().funMaybeLazy()) return abort("Direct eval in global code"); + if (info().funMaybeLazy()->isArrow()) + return abort("Direct eval from arrow function"); + // The 'this' value for the outer and eval scripts must be the // same. This is not guaranteed if a primitive string/number/etc. // is passed through to the eval invoke as the primitive may be