facebook / hermes

A JavaScript engine optimized for running React Native.
https://hermesengine.dev/
MIT License
9.87k stars 633 forks source link

lexical function declaration in labeled statements #157

Closed YuanWangC closed 4 years ago

YuanWangC commented 4 years ago

When I execute the testcase below, hermes throw an error: Function declaration not allowed as body of labeled statement, but other engines (v8, Chakra, spiderMonkey etc.) did not throw exceptions. Is this an issue of hermes?

version

3826084

testcase

var NISLFuzzingFunc = function() {
    a: function f(){return true;}
};
NISLFuzzingFunc();

command

build_release/bin/hermes -w testcase.js

output

error: Function declaration not allowed as body of labeled statement

avp commented 4 years ago

ECMAScript disallows a FunctionDeclaration as the body of a labeled statement here: https://www.ecma-international.org/ecma-262/10.0/index.html#sec-labelled-statements-static-semantics-early-errors

However, there is an Annex B note that goes back and disallows them only in strict mode: https://www.ecma-international.org/ecma-262/10.0/index.html#sec-labelled-function-declarations

The current implementation chooses not to support this particular part of Annex B. Note that the clause is only included for web browser compatibility. Hermes doesn't support certain parts of Annex B to simplify the code base, though we can certainly discuss these features on a case-by-case basis.