anba / es6draft Goto Github PK
View Code? Open in Web Editor NEWECMAScript 2015 (ECMA-262 6th Edition) compiler and runtime
License: MIT License
ECMAScript 2015 (ECMA-262 6th Edition) compiler and runtime
License: MIT License
The project name implies it doesn’t implement ES6/ES2015 fully, let alone more recent additions to the spec. But this is not true!
Don’t be modest :) Have you considered renaming the project to something less ephemeral?
I am currently experimenting with es6draft, and I am wondering whether its behaviour with the following piece of code is correct:
function* f2() {
function* g() {
try {
yield 1;
yield 2;
} finally {
yield 3;
print("Should be reachable???");
yield 4;
}
}
yield* g();
yield 5;
}
var g2 = f2();
g2.next(); // -> yields {value: 1, done: false}
g2.return(42); // -> yields {value: 3, done: true}
g2.next(); // -> yields {value: undefined, done: true}
The comments of the form // ->
show what es6draft returns. Is this behaviour really the one that is intended by the latest draft of ES6? For example, the print statement in the finally clause is never being executed.
(Reading the spec, it looks to me that es6draft is correct in its behaviour, but does it make sense?)
js> Reflect.ownKeys(Array.prototype).filter(v => v==="length")
[ "length", "length" ]
I'm reading your code and trying to understand, I konw you write the code base on ecmascript specification, but there are some terms or explaination that I can't understand.
So I want to know whether you have some extra docs to help me to understand, thank you very much.
README.md says "Implements ES2018 Draft 2018-10-25, ES2018 Intl Draft 2018-10-24".
Presumably the years in the dates should be 2017.
$ pbpaste
"some code copied from somewhere"
$ pbpaste | ./es6draft
js> "some code copied from somewhere"
js> // hanged here
js> (new class extends RegExp {
exec(){
return {index: 0};
}
})[Symbol.replace]("a", "b")
java.lang.NullPointerException
at com.github.anba.es6draft.runtime.objects.text.RegExpPrototype$Properties.replace(RegExpPrototype.java:470)
at #typein_1.~script(typein:3)
at com.github.anba.es6draft.runtime.internal.RuntimeInfo$CompiledScriptBody.evaluate(RuntimeInfo.java:310)
at com.github.anba.es6draft.compiler.CompiledScript.evaluate(CompiledScript.java:28)
at com.github.anba.es6draft.Scripts.ScriptEvaluation(Scripts.java:50)
at com.github.anba.es6draft.repl.Repl.eval(Repl.java:782)
at com.github.anba.es6draft.repl.Repl.access$300(Repl.java:97)
at com.github.anba.es6draft.repl.Repl$InteractiveTaskSource$EvalPrintTask.execute(Repl.java:911)
at com.github.anba.es6draft.runtime.World.executeTasks(World.java:221)
at com.github.anba.es6draft.runtime.World.runEventLoop(World.java:198)
at com.github.anba.es6draft.repl.Repl.loop(Repl.java:808)
at com.github.anba.es6draft.repl.Repl.main(Repl.java:108)
The ES6 spec defines Symbol.prototype[Symbol.toPrimitive]
as a function with a single parameter.
According to section 17, in the absence of any text specifying otherwise, the function's length
property value should be dictated by its formal parameter list:
Every built-in Function object, including constructors, has a length
property whose value is an integer. Unless otherwise specified, this value
is equal to the largest number of named arguments shown in the subclause
headings for the function description, including optional parameters.
This is a bit disappointing because the parameter isn't actually referenced in the algorithm, but I believe following the letter of the spec means defining the length
property to 1
.
js> print("1", "2", "3")
1 2 3
js> console.log("1", "2", "3")
1 "2" "3"
js> console.error("1", "2", "3")
1 "2" "3"
[deleted]
js> "ab".match(/([ab]*?)*/)
[ "", "" ] // should be ["ab", "b"]
I'm afraid I can't explain myself very well due to my bad english, so I will give you some examples to demonstrate:
$ pbpaste
var foo = Number
`123`
print(typeof foo)
SpiderMonkey:
pbpaste | js
js> var foo = Number
js> `123`
"123"
js> print(typeof foo)
function
$ pbpaste | js -
number
es6draft:
$ pbpaste | ./es6draft
js> var foo = Number
js> `123`
"123"
js> print(typeof foo)
function
$ pbpaste | ./es6draft -
"-" is not a valid option
$ pbpaste | ./es6draft /dev/stdin
number
When a function's name
property is derived from a Symbol value that has no
description, the name should be "[]"
.
$ ./bin/es6draft --version
es6draft rev38 (build: 2015-07-06T15:04:38)
$ ./bin/es6draft -e 'var s = Symbol(); var o = { [s]: ()=>{} }; print(o[s].name);'
$
(espected: "[]")
19.4.1.1 Symbol ( [ description ] )
When Symbol is called with optional argument description, the following steps
are taken:
- If NewTarget is not undefined, throw a TypeError exception.
- If description is undefined, let descString be undefined.
- Else, let descString be ToString(description).
- ReturnIfAbrupt(descString).
- Return a new unique Symbol value whose [[Description]] value is descString.
9.2.11 SetFunctionName (F, name, prefix)
The abstract operation SetFunctionName requires a Function argument F, a
String or Symbol argument name and optionally a String argument prefix. This
operation adds a name property to F by performing the following steps:
- Assert: F is an extensible object that does not have a name own property.
- Assert: Type(name) is either Symbol or String.
- Assert: If prefix was passed then Type(prefix) is String.
- If Type(name) is Symbol, then
- Let description be name’s [[Description]] value.
- If description is undefined, let name be the empty String.
- Else, let name be the concatenation of "[", description, and "]".
- If prefix was passed, then
- Let name be the concatenation of prefix, code unit 0x0020 (SPACE), and
name.- Return DefinePropertyOrThrow(F, "name", PropertyDescriptor{[[Value]]:
name, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]:
true}).- Assert: the result is never an abrupt completion.
I have to admit that I haven't taken a closer look at your code base. Do you think it is feasible to translate your work form Java to C++? In the latter case it could be compiled with Emscripten and after adapting it to the browser environment, one would have a nearly 100% complete implementation for ES6 on the browser. (And would be prepared when ES7 is specced.)
With asm.js, I don't think it would run slower than the current code in the JVM.
js> ({/ /(){}})
java.lang.AssertionError
at com.github.anba.es6draft.parser.TokenStream.peekToken(TokenStream.java:372)
at com.github.anba.es6draft.parser.Parser.SAFE_LOOKAHEAD(Parser.java:1810)
at com.github.anba.es6draft.parser.Parser.propertyDefinition(Parser.java:7558)
at com.github.anba.es6draft.parser.Parser.objectLiteral(Parser.java:7386)
at com.github.anba.es6draft.parser.Parser.primaryExpression(Parser.java:6921)
at com.github.anba.es6draft.parser.Parser.leftHandSideExpression(Parser.java:7986)
at com.github.anba.es6draft.parser.Parser.unaryExpression(Parser.java:8242)
at com.github.anba.es6draft.parser.Parser.binaryExpression(Parser.java:8343)
at com.github.anba.es6draft.parser.Parser.assignmentExpression(Parser.java:8507)
at com.github.anba.es6draft.parser.Parser.assignmentExpressionNoValidation(Parser.java:8466)
at com.github.anba.es6draft.parser.Parser.coverParenthesizedExpressionAndArrowParameterList(Parser.java:7001)
at com.github.anba.es6draft.parser.Parser.primaryExpression(Parser.java:6932)
at com.github.anba.es6draft.parser.Parser.leftHandSideExpression(Parser.java:7986)
at com.github.anba.es6draft.parser.Parser.unaryExpression(Parser.java:8242)
at com.github.anba.es6draft.parser.Parser.binaryExpression(Parser.java:8343)
at com.github.anba.es6draft.parser.Parser.assignmentExpression(Parser.java:8507)
at com.github.anba.es6draft.parser.Parser.assignmentExpression(Parser.java:8451)
at com.github.anba.es6draft.parser.Parser.expression(Parser.java:8922)
at com.github.anba.es6draft.parser.Parser.expressionStatement(Parser.java:5585)
at com.github.anba.es6draft.parser.Parser.statement(Parser.java:4933)
at ...(Frames omitted:13)
If Promise.resolve
is invoked with a Promise instance as its first argument,
that object should only be returned if its constructor
property matches the
current "this" value.
$ ./bin/es6draft --version
es6draft rev38 (build: 2015-07-06T15:04:38)
$ ./bin/es6draft
js> var p1 = new Promise(function() {});
js> p1.constructor = null;
null
js> Promise.resolve(p1) === p1
true
(expected: false)
25.4.4.5 Promise.resolve ( x )
- Let C be the this value.
- If Type(C) is not Object, throw a TypeError exception.
- If IsPromise(x) is true,
- Let xConstructor be Get(x, "constructor").
- ReturnIfAbrupt(xConstructor).
- If SameValue(xConstructor, C) is true, return x.
See also:
How would you feel about attaching precompiled .jar
files to each release (i.e. pages like https://github.com/anba/es6draft/releases/tag/rev37) from now on?
This way, people could download the .jar
and run it without having to compile from source.
It would also enable adding es6draft support to jsvu: GoogleChromeLabs/jsvu#26
What do you think?
If a "RegExp-like" object sets its own lastIndex
property to an out-of-bounds
value during a "split" operation, es6draft will crash.
Example:
var obj = {
constructor: function() {}
};
var fakeRe = {
exec: function() {
fakeRe.lastIndex = 999;
return [];
}
};
obj.constructor[Symbol.species] = function() {
return fakeRe;
};
RegExp.prototype[Symbol.split].call(obj, 'a');
Produces the following error:
java.lang.StringIndexOutOfBoundsException: String index out of range: -998
at java.lang.String.substring(String.java:1955)
at com.github.anba.es6draft.runtime.objects.text.RegExpPrototype$Properties.split(RegExpPrototype.java:672)
at com.github.anba.es6draft.runtime.types.builtins.NativeFunction.call(NativeFunction.java:97)
at com.github.anba.es6draft.runtime.types.builtins.BuiltinFunction.tailCall(BuiltinFunction.java:206)
at com.github.anba.es6draft.runtime.internal.TailCallInvocation$CallTailCallInvocation.apply(TailCallInvocation.java:66)
at com.github.anba.es6draft.runtime.internal.TailCallInvocation.tailCallTrampoline(TailCallInvocation.java:179)
at #typein_1.~script_code(/test262/tmp2.js:14)
at #typein_1.!script(/test262/tmp2.js:1)
at com.github.anba.es6draft.runtime.internal.RuntimeInfo$CompiledScriptBody.evaluate(RuntimeInfo.java:233)
at com.github.anba.es6draft.compiler.CompiledScript.evaluate(CompiledScript.java:29)
at com.github.anba.es6draft.repl.Repl.eval(Repl.java:801)
at com.github.anba.es6draft.repl.Repl.access$300(Repl.java:89)
at com.github.anba.es6draft.repl.Repl$ScriptEvaluationTask.execute(Repl.java:1146)
at com.github.anba.es6draft.runtime.World.executeTasks(World.java:223)
at com.github.anba.es6draft.runtime.World.runEventLoop(World.java:200)
at com.github.anba.es6draft.repl.Repl.loop(Repl.java:827)
at com.github.anba.es6draft.repl.Repl.main(Repl.java:100)
Here's the relevant source code:
/* step 25 */
String t = s.substring(p, size);
This seems like it may be an omission in the spec itself, since an explicit
RangeError might be appropriate here. I've opened a bug on the spec bug tracker
to discuss that possibility: https://bugs.ecmascript.org/show_bug.cgi?id=4434
As it stands, though, the most logical behavior may be to silently skip
appending the final string value.
js> var __proto__ = 1
js> __proto__ === Object.prototype
true
js> let __proto__ = 1
js> __proto__ === 1
true
js> Object.defineProperty(Object.prototype, "foo", {set(v){print("set foo =", v)}})
{}
js> var foo = 1
set foo = 1
@anba Is this intentional or a bug? Thanks!
js> Reflect.parse(`import a,{b} from ""`)
com.github.anba.es6draft.runtime.objects.reflect.ReflectParser$NotImplementedExpception: class com.github.anba.es6draft.ast.ImportClause
at com.github.anba.es6draft.runtime.objects.reflect.ReflectParser.visit(ReflectParser.java:1552)
at com.github.anba.es6draft.runtime.objects.reflect.ReflectParser.visit(ReflectParser.java:42)
at com.github.anba.es6draft.ast.ImportClause.accept(ImportClause.java:42)
at com.github.anba.es6draft.runtime.objects.reflect.ReflectParser.visit(ReflectParser.java:1523)
at com.github.anba.es6draft.runtime.objects.reflect.ReflectParser.visit(ReflectParser.java:42)
at com.github.anba.es6draft.ast.ImportDeclaration.accept(ImportDeclaration.java:51)
at com.github.anba.es6draft.runtime.objects.reflect.ReflectParser.createList(ReflectParser.java:416)
at com.github.anba.es6draft.runtime.objects.reflect.ReflectParser.visit(ReflectParser.java:1718)
at com.github.anba.es6draft.runtime.objects.reflect.ReflectParser.visit(ReflectParser.java:42)
at com.github.anba.es6draft.ast.Module.accept(Module.java:61)
at com.github.anba.es6draft.runtime.objects.reflect.ReflectParser.parse(ReflectParser.java:275)
at com.github.anba.es6draft.runtime.objects.reflect.ReflectParser.parse(ReflectParser.java:239)
at com.github.anba.es6draft.runtime.objects.reflect.Reflect$ParseProperty.parse(Reflect.java:509)
at #typein_1.~script(typein:1)
at com.github.anba.es6draft.runtime.internal.RuntimeInfo$CompiledScriptBody.evaluate(RuntimeInfo.java:289)
at com.github.anba.es6draft.compiler.CompiledScript.evaluate(CompiledScript.java:28)
at com.github.anba.es6draft.Scripts.ScriptEvaluation(Scripts.java:44)
at com.github.anba.es6draft.repl.Repl.eval(Repl.java:785)
at com.github.anba.es6draft.repl.Repl.access$300(Repl.java:97)
at com.github.anba.es6draft.repl.Repl$InteractiveTaskSource$EvalPrintTask.execute(Repl.java:914)
at ...(Frames omitted:4)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.