提交 0cd449f4 编写于 作者: S sundar

8033763: Add tests to assert map identity of certain objects

Reviewed-by: hannesw, lagergren
上级 a6b98e01
......@@ -279,6 +279,11 @@ grant codeBase "file:/${basedir}/test/script/trusted/*" {
permission java.security.AllPermission;
};
grant codeBase "file:/${basedir}/test/script/maptests/*" {
permission java.io.FilePermission "${basedir}/test/script/maptests/*","read";
permission java.lang.RuntimePermission "nashorn.debugMode";
};
grant codeBase "file:/${basedir}/test/script/basic/*" {
permission java.io.FilePermission "${basedir}/test/script/-", "read";
permission java.io.FilePermission "$${user.dir}", "read";
......
......@@ -112,6 +112,7 @@ run.classpath=\
test.dir=test
test.script.dir=test/script
test.basic.dir=test/script/basic
test.maptests.dir=test/script/maptests
test.error.dir=test/script/error
test.sandbox.dir=test/script/sandbox
test.trusted.dir=test/script/trusted
......@@ -121,7 +122,7 @@ test262.suite.dir=${test262.dir}/test/suite
testjfx.dir=${test.script.dir}/jfx
test-sys-prop.test.dir=${test.dir}
test-sys-prop.test.js.roots=${test.basic.dir} ${test.error.dir} ${test.sandbox.dir} ${test.trusted.dir}
test-sys-prop.test.js.roots=${test.basic.dir} ${test.maptests.dir} ${test.error.dir} ${test.sandbox.dir} ${test.trusted.dir}
test-sys-prop.test262.suite.dir=${test262.suite.dir}
test-sys-prop.es5conform.testcases.dir=${test.external.dir}/ES5Conform/TestCases
test-sys-prop.test.basic.dir=${test.basic.dir}
......@@ -264,7 +265,7 @@ run.test.jvmargs.octane.main=${run.test.jvmargs.common}
run.test.jvmsecurityargs=-Xverify:all -Djava.security.manager -Djava.security.policy=${basedir}/build/nashorn.policy
# VM options for script tests with @fork option
test-sys-prop.test.fork.jvm.options=${run.test.jvmargs.main} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs}
test-sys-prop.test.fork.jvm.options=${run.test.jvmargs.main} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -cp ${run.test.classpath}
# path of rhino.jar for benchmarks
rhino.jar=
......
/*
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @option -Dnashorn.debug=true
* @fork
*/
load(__DIR__ + "maputil.js");
function Foo() {
return {
get foo() { return 42; },
set foo(x) {}
}
}
var obj1 = Foo();
var obj2 = Foo();
assertSameMap(obj1, obj2, "Object literals before change");
Object.defineProperty(obj2, "foo", { get: function() { return 'hello' } });
assertSameMap(obj1, obj2);
Object.defineProperty(obj2, "foo", { set: function(x) { print(x) } });
assertSameMap(obj1, obj2);
/*
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @option -Dnashorn.debug=true
* @fork
*/
load(__DIR__ + "maputil.js");
// check that builtin objects share property map
assertSameMap(new Boolean(true), new Boolean(false));
assertSameMap(new Number(3), new Number(Math.PI));
assertSameMap(new String('hello'), new String('world'));
assertSameMap(new Object(), new Object());
assertSameMap(/hello/, /world/);
// try w/without regexp flags
assertSameMap(/hello/i, /world/g);
assertSameMap(new Date(), new Date());
assertSameMap(new Date(2000, 1, 1), new Date(1972, 5, 6));
assertSameMap(Function(), Function());
assertSameMap(Function("x", "return x"), Function("x", "return x*x"));
assertSameMap(new Error(), new Error());
assertSameMap(new Error('foo'), new Error('bar'));
assertSameMap(new EvalError(), new EvalError());
assertSameMap(new EvalError('foo'), new EvalError('bar'));
assertSameMap(new RangeError(), new RangeError());
assertSameMap(new RangeError('foo'), new RangeError('bar'));
assertSameMap(new ReferenceError(), new ReferenceError());
assertSameMap(new ReferenceError('foo'), new ReferenceError('bar'));
assertSameMap(new SyntaxError(), new SyntaxError());
assertSameMap(new SyntaxError('foo'), new SyntaxError('bar'));
assertSameMap(new TypeError(), new TypeError());
assertSameMap(new TypeError('foo'), new TypeError('bar'));
assertSameMap(new URIError(), new URIError());
assertSameMap(new URIError('foo'), new URIError('bar'));
/*
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @option -Dnashorn.debug=true
* @fork
*/
load(__DIR__ + "point.js");
// use constructor defined in a different script file
// These objects should share the map
assertSameMap(new Point(2, 3), new Point(43, 23));
assertSameMap(new Point(), new Point());
assertSameMap(new Point(), new Point(3, 1));
/*
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @subtest
*/
function assertSameMap(obj1, obj2, msg) {
if (! Debug.identical(Debug.map(obj1), Debug.map(obj2))) {
fail(obj1.constructor + " instances don't share map");
}
}
function assertNotSameMap(obj1, obj2, msg) {
if (Debug.identical(Debug.map(obj1), Debug.map(obj2))) {
fail(obj1.constructor + " and " + obj2.constructor + " instances share map");
}
}
/*
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @option -Dnashorn.debug=true
* @fork
*/
load(__DIR__ + "maputil.js");
// Objects created by Object.create
var obj1 = Object.create(Object.prototype);
var obj2 = Object.create(Object.prototype);
assertSameMap(obj1, obj2);
var proto = { foo: 233 };
obj1 = Object.create(proto);
obj2 = Object.create(proto);
assertSameMap(obj1, obj2);
/*
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @option -Dnashorn.debug=true
* @fork
*/
load(__DIR__ + "maputil.js");
// Object literals created at the same callsite
function makeObject() {
return { foo: 34 }
}
assertSameMap(makeObject(), makeObject());
function makeObject2() {
return { foo: 42, bar: 'hello' }
}
assertSameMap(makeObject2(), makeObject2());
// Object literals created at different callsites
assertSameMap({}, {});
assertSameMap({foo: 4}, {foo: 'hello'});
assertSameMap({foo: 34, bar: 'fdgd'}, {foo: 'world', bar: 54});
/*
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @subtest
*/
function Point(x, y) {
this.x =x; this.y =y;
}
Point.prototype.toString = function() {
return "(" + this.x + "," + this.y + ")";
}
Point.prototype.modulus = function() {
return Math.sqrt(this.x*this.x + this.y*this.y);
}
Point.prototype.argument = function() {
return Math.atan2(this.y, this.x);
}
load(__DIR__ + "maputil.js");
assertSameMap(new Point(2, 3), new Point(43, 23));
assertSameMap(new Point(), new Point());
assertSameMap(new Point(), new Point(3, 1));
/*
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @option -Dnashorn.debug=true
* @fork
*/
load(__DIR__ + "maputil.js");
function Foo() {}
var obj1 = new Foo();
var obj2 = new Foo();
assertSameMap(obj1, obj2);
// property addition at same callsite
function addX(obj, val) {
obj.x = val;
}
addX(obj1, 3);
addX(obj2, 'hello');
assertSameMap(obj1, obj2);
/*
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @option -Dnashorn.debug=true
* @fork
*/
load(__DIR__ + "maputil.js");
function Foo() {
this.x = 33;
}
var obj1 = new Foo();
var obj2 = new Foo();
assertSameMap(obj1, obj2);
// property deletion at same callsite
function deleteX(obj) {
delete obj.x;
}
deleteX(obj1);
deleteX(obj2);
assertSameMap(obj1, obj2);
/*
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @option -Dnashorn.debug=true
* @fork
*/
load(__DIR__ + "maputil.js");
// add/delete property to proto (direct/indirect) should
// not affect the property map of the objects
var proto2 = { foo: 334 }
var proto = Object.create(proto2);
proto.bar = "hello";
var obj1 = Object.create(proto);
var obj2 = Object.create(proto);
assertSameMap(obj1, obj2);
proto.newX = 'world';
assertSameMap(obj1, obj2);
delete proto.newX;
assertSameMap(obj1, obj2);
proto2.newX = "foo";
assertSameMap(obj1, obj2);
delete proto2.newX;
assertSameMap(obj1, obj2);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册