UNPKG

yzhanjsinterpreter

Version:

A JavaScript Interpreter Using JS itself. JavaScript 解释器,包含词法分析、语法解析和执行

17 lines (16 loc) 654 B
const JSFunction = require('../JSFunction.js') const Task = require('../Task.js') module.exports = class extends JSFunction { constructor(executor, promiseInstance) { super(null, executor) this.promiseInstance = promiseInstance this.then = null // will pass from (then instance).call } call(currentEnv, args) { const rejectReason = args[0] const { then, executor, promiseInstance } = this if (then !== null) executor.microTaskQueue.push(new Task(currentEnv, then, [rejectReason])) promiseInstance.setProperty('state', { value: 'rejected' }) promiseInstance.setProperty('rejectReason', { value: rejectReason }) } }