test/jdk/javax/script/Test3.js
author ssadetsky
Wed, 03 Apr 2019 15:43:25 -0700
branchJDK-8200758-branch
changeset 57303 eff0cf668c29
parent 47216 71c04702a3d5
permissions -rw-r--r--
8221876:[macOS] JPackage install takes long time Reviewed-by: almatvee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16038
de84354579d3 8009115: jtreg tests under jdk/test/javax/script should use nashorn as script engine
sundar
parents: 2
diff changeset
     1
var ScriptContext = javax.script.ScriptContext;
de84354579d3 8009115: jtreg tests under jdk/test/javax/script should use nashorn as script engine
sundar
parents: 2
diff changeset
     2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
if (key == undefined || key != 'engine value') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
    throw "unexpected engine scope value";
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
// pre-defined context variable refers to current ScriptContext
16038
de84354579d3 8009115: jtreg tests under jdk/test/javax/script should use nashorn as script engine
sundar
parents: 2
diff changeset
     8
if (context.getAttribute('key', ScriptContext.GLOBAL_SCOPE) != 'global value') {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
    throw "unexpected global scope value";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
// change the engine scope value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
key = 'new engine value';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
16038
de84354579d3 8009115: jtreg tests under jdk/test/javax/script should use nashorn as script engine
sundar
parents: 2
diff changeset
    15
if (context.getAttribute('key', ScriptContext.GLOBAL_SCOPE) != 'global value') {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
    throw "global scope should not change here";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
// delete engine scope value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
delete key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
16038
de84354579d3 8009115: jtreg tests under jdk/test/javax/script should use nashorn as script engine
sundar
parents: 2
diff changeset
    22
if (key == undefined && key != 'global value') {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
    throw 'global scope should be visible after engine scope removal';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
}