protected override Completion ExecuteInternal(EvaluationContext context)
        {
            var engine = context.Engine;
            var env    = engine.ExecutionContext.LexicalEnvironment;
            var F      = _classDefinition.BuildConstructor(context, env);

            var classBinding = _classDefinition._className;

            if (classBinding != null)
            {
                env.InitializeBinding(classBinding, F);
            }

            return(Completion.Empty());
        }
예제 #2
0
    public Module LoadModule(Engine engine, ResolvedSpecifier resolved)
    {
        Module module;

        try
        {
            string code;
            lock (_fileSystem)
            {
                var fileName = Path.Combine(_basePath, resolved.Key).Replace('\\', '/');
                using var stream = new StreamReader(_fileSystem.OpenFile(fileName, FileMode.Open, FileAccess.Read));
                code             = stream.ReadToEnd();
            }

            var parserOptions = new ParserOptions(resolved.Uri?.LocalPath !)
            {
                AdaptRegexp = true,
                Tolerant    = true
            };

            module = new JavaScriptParser(code, parserOptions).ParseModule();
        }
        catch (ParserException ex)
        {
            ExceptionHelper.ThrowSyntaxError(engine.Realm, $"Error while loading module: error in module '{resolved.Uri?.LocalPath}': {ex.Error}");
            module = null;
        }
        catch (Exception ex)
        {
            var message = $"Could not load module {resolved.Uri?.LocalPath}: {ex.Message}";
            ExceptionHelper.ThrowJavaScriptException(engine, message, Completion.Empty());
            module = null;
        }

        return(module);
    }
예제 #3
0
    protected override Completion ExecuteInternal(EvaluationContext context)
    {
        var     env = context.Engine.ExecutionContext.LexicalEnvironment;
        JsValue value;

        if (_classDefinition is not null)
        {
            value = _classDefinition.BuildConstructor(context, env);
            var classBinding = _classDefinition._className;
            if (classBinding != null)
            {
                env.CreateMutableBinding(classBinding);
                env.InitializeBinding(classBinding, value);
            }
        }
        else if (_functionDeclaration is not null)
        {
            value = _functionDeclaration.Execute(context).GetValueOrDefault();
        }
        else if (_assignmentExpression is not null)
        {
            value = _assignmentExpression.GetValue(context).GetValueOrDefault();
        }
        else
        {
            value = _simpleExpression !.GetValue(context).GetValueOrDefault();
        }

        if (value is ObjectInstance oi && !oi.HasOwnProperty("name"))
        {
            oi.SetFunctionName("default");
        }

        env.InitializeBinding("*default*", value);
        return(Completion.Empty());
    }
예제 #4
0
 protected override Completion ExecuteInternal(EvaluationContext context)
 {
     return(Completion.Empty());
 }
예제 #5
0
 protected override Completion ExecuteInternal(EvaluationContext context)
 {
     // just to ensure module context or valid
     context.Engine.GetActiveScriptOrModule().AsModule(context.Engine, context.LastSyntaxNode.Location);
     return(Completion.Empty());
 }