-
Notifications
You must be signed in to change notification settings - Fork 858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move the whole LiveConnect initializion in "initStandardObjects" #1677
Open
rPraml
wants to merge
5
commits into
mozilla:master
Choose a base branch
from
FOCONIS:refactor-liveconnect
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1619bfe
Do not pass instances of 'Undefined' to wrapper factory
rPraml 0c0ac19
move the 'toJavaDeclaration' from MemberBox to NativeJavaMethod
rPraml afed5a1
Move "unsafe" objects to InitStandardObjects
rPraml def8d3d
Mark the top scope, that liveConnect is enabled
rPraml 1edfdea
spotless
rPraml File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,26 +89,6 @@ Class<?> getDeclaringClass() { | |
return memberObject.getDeclaringClass(); | ||
} | ||
|
||
String toJavaDeclaration() { | ||
StringBuilder sb = new StringBuilder(); | ||
if (isMethod()) { | ||
Method method = method(); | ||
sb.append(method.getReturnType()); | ||
sb.append(' '); | ||
sb.append(method.getName()); | ||
} else { | ||
Constructor<?> ctor = ctor(); | ||
String name = ctor.getDeclaringClass().getName(); | ||
int lastDot = name.lastIndexOf('.'); | ||
if (lastDot >= 0) { | ||
name = name.substring(lastDot + 1); | ||
} | ||
sb.append(name); | ||
} | ||
sb.append(JavaMembers.liveConnectSignature(argTypes)); | ||
return sb.toString(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a liveconnect only thing, so I moved it away from here |
||
} | ||
|
||
@Override | ||
public String toString() { | ||
return memberObject.toString(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,7 +148,6 @@ public static ScriptableObject initSafeStandardObjects( | |
} | ||
|
||
scope.associateValue(LIBRARY_SCOPE_KEY, scope); | ||
new ClassCache().associate(scope); | ||
|
||
BaseFunction.init(cx, scope, sealed); | ||
NativeObject.init(scope, sealed); | ||
|
@@ -190,25 +189,13 @@ public static ScriptableObject initSafeStandardObjects( | |
NativeStringIterator.init(scope, sealed); | ||
|
||
NativeJavaObject.init(scope, sealed); | ||
NativeJavaMap.init(scope, sealed); | ||
|
||
boolean withXml = | ||
cx.hasFeature(Context.FEATURE_E4X) && cx.getE4xImplementationFactory() != null; | ||
|
||
// define lazy-loaded properties using their class name | ||
new LazilyLoadedCtor( | ||
scope, "RegExp", "org.mozilla.javascript.regexp.NativeRegExp", sealed, true); | ||
new LazilyLoadedCtor( | ||
scope, "Continuation", "org.mozilla.javascript.NativeContinuation", sealed, true); | ||
|
||
if (withXml) { | ||
String xmlImpl = cx.getE4xImplementationFactory().getImplementationClassName(); | ||
new LazilyLoadedCtor(scope, "XML", xmlImpl, sealed, true); | ||
new LazilyLoadedCtor(scope, "XMLList", xmlImpl, sealed, true); | ||
new LazilyLoadedCtor(scope, "Namespace", xmlImpl, sealed, true); | ||
new LazilyLoadedCtor(scope, "QName", xmlImpl, sealed, true); | ||
} | ||
|
||
if (((cx.getLanguageVersion() >= Context.VERSION_1_8) | ||
&& cx.hasFeature(Context.FEATURE_V8_EXTENSIONS)) | ||
|| (cx.getLanguageVersion() >= Context.VERSION_ES6)) { | ||
|
@@ -299,10 +286,32 @@ public static ScriptableObject initSafeStandardObjects( | |
return scope; | ||
} | ||
|
||
public static boolean isLiveConnectEnabled(Scriptable scope) { | ||
return Boolean.TRUE.equals(ScriptableObject.getTopScopeValue(scope, LIVE_CONNECT_ENABLED)); | ||
} | ||
|
||
public static ScriptableObject initStandardObjects( | ||
Context cx, ScriptableObject scope, boolean sealed) { | ||
ScriptableObject s = initSafeStandardObjects(cx, scope, sealed); | ||
|
||
// The following obects are "unsafe", as they allow access to java classes with reflection | ||
s.associateValue(LIVE_CONNECT_ENABLED, Boolean.TRUE); | ||
new ClassCache().associate(s); | ||
|
||
NativeJavaObject.init(s, sealed); | ||
NativeJavaMap.init(s, sealed); | ||
|
||
boolean withXml = | ||
cx.hasFeature(Context.FEATURE_E4X) && cx.getE4xImplementationFactory() != null; | ||
|
||
if (withXml) { | ||
String xmlImpl = cx.getE4xImplementationFactory().getImplementationClassName(); | ||
new LazilyLoadedCtor(s, "XML", xmlImpl, sealed, true); | ||
new LazilyLoadedCtor(s, "XMLList", xmlImpl, sealed, true); | ||
new LazilyLoadedCtor(s, "Namespace", xmlImpl, sealed, true); | ||
new LazilyLoadedCtor(s, "QName", xmlImpl, sealed, true); | ||
} | ||
|
||
new LazilyLoadedCtor( | ||
s, "Packages", "org.mozilla.javascript.NativeJavaTopPackage", sealed, true); | ||
new LazilyLoadedCtor( | ||
|
@@ -1453,6 +1462,7 @@ public static Optional<Double> canonicalNumericIndexString(String arg) { | |
// XXX: this is until setDefaultNamespace will learn how to store NS | ||
// properly and separates namespace form Scriptable.get etc. | ||
private static final String DEFAULT_NS_TAG = "__default_namespace__"; | ||
private static final String LIVE_CONNECT_ENABLED = "__live_connect_enabled__"; | ||
|
||
public static Object setDefaultNamespace(Object namespace, Context cx) { | ||
Scriptable scope = cx.currentActivationCall; | ||
|
@@ -4402,26 +4412,27 @@ public static Scriptable newCatchScope( | |
if (errorObject instanceof NativeError) { | ||
((NativeError) errorObject).setStackProvider(re); | ||
} | ||
|
||
if (javaException != null && isVisible(cx, javaException)) { | ||
Object wrap = cx.getWrapFactory().wrap(cx, scope, javaException, null); | ||
ScriptableObject.defineProperty( | ||
errorObject, | ||
"javaException", | ||
wrap, | ||
ScriptableObject.PERMANENT | ||
| ScriptableObject.READONLY | ||
| ScriptableObject.DONTENUM); | ||
} | ||
if (isVisible(cx, re)) { | ||
Object wrap = cx.getWrapFactory().wrap(cx, scope, re, null); | ||
ScriptableObject.defineProperty( | ||
errorObject, | ||
"rhinoException", | ||
wrap, | ||
ScriptableObject.PERMANENT | ||
| ScriptableObject.READONLY | ||
| ScriptableObject.DONTENUM); | ||
if (ScriptRuntime.isLiveConnectEnabled(scope)) { | ||
if (javaException != null && isVisible(cx, javaException)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do not declare these additional properties, when the scope does not support liveConnect |
||
Object wrap = cx.getWrapFactory().wrap(cx, scope, javaException, null); | ||
ScriptableObject.defineProperty( | ||
errorObject, | ||
"javaException", | ||
wrap, | ||
ScriptableObject.PERMANENT | ||
| ScriptableObject.READONLY | ||
| ScriptableObject.DONTENUM); | ||
} | ||
if (isVisible(cx, re)) { | ||
Object wrap = cx.getWrapFactory().wrap(cx, scope, re, null); | ||
ScriptableObject.defineProperty( | ||
errorObject, | ||
"rhinoException", | ||
wrap, | ||
ScriptableObject.PERMANENT | ||
| ScriptableObject.READONLY | ||
| ScriptableObject.DONTENUM); | ||
} | ||
} | ||
obj = errorObject; | ||
} | ||
|
@@ -4501,26 +4512,27 @@ public static Scriptable wrapException(Throwable t, Scriptable scope, Context cx | |
if (errorObject instanceof NativeError) { | ||
((NativeError) errorObject).setStackProvider(re); | ||
} | ||
|
||
if (javaException != null && isVisible(cx, javaException)) { | ||
Object wrap = cx.getWrapFactory().wrap(cx, scope, javaException, null); | ||
ScriptableObject.defineProperty( | ||
errorObject, | ||
"javaException", | ||
wrap, | ||
ScriptableObject.PERMANENT | ||
| ScriptableObject.READONLY | ||
| ScriptableObject.DONTENUM); | ||
} | ||
if (isVisible(cx, re)) { | ||
Object wrap = cx.getWrapFactory().wrap(cx, scope, re, null); | ||
ScriptableObject.defineProperty( | ||
errorObject, | ||
"rhinoException", | ||
wrap, | ||
ScriptableObject.PERMANENT | ||
| ScriptableObject.READONLY | ||
| ScriptableObject.DONTENUM); | ||
if (ScriptRuntime.isLiveConnectEnabled(scope)) { | ||
if (javaException != null && isVisible(cx, javaException)) { | ||
Object wrap = cx.getWrapFactory().wrap(cx, scope, javaException, null); | ||
ScriptableObject.defineProperty( | ||
errorObject, | ||
"javaException", | ||
wrap, | ||
ScriptableObject.PERMANENT | ||
| ScriptableObject.READONLY | ||
| ScriptableObject.DONTENUM); | ||
} | ||
if (isVisible(cx, re)) { | ||
Object wrap = cx.getWrapFactory().wrap(cx, scope, re, null); | ||
ScriptableObject.defineProperty( | ||
errorObject, | ||
"rhinoException", | ||
wrap, | ||
ScriptableObject.PERMANENT | ||
| ScriptableObject.READONLY | ||
| ScriptableObject.DONTENUM); | ||
} | ||
} | ||
return errorObject; | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not pass undefined to wrapperFactory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate on the 'why' of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Undefined
is already a js compatible object, so I think, it does not need ajavaToJs
conversion.Background: I plan to make the wrapperFactory optional (no wrapperFactory == no liveConnect) and I found some failing tests, that have passed
undefined
here, although they do not use use liveConnectI will line up the code with the documentation. (Function mentioned in doc, but not handled in code) and maybe extract this in a separate commit.