Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

重学js —— 函数:异步 Generator 函数定义和异步箭头函数定义 #85

Open
lizhongzhen11 opened this issue Mar 11, 2020 · 0 comments
Labels
js基础 Good for newcomers 重学js 重学js系列 规范+MDN

Comments

@lizhongzhen11
Copy link
Owner

异步 Generator 函数定义异步箭头函数定义

异步 Generator EvaluateBody

伴有参数 functionObjectList argumentsList

AsyncGeneratorBody : FunctionBody

  1. 执行 ? FunctionDeclarationInstantiation(functionObject, argumentsList)
  2. 定义 generator? OrdinaryCreateFromConstructor(functionObject, "%AsyncGenerator.prototype%", « [[AsyncGeneratorState]], [[AsyncGeneratorContext]], [[AsyncGeneratorQueue]] »)
  3. 执行 ! AsyncGeneratorStart(G, FunctionBody)
  4. 返回 Completion { [[Type]]: return, [[Value]]: generator, [[Target]]: empty }

异步 Generator 实例化函数对象

伴有参数 scope

AsyncGeneratorDeclaration : async function * 绑定标识符 ( 形参 ) { AsyncGeneratorBody }

  1. 定义 name绑定标识符 字符串值
  2. 定义 F! OrdinaryFunctionCreate(%AsyncGenerator%, 形参, AsyncGeneratorBody, non-lexical-this, scope)
  3. 定义 prototype! OrdinaryObjectCreate(%AsyncGenerator.prototype%)
  4. 执行 ! DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })
  5. 执行 ! SetFunctionName(F, name)
  6. F.[[SourceText]] 赋值为 AsyncGeneratorDeclaration 匹配的 源文本
  7. 返回 F

AsyncGeneratorDeclaration : async function * ( 形参 ) { AsyncGeneratorBody }

  1. 定义 FOrdinaryFunctionCreate(%AsyncGenerator%, 形参, AsyncGeneratorBody, non-lexical-this, scope)
  2. 定义 prototypeOrdinaryObjectCreate(%AsyncGenerator.prototype%)
  3. 执行 DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })
  4. 执行 SetFunctionName(F, "default")
  5. F.[[SourceText]] 赋值为 AsyncGeneratorDeclaration 匹配的 源文本
  6. 返回 F

注意:任何匿名 AsyncGeneratorDeclaration 只能作为 export default 声明的一部分出现

异步 Generator 求值

AsyncGeneratorExpression : async function * ( 形参 ) { AsyncGeneratorBody }

  1. 定义 scope运行时执行上下文LexicalEnvironment
  2. 定义 closure! OrdinaryFunctionCreate(%AsyncGenerator%, 形参, AsyncGeneratorBody, non-lexical-this, scope)
  3. 定义 prototype! OrdinaryObjectCreate(%AsyncGenerator.prototype%)
  4. 执行 ! DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })
  5. closure.[[SourceText]] 赋值为 AsyncGeneratorExpression 匹配的 源文本
  6. 返回 closure

AsyncGeneratorExpression : async function * 绑定标识符 ( 形参 ) { AsyncGeneratorBody }

  1. 定义 scope运行时执行上下文LexicalEnvironment
  2. 定义 funcEnv! NewDeclarativeEnvironment(scope)
  3. 定义 envRecfuncEnvEnvironmentRecord
  4. 定义 name绑定标识符 字符串值
  5. 执行 ! envRec.CreateImmutableBinding(name, false)
  6. 定义 closure! OrdinaryFunctionCreate(%AsyncGenerator%, 形参, AsyncGeneratorBody, non-lexical-this, funcEnv)
  7. 定义 prototype! OrdinaryObjectCreate(%AsyncGenerator.prototype%)
  8. 执行 ! DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })
  9. 执行 ! SetFunctionName(closure, name)
  10. 执行 ! envRec.InitializeBinding(name, closure)
  11. closure.[[SourceText]] 赋值为 AsyncGeneratorExpression 匹配的 源文本
  12. 返回 closure

异步箭头函数 BoundNames

CoverCallExpressionAndAsyncArrowHead : MemberExpression Arguments

  1. 定义 headCoverCallExpressionAndAsyncArrowHeadCoveredAsyncArrowHead
  2. 返回 head

异步箭头函数 EvaluateBody

伴有参数 functionObjectList argumentsList

AsyncConciseBody : ExpressionBody

  1. 定义 promiseCapability! NewPromiseCapability(%Promise%)
  2. 定义 declResultFunctionDeclarationInstantiation(functionObject, argumentsList)
  3. 如果 declResult 不是 abrupt completion
    1. 执行 ! AsyncFunctionStart(promiseCapability, ExpressionBody)
  4. 否则,
    1. 执行 ! Call(promiseCapability.[[Reject]], undefined, « declResult.[[Value]] »)
  5. 返回 Completion { [[Type]]: return, [[Value]]: promiseCapability.[[Promise]], [[Target]]: empty }

异步箭头函数 求值

AsyncArrowFunction : async AsyncArrowBindingIdentifier => AsyncConciseBody

  1. 定义 scope运行时执行上下文LexicalEnvironment
  2. 定义 parametersAsyncArrowBindingIdentifier
  3. 定义 closure! OrdinaryFunctionCreate(%AsyncFunction.prototype%, parameters, AsyncConciseBody, lexical-this, scope)
  4. closure.[[SourceText]] 赋值为 AsyncArrowFunction 匹配的 源文本
  5. 返回 closure

AsyncArrowFunction : CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody

  1. 定义 scope运行时执行上下文LexicalEnvironment
  2. 定义 headCoverCallExpressionAndAsyncArrowHeadCoveredAsyncArrowHead
  3. 定义 parametersheadArrowFormalParameters
  4. 定义 closure! OrdinaryFunctionCreate(%AsyncFunction.prototype%, parameters, AsyncConciseBody, lexical-this, scope)
  5. closure.[[SourceText]] 赋值为 AsyncArrowFunction 匹配的 源文本
  6. 返回 closure
@lizhongzhen11 lizhongzhen11 added js基础 Good for newcomers 重学js 重学js系列 规范+MDN labels Mar 11, 2020
This was referenced Mar 11, 2020
@lizhongzhen11 lizhongzhen11 changed the title 重学js —— 异步 Generator 函数定义和异步箭头函数定义 重学js —— 函数:异步 Generator 函数定义和异步箭头函数定义 Mar 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
js基础 Good for newcomers 重学js 重学js系列 规范+MDN
Projects
None yet
Development

No branches or pull requests

1 participant