use of com.github.anba.es6draft.runtime.types.builtins.FunctionObject in project es6draft by anba.
the class ShellFunctions method disassemble.
/**
* shell-function: {@code disassemble([function])}
*
* @param cx
* the execution context
* @param caller
* the caller context
* @param args
* the arguments
* @throws IOException
* if there was any I/O error
* @throws MalformedNameException
* if the module name cannot be normalized
*/
@Function(name = "disassemble", arity = 1)
public void disassemble(ExecutionContext cx, ExecutionContext caller, Object... args) throws IOException, MalformedNameException {
DebugInfo debugInfo = null;
if (args.length == 0) {
FunctionObject currentFunction = caller.getCurrentFunction();
Executable currentExec = caller.getCurrentExecutable();
if (currentFunction != null && currentFunction.getExecutable() == currentExec) {
debugInfo = currentFunction.getCode().debugInfo();
} else if (currentExec != null && currentExec.getSourceObject() != null) {
debugInfo = currentExec.getSourceObject().debugInfo();
}
} else if (args[0] instanceof FunctionObject) {
debugInfo = ((FunctionObject) args[0]).getCode().debugInfo();
} else {
String sourceCode = ToFlatString(cx, args[0]);
boolean isModule = false;
if (args.length > 1 && Type.isObject(args[1])) {
isModule = ToBoolean(Get(cx, Type.objectValue(args[1]), "module"));
}
ScriptLoader scriptLoader = cx.getRealm().getScriptLoader();
if (isModule) {
ModuleLoader moduleLoader = cx.getRealm().getModuleLoader();
SourceIdentifier identifier = moduleLoader.normalizeName("disassemble", null);
ModuleSource src = new StringModuleSource(identifier, sourceCode);
SourceTextModuleRecord module = ParseModule(scriptLoader, identifier, src);
debugInfo = module.getScriptCode().getSourceObject().debugInfo();
} else {
Source source = new Source("<disassemble>", 1);
Script script = scriptLoader.compile(scriptLoader.parseScript(source, sourceCode), "#disassemble");
debugInfo = script.getSourceObject().debugInfo();
}
}
if (debugInfo != null) {
PrintWriter writer = cx.getRuntimeContext().getConsole().writer();
for (DebugInfo.Method method : debugInfo.getMethods()) {
writer.println(method.disassemble());
}
}
}
use of com.github.anba.es6draft.runtime.types.builtins.FunctionObject in project es6draft by anba.
the class MozShellFunctions method debugInfo.
private static DebugInfo debugInfo(ExecutionContext caller, Object... args) {
if (args.length == 0) {
FunctionObject currentFunction = caller.getCurrentFunction();
Executable currentExec = caller.getCurrentExecutable();
if (currentFunction != null && currentFunction.getExecutable() == currentExec) {
return currentFunction.getCode().debugInfo();
} else if (currentExec != null && currentExec.getSourceObject() != null) {
return currentExec.getSourceObject().debugInfo();
}
} else if (args[0] instanceof FunctionObject) {
return ((FunctionObject) args[0]).getCode().debugInfo();
}
return null;
}
use of com.github.anba.es6draft.runtime.types.builtins.FunctionObject in project es6draft by anba.
the class Bootstrap method superSetup.
@SuppressWarnings("unused")
private static MethodHandle superSetup(MutableCallSite callsite, Constructor constructor, ExecutionContext cx, Constructor newTarget, Object[] arguments) {
MethodHandle target, test;
if (constructor instanceof FunctionObject && constructor instanceof Constructor) {
FunctionObject fn = (FunctionObject) constructor;
test = MethodHandles.insertArguments(testFunctionObjectMH, 1, fn.getMethodInfo());
target = fn.getConstructMethod();
} else if (constructor instanceof BuiltinConstructor) {
BuiltinConstructor fn = (BuiltinConstructor) constructor;
test = MethodHandles.insertArguments(testBuiltinFunctionMH, 1, fn.getMethodInfo());
target = fn.getConstructMethod();
} else {
target = test = null;
}
if (test != null) {
test = test.asType(test.type().changeParameterType(0, Constructor.class));
}
return setCallSiteTarget(callsite, target, test, superGenericMH);
}
use of com.github.anba.es6draft.runtime.types.builtins.FunctionObject in project es6draft by anba.
the class Bootstrap method constructSetup.
@SuppressWarnings("unused")
private static MethodHandle constructSetup(MutableCallSite callsite, Object constructor, ExecutionContext cx, Object[] arguments) {
MethodHandle target, test;
if (constructor instanceof FunctionObject && constructor instanceof Constructor) {
FunctionObject fn = (FunctionObject) constructor;
test = MethodHandles.insertArguments(testFunctionObjectMH, 1, fn.getMethodInfo());
target = fn.getConstructMethod();
} else if (constructor instanceof BuiltinConstructor) {
BuiltinConstructor fn = (BuiltinConstructor) constructor;
test = MethodHandles.insertArguments(testBuiltinFunctionMH, 1, fn.getMethodInfo());
target = fn.getConstructMethod();
} else {
target = test = null;
}
if (target != null) {
// Insert constructor as newTarget argument.
target = target.asType(target.type().changeParameterType(2, constructor.getClass()));
target = MethodHandles.permuteArguments(target, target.type().dropParameterTypes(2, 3), 0, 1, 0, 2);
}
return setCallSiteTarget(callsite, target, test, constructGenericMH);
}
use of com.github.anba.es6draft.runtime.types.builtins.FunctionObject in project es6draft by anba.
the class RuntimeFunctions method IsFunctionExpression.
/**
* Native function: {@code %IsFunctionExpression(<function>)}.
* <p>
* Returns {@code true} if <var>function</var> is a function expression.
*
* @param function
* the function object
* @return {@code true} if <var>function</var> is a function expression
*/
public static boolean IsFunctionExpression(Callable function) {
if (!(function instanceof FunctionObject)) {
return false;
}
FunctionObject funObj = (FunctionObject) function;
RuntimeInfo.Function code = funObj.getCode();
if (code == null) {
return false;
}
return code.is(RuntimeInfo.FunctionFlags.Expression) && !code.is(RuntimeInfo.FunctionFlags.Arrow);
}
Aggregations