Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_nashorn
提交
4ba8f72c
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,发现更多精彩内容 >>
提交
4ba8f72c
编写于
3月 17, 2014
作者:
S
sundar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8037400: Remove getInitialMap getters and GlobalObject interface
Reviewed-by: lagergren, jlaskey, attila
上级
7224aa68
变更
54
隐藏空白更改
内联
并排
Showing
54 changed file
with
376 addition
and
594 deletion
+376
-594
make/build.xml
make/build.xml
+2
-0
src/jdk/nashorn/api/scripting/NashornScriptEngine.java
src/jdk/nashorn/api/scripting/NashornScriptEngine.java
+33
-34
src/jdk/nashorn/api/scripting/ScriptObjectMirror.java
src/jdk/nashorn/api/scripting/ScriptObjectMirror.java
+11
-11
src/jdk/nashorn/internal/objects/AccessorPropertyDescriptor.java
.../nashorn/internal/objects/AccessorPropertyDescriptor.java
+1
-5
src/jdk/nashorn/internal/objects/ArrayBufferView.java
src/jdk/nashorn/internal/objects/ArrayBufferView.java
+1
-5
src/jdk/nashorn/internal/objects/DataPropertyDescriptor.java
src/jdk/nashorn/internal/objects/DataPropertyDescriptor.java
+1
-5
src/jdk/nashorn/internal/objects/GenericPropertyDescriptor.java
...k/nashorn/internal/objects/GenericPropertyDescriptor.java
+1
-5
src/jdk/nashorn/internal/objects/Global.java
src/jdk/nashorn/internal/objects/Global.java
+141
-29
src/jdk/nashorn/internal/objects/NativeArray.java
src/jdk/nashorn/internal/objects/NativeArray.java
+1
-5
src/jdk/nashorn/internal/objects/NativeArrayBuffer.java
src/jdk/nashorn/internal/objects/NativeArrayBuffer.java
+1
-5
src/jdk/nashorn/internal/objects/NativeBoolean.java
src/jdk/nashorn/internal/objects/NativeBoolean.java
+1
-5
src/jdk/nashorn/internal/objects/NativeDate.java
src/jdk/nashorn/internal/objects/NativeDate.java
+1
-5
src/jdk/nashorn/internal/objects/NativeError.java
src/jdk/nashorn/internal/objects/NativeError.java
+1
-5
src/jdk/nashorn/internal/objects/NativeEvalError.java
src/jdk/nashorn/internal/objects/NativeEvalError.java
+1
-5
src/jdk/nashorn/internal/objects/NativeJSAdapter.java
src/jdk/nashorn/internal/objects/NativeJSAdapter.java
+1
-5
src/jdk/nashorn/internal/objects/NativeJavaImporter.java
src/jdk/nashorn/internal/objects/NativeJavaImporter.java
+1
-5
src/jdk/nashorn/internal/objects/NativeNumber.java
src/jdk/nashorn/internal/objects/NativeNumber.java
+1
-5
src/jdk/nashorn/internal/objects/NativeRangeError.java
src/jdk/nashorn/internal/objects/NativeRangeError.java
+1
-5
src/jdk/nashorn/internal/objects/NativeReferenceError.java
src/jdk/nashorn/internal/objects/NativeReferenceError.java
+1
-5
src/jdk/nashorn/internal/objects/NativeRegExp.java
src/jdk/nashorn/internal/objects/NativeRegExp.java
+1
-5
src/jdk/nashorn/internal/objects/NativeRegExpExecResult.java
src/jdk/nashorn/internal/objects/NativeRegExpExecResult.java
+1
-5
src/jdk/nashorn/internal/objects/NativeString.java
src/jdk/nashorn/internal/objects/NativeString.java
+1
-5
src/jdk/nashorn/internal/objects/NativeSyntaxError.java
src/jdk/nashorn/internal/objects/NativeSyntaxError.java
+1
-5
src/jdk/nashorn/internal/objects/NativeTypeError.java
src/jdk/nashorn/internal/objects/NativeTypeError.java
+1
-5
src/jdk/nashorn/internal/objects/NativeURIError.java
src/jdk/nashorn/internal/objects/NativeURIError.java
+1
-5
src/jdk/nashorn/internal/objects/PrototypeObject.java
src/jdk/nashorn/internal/objects/PrototypeObject.java
+0
-4
src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java
src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java
+8
-28
src/jdk/nashorn/internal/runtime/Context.java
src/jdk/nashorn/internal/runtime/Context.java
+34
-44
src/jdk/nashorn/internal/runtime/DebuggerSupport.java
src/jdk/nashorn/internal/runtime/DebuggerSupport.java
+2
-2
src/jdk/nashorn/internal/runtime/ECMAErrors.java
src/jdk/nashorn/internal/runtime/ECMAErrors.java
+29
-28
src/jdk/nashorn/internal/runtime/GlobalObject.java
src/jdk/nashorn/internal/runtime/GlobalObject.java
+0
-228
src/jdk/nashorn/internal/runtime/JSONFunctions.java
src/jdk/nashorn/internal/runtime/JSONFunctions.java
+11
-10
src/jdk/nashorn/internal/runtime/JSType.java
src/jdk/nashorn/internal/runtime/JSType.java
+5
-4
src/jdk/nashorn/internal/runtime/ListAdapter.java
src/jdk/nashorn/internal/runtime/ListAdapter.java
+7
-6
src/jdk/nashorn/internal/runtime/NativeJavaPackage.java
src/jdk/nashorn/internal/runtime/NativeJavaPackage.java
+1
-2
src/jdk/nashorn/internal/runtime/ParserException.java
src/jdk/nashorn/internal/runtime/ParserException.java
+2
-1
src/jdk/nashorn/internal/runtime/ScriptFunction.java
src/jdk/nashorn/internal/runtime/ScriptFunction.java
+3
-2
src/jdk/nashorn/internal/runtime/ScriptFunctionData.java
src/jdk/nashorn/internal/runtime/ScriptFunctionData.java
+3
-2
src/jdk/nashorn/internal/runtime/ScriptObject.java
src/jdk/nashorn/internal/runtime/ScriptObject.java
+10
-10
src/jdk/nashorn/internal/runtime/ScriptRuntime.java
src/jdk/nashorn/internal/runtime/ScriptRuntime.java
+1
-1
src/jdk/nashorn/internal/runtime/SetMethodCreator.java
src/jdk/nashorn/internal/runtime/SetMethodCreator.java
+1
-1
src/jdk/nashorn/internal/runtime/UserAccessorProperty.java
src/jdk/nashorn/internal/runtime/UserAccessorProperty.java
+3
-2
src/jdk/nashorn/internal/runtime/arrays/ArrayData.java
src/jdk/nashorn/internal/runtime/arrays/ArrayData.java
+2
-2
src/jdk/nashorn/internal/runtime/arrays/ByteBufferArrayData.java
.../nashorn/internal/runtime/arrays/ByteBufferArrayData.java
+3
-2
src/jdk/nashorn/internal/runtime/arrays/FrozenArrayFilter.java
...dk/nashorn/internal/runtime/arrays/FrozenArrayFilter.java
+2
-2
src/jdk/nashorn/internal/runtime/arrays/SealedArrayFilter.java
...dk/nashorn/internal/runtime/arrays/SealedArrayFilter.java
+2
-2
src/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java
...internal/runtime/linker/JavaAdapterBytecodeGenerator.java
+13
-9
src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java
...k/nashorn/internal/runtime/linker/JavaAdapterFactory.java
+3
-3
src/jdk/nashorn/internal/runtime/linker/NashornPrimitiveLinker.java
...shorn/internal/runtime/linker/NashornPrimitiveLinker.java
+2
-2
src/jdk/nashorn/tools/Shell.java
src/jdk/nashorn/tools/Shell.java
+10
-9
test/src/jdk/nashorn/internal/codegen/CompilerTest.java
test/src/jdk/nashorn/internal/codegen/CompilerTest.java
+3
-2
test/src/jdk/nashorn/internal/performance/PerformanceWrapper.java
.../jdk/nashorn/internal/performance/PerformanceWrapper.java
+2
-2
test/src/jdk/nashorn/internal/runtime/ContextTest.java
test/src/jdk/nashorn/internal/runtime/ContextTest.java
+3
-2
test/src/jdk/nashorn/internal/test/framework/SharedContextEvaluator.java
...shorn/internal/test/framework/SharedContextEvaluator.java
+3
-3
未找到文件。
make/build.xml
浏览文件 @
4ba8f72c
...
...
@@ -122,6 +122,7 @@
<compilerarg
value=
"-Xlint:unchecked"
/>
<compilerarg
value=
"-Xlint:deprecation"
/>
<compilerarg
value=
"-XDignore.symbol.file"
/>
<compilerarg
value=
"-Xdiags:verbose"
/>
</javac>
<copy
todir=
"${build.classes.dir}/META-INF/services"
>
<fileset
dir=
"${meta.inf.dir}/services/"
/>
...
...
@@ -240,6 +241,7 @@
<compilerarg
value=
"-J-Djava.ext.dirs="
/>
<compilerarg
value=
"-Xlint:unchecked"
/>
<compilerarg
value=
"-Xlint:deprecation"
/>
<compilerarg
value=
"-Xdiags:verbose"
/>
</javac>
<copy
todir=
"${build.test.classes.dir}/META-INF/services"
>
...
...
src/jdk/nashorn/api/scripting/NashornScriptEngine.java
浏览文件 @
4ba8f72c
...
...
@@ -57,9 +57,9 @@ import javax.script.ScriptEngine;
import
javax.script.ScriptEngineFactory
;
import
javax.script.ScriptException
;
import
javax.script.SimpleBindings
;
import
jdk.nashorn.internal.objects.Global
;
import
jdk.nashorn.internal.runtime.Context
;
import
jdk.nashorn.internal.runtime.ErrorManager
;
import
jdk.nashorn.internal.runtime.GlobalObject
;
import
jdk.nashorn.internal.runtime.Property
;
import
jdk.nashorn.internal.runtime.ScriptFunction
;
import
jdk.nashorn.internal.runtime.ScriptObject
;
...
...
@@ -99,7 +99,7 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
private
final
boolean
_global_per_engine
;
// This is the initial default Nashorn global object.
// This is used as "shared" global if above option is true.
private
final
ScriptObject
global
;
private
final
Global
global
;
// initialized bit late to be made 'final'.
// Property object for "context" property of global object.
private
volatile
Property
contextProperty
;
...
...
@@ -264,7 +264,7 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
public
Object
__noSuchProperty__
(
final
Object
self
,
final
ScriptContext
ctxt
,
final
String
name
)
{
if
(
ctxt
!=
null
)
{
final
int
scope
=
ctxt
.
getAttributesScope
(
name
);
final
ScriptObject
ctxtGlobal
=
getNashornGlobalFrom
(
ctxt
);
final
Global
ctxtGlobal
=
getNashornGlobalFrom
(
ctxt
);
if
(
scope
!=
-
1
)
{
return
ScriptObjectMirror
.
unwrap
(
ctxt
.
getAttribute
(
name
,
scope
),
ctxtGlobal
);
}
...
...
@@ -317,7 +317,7 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
}
ScriptObject
realSelf
=
null
;
ScriptObject
realGlobal
=
null
;
Global
realGlobal
=
null
;
if
(
thiz
==
null
)
{
// making interface out of global functions
realSelf
=
realGlobal
=
getNashornGlobalFrom
(
context
);
...
...
@@ -346,7 +346,7 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
}
try
{
final
ScriptObject
oldGlobal
=
Context
.
getGlobal
();
final
Global
oldGlobal
=
Context
.
getGlobal
();
final
boolean
globalChanged
=
(
oldGlobal
!=
realGlobal
);
try
{
if
(
globalChanged
)
{
...
...
@@ -371,7 +371,7 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
}
// Retrieve nashorn Global object for a given ScriptContext object
private
ScriptObject
getNashornGlobalFrom
(
final
ScriptContext
ctxt
)
{
private
Global
getNashornGlobalFrom
(
final
ScriptContext
ctxt
)
{
if
(
_global_per_engine
)
{
// shared single global object for all ENGINE_SCOPE Bindings
return
global
;
...
...
@@ -380,18 +380,18 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
final
Bindings
bindings
=
ctxt
.
getBindings
(
ScriptContext
.
ENGINE_SCOPE
);
// is this Nashorn's own Bindings implementation?
if
(
bindings
instanceof
ScriptObjectMirror
)
{
final
ScriptObject
sobj
=
globalFromMirror
((
ScriptObjectMirror
)
bindings
);
if
(
sobj
!=
null
)
{
return
sobj
;
final
Global
glob
=
globalFromMirror
((
ScriptObjectMirror
)
bindings
);
if
(
glob
!=
null
)
{
return
glob
;
}
}
// Arbitrary user Bindings implementation. Look for NASHORN_GLOBAL in it!
Object
scope
=
bindings
.
get
(
NASHORN_GLOBAL
);
if
(
scope
instanceof
ScriptObjectMirror
)
{
final
ScriptObject
sobj
=
globalFromMirror
((
ScriptObjectMirror
)
scope
);
if
(
sobj
!=
null
)
{
return
sobj
;
final
Global
glob
=
globalFromMirror
((
ScriptObjectMirror
)
scope
);
if
(
glob
!=
null
)
{
return
glob
;
}
}
...
...
@@ -399,14 +399,14 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
// Create new global instance mirror and associate with the Bindings.
final
ScriptObjectMirror
mirror
=
createGlobalMirror
(
ctxt
);
bindings
.
put
(
NASHORN_GLOBAL
,
mirror
);
return
mirror
.
get
ScriptObject
();
return
mirror
.
get
HomeGlobal
();
}
// Retrieve nashorn Global object from a given ScriptObjectMirror
private
ScriptObject
globalFromMirror
(
final
ScriptObjectMirror
mirror
)
{
private
Global
globalFromMirror
(
final
ScriptObjectMirror
mirror
)
{
ScriptObject
sobj
=
mirror
.
getScriptObject
();
if
(
sobj
instanceof
Global
Object
&&
isOfContext
(
sobj
,
nashornContext
))
{
return
sobj
;
if
(
sobj
instanceof
Global
&&
isOfContext
((
Global
)
sobj
,
nashornContext
))
{
return
(
Global
)
sobj
;
}
return
null
;
...
...
@@ -414,15 +414,15 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
// Create a new ScriptObjectMirror wrapping a newly created Nashorn Global object
private
ScriptObjectMirror
createGlobalMirror
(
final
ScriptContext
ctxt
)
{
final
ScriptObject
newGlobal
=
createNashornGlobal
(
ctxt
);
final
Global
newGlobal
=
createNashornGlobal
(
ctxt
);
return
new
ScriptObjectMirror
(
newGlobal
,
newGlobal
);
}
// Create a new Nashorn Global object
private
ScriptObject
createNashornGlobal
(
final
ScriptContext
ctxt
)
{
final
ScriptObject
newGlobal
=
AccessController
.
doPrivileged
(
new
PrivilegedAction
<
ScriptObject
>()
{
private
Global
createNashornGlobal
(
final
ScriptContext
ctxt
)
{
final
Global
newGlobal
=
AccessController
.
doPrivileged
(
new
PrivilegedAction
<
Global
>()
{
@Override
public
ScriptObject
run
()
{
public
Global
run
()
{
try
{
return
nashornContext
.
newGlobal
();
}
catch
(
final
RuntimeException
e
)
{
...
...
@@ -460,7 +460,7 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
}
// scripts should see "context" and "engine" as variables in the given global object
private
void
setContextVariables
(
final
ScriptObject
ctxtGlobal
,
final
ScriptContext
ctxt
)
{
private
void
setContextVariables
(
final
Global
ctxtGlobal
,
final
ScriptContext
ctxt
)
{
// set "context" global variable via contextProperty - because this
// property is non-writable
contextProperty
.
setObjectValue
(
ctxtGlobal
,
ctxtGlobal
,
ctxt
,
false
);
...
...
@@ -470,7 +470,7 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
}
// if no arguments passed, expose it
if
(!
(
args
instanceof
ScriptObject
))
{
args
=
((
GlobalObject
)
ctxtGlobal
)
.
wrapAsObject
(
args
);
args
=
ctxtGlobal
.
wrapAsObject
(
args
);
ctxtGlobal
.
set
(
"arguments"
,
args
,
false
);
}
}
...
...
@@ -478,7 +478,7 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
private
Object
invokeImpl
(
final
Object
selfObject
,
final
String
name
,
final
Object
...
args
)
throws
ScriptException
,
NoSuchMethodException
{
name
.
getClass
();
// null check
ScriptObject
invokeGlobal
=
null
;
Global
invokeGlobal
=
null
;
ScriptObjectMirror
selfMirror
=
null
;
if
(
selfObject
instanceof
ScriptObjectMirror
)
{
selfMirror
=
(
ScriptObjectMirror
)
selfObject
;
...
...
@@ -489,7 +489,7 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
}
else
if
(
selfObject
instanceof
ScriptObject
)
{
// invokeMethod called from script code - in which case we may get 'naked' ScriptObject
// Wrap it with oldGlobal to make a ScriptObjectMirror for the same.
final
ScriptObject
oldGlobal
=
Context
.
getGlobal
();
final
Global
oldGlobal
=
Context
.
getGlobal
();
invokeGlobal
=
oldGlobal
;
if
(
oldGlobal
==
null
)
{
throw
new
IllegalArgumentException
(
getMessage
(
"no.current.nashorn.global"
));
...
...
@@ -502,7 +502,7 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
selfMirror
=
(
ScriptObjectMirror
)
ScriptObjectMirror
.
wrap
(
selfObject
,
oldGlobal
);
}
else
if
(
selfObject
==
null
)
{
// selfObject is null => global function call
final
ScriptObject
ctxtGlobal
=
getNashornGlobalFrom
(
context
);
final
Global
ctxtGlobal
=
getNashornGlobalFrom
(
context
);
invokeGlobal
=
ctxtGlobal
;
selfMirror
=
(
ScriptObjectMirror
)
ScriptObjectMirror
.
wrap
(
ctxtGlobal
,
ctxtGlobal
);
}
...
...
@@ -532,11 +532,11 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
return
evalImpl
(
script
,
ctxt
,
getNashornGlobalFrom
(
ctxt
));
}
private
Object
evalImpl
(
final
ScriptFunction
script
,
final
ScriptContext
ctxt
,
final
ScriptObject
ctxtGlobal
)
throws
ScriptException
{
private
Object
evalImpl
(
final
ScriptFunction
script
,
final
ScriptContext
ctxt
,
final
Global
ctxtGlobal
)
throws
ScriptException
{
if
(
script
==
null
)
{
return
null
;
}
final
ScriptObject
oldGlobal
=
Context
.
getGlobal
();
final
Global
oldGlobal
=
Context
.
getGlobal
();
final
boolean
globalChanged
=
(
oldGlobal
!=
ctxtGlobal
);
try
{
if
(
globalChanged
)
{
...
...
@@ -558,7 +558,7 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
}
}
private
static
void
throwAsScriptException
(
final
Exception
e
,
final
ScriptObject
global
)
throws
ScriptException
{
private
static
void
throwAsScriptException
(
final
Exception
e
,
final
Global
global
)
throws
ScriptException
{
if
(
e
instanceof
ScriptException
)
{
throw
(
ScriptException
)
e
;
}
else
if
(
e
instanceof
NashornException
)
{
...
...
@@ -582,7 +582,7 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
return
new
CompiledScript
()
{
@Override
public
Object
eval
(
final
ScriptContext
ctxt
)
throws
ScriptException
{
final
ScriptObject
globalObject
=
getNashornGlobalFrom
(
ctxt
);
final
Global
globalObject
=
getNashornGlobalFrom
(
ctxt
);
// Are we running the script in the correct global?
if
(
func
.
getScope
()
==
globalObject
)
{
return
evalImpl
(
func
,
ctxt
,
globalObject
);
...
...
@@ -602,8 +602,8 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
return
compileImpl
(
source
,
getNashornGlobalFrom
(
ctxt
));
}
private
ScriptFunction
compileImpl
(
final
Source
source
,
final
ScriptObject
newGlobal
)
throws
ScriptException
{
final
ScriptObject
oldGlobal
=
Context
.
getGlobal
();
private
ScriptFunction
compileImpl
(
final
Source
source
,
final
Global
newGlobal
)
throws
ScriptException
{
final
Global
oldGlobal
=
Context
.
getGlobal
();
final
boolean
globalChanged
=
(
oldGlobal
!=
newGlobal
);
try
{
if
(
globalChanged
)
{
...
...
@@ -641,8 +641,7 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
return
true
;
}
private
static
boolean
isOfContext
(
final
ScriptObject
global
,
final
Context
context
)
{
assert
global
instanceof
GlobalObject:
"Not a Global object"
;
return
((
GlobalObject
)
global
).
isOfContext
(
context
);
private
static
boolean
isOfContext
(
final
Global
global
,
final
Context
context
)
{
return
global
.
isOfContext
(
context
);
}
}
src/jdk/nashorn/api/scripting/ScriptObjectMirror.java
浏览文件 @
4ba8f72c
...
...
@@ -42,10 +42,10 @@ import java.util.Map;
import
java.util.Set
;
import
java.util.concurrent.Callable
;
import
javax.script.Bindings
;
import
jdk.nashorn.internal.objects.Global
;
import
jdk.nashorn.internal.runtime.arrays.ArrayData
;
import
jdk.nashorn.internal.runtime.ConsString
;
import
jdk.nashorn.internal.runtime.Context
;
import
jdk.nashorn.internal.runtime.GlobalObject
;
import
jdk.nashorn.internal.runtime.JSType
;
import
jdk.nashorn.internal.runtime.ScriptFunction
;
import
jdk.nashorn.internal.runtime.ScriptObject
;
...
...
@@ -64,7 +64,7 @@ public final class ScriptObjectMirror extends AbstractJSObject implements Bindin
private
static
final
AccessControlContext
GET_CONTEXT_ACC_CTXT
=
getContextAccCtxt
();
private
final
ScriptObject
sobj
;
private
final
ScriptObject
global
;
private
final
Global
global
;
private
final
boolean
strict
;
@Override
...
...
@@ -95,7 +95,7 @@ public final class ScriptObjectMirror extends AbstractJSObject implements Bindin
@Override
public
Object
call
(
final
Object
thiz
,
final
Object
...
args
)
{
final
ScriptObject
oldGlobal
=
Context
.
getGlobal
();
final
Global
oldGlobal
=
Context
.
getGlobal
();
final
boolean
globalChanged
=
(
oldGlobal
!=
global
);
try
{
...
...
@@ -125,7 +125,7 @@ public final class ScriptObjectMirror extends AbstractJSObject implements Bindin
@Override
public
Object
newObject
(
final
Object
...
args
)
{
final
ScriptObject
oldGlobal
=
Context
.
getGlobal
();
final
Global
oldGlobal
=
Context
.
getGlobal
();
final
boolean
globalChanged
=
(
oldGlobal
!=
global
);
try
{
...
...
@@ -171,7 +171,7 @@ public final class ScriptObjectMirror extends AbstractJSObject implements Bindin
public
Object
callMember
(
final
String
functionName
,
final
Object
...
args
)
{
functionName
.
getClass
();
// null check
final
ScriptObject
oldGlobal
=
Context
.
getGlobal
();
final
Global
oldGlobal
=
Context
.
getGlobal
();
final
boolean
globalChanged
=
(
oldGlobal
!=
global
);
try
{
...
...
@@ -642,7 +642,7 @@ public final class ScriptObjectMirror extends AbstractJSObject implements Bindin
*/
public
static
Object
wrap
(
final
Object
obj
,
final
Object
homeGlobal
)
{
if
(
obj
instanceof
ScriptObject
)
{
return
homeGlobal
instanceof
ScriptObject
?
new
ScriptObjectMirror
((
ScriptObject
)
obj
,
(
ScriptObject
)
homeGlobal
)
:
obj
;
return
homeGlobal
instanceof
Global
?
new
ScriptObjectMirror
((
ScriptObject
)
obj
,
(
Global
)
homeGlobal
)
:
obj
;
}
if
(
obj
instanceof
ConsString
)
{
return
obj
.
toString
();
...
...
@@ -710,13 +710,13 @@ public final class ScriptObjectMirror extends AbstractJSObject implements Bindin
// package-privates below this.
ScriptObjectMirror
(
final
ScriptObject
sobj
,
final
ScriptObject
global
)
{
ScriptObjectMirror
(
final
ScriptObject
sobj
,
final
Global
global
)
{
assert
sobj
!=
null
:
"ScriptObjectMirror on null!"
;
assert
global
instanceof
GlobalObject
:
"global is not a GlobalObject
"
;
assert
global
!=
null
:
"home Global is null
"
;
this
.
sobj
=
sobj
;
this
.
global
=
global
;
this
.
strict
=
((
GlobalObject
)
global
)
.
isStrictContext
();
this
.
strict
=
global
.
isStrictContext
();
}
// accessors for script engine
...
...
@@ -724,7 +724,7 @@ public final class ScriptObjectMirror extends AbstractJSObject implements Bindin
return
sobj
;
}
ScriptObject
getHomeGlobal
()
{
Global
getHomeGlobal
()
{
return
global
;
}
...
...
@@ -734,7 +734,7 @@ public final class ScriptObjectMirror extends AbstractJSObject implements Bindin
// internals only below this.
private
<
V
>
V
inGlobal
(
final
Callable
<
V
>
callable
)
{
final
ScriptObject
oldGlobal
=
Context
.
getGlobal
();
final
Global
oldGlobal
=
Context
.
getGlobal
();
final
boolean
globalChanged
=
(
oldGlobal
!=
global
);
if
(
globalChanged
)
{
Context
.
setGlobal
(
global
);
...
...
src/jdk/nashorn/internal/objects/AccessorPropertyDescriptor.java
浏览文件 @
4ba8f72c
...
...
@@ -67,12 +67,8 @@ public final class AccessorPropertyDescriptor extends ScriptObject implements Pr
// initialized by nasgen
private
static
PropertyMap
$nasgenmap
$
;
static
PropertyMap
getInitialMap
()
{
return
$nasgenmap
$
;
}
AccessorPropertyDescriptor
(
final
boolean
configurable
,
final
boolean
enumerable
,
final
Object
get
,
final
Object
set
,
final
Global
global
)
{
super
(
global
.
getObjectPrototype
(),
getInitialMap
()
);
super
(
global
.
getObjectPrototype
(),
$nasgenmap
$
);
this
.
configurable
=
configurable
;
this
.
enumerable
=
enumerable
;
this
.
get
=
get
;
...
...
src/jdk/nashorn/internal/objects/ArrayBufferView.java
浏览文件 @
4ba8f72c
...
...
@@ -42,12 +42,8 @@ abstract class ArrayBufferView extends ScriptObject {
// initialized by nasgen
private
static
PropertyMap
$nasgenmap
$
;
static
PropertyMap
getInitialMap
()
{
return
$nasgenmap
$
;
}
private
ArrayBufferView
(
final
NativeArrayBuffer
buffer
,
final
int
byteOffset
,
final
int
elementLength
,
final
Global
global
)
{
super
(
getInitialMap
()
);
super
(
$nasgenmap
$
);
checkConstructorArgs
(
buffer
,
byteOffset
,
elementLength
);
this
.
setProto
(
getPrototype
(
global
));
this
.
setArray
(
factory
().
createArrayData
(
buffer
,
byteOffset
,
elementLength
));
...
...
src/jdk/nashorn/internal/objects/DataPropertyDescriptor.java
浏览文件 @
4ba8f72c
...
...
@@ -64,12 +64,8 @@ public final class DataPropertyDescriptor extends ScriptObject implements Proper
// initialized by nasgen
private
static
PropertyMap
$nasgenmap
$
;
static
PropertyMap
getInitialMap
()
{
return
$nasgenmap
$
;
}
DataPropertyDescriptor
(
final
boolean
configurable
,
final
boolean
enumerable
,
final
boolean
writable
,
final
Object
value
,
final
Global
global
)
{
super
(
global
.
getObjectPrototype
(),
getInitialMap
()
);
super
(
global
.
getObjectPrototype
(),
$nasgenmap
$
);
this
.
configurable
=
configurable
;
this
.
enumerable
=
enumerable
;
this
.
writable
=
writable
;
...
...
src/jdk/nashorn/internal/objects/GenericPropertyDescriptor.java
浏览文件 @
4ba8f72c
...
...
@@ -55,12 +55,8 @@ public final class GenericPropertyDescriptor extends ScriptObject implements Pro
// initialized by nasgen
private
static
PropertyMap
$nasgenmap
$
;
static
PropertyMap
getInitialMap
()
{
return
$nasgenmap
$
;
}
GenericPropertyDescriptor
(
final
boolean
configurable
,
final
boolean
enumerable
,
final
Global
global
)
{
super
(
global
.
getObjectPrototype
(),
getInitialMap
()
);
super
(
global
.
getObjectPrototype
(),
$nasgenmap
$
);
this
.
configurable
=
configurable
;
this
.
enumerable
=
enumerable
;
}
...
...
src/jdk/nashorn/internal/objects/Global.java
浏览文件 @
4ba8f72c
...
...
@@ -48,7 +48,6 @@ import jdk.nashorn.internal.objects.annotations.ScriptClass;
import
jdk.nashorn.internal.runtime.ConsString
;
import
jdk.nashorn.internal.runtime.Context
;
import
jdk.nashorn.internal.runtime.GlobalFunctions
;
import
jdk.nashorn.internal.runtime.GlobalObject
;
import
jdk.nashorn.internal.runtime.JSType
;
import
jdk.nashorn.internal.runtime.NativeJavaPackage
;
import
jdk.nashorn.internal.runtime.PropertyDescriptor
;
...
...
@@ -70,7 +69,7 @@ import jdk.nashorn.internal.scripts.JO;
* Representation of global scope.
*/
@ScriptClass
(
"Global"
)
public
final
class
Global
extends
ScriptObject
implements
GlobalObject
,
Scope
{
public
final
class
Global
extends
ScriptObject
implements
Scope
{
private
final
InvokeByName
TO_STRING
=
new
InvokeByName
(
"toString"
,
ScriptObject
.
class
);
private
final
InvokeByName
VALUE_OF
=
new
InvokeByName
(
"valueOf"
,
ScriptObject
.
class
);
...
...
@@ -433,11 +432,9 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
* @return the global singleton
*/
public
static
Global
instance
()
{
ScriptObject
global
=
Context
.
getGlobal
();
if
(!
(
global
instanceof
Global
))
{
throw
new
IllegalStateException
(
"no current global instance"
);
}
return
(
Global
)
global
;
Global
global
=
Context
.
getGlobal
();
global
.
getClass
();
// null check
return
global
;
}
/**
...
...
@@ -458,19 +455,30 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
return
instance
().
getContext
();
}
//
GlobalObject interface implementation
//
Runtime interface to Global
@Override
/**
* Is this global of the given Context?
* @param ctxt the context
* @return true if this global belongs to the given Context
*/
public
boolean
isOfContext
(
final
Context
ctxt
)
{
return
this
.
context
==
ctxt
;
}
@Override
/**
* Does this global belong to a strict Context?
* @return true if this global belongs to a strict Context
*/
public
boolean
isStrictContext
()
{
return
context
.
getEnv
().
_strict
;
}
@Override
/**
* Initialize standard builtin objects like "Object", "Array", "Function" etc.
* as well as our extension builtin objects like "Java", "JSAdapter" as properties
* of the global scope object.
*/
public
void
initBuiltinObjects
()
{
if
(
this
.
builtinObject
!=
null
)
{
// already initialized, just return
...
...
@@ -480,12 +488,26 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
init
();
}
@Override
/**
* Create a new ScriptFunction object
*
* @param name function name
* @param handle invocation handle for function
* @param scope the scope
* @param strict are we in strict mode
*
* @return new script function
*/
public
ScriptFunction
newScriptFunction
(
final
String
name
,
final
MethodHandle
handle
,
final
ScriptObject
scope
,
final
boolean
strict
)
{
return
new
ScriptFunctionImpl
(
name
,
handle
,
scope
,
null
,
strict
?
ScriptFunctionData
.
IS_STRICT_CONSTRUCTOR
:
ScriptFunctionData
.
IS_CONSTRUCTOR
);
}
@Override
/**
* Wrap a Java object as corresponding script object
*
* @param obj object to wrap
* @return wrapped object
*/
public
Object
wrapAsObject
(
final
Object
obj
)
{
if
(
obj
instanceof
Boolean
)
{
return
new
NativeBoolean
((
Boolean
)
obj
,
this
);
...
...
@@ -507,7 +529,14 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
}
}
@Override
/**
* Lookup helper for JS primitive types
*
* @param request the link request for the dynamic call site.
* @param self self reference
*
* @return guarded invocation
*/
public
GuardedInvocation
primitiveLookup
(
final
LinkRequest
request
,
final
Object
self
)
{
if
(
self
instanceof
String
||
self
instanceof
ConsString
)
{
return
NativeString
.
lookupPrimitive
(
request
,
self
);
...
...
@@ -519,12 +548,23 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
throw
new
IllegalArgumentException
(
"Unsupported primitive: "
+
self
);
}
@Override
/**
* Create a new empty script object
*
* @return the new ScriptObject
*/
public
ScriptObject
newObject
()
{
return
new
JO
(
getObjectPrototype
(),
JO
.
getInitialMap
());
}
@Override
/**
* Default value of given type
*
* @param sobj script object
* @param typeHint type hint
*
* @return default value
*/
public
Object
getDefaultValue
(
final
ScriptObject
sobj
,
final
Class
<?>
typeHint
)
{
// When the [[DefaultValue]] internal method of O is called with no hint,
// then it behaves as if the hint were Number, unless O is a Date object
...
...
@@ -584,7 +624,12 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
return
UNDEFINED
;
}
@Override
/**
* Is the given ScriptObject an ECMAScript Error object?
*
* @param sobj the object being checked
* @return true if sobj is an Error object
*/
public
boolean
isError
(
final
ScriptObject
sobj
)
{
final
ScriptObject
errorProto
=
getErrorPrototype
();
ScriptObject
proto
=
sobj
.
getProto
();
...
...
@@ -597,52 +642,108 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
return
false
;
}
@Override
/**
* Create a new ECMAScript Error object.
*
* @param msg error message
* @return newly created Error object
*/
public
ScriptObject
newError
(
final
String
msg
)
{
return
new
NativeError
(
msg
,
this
);
}
@Override
/**
* Create a new ECMAScript EvalError object.
*
* @param msg error message
* @return newly created EvalError object
*/
public
ScriptObject
newEvalError
(
final
String
msg
)
{
return
new
NativeEvalError
(
msg
,
this
);
}
@Override
/**
* Create a new ECMAScript RangeError object.
*
* @param msg error message
* @return newly created RangeError object
*/
public
ScriptObject
newRangeError
(
final
String
msg
)
{
return
new
NativeRangeError
(
msg
,
this
);
}
@Override
/**
* Create a new ECMAScript ReferenceError object.
*
* @param msg error message
* @return newly created ReferenceError object
*/
public
ScriptObject
newReferenceError
(
final
String
msg
)
{
return
new
NativeReferenceError
(
msg
,
this
);
}
@Override
/**
* Create a new ECMAScript SyntaxError object.
*
* @param msg error message
* @return newly created SyntaxError object
*/
public
ScriptObject
newSyntaxError
(
final
String
msg
)
{
return
new
NativeSyntaxError
(
msg
,
this
);
}
@Override
/**
* Create a new ECMAScript TypeError object.
*
* @param msg error message
* @return newly created TypeError object
*/
public
ScriptObject
newTypeError
(
final
String
msg
)
{
return
new
NativeTypeError
(
msg
,
this
);
}
@Override
/**
* Create a new ECMAScript URIError object.
*
* @param msg error message
* @return newly created URIError object
*/
public
ScriptObject
newURIError
(
final
String
msg
)
{
return
new
NativeURIError
(
msg
,
this
);
}
@Override
/**
* Create a new ECMAScript GenericDescriptor object.
*
* @param configurable is the property configurable?
* @param enumerable is the property enumerable?
* @return newly created GenericDescriptor object
*/
public
PropertyDescriptor
newGenericDescriptor
(
final
boolean
configurable
,
final
boolean
enumerable
)
{
return
new
GenericPropertyDescriptor
(
configurable
,
enumerable
,
this
);
}
@Override
/**
* Create a new ECMAScript DatePropertyDescriptor object.
*
* @param value of the data property
* @param configurable is the property configurable?
* @param enumerable is the property enumerable?
* @return newly created DataPropertyDescriptor object
*/
public
PropertyDescriptor
newDataDescriptor
(
final
Object
value
,
final
boolean
configurable
,
final
boolean
enumerable
,
final
boolean
writable
)
{
return
new
DataPropertyDescriptor
(
configurable
,
enumerable
,
writable
,
value
,
this
);
}
@Override
/**
* Create a new ECMAScript AccessorPropertyDescriptor object.
*
* @param get getter function of the user accessor property
* @param set setter function of the user accessor property
* @param configurable is the property configurable?
* @param enumerable is the property enumerable?
* @return newly created AccessorPropertyDescriptor object
*/
public
PropertyDescriptor
newAccessorDescriptor
(
final
Object
get
,
final
Object
set
,
final
boolean
configurable
,
final
boolean
enumerable
)
{
final
AccessorPropertyDescriptor
desc
=
new
AccessorPropertyDescriptor
(
configurable
,
enumerable
,
get
==
null
?
UNDEFINED
:
get
,
set
==
null
?
UNDEFINED
:
set
,
this
);
...
...
@@ -675,14 +776,25 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
private
final
Map
<
Object
,
InvokeByName
>
namedInvokers
=
new
ConcurrentHashMap
<>();
@Override
/**
* Get cached InvokeByName object for the given key
* @param key key to be associated with InvokeByName object
* @param creator if InvokeByName is absent 'creator' is called to make one (lazy init)
* @return InvokeByName object associated with the key.
*/
public
InvokeByName
getInvokeByName
(
final
Object
key
,
final
Callable
<
InvokeByName
>
creator
)
{
return
getLazilyCreatedValue
(
key
,
creator
,
namedInvokers
);
}
private
final
Map
<
Object
,
MethodHandle
>
dynamicInvokers
=
new
ConcurrentHashMap
<>();
@Override
/**
* Get cached dynamic method handle for the given key
* @param key key to be associated with dynamic method handle
* @param creator if method handle is absent 'creator' is called to make one (lazy init)
* @return dynamic method handle associated with the key.
*/
public
MethodHandle
getDynamicInvoker
(
final
Object
key
,
final
Callable
<
MethodHandle
>
creator
)
{
return
getLazilyCreatedValue
(
key
,
creator
,
dynamicInvokers
);
}
...
...
src/jdk/nashorn/internal/objects/NativeArray.java
浏览文件 @
4ba8f72c
...
...
@@ -156,10 +156,6 @@ public final class NativeArray extends ScriptObject {
// initialized by nasgen
private
static
PropertyMap
$nasgenmap
$
;
static
PropertyMap
getInitialMap
()
{
return
$nasgenmap
$
;
}
/*
* Constructors.
*/
...
...
@@ -208,7 +204,7 @@ public final class NativeArray extends ScriptObject {
}
NativeArray
(
final
ArrayData
arrayData
,
final
Global
global
)
{
super
(
global
.
getArrayPrototype
(),
getInitialMap
()
);
super
(
global
.
getArrayPrototype
(),
$nasgenmap
$
);
this
.
setArray
(
arrayData
);
this
.
setIsArray
();
}
...
...
src/jdk/nashorn/internal/objects/NativeArrayBuffer.java
浏览文件 @
4ba8f72c
...
...
@@ -44,10 +44,6 @@ final class NativeArrayBuffer extends ScriptObject {
// initialized by nasgen
private
static
PropertyMap
$nasgenmap
$
;
static
PropertyMap
getInitialMap
()
{
return
$nasgenmap
$
;
}
@Constructor
(
arity
=
1
)
public
static
Object
constructor
(
final
boolean
newObj
,
final
Object
self
,
final
Object
...
args
)
{
if
(
args
.
length
==
0
)
{
...
...
@@ -58,7 +54,7 @@ final class NativeArrayBuffer extends ScriptObject {
}
protected
NativeArrayBuffer
(
final
byte
[]
byteArray
,
final
Global
global
)
{
super
(
global
.
getArrayBufferPrototype
(),
getInitialMap
()
);
super
(
global
.
getArrayBufferPrototype
(),
$nasgenmap
$
);
this
.
buffer
=
byteArray
;
}
...
...
src/jdk/nashorn/internal/objects/NativeBoolean.java
浏览文件 @
4ba8f72c
...
...
@@ -59,17 +59,13 @@ public final class NativeBoolean extends ScriptObject {
// initialized by nasgen
private
static
PropertyMap
$nasgenmap
$
;
static
PropertyMap
getInitialMap
()
{
return
$nasgenmap
$
;
}
private
NativeBoolean
(
final
boolean
value
,
final
ScriptObject
proto
,
final
PropertyMap
map
)
{
super
(
proto
,
map
);
this
.
value
=
value
;
}
NativeBoolean
(
final
boolean
flag
,
final
Global
global
)
{
this
(
flag
,
global
.
getBooleanPrototype
(),
getInitialMap
()
);
this
(
flag
,
global
.
getBooleanPrototype
(),
$nasgenmap
$
);
}
NativeBoolean
(
final
boolean
flag
)
{
...
...
src/jdk/nashorn/internal/objects/NativeDate.java
浏览文件 @
4ba8f72c
...
...
@@ -114,10 +114,6 @@ public final class NativeDate extends ScriptObject {
// initialized by nasgen
private
static
PropertyMap
$nasgenmap
$
;
static
PropertyMap
getInitialMap
()
{
return
$nasgenmap
$
;
}
private
NativeDate
(
final
double
time
,
final
ScriptObject
proto
,
final
PropertyMap
map
)
{
super
(
proto
,
map
);
final
ScriptEnvironment
env
=
Global
.
getEnv
();
...
...
@@ -127,7 +123,7 @@ public final class NativeDate extends ScriptObject {
}
NativeDate
(
final
double
time
,
final
Global
global
)
{
this
(
time
,
global
.
getDatePrototype
(),
getInitialMap
()
);
this
(
time
,
global
.
getDatePrototype
(),
$nasgenmap
$
);
}
private
NativeDate
(
final
double
time
)
{
...
...
src/jdk/nashorn/internal/objects/NativeError.java
浏览文件 @
4ba8f72c
...
...
@@ -92,10 +92,6 @@ public final class NativeError extends ScriptObject {
// initialized by nasgen
private
static
PropertyMap
$nasgenmap
$
;
static
PropertyMap
getInitialMap
()
{
return
$nasgenmap
$
;
}
@SuppressWarnings
(
"LeakingThisInConstructor"
)
private
NativeError
(
final
Object
msg
,
final
ScriptObject
proto
,
final
PropertyMap
map
)
{
super
(
proto
,
map
);
...
...
@@ -108,7 +104,7 @@ public final class NativeError extends ScriptObject {
}
NativeError
(
final
Object
msg
,
final
Global
global
)
{
this
(
msg
,
global
.
getErrorPrototype
(),
getInitialMap
()
);
this
(
msg
,
global
.
getErrorPrototype
(),
$nasgenmap
$
);
}
private
NativeError
(
final
Object
msg
)
{
...
...
src/jdk/nashorn/internal/objects/NativeEvalError.java
浏览文件 @
4ba8f72c
...
...
@@ -62,10 +62,6 @@ public final class NativeEvalError extends ScriptObject {
// initialized by nasgen
private
static
PropertyMap
$nasgenmap
$
;
static
PropertyMap
getInitialMap
()
{
return
$nasgenmap
$
;
}
@SuppressWarnings
(
"LeakingThisInConstructor"
)
private
NativeEvalError
(
final
Object
msg
,
final
ScriptObject
proto
,
final
PropertyMap
map
)
{
super
(
proto
,
map
);
...
...
@@ -78,7 +74,7 @@ public final class NativeEvalError extends ScriptObject {
}
NativeEvalError
(
final
Object
msg
,
final
Global
global
)
{
this
(
msg
,
global
.
getEvalErrorPrototype
(),
getInitialMap
()
);
this
(
msg
,
global
.
getEvalErrorPrototype
(),
$nasgenmap
$
);
}
private
NativeEvalError
(
final
Object
msg
)
{
...
...
src/jdk/nashorn/internal/objects/NativeJSAdapter.java
浏览文件 @
4ba8f72c
...
...
@@ -146,10 +146,6 @@ public final class NativeJSAdapter extends ScriptObject {
// initialized by nasgen
private
static
PropertyMap
$nasgenmap
$
;
static
PropertyMap
getInitialMap
()
{
return
$nasgenmap
$
;
}
NativeJSAdapter
(
final
Object
overrides
,
final
ScriptObject
adaptee
,
final
ScriptObject
proto
,
final
PropertyMap
map
)
{
super
(
proto
,
map
);
this
.
adaptee
=
wrapAdaptee
(
adaptee
);
...
...
@@ -577,7 +573,7 @@ public final class NativeJSAdapter extends ScriptObject {
proto
=
global
.
getJSAdapterPrototype
();
}
return
new
NativeJSAdapter
(
overrides
,
(
ScriptObject
)
adaptee
,
(
ScriptObject
)
proto
,
getInitialMap
()
);
return
new
NativeJSAdapter
(
overrides
,
(
ScriptObject
)
adaptee
,
(
ScriptObject
)
proto
,
$nasgenmap
$
);
}
@Override
...
...
src/jdk/nashorn/internal/objects/NativeJavaImporter.java
浏览文件 @
4ba8f72c
...
...
@@ -60,17 +60,13 @@ public final class NativeJavaImporter extends ScriptObject {
// initialized by nasgen
private
static
PropertyMap
$nasgenmap
$
;
static
PropertyMap
getInitialMap
()
{
return
$nasgenmap
$
;
}
private
NativeJavaImporter
(
final
Object
[]
args
,
final
ScriptObject
proto
,
final
PropertyMap
map
)
{
super
(
proto
,
map
);
this
.
args
=
args
;
}
private
NativeJavaImporter
(
final
Object
[]
args
,
final
Global
global
)
{
this
(
args
,
global
.
getJavaImporterPrototype
(),
getInitialMap
()
);
this
(
args
,
global
.
getJavaImporterPrototype
(),
$nasgenmap
$
);
}
private
NativeJavaImporter
(
final
Object
[]
args
)
{
...
...
src/jdk/nashorn/internal/objects/NativeNumber.java
浏览文件 @
4ba8f72c
...
...
@@ -90,10 +90,6 @@ public final class NativeNumber extends ScriptObject {
// initialized by nasgen
private
static
PropertyMap
$nasgenmap
$
;
static
PropertyMap
getInitialMap
()
{
return
$nasgenmap
$
;
}
private
NativeNumber
(
final
double
value
,
final
ScriptObject
proto
,
final
PropertyMap
map
)
{
super
(
proto
,
map
);
this
.
value
=
value
;
...
...
@@ -102,7 +98,7 @@ public final class NativeNumber extends ScriptObject {
}
NativeNumber
(
final
double
value
,
final
Global
global
)
{
this
(
value
,
global
.
getNumberPrototype
(),
getInitialMap
()
);
this
(
value
,
global
.
getNumberPrototype
(),
$nasgenmap
$
);
}
private
NativeNumber
(
final
double
value
)
{
...
...
src/jdk/nashorn/internal/objects/NativeRangeError.java
浏览文件 @
4ba8f72c
...
...
@@ -62,10 +62,6 @@ public final class NativeRangeError extends ScriptObject {
// initialized by nasgen
private
static
PropertyMap
$nasgenmap
$
;
static
PropertyMap
getInitialMap
()
{
return
$nasgenmap
$
;
}
@SuppressWarnings
(
"LeakingThisInConstructor"
)
private
NativeRangeError
(
final
Object
msg
,
final
ScriptObject
proto
,
final
PropertyMap
map
)
{
super
(
proto
,
map
);
...
...
@@ -78,7 +74,7 @@ public final class NativeRangeError extends ScriptObject {
}
NativeRangeError
(
final
Object
msg
,
final
Global
global
)
{
this
(
msg
,
global
.
getRangeErrorPrototype
(),
getInitialMap
()
);
this
(
msg
,
global
.
getRangeErrorPrototype
(),
$nasgenmap
$
);
}
private
NativeRangeError
(
final
Object
msg
)
{
...
...
src/jdk/nashorn/internal/objects/NativeReferenceError.java
浏览文件 @
4ba8f72c
...
...
@@ -62,10 +62,6 @@ public final class NativeReferenceError extends ScriptObject {
// initialized by nasgen
private
static
PropertyMap
$nasgenmap
$
;
static
PropertyMap
getInitialMap
()
{
return
$nasgenmap
$
;
}
@SuppressWarnings
(
"LeakingThisInConstructor"
)
private
NativeReferenceError
(
final
Object
msg
,
final
ScriptObject
proto
,
final
PropertyMap
map
)
{
super
(
proto
,
map
);
...
...
@@ -78,7 +74,7 @@ public final class NativeReferenceError extends ScriptObject {
}
NativeReferenceError
(
final
Object
msg
,
final
Global
global
)
{
this
(
msg
,
global
.
getReferenceErrorPrototype
(),
getInitialMap
()
);
this
(
msg
,
global
.
getReferenceErrorPrototype
(),
$nasgenmap
$
);
}
private
NativeReferenceError
(
final
Object
msg
)
{
...
...
src/jdk/nashorn/internal/objects/NativeRegExp.java
浏览文件 @
4ba8f72c
...
...
@@ -70,12 +70,8 @@ public final class NativeRegExp extends ScriptObject {
// initialized by nasgen
private
static
PropertyMap
$nasgenmap
$
;
static
PropertyMap
getInitialMap
()
{
return
$nasgenmap
$
;
}
private
NativeRegExp
(
final
Global
global
)
{
super
(
global
.
getRegExpPrototype
(),
getInitialMap
()
);
super
(
global
.
getRegExpPrototype
(),
$nasgenmap
$
);
this
.
globalObject
=
global
;
}
...
...
src/jdk/nashorn/internal/objects/NativeRegExpExecResult.java
浏览文件 @
4ba8f72c
...
...
@@ -53,12 +53,8 @@ public final class NativeRegExpExecResult extends ScriptObject {
// initialized by nasgen
private
static
PropertyMap
$nasgenmap
$
;
static
PropertyMap
getInitialMap
()
{
return
$nasgenmap
$
;
}
NativeRegExpExecResult
(
final
RegExpResult
result
,
final
Global
global
)
{
super
(
global
.
getArrayPrototype
(),
getInitialMap
()
);
super
(
global
.
getArrayPrototype
(),
$nasgenmap
$
);
setIsArray
();
this
.
setArray
(
ArrayData
.
allocate
(
result
.
getGroups
().
clone
()));
this
.
index
=
result
.
getIndex
();
...
...
src/jdk/nashorn/internal/objects/NativeString.java
浏览文件 @
4ba8f72c
...
...
@@ -78,16 +78,12 @@ public final class NativeString extends ScriptObject {
// initialized by nasgen
private
static
PropertyMap
$nasgenmap
$
;
static
PropertyMap
getInitialMap
()
{
return
$nasgenmap
$
;
}
private
NativeString
(
final
CharSequence
value
)
{
this
(
value
,
Global
.
instance
());
}
NativeString
(
final
CharSequence
value
,
final
Global
global
)
{
this
(
value
,
global
.
getStringPrototype
(),
getInitialMap
()
);
this
(
value
,
global
.
getStringPrototype
(),
$nasgenmap
$
);
}
private
NativeString
(
final
CharSequence
value
,
final
ScriptObject
proto
,
final
PropertyMap
map
)
{
...
...
src/jdk/nashorn/internal/objects/NativeSyntaxError.java
浏览文件 @
4ba8f72c
...
...
@@ -62,13 +62,9 @@ public final class NativeSyntaxError extends ScriptObject {
// initialized by nasgen
private
static
PropertyMap
$nasgenmap
$
;
static
PropertyMap
getInitialMap
()
{
return
$nasgenmap
$
;
}
@SuppressWarnings
(
"LeakingThisInConstructor"
)
NativeSyntaxError
(
final
Object
msg
,
final
Global
global
)
{
super
(
global
.
getSyntaxErrorPrototype
(),
getInitialMap
()
);
super
(
global
.
getSyntaxErrorPrototype
(),
$nasgenmap
$
);
if
(
msg
!=
UNDEFINED
)
{
this
.
instMessage
=
JSType
.
toString
(
msg
);
}
else
{
...
...
src/jdk/nashorn/internal/objects/NativeTypeError.java
浏览文件 @
4ba8f72c
...
...
@@ -62,13 +62,9 @@ public final class NativeTypeError extends ScriptObject {
// initialized by nasgen
private
static
PropertyMap
$nasgenmap
$
;
static
PropertyMap
getInitialMap
()
{
return
$nasgenmap
$
;
}
@SuppressWarnings
(
"LeakingThisInConstructor"
)
NativeTypeError
(
final
Object
msg
,
final
Global
global
)
{
super
(
global
.
getTypeErrorPrototype
(),
getInitialMap
()
);
super
(
global
.
getTypeErrorPrototype
(),
$nasgenmap
$
);
if
(
msg
!=
UNDEFINED
)
{
this
.
instMessage
=
JSType
.
toString
(
msg
);
}
else
{
...
...
src/jdk/nashorn/internal/objects/NativeURIError.java
浏览文件 @
4ba8f72c
...
...
@@ -61,13 +61,9 @@ public final class NativeURIError extends ScriptObject {
// initialized by nasgen
private
static
PropertyMap
$nasgenmap
$
;
static
PropertyMap
getInitialMap
()
{
return
$nasgenmap
$
;
}
@SuppressWarnings
(
"LeakingThisInConstructor"
)
NativeURIError
(
final
Object
msg
,
final
Global
global
)
{
super
(
global
.
getURIErrorPrototype
(),
getInitialMap
()
);
super
(
global
.
getURIErrorPrototype
(),
$nasgenmap
$
);
if
(
msg
!=
UNDEFINED
)
{
this
.
instMessage
=
JSType
.
toString
(
msg
);
}
else
{
...
...
src/jdk/nashorn/internal/objects/PrototypeObject.java
浏览文件 @
4ba8f72c
...
...
@@ -57,10 +57,6 @@ public class PrototypeObject extends ScriptObject {
map
$
=
PropertyMap
.
newMap
(
properties
);
}
static
PropertyMap
getInitialMap
()
{
return
map
$
;
}
private
PrototypeObject
(
final
Global
global
,
final
PropertyMap
map
)
{
super
(
global
.
getObjectPrototype
(),
map
!=
map
$
?
map
.
addAll
(
map
$
)
:
map
$
);
}
...
...
src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java
浏览文件 @
4ba8f72c
...
...
@@ -55,27 +55,11 @@ public class ScriptFunctionImpl extends ScriptFunction {
// property map for non-strict, non-bound functions.
private
static
final
PropertyMap
map
$
;
static
PropertyMap
getInitialMap
()
{
return
map
$
;
}
static
PropertyMap
getInitialAnonymousMap
()
{
return
AnonymousFunction
.
getInitialMap
();
}
static
PropertyMap
getInitialStrictMap
()
{
return
strictmodemap
$
;
}
static
PropertyMap
getInitialBoundMap
()
{
return
boundfunctionmap
$
;
}
// Marker object for lazily initialized prototype object
private
static
final
Object
LAZY_PROTOTYPE
=
new
Object
();
private
ScriptFunctionImpl
(
final
String
name
,
final
MethodHandle
invokeHandle
,
final
MethodHandle
[]
specs
,
final
Global
global
)
{
super
(
name
,
invokeHandle
,
getInitialMap
()
,
null
,
specs
,
ScriptFunctionData
.
IS_BUILTIN_CONSTRUCTOR
);
super
(
name
,
invokeHandle
,
map
$
,
null
,
specs
,
ScriptFunctionData
.
IS_BUILTIN_CONSTRUCTOR
);
init
(
global
);
}
...
...
@@ -92,7 +76,7 @@ public class ScriptFunctionImpl extends ScriptFunction {
}
private
ScriptFunctionImpl
(
final
String
name
,
final
MethodHandle
invokeHandle
,
final
PropertyMap
map
,
final
MethodHandle
[]
specs
,
final
Global
global
)
{
super
(
name
,
invokeHandle
,
map
.
addAll
(
getInitialMap
()
),
null
,
specs
,
ScriptFunctionData
.
IS_BUILTIN_CONSTRUCTOR
);
super
(
name
,
invokeHandle
,
map
.
addAll
(
map
$
),
null
,
specs
,
ScriptFunctionData
.
IS_BUILTIN_CONSTRUCTOR
);
init
(
global
);
}
...
...
@@ -110,7 +94,7 @@ public class ScriptFunctionImpl extends ScriptFunction {
}
private
ScriptFunctionImpl
(
final
String
name
,
final
MethodHandle
methodHandle
,
final
ScriptObject
scope
,
final
MethodHandle
[]
specs
,
final
int
flags
,
final
Global
global
)
{
super
(
name
,
methodHandle
,
getMap
(
global
,
isStrict
(
flags
)),
scope
,
specs
,
flags
);
super
(
name
,
methodHandle
,
getMap
(
isStrict
(
flags
)),
scope
,
specs
,
flags
);
init
(
global
);
}
...
...
@@ -128,7 +112,7 @@ public class ScriptFunctionImpl extends ScriptFunction {
}
private
ScriptFunctionImpl
(
final
RecompilableScriptFunctionData
data
,
final
ScriptObject
scope
,
final
Global
global
)
{
super
(
data
,
getMap
(
global
,
data
.
isStrict
()),
scope
);
super
(
data
,
getMap
(
data
.
isStrict
()),
scope
);
init
(
global
);
}
...
...
@@ -148,7 +132,7 @@ public class ScriptFunctionImpl extends ScriptFunction {
* @param global the global object
*/
ScriptFunctionImpl
(
final
ScriptFunctionData
data
,
final
Global
global
)
{
super
(
data
,
getInitialBoundMap
()
,
null
);
super
(
data
,
boundfunctionmap
$
,
null
);
init
(
global
);
}
...
...
@@ -176,8 +160,8 @@ public class ScriptFunctionImpl extends ScriptFunction {
}
// Choose the map based on strict mode!
private
static
PropertyMap
getMap
(
final
Global
global
,
final
boolean
strict
)
{
return
strict
?
getInitialStrictMap
()
:
getInitialMap
()
;
private
static
PropertyMap
getMap
(
final
boolean
strict
)
{
return
strict
?
strictmodemap
$
:
map
$
;
}
private
static
PropertyMap
createBoundFunctionMap
(
final
PropertyMap
strictModeMap
)
{
...
...
@@ -191,12 +175,8 @@ public class ScriptFunctionImpl extends ScriptFunction {
private
static
class
AnonymousFunction
extends
ScriptFunctionImpl
{
private
static
final
PropertyMap
anonmap
$
=
PropertyMap
.
newMap
();
static
PropertyMap
getInitialMap
()
{
return
anonmap
$
;
}
AnonymousFunction
(
final
Global
global
)
{
super
(
""
,
GlobalFunctions
.
ANONYMOUS
,
getInitialAnonymousMap
()
,
null
);
super
(
""
,
GlobalFunctions
.
ANONYMOUS
,
anonmap
$
,
null
);
}
}
...
...
src/jdk/nashorn/internal/runtime/Context.java
浏览文件 @
4ba8f72c
...
...
@@ -157,7 +157,7 @@ public final class Context {
/** Is Context global debug mode enabled ? */
public
static
final
boolean
DEBUG
=
Options
.
getBooleanProperty
(
"nashorn.debug"
);
private
static
final
ThreadLocal
<
ScriptObject
>
currentGlobal
=
new
ThreadLocal
<>();
private
static
final
ThreadLocal
<
Global
>
currentGlobal
=
new
ThreadLocal
<>();
// class cache
private
ClassCache
classCache
;
...
...
@@ -166,10 +166,10 @@ public final class Context {
* Get the current global scope
* @return the current global scope
*/
public
static
ScriptObject
getGlobal
()
{
public
static
Global
getGlobal
()
{
// This class in a package.access protected package.
// Trusted code only can call this method.
return
getGlobalTrusted
();
return
currentGlobal
.
get
();
}
/**
...
...
@@ -178,10 +178,19 @@ public final class Context {
*/
public
static
void
setGlobal
(
final
ScriptObject
global
)
{
if
(
global
!=
null
&&
!(
global
instanceof
Global
))
{
throw
new
IllegalArgumentException
(
"
global is not an instance of G
lobal!"
);
throw
new
IllegalArgumentException
(
"
not a g
lobal!"
);
}
setGlobal
((
Global
)
global
);
}
setGlobalTrusted
(
global
);
/**
* Set the current global scope
* @param global the global scope
*/
public
static
void
setGlobal
(
final
Global
global
)
{
// This class in a package.access protected package.
// Trusted code only can call this method.
currentGlobal
.
set
(
global
);
}
/**
...
...
@@ -202,7 +211,7 @@ public final class Context {
* @return error writer of the current context
*/
public
static
PrintWriter
getCurrentErr
()
{
final
ScriptObject
global
=
getGlobal
Trusted
();
final
ScriptObject
global
=
getGlobal
();
return
(
global
!=
null
)?
global
.
getContext
().
getErr
()
:
new
PrintWriter
(
System
.
err
);
}
...
...
@@ -407,7 +416,7 @@ public final class Context {
* @return the property map of the current global scope
*/
public
static
PropertyMap
getGlobalMap
()
{
return
Context
.
getGlobal
Trusted
().
getMap
();
return
Context
.
getGlobal
().
getMap
();
}
/**
...
...
@@ -437,7 +446,7 @@ public final class Context {
final
String
file
=
(
location
==
UNDEFINED
||
location
==
null
)
?
"<eval>"
:
location
.
toString
();
final
Source
source
=
new
Source
(
file
,
string
);
final
boolean
directEval
=
location
!=
UNDEFINED
;
// is this direct 'eval' call or indirectly invoked eval?
final
ScriptObject
global
=
Context
.
getGlobalTrusted
();
final
Global
global
=
Context
.
getGlobal
();
ScriptObject
scope
=
initialScope
;
...
...
@@ -469,7 +478,7 @@ public final class Context {
// in the caller's environment. A new environment is created!
if
(
strictFlag
)
{
// Create a new scope object
final
ScriptObject
strictEvalScope
=
((
GlobalObject
)
global
)
.
newObject
();
final
ScriptObject
strictEvalScope
=
global
.
newObject
();
// bless it as a "scope"
strictEvalScope
.
setIsScope
();
...
...
@@ -594,10 +603,10 @@ public final class Context {
* @throws IOException if source cannot be found or loaded
*/
public
Object
loadWithNewGlobal
(
final
Object
from
,
final
Object
...
args
)
throws
IOException
{
final
ScriptObject
oldGlobal
=
getGlobalTrusted
();
final
ScriptObject
newGlobal
=
AccessController
.
doPrivileged
(
new
PrivilegedAction
<
ScriptObject
>()
{
final
Global
oldGlobal
=
getGlobal
();
final
Global
newGlobal
=
AccessController
.
doPrivileged
(
new
PrivilegedAction
<
Global
>()
{
@Override
public
ScriptObject
run
()
{
public
Global
run
()
{
try
{
return
newGlobal
();
}
catch
(
final
RuntimeException
e
)
{
...
...
@@ -610,17 +619,17 @@ public final class Context {
},
CREATE_GLOBAL_ACC_CTXT
);
// initialize newly created Global instance
initGlobal
(
newGlobal
);
setGlobal
Trusted
(
newGlobal
);
setGlobal
(
newGlobal
);
final
Object
[]
wrapped
=
args
==
null
?
ScriptRuntime
.
EMPTY_ARRAY
:
ScriptObjectMirror
.
wrapArray
(
args
,
oldGlobal
);
newGlobal
.
put
(
"arguments"
,
((
GlobalObject
)
newGlobal
)
.
wrapAsObject
(
wrapped
),
env
.
_strict
);
newGlobal
.
put
(
"arguments"
,
newGlobal
.
wrapAsObject
(
wrapped
),
env
.
_strict
);
try
{
// wrap objects from newGlobal's world as mirrors - but if result
// is from oldGlobal's world, unwrap it!
return
ScriptObjectMirror
.
unwrap
(
ScriptObjectMirror
.
wrap
(
load
(
newGlobal
,
from
),
newGlobal
),
oldGlobal
);
}
finally
{
setGlobal
Trusted
(
oldGlobal
);
setGlobal
(
oldGlobal
);
}
}
...
...
@@ -795,7 +804,7 @@ public final class Context {
*
* @return the initialized global scope object.
*/
public
ScriptObject
createGlobal
()
{
public
Global
createGlobal
()
{
return
initGlobal
(
newGlobal
());
}
...
...
@@ -803,7 +812,7 @@ public final class Context {
* Create a new uninitialized global scope object
* @return the global script object
*/
public
ScriptObject
newGlobal
()
{
public
Global
newGlobal
()
{
return
new
Global
(
this
);
}
...
...
@@ -813,20 +822,16 @@ public final class Context {
* @param global the global
* @return the initialized global scope object.
*/
public
ScriptObject
initGlobal
(
final
ScriptObject
global
)
{
if
(!
(
global
instanceof
GlobalObject
))
{
throw
new
IllegalArgumentException
(
"not a global object!"
);
}
public
Global
initGlobal
(
final
Global
global
)
{
// Need only minimal global object, if we are just compiling.
if
(!
env
.
_compile_only
)
{
final
ScriptObject
oldGlobal
=
Context
.
getGlobalTrusted
();
final
Global
oldGlobal
=
Context
.
getGlobal
();
try
{
Context
.
setGlobal
Trusted
(
global
);
Context
.
setGlobal
(
global
);
// initialize global scope with builtin global objects
((
GlobalObject
)
global
)
.
initBuiltinObjects
();
global
.
initBuiltinObjects
();
}
finally
{
Context
.
setGlobal
Trusted
(
oldGlobal
);
Context
.
setGlobal
(
oldGlobal
);
}
}
...
...
@@ -834,30 +839,15 @@ public final class Context {
}
/**
* Trusted variant
s
- package-private
* Trusted variant - package-private
*/
/**
* Return the current global scope
* @return current global scope
*/
static
ScriptObject
getGlobalTrusted
()
{
return
currentGlobal
.
get
();
}
/**
* Set the current global scope
*/
static
void
setGlobalTrusted
(
ScriptObject
global
)
{
currentGlobal
.
set
(
global
);
}
/**
* Return the current global's context
* @return current global's context
*/
static
Context
getContextTrusted
()
{
return
Context
.
getGlobalTrusted
(
).
getContext
();
return
((
ScriptObject
)
Context
.
getGlobal
()
).
getContext
();
}
/**
...
...
@@ -926,7 +916,7 @@ public final class Context {
}
// Package as a JavaScript function and pass function back to shell.
return
((
GlobalObject
)
Context
.
getGlobalTrusted
()
).
newScriptFunction
(
RUN_SCRIPT
.
symbolName
(),
runMethodHandle
,
scope
,
strict
);
return
Context
.
getGlobal
(
).
newScriptFunction
(
RUN_SCRIPT
.
symbolName
(),
runMethodHandle
,
scope
,
strict
);
}
private
ScriptFunction
compileScript
(
final
Source
source
,
final
ScriptObject
scope
,
final
ErrorManager
errMan
)
{
...
...
src/jdk/nashorn/internal/runtime/DebuggerSupport.java
浏览文件 @
4ba8f72c
...
...
@@ -75,7 +75,7 @@ final class DebuggerSupport {
* @return context global.
*/
static
Object
getGlobal
()
{
return
Context
.
getGlobal
Trusted
();
return
Context
.
getGlobal
();
}
/**
...
...
@@ -87,7 +87,7 @@ final class DebuggerSupport {
* @return Result of eval as string, or, an exception or null depending on returnException.
*/
static
Object
eval
(
final
ScriptObject
scope
,
final
Object
self
,
final
String
string
,
final
boolean
returnException
)
{
final
ScriptObject
global
=
Context
.
getGlobal
Trusted
();
final
ScriptObject
global
=
Context
.
getGlobal
();
final
ScriptObject
initialScope
=
scope
!=
null
?
scope
:
global
;
final
Object
callThis
=
self
!=
null
?
self
:
global
;
final
Context
context
=
global
.
getContext
();
...
...
src/jdk/nashorn/internal/runtime/ECMAErrors.java
浏览文件 @
4ba8f72c
...
...
@@ -31,6 +31,7 @@ import java.util.ResourceBundle;
import
jdk.nashorn.api.scripting.NashornException
;
import
jdk.nashorn.internal.scripts.JS
;
import
jdk.nashorn.internal.codegen.CompilerConstants
;
import
jdk.nashorn.internal.objects.Global
;
/**
* Helper class to throw various standard "ECMA error" exceptions such as Error, ReferenceError, TypeError etc.
...
...
@@ -66,7 +67,7 @@ public final class ECMAErrors {
* @return the resulting {@link ECMAException}
*/
public
static
ECMAException
asEcmaException
(
final
ParserException
e
)
{
return
asEcmaException
(
Context
.
getGlobal
Trusted
(),
e
);
return
asEcmaException
(
Context
.
getGlobal
(),
e
);
}
/**
...
...
@@ -78,11 +79,11 @@ public final class ECMAErrors {
*
* @return the resulting {@link ECMAException}
*/
public
static
ECMAException
asEcmaException
(
final
ScriptObject
global
,
final
ParserException
e
)
{
public
static
ECMAException
asEcmaException
(
final
Global
global
,
final
ParserException
e
)
{
final
JSErrorType
errorType
=
e
.
getErrorType
();
assert
errorType
!=
null
:
"error type for "
+
e
+
" was null"
;
final
Global
Object
globalObj
=
(
GlobalObject
)
global
;
final
Global
globalObj
=
global
;
final
String
msg
=
e
.
getMessage
();
// translate to ECMAScript Error object using error type
...
...
@@ -116,7 +117,7 @@ public final class ECMAErrors {
* @return the resulting {@link ECMAException}
*/
public
static
ECMAException
syntaxError
(
final
String
msgId
,
final
String
...
args
)
{
return
syntaxError
(
Context
.
getGlobal
Trusted
(),
msgId
,
args
);
return
syntaxError
(
Context
.
getGlobal
(),
msgId
,
args
);
}
/**
...
...
@@ -128,7 +129,7 @@ public final class ECMAErrors {
*
* @return the resulting {@link ECMAException}
*/
public
static
ECMAException
syntaxError
(
final
ScriptObject
global
,
final
String
msgId
,
final
String
...
args
)
{
public
static
ECMAException
syntaxError
(
final
Global
global
,
final
String
msgId
,
final
String
...
args
)
{
return
syntaxError
(
global
,
null
,
msgId
,
args
);
}
...
...
@@ -142,7 +143,7 @@ public final class ECMAErrors {
* @return the resulting {@link ECMAException}
*/
public
static
ECMAException
syntaxError
(
final
Throwable
cause
,
final
String
msgId
,
final
String
...
args
)
{
return
syntaxError
(
Context
.
getGlobal
Trusted
(),
cause
,
msgId
,
args
);
return
syntaxError
(
Context
.
getGlobal
(),
cause
,
msgId
,
args
);
}
/**
...
...
@@ -155,9 +156,9 @@ public final class ECMAErrors {
*
* @return the resulting {@link ECMAException}
*/
public
static
ECMAException
syntaxError
(
final
ScriptObject
global
,
final
Throwable
cause
,
final
String
msgId
,
final
String
...
args
)
{
public
static
ECMAException
syntaxError
(
final
Global
global
,
final
Throwable
cause
,
final
String
msgId
,
final
String
...
args
)
{
final
String
msg
=
getMessage
(
"syntax.error."
+
msgId
,
args
);
return
error
(
((
GlobalObject
)
global
)
.
newSyntaxError
(
msg
),
cause
);
return
error
(
global
.
newSyntaxError
(
msg
),
cause
);
}
/**
...
...
@@ -169,7 +170,7 @@ public final class ECMAErrors {
* @return the resulting {@link ECMAException}
*/
public
static
ECMAException
typeError
(
final
String
msgId
,
final
String
...
args
)
{
return
typeError
(
Context
.
getGlobal
Trusted
(),
msgId
,
args
);
return
typeError
(
Context
.
getGlobal
(),
msgId
,
args
);
}
/**
...
...
@@ -181,7 +182,7 @@ public final class ECMAErrors {
*
* @return the resulting {@link ECMAException}
*/
public
static
ECMAException
typeError
(
final
ScriptObject
global
,
final
String
msgId
,
final
String
...
args
)
{
public
static
ECMAException
typeError
(
final
Global
global
,
final
String
msgId
,
final
String
...
args
)
{
return
typeError
(
global
,
null
,
msgId
,
args
);
}
...
...
@@ -195,7 +196,7 @@ public final class ECMAErrors {
* @return the resulting {@link ECMAException}
*/
public
static
ECMAException
typeError
(
final
Throwable
cause
,
final
String
msgId
,
final
String
...
args
)
{
return
typeError
(
Context
.
getGlobal
Trusted
(),
cause
,
msgId
,
args
);
return
typeError
(
Context
.
getGlobal
(),
cause
,
msgId
,
args
);
}
/**
...
...
@@ -208,9 +209,9 @@ public final class ECMAErrors {
*
* @return the resulting {@link ECMAException}
*/
public
static
ECMAException
typeError
(
final
ScriptObject
global
,
final
Throwable
cause
,
final
String
msgId
,
final
String
...
args
)
{
public
static
ECMAException
typeError
(
final
Global
global
,
final
Throwable
cause
,
final
String
msgId
,
final
String
...
args
)
{
final
String
msg
=
getMessage
(
"type.error."
+
msgId
,
args
);
return
error
(
((
GlobalObject
)
global
)
.
newTypeError
(
msg
),
cause
);
return
error
(
global
.
newTypeError
(
msg
),
cause
);
}
/**
...
...
@@ -222,7 +223,7 @@ public final class ECMAErrors {
* @return the resulting {@link ECMAException}
*/
public
static
ECMAException
rangeError
(
final
String
msgId
,
final
String
...
args
)
{
return
rangeError
(
Context
.
getGlobal
Trusted
(),
msgId
,
args
);
return
rangeError
(
Context
.
getGlobal
(),
msgId
,
args
);
}
/**
...
...
@@ -234,7 +235,7 @@ public final class ECMAErrors {
*
* @return the resulting {@link ECMAException}
*/
public
static
ECMAException
rangeError
(
final
ScriptObject
global
,
final
String
msgId
,
final
String
...
args
)
{
public
static
ECMAException
rangeError
(
final
Global
global
,
final
String
msgId
,
final
String
...
args
)
{
return
rangeError
(
global
,
null
,
msgId
,
args
);
}
...
...
@@ -248,7 +249,7 @@ public final class ECMAErrors {
* @return the resulting {@link ECMAException}
*/
public
static
ECMAException
rangeError
(
final
Throwable
cause
,
final
String
msgId
,
final
String
...
args
)
{
return
rangeError
(
Context
.
getGlobal
Trusted
(),
cause
,
msgId
,
args
);
return
rangeError
(
Context
.
getGlobal
(),
cause
,
msgId
,
args
);
}
/**
...
...
@@ -261,9 +262,9 @@ public final class ECMAErrors {
*
* @return the resulting {@link ECMAException}
*/
public
static
ECMAException
rangeError
(
final
ScriptObject
global
,
final
Throwable
cause
,
final
String
msgId
,
final
String
...
args
)
{
public
static
ECMAException
rangeError
(
final
Global
global
,
final
Throwable
cause
,
final
String
msgId
,
final
String
...
args
)
{
final
String
msg
=
getMessage
(
"range.error."
+
msgId
,
args
);
return
error
(
((
GlobalObject
)
global
)
.
newRangeError
(
msg
),
cause
);
return
error
(
global
.
newRangeError
(
msg
),
cause
);
}
/**
...
...
@@ -275,7 +276,7 @@ public final class ECMAErrors {
* @return the resulting {@link ECMAException}
*/
public
static
ECMAException
referenceError
(
final
String
msgId
,
final
String
...
args
)
{
return
referenceError
(
Context
.
getGlobal
Trusted
(),
msgId
,
args
);
return
referenceError
(
Context
.
getGlobal
(),
msgId
,
args
);
}
/**
...
...
@@ -287,7 +288,7 @@ public final class ECMAErrors {
*
* @return the resulting {@link ECMAException}
*/
public
static
ECMAException
referenceError
(
final
ScriptObject
global
,
final
String
msgId
,
final
String
...
args
)
{
public
static
ECMAException
referenceError
(
final
Global
global
,
final
String
msgId
,
final
String
...
args
)
{
return
referenceError
(
global
,
null
,
msgId
,
args
);
}
...
...
@@ -301,7 +302,7 @@ public final class ECMAErrors {
* @return the resulting {@link ECMAException}
*/
public
static
ECMAException
referenceError
(
final
Throwable
cause
,
final
String
msgId
,
final
String
...
args
)
{
return
referenceError
(
Context
.
getGlobal
Trusted
(),
cause
,
msgId
,
args
);
return
referenceError
(
Context
.
getGlobal
(),
cause
,
msgId
,
args
);
}
/**
...
...
@@ -314,9 +315,9 @@ public final class ECMAErrors {
*
* @return the resulting {@link ECMAException}
*/
public
static
ECMAException
referenceError
(
final
ScriptObject
global
,
final
Throwable
cause
,
final
String
msgId
,
final
String
...
args
)
{
public
static
ECMAException
referenceError
(
final
Global
global
,
final
Throwable
cause
,
final
String
msgId
,
final
String
...
args
)
{
final
String
msg
=
getMessage
(
"reference.error."
+
msgId
,
args
);
return
error
(
((
GlobalObject
)
global
)
.
newReferenceError
(
msg
),
cause
);
return
error
(
global
.
newReferenceError
(
msg
),
cause
);
}
/**
...
...
@@ -328,7 +329,7 @@ public final class ECMAErrors {
* @return the resulting {@link ECMAException}
*/
public
static
ECMAException
uriError
(
final
String
msgId
,
final
String
...
args
)
{
return
uriError
(
Context
.
getGlobal
Trusted
(),
msgId
,
args
);
return
uriError
(
Context
.
getGlobal
(),
msgId
,
args
);
}
/**
...
...
@@ -340,7 +341,7 @@ public final class ECMAErrors {
*
* @return the resulting {@link ECMAException}
*/
public
static
ECMAException
uriError
(
final
ScriptObject
global
,
final
String
msgId
,
final
String
...
args
)
{
public
static
ECMAException
uriError
(
final
Global
global
,
final
String
msgId
,
final
String
...
args
)
{
return
uriError
(
global
,
null
,
msgId
,
args
);
}
...
...
@@ -354,7 +355,7 @@ public final class ECMAErrors {
* @return the resulting {@link ECMAException}
*/
public
static
ECMAException
uriError
(
final
Throwable
cause
,
final
String
msgId
,
final
String
...
args
)
{
return
uriError
(
Context
.
getGlobal
Trusted
(),
cause
,
msgId
,
args
);
return
uriError
(
Context
.
getGlobal
(),
cause
,
msgId
,
args
);
}
/**
...
...
@@ -367,9 +368,9 @@ public final class ECMAErrors {
*
* @return the resulting {@link ECMAException}
*/
public
static
ECMAException
uriError
(
final
ScriptObject
global
,
final
Throwable
cause
,
final
String
msgId
,
final
String
...
args
)
{
public
static
ECMAException
uriError
(
final
Global
global
,
final
Throwable
cause
,
final
String
msgId
,
final
String
...
args
)
{
final
String
msg
=
getMessage
(
"uri.error."
+
msgId
,
args
);
return
error
(
((
GlobalObject
)
global
)
.
newURIError
(
msg
),
cause
);
return
error
(
global
.
newURIError
(
msg
),
cause
);
}
/**
...
...
src/jdk/nashorn/internal/runtime/GlobalObject.java
已删除
100644 → 0
浏览文件 @
7224aa68
/*
* 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
package
jdk.nashorn.internal.runtime
;
import
java.lang.invoke.MethodHandle
;
import
java.util.concurrent.Callable
;
import
jdk.internal.dynalink.linker.GuardedInvocation
;
import
jdk.internal.dynalink.linker.LinkRequest
;
import
jdk.nashorn.internal.runtime.linker.InvokeByName
;
/**
* Runtime interface to the global scope objects.
*/
public
interface
GlobalObject
{
/**
* Is this global of the given Context?
* @param ctxt the context
* @return true if this global belongs to the given Context
*/
public
boolean
isOfContext
(
final
Context
ctxt
);
/**
* Does this global belong to a strict Context?
* @return true if this global belongs to a strict Context
*/
public
boolean
isStrictContext
();
/**
* Initialize standard builtin objects like "Object", "Array", "Function" etc.
* as well as our extension builtin objects like "Java", "JSAdapter" as properties
* of the global scope object.
*/
public
void
initBuiltinObjects
();
/**
* Wrapper for {@link jdk.nashorn.internal.objects.Global#newScriptFunction(String, MethodHandle, ScriptObject, boolean)}
*
* @param name function name
* @param handle invocation handle for function
* @param scope the scope
* @param strict are we in strict mode
*
* @return new script function
*/
public
ScriptFunction
newScriptFunction
(
String
name
,
MethodHandle
handle
,
ScriptObject
scope
,
boolean
strict
);
/**
* Wrapper for {@link jdk.nashorn.internal.objects.Global#wrapAsObject(Object)}
*
* @param obj object to wrap
* @return wrapped object
*/
public
Object
wrapAsObject
(
Object
obj
);
/**
* Wrapper for {@link jdk.nashorn.internal.objects.Global#primitiveLookup(LinkRequest, Object)}
*
* @param request the link request for the dynamic call site.
* @param self self reference
*
* @return guarded invocation
*/
public
GuardedInvocation
primitiveLookup
(
LinkRequest
request
,
Object
self
);
/**
* Wrapper for {@link jdk.nashorn.internal.objects.Global#newObject()}
*
* @return the new ScriptObject
*/
public
ScriptObject
newObject
();
/**
* Wrapper for {@link jdk.nashorn.internal.objects.Global#isError(ScriptObject)}
*
* @param sobj to check if it is an error object
* @return true if error object
*/
public
boolean
isError
(
ScriptObject
sobj
);
/**
* Wrapper for {@link jdk.nashorn.internal.objects.Global#newError(String)}
*
* @param msg the error message
*
* @return the new ScriptObject representing the error
*/
public
ScriptObject
newError
(
String
msg
);
/**
* Wrapper for {@link jdk.nashorn.internal.objects.Global#newEvalError(String)}
*
* @param msg the error message
*
* @return the new ScriptObject representing the eval error
*/
public
ScriptObject
newEvalError
(
String
msg
);
/**
* Wrapper for {@link jdk.nashorn.internal.objects.Global#newRangeError(String)}
*
* @param msg the error message
*
* @return the new ScriptObject representing the range error
*/
public
ScriptObject
newRangeError
(
String
msg
);
/**
* Wrapper for {@link jdk.nashorn.internal.objects.Global#newReferenceError(String)}
*
* @param msg the error message
*
* @return the new ScriptObject representing the reference error
*/
public
ScriptObject
newReferenceError
(
String
msg
);
/**
* Wrapper for {@link jdk.nashorn.internal.objects.Global#newSyntaxError(String)}
*
* @param msg the error message
*
* @return the new ScriptObject representing the syntax error
*/
public
ScriptObject
newSyntaxError
(
String
msg
);
/**
* Wrapper for {@link jdk.nashorn.internal.objects.Global#newTypeError(String)}
*
* @param msg the error message
*
* @return the new ScriptObject representing the type error
*/
public
ScriptObject
newTypeError
(
String
msg
);
/**
* Wrapper for {@link jdk.nashorn.internal.objects.Global#newURIError(String)}
*
* @param msg the error message
*
* @return the new ScriptObject representing the URI error
*/
public
ScriptObject
newURIError
(
String
msg
);
/**
* Wrapper for {@link jdk.nashorn.internal.objects.Global#newGenericDescriptor(boolean, boolean)}
*
* @param configurable is the described property configurable
* @param enumerable is the described property enumerable
*
* @return property descriptor
*/
public
PropertyDescriptor
newGenericDescriptor
(
boolean
configurable
,
boolean
enumerable
);
/**
* Wrapper for {@link jdk.nashorn.internal.objects.Global#newDataDescriptor(Object, boolean, boolean, boolean)}
*
* @param value data value
* @param configurable is the described property configurable
* @param enumerable is the described property enumerable
* @param writable is the described property writable
*
* @return property descriptor
*/
public
PropertyDescriptor
newDataDescriptor
(
Object
value
,
boolean
configurable
,
boolean
enumerable
,
boolean
writable
);
/**
* Wrapper for {@link jdk.nashorn.internal.objects.Global#newAccessorDescriptor(Object, Object, boolean, boolean)}
*
* @param get property getter, or null if none
* @param set property setter, or null if none
* @param configurable is the described property configurable
* @param enumerable is the described property enumerable
*
* @return property descriptor
*/
public
PropertyDescriptor
newAccessorDescriptor
(
Object
get
,
Object
set
,
boolean
configurable
,
boolean
enumerable
);
/**
* Wrapper for {@link jdk.nashorn.internal.objects.Global#getDefaultValue(ScriptObject, Class)}
*
* @param sobj script object
* @param typeHint type hint
*
* @return default value
*/
public
Object
getDefaultValue
(
ScriptObject
sobj
,
Class
<?>
typeHint
);
/**
* Get cached InvokeByName object for the given key
* @param key key to be associated with InvokeByName object
* @param creator if InvokeByName is absent 'creator' is called to make one (lazy init)
* @return InvokeByName object associated with the key.
*/
public
InvokeByName
getInvokeByName
(
final
Object
key
,
final
Callable
<
InvokeByName
>
creator
);
/**
* Get cached dynamic method handle for the given key
* @param key key to be associated with dynamic method handle
* @param creator if method handle is absent 'creator' is called to make one (lazy init)
* @return dynamic method handle associated with the key.
*/
public
MethodHandle
getDynamicInvoker
(
final
Object
key
,
final
Callable
<
MethodHandle
>
creator
);
}
src/jdk/nashorn/internal/runtime/JSONFunctions.java
浏览文件 @
4ba8f72c
...
...
@@ -33,6 +33,7 @@ import jdk.nashorn.internal.ir.Node;
import
jdk.nashorn.internal.ir.ObjectNode
;
import
jdk.nashorn.internal.ir.PropertyNode
;
import
jdk.nashorn.internal.ir.UnaryNode
;
import
jdk.nashorn.internal.objects.Global
;
import
jdk.nashorn.internal.parser.JSONParser
;
import
jdk.nashorn.internal.parser.TokenType
;
import
jdk.nashorn.internal.runtime.arrays.ArrayIndex
;
...
...
@@ -47,7 +48,7 @@ public final class JSONFunctions {
private
static
final
Object
REVIVER_INVOKER
=
new
Object
();
private
static
MethodHandle
getREVIVER_INVOKER
()
{
return
((
GlobalObject
)
Context
.
getGlobal
()
).
getDynamicInvoker
(
REVIVER_INVOKER
,
return
Context
.
getGlobal
(
).
getDynamicInvoker
(
REVIVER_INVOKER
,
new
Callable
<
MethodHandle
>()
{
@Override
public
MethodHandle
call
()
{
...
...
@@ -88,7 +89,7 @@ public final class JSONFunctions {
throw
ECMAErrors
.
syntaxError
(
e
,
"invalid.json"
,
e
.
getMessage
());
}
final
ScriptObject
global
=
Context
.
getGlobalTrusted
();
final
Global
global
=
Context
.
getGlobal
();
Object
unfiltered
=
convertNode
(
global
,
node
);
return
applyReviver
(
global
,
unfiltered
,
reviver
);
}
...
...
@@ -98,10 +99,10 @@ public final class JSONFunctions {
// parse helpers
// apply 'reviver' function if available
private
static
Object
applyReviver
(
final
ScriptObject
global
,
final
Object
unfiltered
,
final
Object
reviver
)
{
private
static
Object
applyReviver
(
final
Global
global
,
final
Object
unfiltered
,
final
Object
reviver
)
{
if
(
reviver
instanceof
ScriptFunction
)
{
assert
global
instanceof
Global
Object
;
final
ScriptObject
root
=
((
GlobalObject
)
global
)
.
newObject
();
assert
global
instanceof
Global
;
final
ScriptObject
root
=
global
.
newObject
();
root
.
addOwnProperty
(
""
,
Property
.
WRITABLE_ENUMERABLE_CONFIGURABLE
,
unfiltered
);
return
walk
(
root
,
""
,
(
ScriptFunction
)
reviver
);
}
...
...
@@ -138,8 +139,8 @@ public final class JSONFunctions {
}
// Converts IR node to runtime value
private
static
Object
convertNode
(
final
ScriptObject
global
,
final
Node
node
)
{
assert
global
instanceof
Global
Object
;
private
static
Object
convertNode
(
final
Global
global
,
final
Node
node
)
{
assert
global
instanceof
Global
;
if
(
node
instanceof
LiteralNode
)
{
// check for array literal
...
...
@@ -157,7 +158,7 @@ public final class JSONFunctions {
for
(
final
Node
elem
:
elements
)
{
values
[
index
++]
=
JSType
.
toNumber
(
convertNode
(
global
,
elem
));
}
return
((
GlobalObject
)
global
)
.
wrapAsObject
(
values
);
return
global
.
wrapAsObject
(
values
);
}
final
Object
[]
values
=
new
Object
[
elements
.
length
];
...
...
@@ -167,14 +168,14 @@ public final class JSONFunctions {
values
[
index
++]
=
convertNode
(
global
,
elem
);
}
return
((
GlobalObject
)
global
)
.
wrapAsObject
(
values
);
return
global
.
wrapAsObject
(
values
);
}
return
((
LiteralNode
<?>)
node
).
getValue
();
}
else
if
(
node
instanceof
ObjectNode
)
{
final
ObjectNode
objNode
=
(
ObjectNode
)
node
;
final
ScriptObject
object
=
((
GlobalObject
)
global
)
.
newObject
();
final
ScriptObject
object
=
global
.
newObject
();
for
(
final
PropertyNode
pNode:
objNode
.
getElements
())
{
final
Node
valueNode
=
pNode
.
getValue
();
...
...
src/jdk/nashorn/internal/runtime/JSType.java
浏览文件 @
4ba8f72c
...
...
@@ -36,6 +36,7 @@ import java.util.List;
import
jdk.internal.dynalink.beans.StaticClass
;
import
jdk.nashorn.api.scripting.JSObject
;
import
jdk.nashorn.internal.codegen.CompilerConstants.Call
;
import
jdk.nashorn.internal.objects.Global
;
import
jdk.nashorn.internal.parser.Lexer
;
import
jdk.nashorn.internal.runtime.arrays.ArrayLikeIterator
;
import
jdk.nashorn.internal.runtime.linker.Bootstrap
;
...
...
@@ -852,7 +853,7 @@ public enum JSType {
* @return the wrapped object
*/
public
static
Object
toScriptObject
(
final
Object
obj
)
{
return
toScriptObject
(
Context
.
getGlobal
Trusted
(),
obj
);
return
toScriptObject
(
Context
.
getGlobal
(),
obj
);
}
/**
...
...
@@ -865,7 +866,7 @@ public enum JSType {
*
* @return the wrapped object
*/
public
static
Object
toScriptObject
(
final
ScriptObject
global
,
final
Object
obj
)
{
public
static
Object
toScriptObject
(
final
Global
global
,
final
Object
obj
)
{
if
(
nullOrUndefined
(
obj
))
{
throw
typeError
(
global
,
"not.an.object"
,
ScriptRuntime
.
safeToString
(
obj
));
}
...
...
@@ -874,7 +875,7 @@ public enum JSType {
return
obj
;
}
return
((
GlobalObject
)
global
)
.
wrapAsObject
(
obj
);
return
global
.
wrapAsObject
(
obj
);
}
/**
...
...
@@ -984,7 +985,7 @@ public enum JSType {
if
(
obj
instanceof
ScriptObject
)
{
if
(
safe
)
{
final
ScriptObject
sobj
=
(
ScriptObject
)
obj
;
final
Global
Object
gobj
=
(
GlobalObject
)
Context
.
getGlobalTrusted
();
final
Global
gobj
=
Context
.
getGlobal
();
return
gobj
.
isError
(
sobj
)
?
ECMAException
.
safeToString
(
sobj
)
:
sobj
.
safeToString
();
...
...
src/jdk/nashorn/internal/runtime/ListAdapter.java
浏览文件 @
4ba8f72c
...
...
@@ -34,6 +34,7 @@ import java.util.RandomAccess;
import
java.util.concurrent.Callable
;
import
jdk.nashorn.api.scripting.JSObject
;
import
jdk.nashorn.api.scripting.ScriptObjectMirror
;
import
jdk.nashorn.internal.objects.Global
;
import
jdk.nashorn.internal.runtime.linker.Bootstrap
;
import
jdk.nashorn.internal.runtime.linker.InvokeByName
;
...
...
@@ -54,7 +55,7 @@ public abstract class ListAdapter extends AbstractList<Object> implements Random
// These add to the back and front of the list
private
static
final
Object
PUSH
=
new
Object
();
private
static
InvokeByName
getPUSH
()
{
return
((
GlobalObject
)
Context
.
getGlobal
()
).
getInvokeByName
(
PUSH
,
return
Context
.
getGlobal
(
).
getInvokeByName
(
PUSH
,
new
Callable
<
InvokeByName
>()
{
@Override
public
InvokeByName
call
()
{
...
...
@@ -65,7 +66,7 @@ public abstract class ListAdapter extends AbstractList<Object> implements Random
private
static
final
Object
UNSHIFT
=
new
Object
();
private
static
InvokeByName
getUNSHIFT
()
{
return
((
GlobalObject
)
Context
.
getGlobal
()
).
getInvokeByName
(
UNSHIFT
,
return
Context
.
getGlobal
(
).
getInvokeByName
(
UNSHIFT
,
new
Callable
<
InvokeByName
>()
{
@Override
public
InvokeByName
call
()
{
...
...
@@ -77,7 +78,7 @@ public abstract class ListAdapter extends AbstractList<Object> implements Random
// These remove from the back and front of the list
private
static
final
Object
POP
=
new
Object
();
private
static
InvokeByName
getPOP
()
{
return
((
GlobalObject
)
Context
.
getGlobal
()
).
getInvokeByName
(
POP
,
return
Context
.
getGlobal
(
).
getInvokeByName
(
POP
,
new
Callable
<
InvokeByName
>()
{
@Override
public
InvokeByName
call
()
{
...
...
@@ -88,7 +89,7 @@ public abstract class ListAdapter extends AbstractList<Object> implements Random
private
static
final
Object
SHIFT
=
new
Object
();
private
static
InvokeByName
getSHIFT
()
{
return
((
GlobalObject
)
Context
.
getGlobal
()
).
getInvokeByName
(
SHIFT
,
return
Context
.
getGlobal
(
).
getInvokeByName
(
SHIFT
,
new
Callable
<
InvokeByName
>()
{
@Override
public
InvokeByName
call
()
{
...
...
@@ -100,7 +101,7 @@ public abstract class ListAdapter extends AbstractList<Object> implements Random
// These insert and remove in the middle of the list
private
static
final
Object
SPLICE_ADD
=
new
Object
();
private
static
InvokeByName
getSPLICE_ADD
()
{
return
((
GlobalObject
)
Context
.
getGlobal
()
).
getInvokeByName
(
SPLICE_ADD
,
return
Context
.
getGlobal
(
).
getInvokeByName
(
SPLICE_ADD
,
new
Callable
<
InvokeByName
>()
{
@Override
public
InvokeByName
call
()
{
...
...
@@ -111,7 +112,7 @@ public abstract class ListAdapter extends AbstractList<Object> implements Random
private
static
final
Object
SPLICE_REMOVE
=
new
Object
();
private
static
InvokeByName
getSPLICE_REMOVE
()
{
return
((
GlobalObject
)
Context
.
getGlobal
()
).
getInvokeByName
(
SPLICE_REMOVE
,
return
Context
.
getGlobal
(
).
getInvokeByName
(
SPLICE_REMOVE
,
new
Callable
<
InvokeByName
>()
{
@Override
public
InvokeByName
call
()
{
...
...
src/jdk/nashorn/internal/runtime/NativeJavaPackage.java
浏览文件 @
4ba8f72c
...
...
@@ -35,7 +35,6 @@ import jdk.internal.dynalink.linker.LinkRequest;
import
jdk.internal.dynalink.support.Guards
;
import
jdk.nashorn.internal.lookup.MethodHandleFactory
;
import
jdk.nashorn.internal.lookup.MethodHandleFunctionality
;
import
jdk.nashorn.internal.objects.NativeJava
;
import
jdk.nashorn.internal.objects.annotations.Attribute
;
import
jdk.nashorn.internal.objects.annotations.Function
;
...
...
@@ -52,7 +51,7 @@ import jdk.nashorn.internal.objects.annotations.Function;
* var ArrayList = java.util.ArrayList
* var list = new ArrayList
* </pre>
* You can also use {@link NativeJava#type(Object, Object)} to access Java classes. These two statements are mostly
* You can also use {@link
jdk.nashorn.internal.objects.
NativeJava#type(Object, Object)} to access Java classes. These two statements are mostly
* equivalent:
* <pre>
* var listType1 = java.util.ArrayList
...
...
src/jdk/nashorn/internal/runtime/ParserException.java
浏览文件 @
4ba8f72c
...
...
@@ -26,6 +26,7 @@
package
jdk.nashorn.internal.runtime
;
import
jdk.nashorn.api.scripting.NashornException
;
import
jdk.nashorn.internal.objects.Global
;
import
jdk.nashorn.internal.parser.Token
;
/**
...
...
@@ -110,7 +111,7 @@ public final class ParserException extends NashornException {
* Throw this {@code ParserException} as one of the 7 native JavaScript errors
* @param global global scope object
*/
public
void
throwAsEcmaException
(
final
ScriptObject
global
)
{
public
void
throwAsEcmaException
(
final
Global
global
)
{
throw
ECMAErrors
.
asEcmaException
(
global
,
this
);
}
}
...
...
src/jdk/nashorn/internal/runtime/ScriptFunction.java
浏览文件 @
4ba8f72c
...
...
@@ -38,6 +38,7 @@ import jdk.internal.dynalink.linker.GuardedInvocation;
import
jdk.internal.dynalink.linker.LinkRequest
;
import
jdk.nashorn.internal.codegen.CompilerConstants.Call
;
import
jdk.nashorn.internal.lookup.MethodHandleFactory
;
import
jdk.nashorn.internal.objects.Global
;
import
jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor
;
import
jdk.nashorn.internal.runtime.linker.NashornGuards
;
...
...
@@ -475,14 +476,14 @@ public abstract class ScriptFunction extends ScriptObject {
if
(
obj
instanceof
ScriptObject
||
!
ScriptFunctionData
.
isPrimitiveThis
(
obj
))
{
return
obj
;
}
return
((
GlobalObject
)
Context
.
getGlobalTrusted
()
).
wrapAsObject
(
obj
);
return
Context
.
getGlobal
(
).
wrapAsObject
(
obj
);
}
@SuppressWarnings
(
"unused"
)
private
static
Object
globalFilter
(
final
Object
object
)
{
// replace whatever we get with the current global object
return
Context
.
getGlobal
Trusted
();
return
Context
.
getGlobal
();
}
/**
...
...
src/jdk/nashorn/internal/runtime/ScriptFunctionData.java
浏览文件 @
4ba8f72c
...
...
@@ -32,6 +32,7 @@ import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
import
java.lang.invoke.MethodHandle
;
import
java.lang.invoke.MethodHandles
;
import
java.lang.invoke.MethodType
;
import
jdk.nashorn.internal.objects.Global
;
import
jdk.nashorn.internal.runtime.linker.JavaAdapterFactory
;
/**
...
...
@@ -372,11 +373,11 @@ public abstract class ScriptFunctionData {
private
Object
convertThisObject
(
final
Object
thiz
)
{
if
(!(
thiz
instanceof
ScriptObject
)
&&
needsWrappedThis
())
{
if
(
JSType
.
nullOrUndefined
(
thiz
))
{
return
Context
.
getGlobal
Trusted
();
return
Context
.
getGlobal
();
}
if
(
isPrimitiveThis
(
thiz
))
{
return
((
GlobalObject
)
Context
.
getGlobalTrusted
()
).
wrapAsObject
(
thiz
);
return
Context
.
getGlobal
(
).
wrapAsObject
(
thiz
);
}
}
...
...
src/jdk/nashorn/internal/runtime/ScriptObject.java
浏览文件 @
4ba8f72c
...
...
@@ -325,18 +325,18 @@ public abstract class ScriptObject implements PropertyAccess {
* @return property descriptor
*/
public
final
PropertyDescriptor
toPropertyDescriptor
()
{
final
Global
Object
global
=
(
GlobalObject
)
Context
.
getGlobalTrusted
();
final
Global
global
=
Context
.
getGlobal
();
final
PropertyDescriptor
desc
;
if
(
isDataDescriptor
())
{
if
(
has
(
SET
)
||
has
(
GET
))
{
throw
typeError
(
(
ScriptObject
)
global
,
"inconsistent.property.descriptor"
);
throw
typeError
(
global
,
"inconsistent.property.descriptor"
);
}
desc
=
global
.
newDataDescriptor
(
UNDEFINED
,
false
,
false
,
false
);
}
else
if
(
isAccessorDescriptor
())
{
if
(
has
(
VALUE
)
||
has
(
WRITABLE
))
{
throw
typeError
(
(
ScriptObject
)
global
,
"inconsistent.property.descriptor"
);
throw
typeError
(
global
,
"inconsistent.property.descriptor"
);
}
desc
=
global
.
newAccessorDescriptor
(
UNDEFINED
,
UNDEFINED
,
false
,
false
);
...
...
@@ -355,7 +355,7 @@ public abstract class ScriptObject implements PropertyAccess {
*
* @return property descriptor
*/
public
static
PropertyDescriptor
toPropertyDescriptor
(
final
ScriptObject
global
,
final
Object
obj
)
{
public
static
PropertyDescriptor
toPropertyDescriptor
(
final
Global
global
,
final
Object
obj
)
{
if
(
obj
instanceof
ScriptObject
)
{
return
((
ScriptObject
)
obj
).
toPropertyDescriptor
();
}
...
...
@@ -374,7 +374,7 @@ public abstract class ScriptObject implements PropertyAccess {
public
Object
getOwnPropertyDescriptor
(
final
String
key
)
{
final
Property
property
=
getMap
().
findProperty
(
key
);
final
Global
Object
global
=
(
GlobalObject
)
Context
.
getGlobalTrusted
();
final
Global
global
=
Context
.
getGlobal
();
if
(
property
!=
null
)
{
final
ScriptFunction
get
=
property
.
getGetterFunction
(
this
);
...
...
@@ -439,7 +439,7 @@ public abstract class ScriptObject implements PropertyAccess {
* @return true if property was successfully defined
*/
public
boolean
defineOwnProperty
(
final
String
key
,
final
Object
propertyDesc
,
final
boolean
reject
)
{
final
ScriptObject
global
=
Context
.
getGlobalTrusted
();
final
Global
global
=
Context
.
getGlobal
();
final
PropertyDescriptor
desc
=
toPropertyDescriptor
(
global
,
propertyDesc
);
final
Object
current
=
getOwnPropertyDescriptor
(
key
);
final
String
name
=
JSType
.
toString
(
key
);
...
...
@@ -637,7 +637,7 @@ public abstract class ScriptObject implements PropertyAccess {
final
int
propFlags
=
Property
.
toFlags
(
pdesc
);
if
(
pdesc
.
type
()
==
PropertyDescriptor
.
GENERIC
)
{
final
Global
Object
global
=
(
GlobalObject
)
Context
.
getGlobalTrusted
();
final
Global
global
=
Context
.
getGlobal
();
final
PropertyDescriptor
dDesc
=
global
.
newDataDescriptor
(
UNDEFINED
,
false
,
false
,
false
);
dDesc
.
fillFrom
((
ScriptObject
)
pdesc
);
...
...
@@ -1150,7 +1150,7 @@ public abstract class ScriptObject implements PropertyAccess {
}
setProto
((
ScriptObject
)
newProto
);
}
else
{
final
ScriptObject
global
=
Context
.
getGlobalTrusted
();
final
Global
global
=
Context
.
getGlobal
();
final
Object
newProtoObject
=
JSType
.
toScriptObject
(
global
,
newProto
);
if
(
newProtoObject
instanceof
ScriptObject
)
{
...
...
@@ -1240,11 +1240,11 @@ public abstract class ScriptObject implements PropertyAccess {
* @return the default value
*/
public
Object
getDefaultValue
(
final
Class
<?>
typeHint
)
{
// We delegate to Global
Object
, as the implementation uses dynamic call sites to invoke object's "toString" and
// We delegate to Global, as the implementation uses dynamic call sites to invoke object's "toString" and
// "valueOf" methods, and in order to avoid those call sites from becoming megamorphic when multiple contexts
// are being executed in a long-running program, we move the code and their associated dynamic call sites
// (Global.TO_STRING and Global.VALUE_OF) into per-context code.
return
((
GlobalObject
)
Context
.
getGlobalTrusted
()
).
getDefaultValue
(
this
,
typeHint
);
return
Context
.
getGlobal
(
).
getDefaultValue
(
this
,
typeHint
);
}
/**
...
...
src/jdk/nashorn/internal/runtime/ScriptRuntime.java
浏览文件 @
4ba8f72c
...
...
@@ -474,7 +474,7 @@ public final class ScriptRuntime {
* @return {@link WithObject} that is the new scope
*/
public
static
ScriptObject
openWith
(
final
ScriptObject
scope
,
final
Object
expression
)
{
final
ScriptObject
global
=
Context
.
getGlobalTrusted
();
final
Global
global
=
Context
.
getGlobal
();
if
(
expression
==
UNDEFINED
)
{
throw
typeError
(
global
,
"cant.apply.with.to.undefined"
);
}
else
if
(
expression
==
null
)
{
...
...
src/jdk/nashorn/internal/runtime/SetMethodCreator.java
浏览文件 @
4ba8f72c
...
...
@@ -148,7 +148,7 @@ final class SetMethodCreator {
}
private
SetMethod
createGlobalPropertySetter
()
{
final
ScriptObject
global
=
Context
.
getGlobal
Trusted
();
final
ScriptObject
global
=
Context
.
getGlobal
();
return
new
SetMethod
(
MH
.
filterArguments
(
global
.
addSpill
(
getName
()),
0
,
ScriptObject
.
GLOBALFILTER
),
null
);
}
...
...
src/jdk/nashorn/internal/runtime/UserAccessorProperty.java
浏览文件 @
4ba8f72c
...
...
@@ -34,6 +34,7 @@ import jdk.nashorn.internal.lookup.Lookup;
import
jdk.nashorn.internal.runtime.linker.Bootstrap
;
import
static
jdk
.
nashorn
.
internal
.
codegen
.
CompilerConstants
.
staticCall
;
import
jdk.nashorn.internal.objects.Global
;
import
static
jdk
.
nashorn
.
internal
.
runtime
.
ECMAErrors
.
typeError
;
import
static
jdk
.
nashorn
.
internal
.
runtime
.
ScriptRuntime
.
UNDEFINED
;
...
...
@@ -73,7 +74,7 @@ public final class UserAccessorProperty extends Property {
private
static
MethodHandle
getINVOKE_UA_GETTER
()
{
return
((
GlobalObject
)
Context
.
getGlobal
()
).
getDynamicInvoker
(
INVOKE_UA_GETTER
,
return
Context
.
getGlobal
(
).
getDynamicInvoker
(
INVOKE_UA_GETTER
,
new
Callable
<
MethodHandle
>()
{
@Override
public
MethodHandle
call
()
{
...
...
@@ -86,7 +87,7 @@ public final class UserAccessorProperty extends Property {
/** Dynamic invoker for setter */
private
static
Object
INVOKE_UA_SETTER
=
new
Object
();
private
static
MethodHandle
getINVOKE_UA_SETTER
()
{
return
((
GlobalObject
)
Context
.
getGlobal
()
).
getDynamicInvoker
(
INVOKE_UA_SETTER
,
return
Context
.
getGlobal
(
).
getDynamicInvoker
(
INVOKE_UA_SETTER
,
new
Callable
<
MethodHandle
>()
{
@Override
public
MethodHandle
call
()
{
...
...
src/jdk/nashorn/internal/runtime/arrays/ArrayData.java
浏览文件 @
4ba8f72c
...
...
@@ -27,7 +27,7 @@ package jdk.nashorn.internal.runtime.arrays;
import
java.lang.invoke.MethodHandle
;
import
java.nio.ByteBuffer
;
import
jdk.nashorn.internal.
runtime.GlobalObject
;
import
jdk.nashorn.internal.
objects.Global
;
import
jdk.nashorn.internal.runtime.JSType
;
import
jdk.nashorn.internal.runtime.PropertyDescriptor
;
...
...
@@ -399,7 +399,7 @@ public abstract class ArrayData {
*
* @return property descriptor for element
*/
public
PropertyDescriptor
getDescriptor
(
final
Global
Object
global
,
final
int
index
)
{
public
PropertyDescriptor
getDescriptor
(
final
Global
global
,
final
int
index
)
{
return
global
.
newDataDescriptor
(
getObject
(
index
),
true
,
true
,
true
);
}
...
...
src/jdk/nashorn/internal/runtime/arrays/ByteBufferArrayData.java
浏览文件 @
4ba8f72c
...
...
@@ -27,7 +27,7 @@ package jdk.nashorn.internal.runtime.arrays;
import
static
jdk
.
nashorn
.
internal
.
runtime
.
ECMAErrors
.
typeError
;
import
java.nio.ByteBuffer
;
import
jdk.nashorn.internal.
runtime.GlobalObject
;
import
jdk.nashorn.internal.
objects.Global
;
import
jdk.nashorn.internal.runtime.PropertyDescriptor
;
import
jdk.nashorn.internal.runtime.ScriptRuntime
;
...
...
@@ -60,7 +60,8 @@ final class ByteBufferArrayData extends ArrayData {
*
* @return property descriptor for element
*/
public
PropertyDescriptor
getDescriptor
(
final
GlobalObject
global
,
final
int
index
)
{
@Override
public
PropertyDescriptor
getDescriptor
(
final
Global
global
,
final
int
index
)
{
// make the index properties not configurable
return
global
.
newDataDescriptor
(
getObject
(
index
),
false
,
true
,
true
);
}
...
...
src/jdk/nashorn/internal/runtime/arrays/FrozenArrayFilter.java
浏览文件 @
4ba8f72c
...
...
@@ -25,9 +25,9 @@
package
jdk.nashorn.internal.runtime.arrays
;
import
jdk.nashorn.internal.objects.Global
;
import
static
jdk
.
nashorn
.
internal
.
runtime
.
ECMAErrors
.
typeError
;
import
jdk.nashorn.internal.runtime.GlobalObject
;
import
jdk.nashorn.internal.runtime.PropertyDescriptor
;
/**
...
...
@@ -44,7 +44,7 @@ final class FrozenArrayFilter extends SealedArrayFilter {
}
@Override
public
PropertyDescriptor
getDescriptor
(
final
Global
Object
global
,
final
int
index
)
{
public
PropertyDescriptor
getDescriptor
(
final
Global
global
,
final
int
index
)
{
return
global
.
newDataDescriptor
(
getObject
(
index
),
false
,
true
,
false
);
}
...
...
src/jdk/nashorn/internal/runtime/arrays/SealedArrayFilter.java
浏览文件 @
4ba8f72c
...
...
@@ -25,9 +25,9 @@
package
jdk.nashorn.internal.runtime.arrays
;
import
jdk.nashorn.internal.objects.Global
;
import
static
jdk
.
nashorn
.
internal
.
runtime
.
ECMAErrors
.
typeError
;
import
jdk.nashorn.internal.runtime.GlobalObject
;
import
jdk.nashorn.internal.runtime.PropertyDescriptor
;
/**
...
...
@@ -62,7 +62,7 @@ class SealedArrayFilter extends ArrayFilter {
}
@Override
public
PropertyDescriptor
getDescriptor
(
final
Global
Object
global
,
final
int
index
)
{
public
PropertyDescriptor
getDescriptor
(
final
Global
global
,
final
int
index
)
{
return
global
.
newDataDescriptor
(
getObject
(
index
),
false
,
true
,
true
);
}
}
src/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java
浏览文件 @
4ba8f72c
...
...
@@ -64,6 +64,7 @@ import jdk.internal.org.objectweb.asm.Label;
import
jdk.internal.org.objectweb.asm.Opcodes
;
import
jdk.internal.org.objectweb.asm.Type
;
import
jdk.internal.org.objectweb.asm.commons.InstructionAdapter
;
import
jdk.nashorn.internal.objects.Global
;
import
jdk.nashorn.internal.runtime.Context
;
import
jdk.nashorn.internal.runtime.ScriptFunction
;
import
jdk.nashorn.internal.runtime.ScriptObject
;
...
...
@@ -134,6 +135,7 @@ final class JavaAdapterBytecodeGenerator {
static
final
Type
CONTEXT_TYPE
=
Type
.
getType
(
Context
.
class
);
static
final
Type
OBJECT_TYPE
=
Type
.
getType
(
Object
.
class
);
static
final
Type
SCRIPT_OBJECT_TYPE
=
Type
.
getType
(
ScriptObject
.
class
);
static
final
Type
GLOBAL_TYPE
=
Type
.
getType
(
Global
.
class
);
static
final
String
CONTEXT_TYPE_NAME
=
CONTEXT_TYPE
.
getInternalName
();
static
final
String
OBJECT_TYPE_NAME
=
OBJECT_TYPE
.
getInternalName
();
...
...
@@ -143,8 +145,10 @@ final class JavaAdapterBytecodeGenerator {
static
final
String
GLOBAL_FIELD_NAME
=
"global"
;
static
final
String
SCRIPT_OBJECT_TYPE_DESCRIPTOR
=
SCRIPT_OBJECT_TYPE
.
getDescriptor
();
static
final
String
GLOBAL_TYPE_DESCRIPTOR
=
GLOBAL_TYPE
.
getDescriptor
();
static
final
String
SET_GLOBAL_METHOD_DESCRIPTOR
=
Type
.
getMethodDescriptor
(
Type
.
VOID_TYPE
,
SCRIPT_OBJECT_TYPE
);
static
final
String
SET_GLOBAL_METHOD_DESCRIPTOR
=
Type
.
getMethodDescriptor
(
Type
.
VOID_TYPE
,
GLOBAL_TYPE
);
static
final
String
VOID_NOARG_METHOD_DESCRIPTOR
=
Type
.
getMethodDescriptor
(
Type
.
VOID_TYPE
);
private
static
final
Type
SCRIPT_FUNCTION_TYPE
=
Type
.
getType
(
ScriptFunction
.
class
);
...
...
@@ -167,7 +171,7 @@ final class JavaAdapterBytecodeGenerator {
private
static
final
String
UNSUPPORTED_OPERATION_TYPE_NAME
=
UNSUPPORTED_OPERATION_TYPE
.
getInternalName
();
private
static
final
String
METHOD_HANDLE_TYPE_DESCRIPTOR
=
METHOD_HANDLE_TYPE
.
getDescriptor
();
private
static
final
String
GET_GLOBAL_METHOD_DESCRIPTOR
=
Type
.
getMethodDescriptor
(
SCRIPT_OBJECT
_TYPE
);
private
static
final
String
GET_GLOBAL_METHOD_DESCRIPTOR
=
Type
.
getMethodDescriptor
(
GLOBAL
_TYPE
);
private
static
final
String
GET_CLASS_METHOD_DESCRIPTOR
=
Type
.
getMethodDescriptor
(
Type
.
getType
(
Class
.
class
));
// Package used when the adapter can't be defined in the adaptee's package (either because it's sealed, or because
...
...
@@ -259,7 +263,7 @@ final class JavaAdapterBytecodeGenerator {
}
private
void
generateGlobalFields
()
{
cw
.
visitField
(
ACC_PRIVATE
|
ACC_FINAL
|
(
classOverride
?
ACC_STATIC
:
0
),
GLOBAL_FIELD_NAME
,
SCRIPT_OBJECT
_TYPE_DESCRIPTOR
,
null
,
null
).
visitEnd
();
cw
.
visitField
(
ACC_PRIVATE
|
ACC_FINAL
|
(
classOverride
?
ACC_STATIC
:
0
),
GLOBAL_FIELD_NAME
,
GLOBAL
_TYPE_DESCRIPTOR
,
null
,
null
).
visitEnd
();
usedFieldNames
.
add
(
GLOBAL_FIELD_NAME
);
}
...
...
@@ -363,7 +367,7 @@ final class JavaAdapterBytecodeGenerator {
}
// Assign "global = Context.getGlobal()"
invokeGetGlobalWithNullCheck
(
mv
);
mv
.
putstatic
(
generatedClassName
,
GLOBAL_FIELD_NAME
,
SCRIPT_OBJECT
_TYPE_DESCRIPTOR
);
mv
.
putstatic
(
generatedClassName
,
GLOBAL_FIELD_NAME
,
GLOBAL
_TYPE_DESCRIPTOR
);
endInitMethod
(
mv
);
}
...
...
@@ -508,7 +512,7 @@ final class JavaAdapterBytecodeGenerator {
// Assign "this.global = Context.getGlobal()"
mv
.
visitVarInsn
(
ALOAD
,
0
);
invokeGetGlobalWithNullCheck
(
mv
);
mv
.
putfield
(
generatedClassName
,
GLOBAL_FIELD_NAME
,
SCRIPT_OBJECT
_TYPE_DESCRIPTOR
);
mv
.
putfield
(
generatedClassName
,
GLOBAL_FIELD_NAME
,
GLOBAL
_TYPE_DESCRIPTOR
);
endInitMethod
(
mv
);
}
...
...
@@ -652,10 +656,10 @@ final class JavaAdapterBytecodeGenerator {
// Load the creatingGlobal object
if
(
classOverride
)
{
// If class handle is defined, load the static defining global
mv
.
getstatic
(
generatedClassName
,
GLOBAL_FIELD_NAME
,
SCRIPT_OBJECT
_TYPE_DESCRIPTOR
);
mv
.
getstatic
(
generatedClassName
,
GLOBAL_FIELD_NAME
,
GLOBAL
_TYPE_DESCRIPTOR
);
}
else
{
mv
.
visitVarInsn
(
ALOAD
,
0
);
mv
.
getfield
(
generatedClassName
,
GLOBAL_FIELD_NAME
,
SCRIPT_OBJECT
_TYPE_DESCRIPTOR
);
mv
.
getfield
(
generatedClassName
,
GLOBAL_FIELD_NAME
,
GLOBAL
_TYPE_DESCRIPTOR
);
}
// stack: [creatingGlobal, handle]
final
Label
setupGlobal
=
new
Label
();
...
...
@@ -674,7 +678,7 @@ final class JavaAdapterBytecodeGenerator {
// stack: [creatingGlobal, creatingGlobal, handle]
// Emit code for switching to the creating global
//
ScriptObject
currentGlobal = Context.getGlobal();
//
Global
currentGlobal = Context.getGlobal();
invokeGetGlobal
(
mv
);
mv
.
dup
();
...
...
@@ -744,7 +748,7 @@ final class JavaAdapterBytecodeGenerator {
final
Label
methodEnd
=
new
Label
();
mv
.
visitLabel
(
methodEnd
);
mv
.
visitLocalVariable
(
"currentGlobal"
,
SCRIPT_OBJECT
_TYPE_DESCRIPTOR
,
null
,
setupGlobal
,
methodEnd
,
currentGlobalVar
);
mv
.
visitLocalVariable
(
"currentGlobal"
,
GLOBAL
_TYPE_DESCRIPTOR
,
null
,
setupGlobal
,
methodEnd
,
currentGlobalVar
);
mv
.
visitLocalVariable
(
"globalsDiffer"
,
Type
.
INT_TYPE
.
getDescriptor
(),
null
,
setupGlobal
,
methodEnd
,
globalsDifferVar
);
if
(
throwableDeclared
)
{
...
...
src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java
浏览文件 @
4ba8f72c
...
...
@@ -48,7 +48,6 @@ import java.util.Map;
import
java.util.concurrent.ConcurrentHashMap
;
import
jdk.internal.dynalink.beans.StaticClass
;
import
jdk.internal.dynalink.support.LinkRequestImpl
;
import
jdk.nashorn.internal.objects.NativeJava
;
import
jdk.nashorn.internal.runtime.Context
;
import
jdk.nashorn.internal.runtime.ECMAException
;
import
jdk.nashorn.internal.runtime.ScriptFunction
;
...
...
@@ -68,8 +67,8 @@ import jdk.nashorn.internal.runtime.ScriptObject;
* generate the adapter class itself; see its documentation for details about the generated class.
* </p><p>
* You normally don't use this class directly, but rather either create adapters from script using
* {@link NativeJava#extend(Object, Object...)}, using the {@code new} operator on abstract classes and interfaces (see
* {@link NativeJava#type(Object, Object)}), or implicitly when passing script functions to Java methods expecting SAM
* {@link
jdk.nashorn.internal.objects.
NativeJava#extend(Object, Object...)}, using the {@code new} operator on abstract classes and interfaces (see
* {@link
jdk.nashorn.internal.objects.
NativeJava#type(Object, Object)}), or implicitly when passing script functions to Java methods expecting SAM
* types.
* </p>
*/
...
...
@@ -337,6 +336,7 @@ public final class JavaAdapterFactory {
private
static
ProtectionDomain
createMinimalPermissionDomain
()
{
// Generated classes need to have at least the permission to access Nashorn runtime and runtime.linker packages.
final
Permissions
permissions
=
new
Permissions
();
permissions
.
add
(
new
RuntimePermission
(
"accessClassInPackage.jdk.nashorn.internal.objects"
));
permissions
.
add
(
new
RuntimePermission
(
"accessClassInPackage.jdk.nashorn.internal.runtime"
));
permissions
.
add
(
new
RuntimePermission
(
"accessClassInPackage.jdk.nashorn.internal.runtime.linker"
));
return
new
ProtectionDomain
(
new
CodeSource
(
null
,
(
CodeSigner
[])
null
),
permissions
);
...
...
src/jdk/nashorn/internal/runtime/linker/NashornPrimitiveLinker.java
浏览文件 @
4ba8f72c
...
...
@@ -37,9 +37,9 @@ import jdk.internal.dynalink.linker.LinkRequest;
import
jdk.internal.dynalink.linker.LinkerServices
;
import
jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker
;
import
jdk.internal.dynalink.support.TypeUtilities
;
import
jdk.nashorn.internal.objects.Global
;
import
jdk.nashorn.internal.runtime.ConsString
;
import
jdk.nashorn.internal.runtime.Context
;
import
jdk.nashorn.internal.runtime.GlobalObject
;
/**
* Internal linker for String, Boolean, and Number objects, only ever used by Nashorn engine and not exposed to other
...
...
@@ -62,7 +62,7 @@ final class NashornPrimitiveLinker implements TypeBasedGuardingDynamicLinker, Gu
final
LinkRequest
request
=
origRequest
.
withoutRuntimeContext
();
// Nashorn has no runtime context
final
Object
self
=
request
.
getReceiver
();
final
Global
Object
global
=
(
GlobalObject
)
Context
.
getGlobal
();
final
Global
global
=
Context
.
getGlobal
();
final
NashornCallSiteDescriptor
desc
=
(
NashornCallSiteDescriptor
)
request
.
getCallSiteDescriptor
();
return
Bootstrap
.
asType
(
global
.
primitiveLookup
(
request
,
self
),
linkerServices
,
desc
);
...
...
src/jdk/nashorn/tools/Shell.java
浏览文件 @
4ba8f72c
...
...
@@ -42,6 +42,7 @@ import jdk.nashorn.internal.codegen.Compiler;
import
jdk.nashorn.internal.ir.FunctionNode
;
import
jdk.nashorn.internal.ir.debug.ASTWriter
;
import
jdk.nashorn.internal.ir.debug.PrintVisitor
;
import
jdk.nashorn.internal.objects.Global
;
import
jdk.nashorn.internal.parser.Parser
;
import
jdk.nashorn.internal.runtime.Context
;
import
jdk.nashorn.internal.runtime.ErrorManager
;
...
...
@@ -148,7 +149,7 @@ public class Shell {
return
COMMANDLINE_ERROR
;
}
final
ScriptObject
global
=
context
.
createGlobal
();
final
Global
global
=
context
.
createGlobal
();
final
ScriptEnvironment
env
=
context
.
getEnv
();
final
List
<
String
>
files
=
env
.
getFiles
();
if
(
files
.
isEmpty
())
{
...
...
@@ -231,8 +232,8 @@ public class Shell {
* @return error code
* @throws IOException when any script file read results in I/O error
*/
private
static
int
compileScripts
(
final
Context
context
,
final
ScriptObject
global
,
final
List
<
String
>
files
)
throws
IOException
{
final
ScriptObject
oldGlobal
=
Context
.
getGlobal
();
private
static
int
compileScripts
(
final
Context
context
,
final
Global
global
,
final
List
<
String
>
files
)
throws
IOException
{
final
Global
oldGlobal
=
Context
.
getGlobal
();
final
boolean
globalChanged
=
(
oldGlobal
!=
global
);
final
ScriptEnvironment
env
=
context
.
getEnv
();
try
{
...
...
@@ -281,8 +282,8 @@ public class Shell {
* @return error code
* @throws IOException when any script file read results in I/O error
*/
private
int
runScripts
(
final
Context
context
,
final
ScriptObject
global
,
final
List
<
String
>
files
)
throws
IOException
{
final
ScriptObject
oldGlobal
=
Context
.
getGlobal
();
private
int
runScripts
(
final
Context
context
,
final
Global
global
,
final
List
<
String
>
files
)
throws
IOException
{
final
Global
oldGlobal
=
Context
.
getGlobal
();
final
boolean
globalChanged
=
(
oldGlobal
!=
global
);
try
{
if
(
globalChanged
)
{
...
...
@@ -339,8 +340,8 @@ public class Shell {
* @return error code
* @throws IOException when any script file read results in I/O error
*/
private
static
int
runFXScripts
(
final
Context
context
,
final
ScriptObject
global
,
final
List
<
String
>
files
)
throws
IOException
{
final
ScriptObject
oldGlobal
=
Context
.
getGlobal
();
private
static
int
runFXScripts
(
final
Context
context
,
final
Global
global
,
final
List
<
String
>
files
)
throws
IOException
{
final
Global
oldGlobal
=
Context
.
getGlobal
();
final
boolean
globalChanged
=
(
oldGlobal
!=
global
);
try
{
if
(
globalChanged
)
{
...
...
@@ -389,11 +390,11 @@ public class Shell {
* @return return code
*/
@SuppressWarnings
(
"resource"
)
private
static
int
readEvalPrint
(
final
Context
context
,
final
ScriptObject
global
)
{
private
static
int
readEvalPrint
(
final
Context
context
,
final
Global
global
)
{
final
String
prompt
=
bundle
.
getString
(
"shell.prompt"
);
final
BufferedReader
in
=
new
BufferedReader
(
new
InputStreamReader
(
System
.
in
));
final
PrintWriter
err
=
context
.
getErr
();
final
ScriptObject
oldGlobal
=
Context
.
getGlobal
();
final
Global
oldGlobal
=
Context
.
getGlobal
();
final
boolean
globalChanged
=
(
oldGlobal
!=
global
);
final
ScriptEnvironment
env
=
context
.
getEnv
();
...
...
test/src/jdk/nashorn/internal/codegen/CompilerTest.java
浏览文件 @
4ba8f72c
...
...
@@ -28,6 +28,7 @@ package jdk.nashorn.internal.codegen;
import
java.io.File
;
import
java.io.PrintWriter
;
import
java.io.StringWriter
;
import
jdk.nashorn.internal.objects.Global
;
import
jdk.nashorn.internal.runtime.Context
;
import
jdk.nashorn.internal.runtime.ErrorManager
;
import
jdk.nashorn.internal.runtime.ScriptFunction
;
...
...
@@ -58,7 +59,7 @@ public class CompilerTest {
}
private
Context
context
;
private
ScriptObject
global
;
private
Global
global
;
@BeforeClass
public
void
setupTest
()
{
...
...
@@ -146,7 +147,7 @@ public class CompilerTest {
log
(
"Begin compiling "
+
file
.
getAbsolutePath
());
}
final
ScriptObject
oldGlobal
=
Context
.
getGlobal
();
final
Global
oldGlobal
=
Context
.
getGlobal
();
final
boolean
globalChanged
=
(
oldGlobal
!=
global
);
try
{
...
...
test/src/jdk/nashorn/internal/performance/PerformanceWrapper.java
浏览文件 @
4ba8f72c
...
...
@@ -31,9 +31,9 @@ import java.util.concurrent.ExecutionException;
import
java.util.concurrent.Future
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeoutException
;
import
jdk.nashorn.internal.objects.Global
;
import
jdk.nashorn.internal.runtime.Context
;
import
jdk.nashorn.internal.runtime.ScriptFunction
;
import
jdk.nashorn.internal.runtime.ScriptObject
;
import
jdk.nashorn.internal.runtime.ScriptRuntime
;
/**
...
...
@@ -89,7 +89,7 @@ public class PerformanceWrapper extends jdk.nashorn.tools.Shell {
@Override
protected
Object
apply
(
final
ScriptFunction
target
,
final
Object
self
)
{
if
(
_runsPerIteration
==
0
&&
_numberOfIterations
==
0
)
{
final
ScriptObject
global
=
jdk
.
nashorn
.
internal
.
runtime
.
Context
.
getGlobal
();
final
Global
global
=
jdk
.
nashorn
.
internal
.
runtime
.
Context
.
getGlobal
();
final
ScriptFunction
_target
=
target
;
final
Object
_self
=
self
;
...
...
test/src/jdk/nashorn/internal/runtime/ContextTest.java
浏览文件 @
4ba8f72c
...
...
@@ -29,6 +29,7 @@ import static org.testng.Assert.assertEquals;
import
static
org
.
testng
.
Assert
.
assertTrue
;
import
java.util.Map
;
import
jdk.nashorn.internal.objects.Global
;
import
jdk.nashorn.internal.runtime.options.Options
;
import
org.testng.annotations.Test
;
...
...
@@ -45,7 +46,7 @@ public class ContextTest {
final
Options
options
=
new
Options
(
""
);
final
ErrorManager
errors
=
new
ErrorManager
();
final
Context
cx
=
new
Context
(
options
,
errors
,
Thread
.
currentThread
().
getContextClassLoader
());
final
ScriptObject
oldGlobal
=
Context
.
getGlobal
();
final
Global
oldGlobal
=
Context
.
getGlobal
();
Context
.
setGlobal
(
cx
.
createGlobal
());
try
{
String
code
=
"22 + 10"
;
...
...
@@ -65,7 +66,7 @@ public class ContextTest {
final
ErrorManager
errors
=
new
ErrorManager
();
final
Context
cx
=
new
Context
(
options
,
errors
,
Thread
.
currentThread
().
getContextClassLoader
());
final
boolean
strict
=
cx
.
getEnv
().
_strict
;
final
ScriptObject
oldGlobal
=
Context
.
getGlobal
();
final
Global
oldGlobal
=
Context
.
getGlobal
();
Context
.
setGlobal
(
cx
.
createGlobal
());
try
{
...
...
test/src/jdk/nashorn/internal/test/framework/SharedContextEvaluator.java
浏览文件 @
4ba8f72c
...
...
@@ -34,10 +34,10 @@ import java.io.IOException;
import
java.io.OutputStream
;
import
java.io.PrintWriter
;
import
jdk.nashorn.api.scripting.NashornException
;
import
jdk.nashorn.internal.objects.Global
;
import
jdk.nashorn.internal.runtime.Context
;
import
jdk.nashorn.internal.runtime.ErrorManager
;
import
jdk.nashorn.internal.runtime.ScriptFunction
;
import
jdk.nashorn.internal.runtime.ScriptObject
;
import
jdk.nashorn.internal.runtime.ScriptRuntime
;
import
jdk.nashorn.internal.runtime.Source
;
import
jdk.nashorn.internal.runtime.options.Options
;
...
...
@@ -110,12 +110,12 @@ public final class SharedContextEvaluator implements ScriptEvaluator {
@Override
public
int
run
(
final
OutputStream
out
,
final
OutputStream
err
,
final
String
[]
args
)
throws
IOException
{
final
ScriptObject
oldGlobal
=
Context
.
getGlobal
();
final
Global
oldGlobal
=
Context
.
getGlobal
();
try
{
ctxOut
.
setDelegatee
(
out
);
ctxErr
.
setDelegatee
(
err
);
final
ErrorManager
errors
=
context
.
getErrorManager
();
final
ScriptObject
global
=
context
.
createGlobal
();
final
Global
global
=
context
.
createGlobal
();
Context
.
setGlobal
(
global
);
// For each file on the command line.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录