Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_nashorn
提交
6e3abded
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,发现更多精彩内容 >>
提交
6e3abded
编写于
6月 04, 2013
作者:
S
sundar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8015830: Javascript mapping of ScriptEngine bindings does not expose keys
Reviewed-by: jlaskey, lagergren
上级
5e99fd36
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
103 addition
and
4 deletion
+103
-4
src/jdk/nashorn/api/scripting/ScriptObjectMirror.java
src/jdk/nashorn/api/scripting/ScriptObjectMirror.java
+19
-4
src/jdk/nashorn/internal/runtime/ScriptObject.java
src/jdk/nashorn/internal/runtime/ScriptObject.java
+11
-0
src/jdk/nashorn/internal/runtime/ScriptRuntime.java
src/jdk/nashorn/internal/runtime/ScriptRuntime.java
+13
-0
test/script/basic/JDK-8015830.js
test/script/basic/JDK-8015830.js
+56
-0
test/script/basic/JDK-8015830.js.EXPECTED
test/script/basic/JDK-8015830.js.EXPECTED
+4
-0
未找到文件。
src/jdk/nashorn/api/scripting/ScriptObjectMirror.java
浏览文件 @
6e3abded
...
...
@@ -31,7 +31,7 @@ import java.util.AbstractMap;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.
Linked
HashSet
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -48,7 +48,7 @@ import jdk.nashorn.internal.runtime.ScriptRuntime;
* access ScriptObject via the javax.script.Bindings interface or
* netscape.javascript.JSObject interface.
*/
final
class
ScriptObjectMirror
extends
JSObject
implements
Bindings
{
public
final
class
ScriptObjectMirror
extends
JSObject
implements
Bindings
{
private
final
ScriptObject
sobj
;
private
final
ScriptObject
global
;
...
...
@@ -217,7 +217,7 @@ final class ScriptObjectMirror extends JSObject implements Bindings {
return
inGlobal
(
new
Callable
<
Set
<
Map
.
Entry
<
String
,
Object
>>>()
{
@Override
public
Set
<
Map
.
Entry
<
String
,
Object
>>
call
()
{
final
Iterator
<
String
>
iter
=
sobj
.
propertyIterator
();
final
Set
<
Map
.
Entry
<
String
,
Object
>>
entries
=
new
HashSet
<>();
final
Set
<
Map
.
Entry
<
String
,
Object
>>
entries
=
new
Linked
HashSet
<>();
while
(
iter
.
hasNext
())
{
final
String
key
=
iter
.
next
();
...
...
@@ -253,7 +253,7 @@ final class ScriptObjectMirror extends JSObject implements Bindings {
return
inGlobal
(
new
Callable
<
Set
<
String
>>()
{
@Override
public
Set
<
String
>
call
()
{
final
Iterator
<
String
>
iter
=
sobj
.
propertyIterator
();
final
Set
<
String
>
keySet
=
new
HashSet
<>();
final
Set
<
String
>
keySet
=
new
Linked
HashSet
<>();
while
(
iter
.
hasNext
())
{
keySet
.
add
(
iter
.
next
());
...
...
@@ -302,6 +302,21 @@ final class ScriptObjectMirror extends JSObject implements Bindings {
});
}
/**
* Delete a property from this object.
*
* @param key the property to be deleted
*
* @return if the delete was successful or not
*/
public
boolean
delete
(
final
Object
key
)
{
return
inGlobal
(
new
Callable
<
Boolean
>()
{
@Override
public
Boolean
call
()
{
return
sobj
.
delete
(
unwrap
(
key
,
global
));
}
});
}
@Override
public
int
size
()
{
return
inGlobal
(
new
Callable
<
Integer
>()
{
...
...
src/jdk/nashorn/internal/runtime/ScriptObject.java
浏览文件 @
6e3abded
...
...
@@ -1511,6 +1511,17 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
return
oldValue
;
}
/**
* Delete a property from the ScriptObject.
* (to help ScriptObjectMirror implementation)
*
* @param key the key of the property
* @return if the delete was successful or not
*/
public
boolean
delete
(
final
Object
key
)
{
return
delete
(
key
,
getContext
().
_strict
);
}
/**
* Return the size of the ScriptObject - i.e. the number of properties
* it contains
...
...
src/jdk/nashorn/internal/runtime/ScriptRuntime.java
浏览文件 @
6e3abded
...
...
@@ -40,6 +40,7 @@ import java.util.Locale;
import
java.util.NoSuchElementException
;
import
java.util.Objects
;
import
jdk.internal.dynalink.beans.StaticClass
;
import
jdk.nashorn.api.scripting.ScriptObjectMirror
;
import
jdk.nashorn.internal.codegen.CompilerConstants.Call
;
import
jdk.nashorn.internal.ir.debug.JSONWriter
;
import
jdk.nashorn.internal.parser.Lexer
;
...
...
@@ -240,6 +241,10 @@ public final class ScriptRuntime {
};
}
if
(
obj
instanceof
ScriptObjectMirror
)
{
return
((
ScriptObjectMirror
)
obj
).
keySet
().
iterator
();
}
return
Collections
.
emptyIterator
();
}
...
...
@@ -280,6 +285,10 @@ public final class ScriptRuntime {
};
}
if
(
obj
instanceof
ScriptObjectMirror
)
{
return
((
ScriptObjectMirror
)
obj
).
values
().
iterator
();
}
if
(
obj
instanceof
Iterable
)
{
return
((
Iterable
<?>)
obj
).
iterator
();
}
...
...
@@ -591,6 +600,10 @@ public final class ScriptRuntime {
throw
typeError
(
"cant.delete.property"
,
safeToString
(
property
),
"null"
);
}
if
(
obj
instanceof
ScriptObjectMirror
)
{
return
((
ScriptObjectMirror
)
obj
).
delete
(
property
);
}
if
(
JSType
.
isPrimitive
(
obj
))
{
return
((
ScriptObject
)
JSType
.
toScriptObject
(
obj
)).
delete
(
property
,
Boolean
.
TRUE
.
equals
(
strict
));
}
...
...
test/script/basic/JDK-8015830.js
0 → 100644
浏览文件 @
6e3abded
/*
* Copyright (c) 2010, 2013, 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-8015830: Javascript mapping of ScriptEngine bindings does not expose keys
*
* @test
* @run
*/
var
m
=
new
javax
.
script
.
ScriptEngineManager
();
var
engine
=
m
.
getEngineByName
(
"
nashorn
"
);
engine
.
eval
(
"
x = 100; doit = function () { }
"
);
var
global
=
engine
.
getBindings
(
javax
.
script
.
ScriptContext
.
ENGINE_SCOPE
);
for
(
k
in
global
){
print
(
k
+
"
=
"
+
global
[
k
]);
}
for
each
(
k
in
global
)
{
print
(
k
);
}
for
(
k
in
global
)
{
delete
global
[
k
];
}
for
(
k
in
global
){
print
(
k
+
"
=
"
+
global
[
k
]);
}
for
each
(
k
in
global
)
{
print
(
k
);
}
test/script/basic/JDK-8015830.js.EXPECTED
0 → 100644
浏览文件 @
6e3abded
x = 100
doit = function () { }
100
function () { }
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录