Tag: ecma262

为什么“dtoa.c”包含这么多代码?

我将是第一个承认我对低级编程的整体知识有点稀疏的人。 我理解许多核心概念,但我不会定期使用它们。 话虽如此,我对dtoa.c需要多少代码感到非常震惊。 在过去的几个月里,我一直在使用C#进行ECMAScript实现,而且我一直在减慢填充引擎中的漏洞。 昨晚我开始研究Number.prototype.toString ,它在ECMAScript规范 (pdf)的 15.7.4.2节中描述。 在第9.8.1节中,注3提供了到dtoa.c的链接,但我正在寻找挑战,所以我等待查看它。 以下是我提出的建议。 private IDynamic ToString(Engine engine, Args args) { var thisBinding = engine.Context.ThisBinding; if (!(thisBinding is NumberObject) && !(thisBinding is NumberPrimitive)) { throw RuntimeError.TypeError(“The current ‘this’ must be a number or a number object.”); } var num = thisBinding.ToNumberPrimitive(); if (double.IsNaN(num)) { return new StringPrimitive(“NaN”); } else […]