src/jdk/nashorn/api/scripting/ScriptObjectMirror.java
Print this page
*** 97,112 ****
if (globalChanged) {
Context.setGlobal(global);
}
final Object val = functionName == null? sobj : sobj.get(functionName);
! if (! (val instanceof ScriptFunction)) {
! throw new NoSuchMethodException("No such function " + ((functionName != null)? functionName : ""));
! }
!
final Object[] modArgs = globalChanged? wrapArray(args, oldGlobal) : args;
return wrap(ScriptRuntime.checkAndApply((ScriptFunction)val, sobj, unwrapArray(modArgs, global)), global);
} catch (final RuntimeException | Error e) {
throw e;
} catch (final Throwable t) {
throw new RuntimeException(t);
} finally {
--- 97,114 ----
if (globalChanged) {
Context.setGlobal(global);
}
final Object val = functionName == null? sobj : sobj.get(functionName);
! if (val instanceof ScriptFunction) {
final Object[] modArgs = globalChanged? wrapArray(args, oldGlobal) : args;
return wrap(ScriptRuntime.checkAndApply((ScriptFunction)val, sobj, unwrapArray(modArgs, global)), global);
+ } else if (val instanceof ScriptObjectMirror && ((ScriptObjectMirror)val).isFunction()) {
+ return ((ScriptObjectMirror)val).call(null, args);
+ }
+
+ throw new NoSuchMethodException("No such function " + ((functionName != null)? functionName : ""));
} catch (final RuntimeException | Error e) {
throw e;
} catch (final Throwable t) {
throw new RuntimeException(t);
} finally {
*** 125,140 ****
if (globalChanged) {
Context.setGlobal(global);
}
final Object val = functionName == null? sobj : sobj.get(functionName);
! if (! (val instanceof ScriptFunction)) {
! throw new RuntimeException("not a constructor " + ((functionName != null)? functionName : ""));
! }
!
final Object[] modArgs = globalChanged? wrapArray(args, oldGlobal) : args;
return wrap(ScriptRuntime.checkAndConstruct((ScriptFunction)val, unwrapArray(modArgs, global)), global);
} catch (final RuntimeException | Error e) {
throw e;
} catch (final Throwable t) {
throw new RuntimeException(t);
} finally {
--- 127,144 ----
if (globalChanged) {
Context.setGlobal(global);
}
final Object val = functionName == null? sobj : sobj.get(functionName);
! if (val instanceof ScriptFunction) {
final Object[] modArgs = globalChanged? wrapArray(args, oldGlobal) : args;
return wrap(ScriptRuntime.checkAndConstruct((ScriptFunction)val, unwrapArray(modArgs, global)), global);
+ } else if (val instanceof ScriptObjectMirror && ((ScriptObjectMirror)val).isFunction()) {
+ return ((ScriptObjectMirror)val).newObject(null, args);
+ }
+
+ throw new RuntimeException("not a constructor " + ((functionName != null)? functionName : ""));
} catch (final RuntimeException | Error e) {
throw e;
} catch (final Throwable t) {
throw new RuntimeException(t);
} finally {