简体   繁体   English

ECMA-262 ReturnIfAbrupt

[英]ECMA-262 ReturnIfAbrupt

Recently, I read the ECMAScript Language Specification. 最近,我阅读了ECMAScript语言规范。 I didn't plan to read the whole specification, I just picked up some parts. 我没有打算阅读整个规范,我只是选了一些部分。 I came cross many questions, one of them is like this: 我遇到了许多问题,其中一个是这样的:

ToLength ToLength

1.Let len be ToInteger(argument).
2.ReturnIfAbrupt(len).
3.If len ≤ +0, then return +0.
4.Return min(len, 2^53-1).

As I understand, it should be like this: 据我了解,它应该是这样的:

var len = ToInteger(argument); // step 1
len = ReturnIfAbrupt(len);// step 2
// step 3
if(len<=0){
    return +0; //-0 is OK too?
}
return Math.min(len, Math.pow(2,53)-1); // step 4

I didn't understand what the meaning of ReturnIfAbrupt(len) is, and I found this: 我不明白ReturnIfAbrupt(len)的含义是什么,我发现了这个:

ReturnIfAbrupt ReturnIfAbrupt

1.If argument is an abrupt completion , then return argument. 1.如果论证是一个突然完成 ,那么回归论证。

2.Else if argument is a Completion Record , then let argument be argument.[[value]]. 2.如果参数是完成记录 ,则让参数为参数。[[value]]。

What is abrupt completion, and the differents between it and Completion Record?Can they combine one step:If argument is an Completion Record , then return argument.Any suggestion will be gratefull! 什么是突然完成,以及它与完成记录之间的区别?它们可以结合一步:如果参数是完成记录 ,那么返回参数。任何建议都会感激不尽!

According to the ECMAScript Spec. 根据ECMAScript规范。

The term “abrupt completion” refers to any completion with a [[type]] value other than normal. 术语“突然完成”是指具有[正常]以外的[[类型]]值的任何完成。

A Completion Record is a "object" with three data member: type ,value and target. 完成记录是具有三个数据成员的“对象”:类型,值和目标。

And http://people.mozilla.org/~jorendorff/es6-draft.html#sec-normalcompletion is a example of Completion Record. http://people.mozilla.org/~jorendorff/es6-draft.html#sec-normalcompletion是完成记录的一个例子。

Still, it is not clear enoughXD , maybe you need further reading on the reading. 不过,目前还不够明确,或许你需要进一步阅读阅读。

My understanding is that in ES 6, when an expression is evaluated, it returns a completion record (which is a specification device for explaining behaviour) that holds information about the result of evaluating the expression. 我的理解是,在ES 6中,当计算表达式时,它返回一个完成记录 (这是一个用于解释行为的规范设备),它包含有关计算表达式结果的信息。

In the case above, if the argument is an abrupt completion record (ie its type is anything other than normal ), then it is returned. 在上面的例子中,如果参数是一个突然的完成记录(即它的类型是除正常之外的任何东西),那么它将被返回。

If the argument is not an abrupt completion record, its value is returned. 如果参数不是突然完成记录,则返回其值。

Which essentially means that if the conversion of the argument to an integer went OK, return the value. 这实质上意味着如果将参数转换为整数,则返回该值。 Otherwise, propigate an error value. 否则,提出错误值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM