8050432: javax.script.filename variable should not be enumerable with nashorn engine's ENGINE_SCOPE bindings
Reviewed-by: jlaskey
This commit is contained in:
parent
47692bbf7e
commit
8a77a443db
nashorn
src/jdk/nashorn/internal/objects
test
@ -1763,6 +1763,8 @@ public final class Global extends ScriptObject implements Scope {
|
||||
final int NOT_ENUMERABLE_NOT_CONFIG = Attribute.NOT_ENUMERABLE | Attribute.NOT_CONFIGURABLE;
|
||||
scontextProperty = addOwnProperty("context", NOT_ENUMERABLE_NOT_CONFIG, null);
|
||||
addOwnProperty("engine", NOT_ENUMERABLE_NOT_CONFIG, engine);
|
||||
// default file name
|
||||
addOwnProperty(ScriptEngine.FILENAME, Attribute.NOT_ENUMERABLE, null);
|
||||
// __noSuchProperty__ hook for ScriptContext search of missing variables
|
||||
final ScriptFunction noSuchProp = ScriptFunctionImpl.makeStrictFunction(NO_SUCH_PROPERTY_NAME, NO_SUCH_PROPERTY);
|
||||
addOwnProperty(NO_SUCH_PROPERTY_NAME, Attribute.NOT_ENUMERABLE, noSuchProp);
|
||||
|
@ -36,24 +36,6 @@ e.eval(<<EOF
|
||||
|
||||
'use strict';
|
||||
|
||||
try {
|
||||
context = 444;
|
||||
print("FAILED!! context write should have thrown error");
|
||||
} catch (e) {
|
||||
if (! (e instanceof TypeError)) {
|
||||
print("TypeError expected but got " + e);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
engine = "hello";
|
||||
print("FAILED!! engine write should have thrown error");
|
||||
} catch (e) {
|
||||
if (! (e instanceof TypeError)) {
|
||||
print("TypeError expected but got " + e);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
delete context;
|
||||
print("FAILED!! context delete should have thrown error");
|
||||
|
40
nashorn/test/script/basic/JDK-8050432.js
Normal file
40
nashorn/test/script/basic/JDK-8050432.js
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* JDK-8050432: javax.script.filename variable should not be enumerable with nashorn engine's ENGINE_SCOPE bindings
|
||||
*
|
||||
* @test
|
||||
* @run
|
||||
*/
|
||||
|
||||
var ScriptEngine = javax.script.ScriptEngine;
|
||||
var m = new javax.script.ScriptEngineManager();
|
||||
var engine = m.getEngineByName("nashorn");
|
||||
|
||||
engine.put(ScriptEngine.FILENAME, "foo");
|
||||
var desc = engine.eval("Object.getOwnPropertyDescriptor(this, '"
|
||||
+ ScriptEngine.FILENAME + "')");
|
||||
if (desc.enumerable) {
|
||||
fail(ScriptEngine.FILENAME + " is enumerable");
|
||||
}
|
@ -607,6 +607,20 @@ public class ScriptEngineTest {
|
||||
assertEquals(res, "hello");
|
||||
}
|
||||
|
||||
// @bug 8050432:javax.script.filename variable should not be enumerable
|
||||
// with nashorn engine's ENGINE_SCOPE bindings
|
||||
@Test
|
||||
public void enumerableGlobalsTest() throws ScriptException {
|
||||
final ScriptEngineManager m = new ScriptEngineManager();
|
||||
final ScriptEngine e = m.getEngineByName("nashorn");
|
||||
|
||||
e.put(ScriptEngine.FILENAME, "test");
|
||||
Object enumerable = e.eval(
|
||||
"Object.getOwnPropertyDescriptor(this, " +
|
||||
" 'javax.script.filename').enumerable");
|
||||
assertEquals(enumerable, Boolean.FALSE);
|
||||
}
|
||||
|
||||
private static void checkProperty(final ScriptEngine e, final String name)
|
||||
throws ScriptException {
|
||||
final String value = System.getProperty(name);
|
||||
|
Loading…
x
Reference in New Issue
Block a user