Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_nashorn
提交
9b8cead5
D
dragonwell8_nashorn
项目概览
openanolis
/
dragonwell8_nashorn
通知
2
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_nashorn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9b8cead5
编写于
6月 20, 2016
作者:
H
hannesw
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8150219: ReferenceError in 1.8.0_72
Reviewed-by: attila, sundar
上级
f77107ea
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
44 addition
and
1 deletion
+44
-1
src/jdk/nashorn/api/scripting/NashornScriptEngine.java
src/jdk/nashorn/api/scripting/NashornScriptEngine.java
+3
-0
src/jdk/nashorn/internal/objects/Global.java
src/jdk/nashorn/internal/objects/Global.java
+16
-1
test/src/jdk/nashorn/api/scripting/test/ScopeTest.java
test/src/jdk/nashorn/api/scripting/test/ScopeTest.java
+25
-0
未找到文件。
src/jdk/nashorn/api/scripting/NashornScriptEngine.java
浏览文件 @
9b8cead5
...
...
@@ -319,6 +319,9 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
// Create new global instance mirror and associate with the Bindings.
final
ScriptObjectMirror
mirror
=
createGlobalMirror
();
bindings
.
put
(
NASHORN_GLOBAL
,
mirror
);
// Since we created this global explicitly for the non-default script context we set the
// current script context in global permanently so that invokes work as expected. See JDK-8150219
mirror
.
getHomeGlobal
().
setInitScriptContext
(
ctxt
);
return
mirror
.
getHomeGlobal
();
}
...
...
src/jdk/nashorn/internal/objects/Global.java
浏览文件 @
9b8cead5
...
...
@@ -928,6 +928,8 @@ public final class Global extends Scope {
private
ThreadLocal
<
ScriptContext
>
scontext
;
// current ScriptEngine associated - can be null.
private
ScriptEngine
engine
;
// initial ScriptContext - usually null and only used for special case
private
volatile
ScriptContext
initscontext
;
// ES6 global lexical scope.
private
final
LexicalScope
lexicalScope
;
...
...
@@ -953,9 +955,22 @@ public final class Global extends Scope {
return
scontext
.
get
();
}
/**
* Set the initial script context
* @param ctxt initial script context
*/
public
void
setInitScriptContext
(
final
ScriptContext
ctxt
)
{
this
.
initscontext
=
ctxt
;
}
private
ScriptContext
currentContext
()
{
final
ScriptContext
sc
=
scontext
!=
null
?
scontext
.
get
()
:
null
;
return
(
sc
!=
null
)?
sc
:
(
engine
!=
null
?
engine
.
getContext
()
:
null
);
if
(
sc
!=
null
)
{
return
sc
;
}
else
if
(
initscontext
!=
null
)
{
return
initscontext
;
}
return
engine
!=
null
?
engine
.
getContext
()
:
null
;
}
@Override
...
...
test/src/jdk/nashorn/api/scripting/test/ScopeTest.java
浏览文件 @
9b8cead5
...
...
@@ -30,6 +30,8 @@ import static org.testng.Assert.assertFalse;
import
static
org
.
testng
.
Assert
.
assertTrue
;
import
static
org
.
testng
.
Assert
.
fail
;
import
javax.script.Bindings
;
import
javax.script.Compilable
;
import
javax.script.CompiledScript
;
import
javax.script.Invocable
;
import
javax.script.ScriptContext
;
import
javax.script.ScriptEngine
;
...
...
@@ -911,4 +913,27 @@ public class ScopeTest {
Object
value
=
((
Invocable
)
engine
).
invokeFunction
(
"newfunc"
);
assertTrue
(((
Number
)
value
).
intValue
()
==
42
);
}
// @bug 8150219 ReferenceError in 1.8.0_72
// When we create a Global for a non-default ScriptContext that needs one keep the
// ScriptContext associated with the Global so that invoke methods work as expected.
@Test
public
void
invokeFunctionWithCustomScriptContextTest
()
throws
Exception
{
final
ScriptEngine
engine
=
new
ScriptEngineManager
().
getEngineByName
(
"nashorn"
);
// create an engine and a ScriptContext, but don't set it as default
ScriptContext
scriptContext
=
new
SimpleScriptContext
();
// Set some value in the context
scriptContext
.
setAttribute
(
"myString"
,
"foo"
,
ScriptContext
.
ENGINE_SCOPE
);
// Evaluate script with custom context and get back a function
final
String
script
=
"function (c) { return myString.indexOf(c); }"
;
CompiledScript
compiledScript
=
((
Compilable
)
engine
).
compile
(
script
);
Object
func
=
compiledScript
.
eval
(
scriptContext
);
// Invoked function should be able to see context it was evaluated with
Object
result
=
((
Invocable
)
engine
).
invokeMethod
(
func
,
"call"
,
func
,
"o"
,
null
);
assertTrue
(((
Number
)
result
).
intValue
()
==
1
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录