Search in sources :

Example 1 with Executable

use of com.github.anba.es6draft.Executable in project es6draft by anba.

the class Realm method sourceInfo.

/**
     * Returns the source info from the caller execution context. If no applicable source is attached to the caller
     * context, the source from the most recent script execution on this realm is returned.
     * 
     * @param caller
     *            the caller context
     * @return the source info or {@code null} if not available
     */
public Source sourceInfo(ExecutionContext caller) {
    Executable callerExec = caller.getCurrentExecutable();
    if (hasSourceInfo(callerExec)) {
        return callerExec.getSourceObject().toSource();
    }
    ExecutionContext scriptContext = getScriptContext();
    if (scriptContext != null) {
        Executable currentExec = scriptContext.getCurrentExecutable();
        if (hasSourceInfo(currentExec)) {
            return currentExec.getSourceObject().toSource();
        }
    }
    // Neither caller nor realm has source info available, return null
    return null;
}
Also used : ExecutionContext.newDefaultExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext.newDefaultExecutionContext) Executable(com.github.anba.es6draft.Executable)

Example 2 with Executable

use of com.github.anba.es6draft.Executable in project es6draft by anba.

the class ScriptRuntime method setLegacyBlockFunction.

/**
     * 18.2.1.2 Runtime Semantics: EvalDeclarationInstantiation( body, varEnv, lexEnv, strict)
     * 
     * @param cx
     *            the execution context
     * @param functionId
     *            the function id
     */
public static void setLegacyBlockFunction(ExecutionContext cx, int functionId) {
    Executable executable = cx.getCurrentExecutable();
    ((CompiledScript) executable).setLegacyBlockFunction(functionId);
}
Also used : CompiledScript(com.github.anba.es6draft.compiler.CompiledScript) Executable(com.github.anba.es6draft.Executable)

Example 3 with Executable

use of com.github.anba.es6draft.Executable 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());
        }
    }
}
Also used : SourceTextModuleRecord(com.github.anba.es6draft.runtime.modules.SourceTextModuleRecord) SharedFunctions.relativePathToScript(com.github.anba.es6draft.repl.global.SharedFunctions.relativePathToScript) SharedFunctions.loadScript(com.github.anba.es6draft.repl.global.SharedFunctions.loadScript) Script(com.github.anba.es6draft.Script) ModuleLoader(com.github.anba.es6draft.runtime.modules.ModuleLoader) SourceIdentifier(com.github.anba.es6draft.runtime.modules.SourceIdentifier) ToFlatString(com.github.anba.es6draft.runtime.AbstractOperations.ToFlatString) FunctionObject(com.github.anba.es6draft.runtime.types.builtins.FunctionObject) StringModuleSource(com.github.anba.es6draft.runtime.modules.loader.StringModuleSource) StringModuleSource(com.github.anba.es6draft.runtime.modules.loader.StringModuleSource) ModuleSource(com.github.anba.es6draft.runtime.modules.ModuleSource) Source(com.github.anba.es6draft.runtime.internal.Source) Executable(com.github.anba.es6draft.Executable) DebugInfo(com.github.anba.es6draft.runtime.internal.DebugInfo) ScriptLoader(com.github.anba.es6draft.runtime.internal.ScriptLoader) StringModuleSource(com.github.anba.es6draft.runtime.modules.loader.StringModuleSource) ModuleSource(com.github.anba.es6draft.runtime.modules.ModuleSource) PrintWriter(java.io.PrintWriter) Function(com.github.anba.es6draft.runtime.internal.Properties.Function)

Example 4 with Executable

use of com.github.anba.es6draft.Executable 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;
}
Also used : FunctionObject(com.github.anba.es6draft.runtime.types.builtins.FunctionObject) BoundFunctionObject(com.github.anba.es6draft.runtime.types.builtins.BoundFunctionObject) Executable(com.github.anba.es6draft.Executable)

Aggregations

Executable (com.github.anba.es6draft.Executable)4 FunctionObject (com.github.anba.es6draft.runtime.types.builtins.FunctionObject)2 Script (com.github.anba.es6draft.Script)1 CompiledScript (com.github.anba.es6draft.compiler.CompiledScript)1 SharedFunctions.loadScript (com.github.anba.es6draft.repl.global.SharedFunctions.loadScript)1 SharedFunctions.relativePathToScript (com.github.anba.es6draft.repl.global.SharedFunctions.relativePathToScript)1 ToFlatString (com.github.anba.es6draft.runtime.AbstractOperations.ToFlatString)1 ExecutionContext.newDefaultExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext.newDefaultExecutionContext)1 DebugInfo (com.github.anba.es6draft.runtime.internal.DebugInfo)1 Function (com.github.anba.es6draft.runtime.internal.Properties.Function)1 ScriptLoader (com.github.anba.es6draft.runtime.internal.ScriptLoader)1 Source (com.github.anba.es6draft.runtime.internal.Source)1 ModuleLoader (com.github.anba.es6draft.runtime.modules.ModuleLoader)1 ModuleSource (com.github.anba.es6draft.runtime.modules.ModuleSource)1 SourceIdentifier (com.github.anba.es6draft.runtime.modules.SourceIdentifier)1 SourceTextModuleRecord (com.github.anba.es6draft.runtime.modules.SourceTextModuleRecord)1 StringModuleSource (com.github.anba.es6draft.runtime.modules.loader.StringModuleSource)1 BoundFunctionObject (com.github.anba.es6draft.runtime.types.builtins.BoundFunctionObject)1 PrintWriter (java.io.PrintWriter)1