Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_nashorn
提交
aed588de
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,发现更多精彩内容 >>
提交
aed588de
编写于
7月 15, 2013
作者:
H
hannesw
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8020354: Object literal property initialization is not done in source order
Reviewed-by: sundar, jlaskey
上级
6d47b7d7
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
76 addition
and
41 deletion
+76
-41
src/jdk/nashorn/internal/parser/Parser.java
src/jdk/nashorn/internal/parser/Parser.java
+24
-41
test/script/basic/JDK-8020354.js
test/script/basic/JDK-8020354.js
+43
-0
test/script/basic/JDK-8020354.js.EXPECTED
test/script/basic/JDK-8020354.js.EXPECTED
+9
-0
未找到文件。
src/jdk/nashorn/internal/parser/Parser.java
浏览文件 @
aed588de
...
...
@@ -55,9 +55,9 @@ import static jdk.nashorn.internal.parser.TokenType.WHILE;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
jdk.nashorn.internal.codegen.CompilerConstants
;
...
...
@@ -1946,14 +1946,14 @@ loop:
// Object context.
// Prepare to accumulate elements.
// final List<
Node> elements = new ArrayList<>();
final
Map
<
String
,
PropertyNode
>
map
=
new
Linked
HashMap
<>();
final
List
<
Property
Node
>
elements
=
new
ArrayList
<>();
final
Map
<
String
,
Integer
>
map
=
new
HashMap
<>();
// Create a block for the object literal.
boolean
commaSeen
=
true
;
boolean
commaSeen
=
true
;
loop:
while
(
true
)
{
switch
(
type
)
{
while
(
true
)
{
switch
(
type
)
{
case
RBRACE:
next
();
break
loop
;
...
...
@@ -1975,14 +1975,16 @@ loop:
// Get and add the next property.
final
PropertyNode
property
=
propertyAssignment
();
final
String
key
=
property
.
getKeyName
();
final
PropertyNode
existingProperty
=
map
.
get
(
key
);
final
Integer
existing
=
map
.
get
(
key
);
if
(
existing
Property
==
null
)
{
map
.
put
(
key
,
property
);
//
elements.add(property);
if
(
existing
==
null
)
{
map
.
put
(
key
,
elements
.
size
()
);
elements
.
add
(
property
);
break
;
}
final
PropertyNode
existingProperty
=
elements
.
get
(
existing
);
// ECMA section 11.1.5 Object Initialiser
// point # 4 on property assignment production
final
Expression
value
=
property
.
getValue
();
...
...
@@ -1993,12 +1995,9 @@ loop:
final
FunctionNode
prevGetter
=
existingProperty
.
getGetter
();
final
FunctionNode
prevSetter
=
existingProperty
.
getSetter
();
boolean
redefinitionOk
=
true
;
// ECMA 11.1.5 strict mode restrictions
if
(
isStrictMode
)
{
if
(
value
!=
null
&&
prevValue
!=
null
)
{
redefinitionOk
=
false
;
}
if
(
isStrictMode
&&
value
!=
null
&&
prevValue
!=
null
)
{
throw
error
(
AbstractParser
.
message
(
"property.redefinition"
,
key
),
property
.
getToken
());
}
final
boolean
isPrevAccessor
=
prevGetter
!=
null
||
prevSetter
!=
null
;
...
...
@@ -2006,49 +2005,33 @@ loop:
// data property redefined as accessor property
if
(
prevValue
!=
null
&&
isAccessor
)
{
redefinitionOk
=
false
;
throw
error
(
AbstractParser
.
message
(
"property.redefinition"
,
key
),
property
.
getToken
())
;
}
// accessor property redefined as data
if
(
isPrevAccessor
&&
value
!=
null
)
{
redefinitionOk
=
false
;
throw
error
(
AbstractParser
.
message
(
"property.redefinition"
,
key
),
property
.
getToken
())
;
}
if
(
isAccessor
&&
isPrevAccessor
)
{
if
(
getter
!=
null
&&
prevGetter
!=
null
||
setter
!=
null
&&
prevSetter
!=
null
)
{
redefinitionOk
=
false
;
setter
!=
null
&&
prevSetter
!=
null
)
{
throw
error
(
AbstractParser
.
message
(
"property.redefinition"
,
key
),
property
.
getToken
())
;
}
}
if
(!
redefinitionOk
)
{
throw
error
(
AbstractParser
.
message
(
"property.redefinition"
,
key
),
property
.
getToken
());
}
PropertyNode
newProperty
=
existingProperty
;
if
(
value
!=
null
)
{
if
(
prevValue
==
null
)
{
map
.
put
(
key
,
newProperty
=
newProperty
.
setValue
(
value
));
}
else
{
final
long
propertyToken
=
Token
.
recast
(
newProperty
.
getToken
(),
COMMARIGHT
);
map
.
put
(
key
,
newProperty
=
newProperty
.
setValue
(
new
BinaryNode
(
propertyToken
,
prevValue
,
value
)));
}
map
.
put
(
key
,
newProperty
=
newProperty
.
setGetter
(
null
).
setSetter
(
null
));
}
if
(
getter
!=
null
)
{
map
.
put
(
key
,
newProperty
=
newProperty
.
setGetter
(
getter
));
}
if
(
setter
!=
null
)
{
map
.
put
(
key
,
newProperty
=
newProperty
.
setSetter
(
setter
));
elements
.
add
(
property
);
}
else
if
(
getter
!=
null
)
{
elements
.
set
(
existing
,
existingProperty
.
setGetter
(
getter
));
}
else
if
(
setter
!=
null
)
{
elements
.
set
(
existing
,
existingProperty
.
setSetter
(
setter
));
}
break
;
}
}
return
new
ObjectNode
(
objectToken
,
finish
,
new
ArrayList
<>(
map
.
values
())
);
return
new
ObjectNode
(
objectToken
,
finish
,
elements
);
}
/**
...
...
test/script/basic/JDK-8020354.js
0 → 100644
浏览文件 @
aed588de
/*
* 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-8020354: Object literal property initialization is not done in source order
*
* @test
* @run
*/
var
obj
=
({
a
:
print
(
1
),
b
:
print
(
2
),
a
:
print
(
3
)});
var
obj
=
({
a
:
print
(
1
),
get
x
()
{
print
(
"
getting x
"
);
return
"
x
"
},
set
x
(
v
)
{
print
(
"
setting x
"
);
},
b
:
print
(
2
),
a
:
print
(
3
)
});
print
(
obj
.
x
);
obj
.
x
=
4
;
test/script/basic/JDK-8020354.js.EXPECTED
0 → 100644
浏览文件 @
aed588de
1
2
3
1
2
3
getting x
x
setting x
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录