bug 531682 - fixing eval(source, scope) to match 191, 192 semantics. r=mrbkap

This commit is contained in:
Igor Bukanov 2009-12-02 19:22:34 +03:00
parent 4ab577e3c3
commit 969bdae222
2 changed files with 38 additions and 1 deletions

View File

@ -1404,7 +1404,9 @@ obj_eval(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
* with object to maintain invariants in the engine (see bug 520164).
*/
if (scopeobj->getParent()) {
withObject = js_NewWithObject(cx, scopeobj, scopeobj->getParent(), 0);
withObject = js_NewWithObject(cx, scopeobj,
JS_GetGlobalForObject(cx, scopeobj),
0);
if (!withObject) {
ok = JS_FALSE;
goto out;

View File

@ -0,0 +1,35 @@
/* -*- Mode: java; tab-width:8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
*/
var gTestfile = 'regress-531682.js';
//-----------------------------------------------------------------------------
var BUGNUMBER = 531682;
var summary = 'Checking proper wrapping of scope in eval(source, scope)';
var actual;
var expect;
//-----------------------------------------------------------------------------
var x = 0;
test();
//-----------------------------------------------------------------------------
function scope1() {
eval('var x = 1;');
return function() { return x; }
}
function test() {
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
// The scope chain in eval should be just scope1() and the global object.
actual = eval('x', scope1());
expect = 0;
reportCompare(expect, actual, summary);
exitFunc ('test');
}