Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell11
提交
ea2cfe6c
D
dragonwell11
项目概览
openanolis
/
dragonwell11
通知
7
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell11
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ea2cfe6c
编写于
10月 13, 2017
作者:
H
hannesw
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8027302: Identifiers containing unicode escapes are not recognized as reserved words
Reviewed-by: jlaskey, sundar
上级
45cf8107
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
358 addition
and
34 deletion
+358
-34
src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/IdentNode.java
...horn/share/classes/jdk/nashorn/internal/ir/IdentNode.java
+10
-0
src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Lexer.java
...horn/share/classes/jdk/nashorn/internal/parser/Lexer.java
+3
-25
src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Parser.java
...orn/share/classes/jdk/nashorn/internal/parser/Parser.java
+18
-9
src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/Messages.properties
...dk/nashorn/internal/runtime/resources/Messages.properties
+1
-0
test/nashorn/script/basic/JDK-8027302.js
test/nashorn/script/basic/JDK-8027302.js
+160
-0
test/nashorn/script/basic/es6/JDK-8027302.js
test/nashorn/script/basic/es6/JDK-8027302.js
+166
-0
未找到文件。
src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/IdentNode.java
浏览文件 @
ea2cfe6c
...
...
@@ -477,4 +477,14 @@ public final class IdentNode extends Expression implements PropertyKey, Function
public
IdentNode
setIsDestructuredParameter
()
{
return
new
IdentNode
(
this
,
name
,
type
,
flags
|
DESTRUCTURED_PARAMETER
,
programPoint
,
conversion
);
}
/**
* Checks whether the source code for this ident contains a unicode escape sequence by comparing
* the length of its name with its length in source code.
*
* @return true if ident source contains a unicode escape sequence
*/
public
boolean
containsEscapes
()
{
return
Token
.
descLength
(
getToken
())
!=
name
.
length
();
}
}
src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Lexer.java
浏览文件 @
ea2cfe6c
...
...
@@ -786,15 +786,9 @@ public class Lexer extends Scanner {
if
(
ch0
==
'\\'
&&
ch1
==
'u'
)
{
skip
(
2
);
final
int
ch
=
hexSequence
(
4
,
TokenType
.
IDENT
);
if
(
isWhitespace
((
char
)
ch
))
{
return
null
;
}
if
(
ch
<
0
)
{
sb
.
append
(
'\\'
);
sb
.
append
(
'u'
);
}
else
{
sb
.
append
((
char
)
ch
);
}
assert
!
isWhitespace
((
char
)
ch
);
assert
ch
>=
0
;
sb
.
append
((
char
)
ch
);
}
else
{
// Add regular character.
sb
.
append
(
ch0
);
...
...
@@ -994,9 +988,6 @@ public class Lexer extends Scanner {
if
(
ch0
==
'\\'
)
{
type
=
ESCSTRING
;
skip
(
1
);
if
(!
isEscapeCharacter
(
ch0
))
{
error
(
Lexer
.
message
(
"invalid.escape.char"
),
STRING
,
position
,
limit
);
}
if
(
isEOL
(
ch0
))
{
// Multiline string literal
skipEOL
(
false
);
...
...
@@ -1093,9 +1084,6 @@ public class Lexer extends Scanner {
}
else
if
(
ch0
==
'\\'
)
{
skip
(
1
);
// EscapeSequence
if
(!
isEscapeCharacter
(
ch0
))
{
error
(
Lexer
.
message
(
"invalid.escape.char"
),
TEMPLATE
,
position
,
limit
);
}
if
(
isEOL
(
ch0
))
{
// LineContinuation
skipEOL
(
false
);
...
...
@@ -1114,16 +1102,6 @@ public class Lexer extends Scanner {
error
(
Lexer
.
message
(
"missing.close.quote"
),
TEMPLATE
,
position
,
limit
);
}
/**
* Is the given character a valid escape char after "\" ?
*
* @param ch character to be checked
* @return if the given character is valid after "\"
*/
protected
boolean
isEscapeCharacter
(
final
char
ch
)
{
return
true
;
}
/**
* Convert string to number.
*
...
...
src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Parser.java
浏览文件 @
ea2cfe6c
...
...
@@ -1472,12 +1472,7 @@ public class Parser extends AbstractParser implements Loggable {
*/
private
void
verifyIdent
(
final
IdentNode
ident
,
final
String
contextString
)
{
verifyStrictIdent
(
ident
,
contextString
);
if
(
isES6
())
{
final
TokenType
tokenType
=
TokenLookup
.
lookupKeyword
(
ident
.
getName
().
toCharArray
(),
0
,
ident
.
getName
().
length
());
if
(
tokenType
!=
IDENT
&&
tokenType
.
getKind
()
!=
TokenKind
.
FUTURESTRICT
)
{
throw
error
(
expectMessage
(
IDENT
));
}
}
checkEscapedKeyword
(
ident
);
}
/**
...
...
@@ -1502,6 +1497,18 @@ public class Parser extends AbstractParser implements Loggable {
}
}
/**
* ES6 11.6.2: A code point in a ReservedWord cannot be expressed by a | UnicodeEscapeSequence.
*/
private
void
checkEscapedKeyword
(
final
IdentNode
ident
)
{
if
(
isES6
()
&&
ident
.
containsEscapes
())
{
final
TokenType
tokenType
=
TokenLookup
.
lookupKeyword
(
ident
.
getName
().
toCharArray
(),
0
,
ident
.
getName
().
length
());
if
(
tokenType
!=
IDENT
&&
!(
tokenType
.
getKind
()
==
TokenKind
.
FUTURESTRICT
&&
!
isStrictMode
))
{
throw
error
(
AbstractParser
.
message
(
"keyword.escaped.character"
),
ident
.
getToken
());
}
}
}
/*
* VariableStatement :
* var VariableDeclarationList ;
...
...
@@ -2646,7 +2653,7 @@ public class Parser extends AbstractParser implements Loggable {
});
}
else
{
// ECMA 12.4.1 strict mode restrictions
verify
Strict
Ident
((
IdentNode
)
exception
,
"catch argument"
);
verifyIdent
((
IdentNode
)
exception
,
"catch argument"
);
}
...
...
@@ -2761,6 +2768,7 @@ public class Parser extends AbstractParser implements Loggable {
break
;
}
detectSpecialProperty
(
ident
);
checkEscapedKeyword
(
ident
);
return
ident
;
case
OCTAL_LEGACY:
if
(
isStrictMode
)
{
...
...
@@ -3404,6 +3412,7 @@ public class Parser extends AbstractParser implements Loggable {
// Catch special functions.
if
(
lhs
instanceof
IdentNode
)
{
detectSpecialFunction
((
IdentNode
)
lhs
);
checkEscapedKeyword
((
IdentNode
)
lhs
);
}
lhs
=
new
CallNode
(
callLine
,
callToken
,
finish
,
lhs
,
arguments
,
false
);
...
...
@@ -3779,7 +3788,7 @@ public class Parser extends AbstractParser implements Loggable {
expect
(
IDENT
);
}
name
=
getIdent
();
verify
Strict
Ident
(
name
,
"function name"
);
verifyIdent
(
name
,
"function name"
);
}
else
if
(
isStatement
)
{
// Nashorn extension: anonymous function statements.
// Do not allow anonymous function statement if extensions
...
...
@@ -4871,7 +4880,7 @@ public class Parser extends AbstractParser implements Loggable {
final
String
contextString
=
"function parameter"
;
if
(
param
instanceof
IdentNode
)
{
final
IdentNode
ident
=
(
IdentNode
)
param
;
verify
Strict
Ident
(
ident
,
contextString
);
verifyIdent
(
ident
,
contextString
);
final
ParserContextFunctionNode
currentFunction
=
lc
.
getCurrentFunction
();
if
(
currentFunction
!=
null
)
{
currentFunction
.
addParameterBinding
(
ident
);
...
...
src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/Messages.properties
浏览文件 @
ea2cfe6c
...
...
@@ -62,6 +62,7 @@ parser.error.regex.syntax={0}
parser.error.trailing.comma.in.json
=
Trailing comma is not allowed in JSON
parser.error.missing.const.assignment
=
Missing assignment to constant "{0}"
parser.error.unterminated.template.expression
=
Expected } after expression in template literal
parser.error.keyword.escaped.character
=
Keyword must not contain escaped characters
# ES6 mode error messages
parser.error.multiple.constructors
=
Class contains more than one constructor
...
...
test/nashorn/script/basic/JDK-8027302.js
0 → 100644
浏览文件 @
ea2cfe6c
/*
* Copyright (c) 2017, 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-8027302: Identifiers containing unicode escapes are not recognized as reserved words
*
* @test
* @run
*/
// keywords containing escapes
try
{
eval
(
"
v
\\
u0061r i;
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
SyntaxError
);
}
try
{
eval
(
"
\\
u0069f (true) ;
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
ReferenceError
);
// no SyntaxError in ES5
}
try
{
eval
(
"
if (true) ;
\\
u0065lse ;
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
ReferenceError
);
// no SyntaxError in ES5
}
try
{
eval
(
"
f
\\
u0075nction x() {}
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
SyntaxError
);
}
try
{
eval
(
"
var f = f
\\
u0075nction() {}
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
SyntaxError
);
}
try
{
eval
(
"
var o = { f: f
\\
u0075nction() {}}
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
SyntaxError
);
}
try
{
eval
(
"
var a = [f
\\
u0075nction() {}]
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
SyntaxError
);
}
// keywords as identifiers, with and without escapes
try
{
eval
(
"
function break() {}
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
SyntaxError
);
}
try
{
eval
(
"
function bre
\\
u0061k() {}
"
);
}
catch
(
e
)
{
fail
(
"
Unexpected error
"
);
}
try
{
eval
(
"
function f(break) {}
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
SyntaxError
);
}
try
{
eval
(
"
function f(bre
\\
u0061k) {}
"
);
}
catch
(
e
)
{
fail
(
"
Unexpected error
"
);
}
try
{
eval
(
"
var break = 3
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
SyntaxError
);
}
try
{
eval
(
"
'use strict'; var break = 3
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
SyntaxError
);
}
try
{
eval
(
"
var bre
\\
u0061k = 3
"
);
}
catch
(
e
)
{
fail
(
"
Unexpected error
"
);
}
try
{
eval
(
"
'use strict'; var bre
\\
u0061k = 3
"
);
}
catch
(
e
)
{
fail
(
"
Unexpected error
"
);
}
try
{
eval
(
"
var package = 3
"
);
}
catch
(
e
)
{
fail
(
"
Unexpected error
"
);
}
try
{
eval
(
"
'use strict'; var package = 3
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
SyntaxError
);
}
try
{
eval
(
"
var p
\\
u0061ckage = 3
"
);
}
catch
(
e
)
{
fail
(
"
Unexpected error
"
);
}
try
{
eval
(
"
'use strict'; var p
\\
u0061ckage = 3
"
);
}
catch
(
e
)
{
fail
(
"
Unexpected error
"
);
}
test/nashorn/script/basic/es6/JDK-8027302.js
0 → 100644
浏览文件 @
ea2cfe6c
/*
* Copyright (c) 2017, 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-8027302: Identifiers containing unicode escapes are not recognized as reserved words
*
* @test
* @run
* @option --language=es6
*/
// keywords containing escapes
try
{
eval
(
"
v
\\
u0061r i;
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
SyntaxError
);
}
try
{
eval
(
"
\\
u0069f (true) ;
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
SyntaxError
);
}
try
{
eval
(
"
if (true) ;
\\
u0065lse ;
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
SyntaxError
);
}
try
{
eval
(
"
f
\\
u0075nction x() {}
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
SyntaxError
);
}
try
{
eval
(
"
var f = f
\\
u0075nction() {}
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
SyntaxError
);
}
try
{
eval
(
"
var o = { f: f
\\
u0075nction() {}}
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
SyntaxError
);
}
try
{
eval
(
"
var a = [f
\\
u0075nction() {}]
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
SyntaxError
);
}
// keywords as identifiers, with and without escapes
try
{
eval
(
"
function break() {}
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
SyntaxError
);
}
try
{
eval
(
"
function bre
\\
u0061k() {}
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
SyntaxError
);
}
try
{
eval
(
"
function f(break) {}
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
SyntaxError
);
}
try
{
eval
(
"
function f(bre
\\
u0061k) {}
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
SyntaxError
);
}
try
{
eval
(
"
var break = 3
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
SyntaxError
);
}
try
{
eval
(
"
'use strict'; var break = 3
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
SyntaxError
);
}
try
{
eval
(
"
var bre
\\
u0061k = 3
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
SyntaxError
);
}
try
{
eval
(
"
'use strict'; var bre
\\
u0061k = 3
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
SyntaxError
);
}
try
{
eval
(
"
var package = 3
"
);
}
catch
(
e
)
{
fail
(
"
Unexpected error
"
);
}
try
{
eval
(
"
'use strict'; var package = 3
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
SyntaxError
);
}
try
{
eval
(
"
var p
\\
u0061ckage = 3
"
);
}
catch
(
e
)
{
fail
(
"
Unexpected error
"
);
}
try
{
eval
(
"
'use strict'; var p
\\
u0061ckage = 3
"
);
fail
(
"
Expected error
"
);
}
catch
(
e
)
{
Assert
.
assertTrue
(
e
instanceof
SyntaxError
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录