什么是Gecko的Javascript解释器引擎语义? [英] What are Gecko's Javascript interpreter engine semantics?

查看:120
本文介绍了什么是Gecko的Javascript解释器引擎语义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑到回答以下关于
参考的回复 ECMAScript语言规范 - 11.13.2复合赋值

考虑为什么这些,

javascript:
   o="";  o = o + (o+=1)    ; alert(o);
   o="";  o =     (o+=1) + o; alert(o);

不一样。从左到右的脚本评估存在时间语义问题(参考: ECMA规范 - 添加运营商)。结果是 + 运算符不一定是可交换的。

are NOT the same. There are temporal semantic issues with left to right script evaluation (ref:ECMA spec. - The addition operator). One consequence is that the + operator is not necessarily commutative.

这也可以通过以下方式看出:

This can also be seen by with:

javascript:
   o=1;  o = o + (o+=1)    ; alert(o);
   o=1;  o =     (o+=1) + o; alert(o);

javascript:
   o=" _ ";  o = o + (o+=1)    ; alert(o);
   o=" _ ";  o =     (o+=1) + o; alert(o);

懒惰的评估范例,由我错误地和不恰当地使用从而造成下面的问题,也是一个坏事个人作案手法的属性。

The lazy evaluation paradigm, erroneously and inappropriately used by me thereby creating the problem below, is also a bad attribute of my personal modus operandi.

以下考虑因素可能已经得到解决,但似乎没有。如果是这样,是否可以提供指向讨论的链接?

The following considerations may already have been addressed, though it seems not. If so, could links to the discussions be provided?

Gecko Javascript运行时引擎的正式指称语义是一个谜。
实证测试令人筋疲力尽,并不能详尽无遗。

The formal denotational semantics of the Gecko Javascript runtime engine are an enigma. Empirical testing is exhausting and cannot be exhaustive.


  • 是否有权威的
    正式规范或官方
    引用确切地定义了Gecko
    如何解释Javascript?

引用, ECMAScript语言规范似乎不充分,尽管为混合物提供了信任像这样的脚本,

The reference, ECMAScript Language Specification, seems inadequate, though credence is provided for the concoction of such scripts like,

javascript: alert( function(){return {}}().life=42 )

以及绑定值时此类结构的结果意义。

with the consequent meaning of such constructs when binding values.


  • 是否有一个明确的范例
    描述了对象和
    实例评估的Javascript代码
    解释?

这将阐明调用(或更确切地说,使用)需求,价值,参考,推理,n的概念ame,......相关与否。 Javascript是一个原型解释器,它给下面的一些问题隐含的意义。

This would clarify the concepts of call by (or rather use by) need, value, reference, inference, name, ... as relevant or not. That, Javascript is a prototyping interpreter, gives implicit meaning to some of the issues below.

预期的结果是什么:

javascript: o={n:0}; f=function(){o.n+=1; return 10};
   alert([
      o.n,            f(),
      o.n,       o.n+=f(),
      o.n, eval('o.n+=f()'), 
      o.n, eval('o.n+='+f()),
      o.n,
   ].join(",\t"));

?是否容易预测结果(正确!)?

? Is it easy to predict the results (correctly!)?

这个问题有点夸张,因为它是用 eval 强迫并强调解释的微妙细微差别。是否可以使用 ECMAScript语言规范或之前提到的其他文件?

The question is a bit rhetorical since it was specifically contrived with eval's to coerce and emphasize the subtle nuances of the interpretation. Can the evaluation of this script (and the aside below) be resolved with either, the ECMAScript Language Specification or another document, alluded to earlier?

(另外,请考虑:

javascript: ra=[];
   alert([
      ra, ra[ra.length]=" partially defined.",
      ra, ra.push("\n RA is not shown"),
      ra, ra.reverse()[42],
   ].join(",\t\t"));

显示:


 RA is not shown, partially defined.,        partially defined.,        
 RA is not shown, partially defined.,       2,      
 RA is not shown, partially defined.,       

其中 ra 的部分评估与上的不相似/ code>'s!

where the partial evaluations of ra are NOT analogous to o.n's!

以及与使用时相比没有异国情调的以下内容:

and the following which is less exotic than using o.n:

javascript: o=""; f=function(){o+=1; return 0};
   alert([
      o,          f(),
      o,       o+=f(),
      o, eval('o+=f()'), 
      o, eval('o+='+f()),
      o,
   ].join(",\t"));

显示:


,   0,  1,  10, 10, 100,    100,    10010,  10010

考虑以下脚本:

javascript:
   asn="\t\t and so now,\t o.n is "; nl="\n\n";
   o={}; f=function(){o.n+=1; return 10};
   alert(["Using:\n",window.navigator.userAgent,
   nl,"The function f() is:\n ",f,
   nl,"What the!!?!? \t\t\t\t\t\t\t initially \t\t o.n is ",          o.n = 0,
 nl,"Called as a procedure: \t\tf() is ", f(),                   asn, o.n,
nl,"but, instead of 12 \t\to.n+=f() is ", o.n+=f(),              asn, o.n,
     nl,"however eval'd\t\to.n+=f() is ", eval("o.n+="+f()),     asn, o.n,
    "!\n\nIt makes no functional difference if, instead of o.n, o['n'] is used.",
    "\nThe expected o.n evaluation sequence is 0, 1, (+1+10=) 12, (+1+10=) 23.",
    "\n_____ _____ _____ _____ _____ _____ _____ _____^^ missing in result",
  ].join(""));

Gecko引擎输出:

The Gecko engine outputs:


Using:
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3)
        Gecko/20100423 Ubuntu/10.04 (lucid) Firefox/3.6.3

The function f() is:
 function () {
    o.n += 1;
    return 10;
}

What the!!?!?                                initially       o.n is 0

Called as a procedure:      f() is 10        and so now,     o.n is 1

but, instead of 12      o.n+=f() is 11       and so now,     o.n is 11

however eval'd          o.n+=f() is 22       and so now,     o.n is 22!

It makes no functional difference if, instead of o.n, o['n'] is used.
The expected o.n evaluation sequence is 0, 1, (+1+10=) 12, (+1+10=) 23.
_____ _____ _____ _____ _____ _____ _____ _____^^ missing in result


推荐答案

JavaScript有一个急切的评估(按值调用)执行模型,在ECMA标准中有明确规定。所有这些问题都可以通过阅读标准来解决。例如,在标准的11.13.2中清楚地说明了结果是11而不是12的原因。 o.n在调用f()之前进行评估,而不是按照步骤2的规定进行评估。

JavaScript has an eager evaluation (call by value) execution model clearly spelled out in the ECMA standard. All of these questions can be resolved by carful reading of the standard. For example, the reason why the result is 11 above and not 12 is clearly spelled out in 11.13.2 of the standard. o.n is evaluated prior to the call to f() not after as specified by step 2.

这篇关于什么是Gecko的Javascript解释器引擎语义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆