boa icon indicating copy to clipboard operation
boa copied to clipboard

Function.prototyp.toString only returns a fixed `[native code]` string

Open FredrikNoren opened this issue 2 years ago • 4 comments

ECMASCript feature Function.prototyp.toString returns the actual javascript implementation in v8. ECMAScript specification

Example code

let f = () => 1 + 1;
console.log(f.toString());

The expected output is () => 1 + 1.

FredrikNoren avatar Apr 02 '24 08:04 FredrikNoren

Is it ok to add in Cursor a fields that will collect source_text: Vec<u32> when callable is parsing (if nested callable is parsing then it just will take slice of it) to solve the issue? Or maybe do it at some lower layer(on BufferedLexer or Lexer) to pass less params?

Is it acceptable to add this fields into Interner? It seems like not fully fit the meaning of Interner, but it looks very convenient because we have &mut Interner in Tokenizer::lex.

Nikita-str avatar Sep 29 '24 10:09 Nikita-str

Yeah, those changes sound good. I would say that on the AST side it would be the Module and the Script the ones holding the script source, and the rest of nodes would just have a span to index that.

jedel1043 avatar Sep 29 '24 15:09 jedel1043

Hmm, do I understand you correctly: collect ALL the source code, and use it whenever we need some part of initial code (e.g. name of functions, string literals, and function source codes)?

Or should it be done only for source codes of functions (it's what I try to do now)?

Nikita-str avatar Sep 29 '24 16:09 Nikita-str

All the code probably, because we're planning to use that to improve the error messages.

jedel1043 avatar Sep 29 '24 17:09 jedel1043