📄 contextfactory.java
字号:
* we try to protect existing scripts that have specified a * version... */ version = cx.getLanguageVersion(); return (version == Context.VERSION_1_0 || version == Context.VERSION_1_1 || version == Context.VERSION_1_2); case Context.FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME: return false; case Context.FEATURE_RESERVED_KEYWORD_AS_IDENTIFIER: return false; case Context.FEATURE_TO_STRING_AS_SOURCE: version = cx.getLanguageVersion(); return version == Context.VERSION_1_2; case Context.FEATURE_PARENT_PROTO_PROPRTIES: return true; case Context.FEATURE_E4X: version = cx.getLanguageVersion(); return (version == Context.VERSION_DEFAULT || version >= Context.VERSION_1_6); case Context.FEATURE_DYNAMIC_SCOPE: return false; case Context.FEATURE_STRICT_VARS: return false; case Context.FEATURE_STRICT_EVAL: return false; } // It is a bug to call the method with unknown featureIndex throw new IllegalArgumentException(String.valueOf(featureIndex)); } /** * Create class loader for generated classes. * This method creates an instance of the default implementation * of {@link GeneratedClassLoader}. Rhino uses this interface to load * generated JVM classes when no {@link SecurityController} * is installed. * Application can override the method to provide custom class loading. */ protected GeneratedClassLoader createClassLoader(ClassLoader parent) { return new DefiningClassLoader(parent); } /** * Get ClassLoader to use when searching for Java classes. * Unless it was explicitly initialized with * {@link #initApplicationClassLoader(ClassLoader)} the method returns * null to indicate that Thread.getContextClassLoader() should be used. */ public final ClassLoader getApplicationClassLoader() { return applicationClassLoader; } /** * Set explicit class loader to use when searching for Java classes. * * @see #getApplicationClassLoader() */ public final void initApplicationClassLoader(ClassLoader loader) { if (loader == null) throw new IllegalArgumentException("loader is null"); if (!Kit.testIfCanLoadRhinoClasses(loader)) throw new IllegalArgumentException( "Loader can not resolve Rhino classes"); if (this.applicationClassLoader != null) throw new IllegalStateException( "applicationClassLoader can only be set once"); checkNotSealed(); this.applicationClassLoader = loader; } /** * Execute top call to script or function. * When the runtime is about to execute a script or function that will * create the first stack frame with scriptable code, it calls this method * to perform the real call. In this way execution of any script * happens inside this function. */ protected Object doTopCall(Callable callable, Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { return callable.call(cx, scope, thisObj, args); } /** * Implementation of * {@link Context#observeInstructionCount(int instructionCount)}. * This can be used to customize {@link Context} without introducing * additional subclasses. */ protected void observeInstructionCount(Context cx, int instructionCount) { } protected void onContextCreated(Context cx) { Object listeners = this.listeners; for (int i = 0; ; ++i) { Listener l = (Listener)Kit.getListener(listeners, i); if (l == null) break; l.contextCreated(cx); } } protected void onContextReleased(Context cx) { Object listeners = this.listeners; for (int i = 0; ; ++i) { Listener l = (Listener)Kit.getListener(listeners, i); if (l == null) break; l.contextReleased(cx); } } public final void addListener(Listener listener) { checkNotSealed(); synchronized (listenersLock) { if (disabledListening) { throw new IllegalStateException(); } listeners = Kit.addListener(listeners, listener); } } public final void removeListener(Listener listener) { checkNotSealed(); synchronized (listenersLock) { if (disabledListening) { throw new IllegalStateException(); } listeners = Kit.removeListener(listeners, listener); } } /** * The method is used only to imlement * Context.disableStaticContextListening() */ final void disableContextListening() { checkNotSealed(); synchronized (listenersLock) { disabledListening = true; listeners = null; } } /** * Checks if this is a sealed ContextFactory. * @see #seal() */ public final boolean isSealed() { return sealed; } /** * Seal this ContextFactory so any attempt to modify it like to add or * remove its listeners will throw an exception. * @see #isSealed() */ public final void seal() { checkNotSealed(); sealed = true; } protected final void checkNotSealed() { if (sealed) throw new IllegalStateException(); } /** * Call {@link ContextAction#run(Context cx)} * using the {@link Context} instance associated with the current thread. * If no Context is associated with the thread, then * {@link #makeContext()} will be called to construct * new Context instance. The instance will be temporary associated * with the thread during call to {@link ContextAction#run(Context)}. * * @see ContextFactory#call(ContextAction) * @see Context#call(ContextFactory factory, Callable callable, * Scriptable scope, Scriptable thisObj, * Object[] args) */ public final Object call(ContextAction action) { return Context.call(this, action); } /** * Same as {@link Context#enter()} with the difference that if a new context * needs to be created, then this context factory is used to create it * instead of the global context factory. * @return a Context associated with the current thread */ public final Context enter() { return enter(null); } /** * Same as {@link Context#enter(Context)} with the difference that if a new * context needs to be created, then this context factory is used to create * it instead of the global context factory. * @return a Context associated with the current thread */ public final Context enter(Context cx) { return Context.enter(cx, this); } /** * Same as {@link Context#exit()}, although if you used {@link #enter()} or * {@link #enter(Context)} methods on this object, you should use this exit * method instead of the static one in {@link Context}. */ public final void exit() { Context.exit(this); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -