语句总是会返回值的

块语句

  1. 对于空 {} 块语句返回(normal, empty)
  2. 对于{ statementList }
    • 对于statementList: statement情况执行statement并返回结果
    • 对于statementList: statementList statement,首先执行statementList并拿到结果v1,如果有提前return则返回v1;否则执行statement拿到结果v2,如果有异常返回{ throw, v };否则判断v2是否为empty;是则将v赋值为v1否则赋值为v2,返回{ normal, v2}

变量语句

  1. 对于声明变量语句var|let|const|class|import|export|function name [= init]返回{ normal, empty }
  2. 对于初始化语句 name=init返回{ normal, init }

空语句

  1. ;返回{ normal, empty }

表达式语句

  1. expression返回 { normal, getValue(expression) }

if语句

  1. if(expression) statement1 else statement2
    • 拿到expression的expRef,并通过ToBoolean(getValue(expRef))判断真假,真则返回statement1的返回值,否则返回statement2的返回值
  2. if(expression) statement 同上,不过判断为假时返回{ normal, empty }

循环语句

  • 各个循环返回值过程基本相同,就使用while(expression) { statement }举例
    1. let v = empty
    2. repeat
      1. let exprRef 为expression 执行后的结果
      2. if ToBoolean(getValue(exprRef)) 为 false, return { normal, v }
      3. let stmt = statement的执行结果
      4. 如果stmt != empty, 则v = stmt.value
      5. 如果stmt.type != continue || stmt.target 不是标签
        1. 如果stmt.type = break && stmt.target是标签则返回 { normal, v }
        2. 否则返回 stmt

break语句

  1. break; 返回{ normal, empty }
  2. break labelname; 返回{ normal, empty, labelname }

return语句

  1. return; 返回{ return, undefined }
  2. return expression; 返回{ return, getValue(exprRef(expression)) }

抛出语句

  1. throw expression; 返回{ throw, getValue(exprRef(expression)) }

try...catch...finally语句

  1. try block catch

    1. let B = Block的结果
    2. if B.type != throw则返回B
    3. 否则返回以B作为参数的catch的执行结果
  2. try block finally

    1. let B = Block结果
    2. let F = finally结果
    3. if F.type == normal返回B的结果
    4. 否则返回F
  3. try block catch finally

    1. let B = block的结果
    2. if B.type != throw,则let C = B
    3. 否则 let C = 以B作为参数的catch的执行结果
    4. let F = finally结果
    5. if F.type == normal返回C的结果
    6. 否则返回F
相关推荐
崔庆才丨静觅17 小时前
hCaptcha 验证码图像识别 API 对接教程
前端
passerby606118 小时前
完成前端时间处理的另一块版图
前端·github·web components
掘了18 小时前
「2025 年终总结」在所有失去的人中,我最怀念我自己
前端·后端·年终总结
崔庆才丨静觅18 小时前
实用免费的 Short URL 短链接 API 对接说明
前端
崔庆才丨静觅18 小时前
5分钟快速搭建 AI 平台并用它赚钱!
前端
崔庆才丨静觅19 小时前
比官方便宜一半以上!Midjourney API 申请及使用
前端
Moment19 小时前
富文本编辑器在 AI 时代为什么这么受欢迎
前端·javascript·后端
崔庆才丨静觅19 小时前
刷屏全网的“nano-banana”API接入指南!0.1元/张量产高清创意图,开发者必藏
前端
剪刀石头布啊19 小时前
jwt介绍
前端
爱敲代码的小鱼19 小时前
AJAX(异步交互的技术来实现从服务端中获取数据):
前端·javascript·ajax