Thanks for the reply. But I'm curious about how you got this error message 'test.js:3: Invalid asm.js: Unexpected token' via d8. When I run these two snippets, I don't get any error message.
130|HWSEA-A:/data/local/tmp/v8/bin $ ./d8 V8 version 9.7.0 (candidate) d8> function A() {"use asm"; function R() {} return R} undefined d8> function B() {"use asm"; function R() {}; return R} undefined d8> 在2023年11月21日星期二 UTC+8 18:41:06<Clemens Backes> 写道: > The difference is that the first snippet is valid asm.js > <http://asmjs.org/spec/latest/> while the second snippet is not. > > d8 prints a message if you try to instantiate the second function (via > `A()`): > test.js:3: Invalid asm.js: Unexpected token > > asm.js code is internally converted to Wasm and then run through the Wasm > pipeline. There is a TODO in the code > <https://source.chromium.org/chromium/chromium/src/+/main:v8/src/snapshot/code-serializer.cc;l=69;drc=46087cf6fe634dcd189cc01bcafef39cc0dad4df> > > to enable serialization of asm.js modules, but this has not been worked on > in the last years. If this is something you need, feel free to open a bug > <https://crbug.com/v8/new> and describe your use case. > > -Clemens > > On Tue, Nov 21, 2023 at 3:55 AM haochen shi <kevinsh...@gmail.com> wrote: > >> I try to create a codeCache via V8. >> >> ``` >> ScriptCompiler::CachedData* CreateCachedData(Local<String> sourceContent, >> Local<String> sourceName) { >> ScriptOrigin* scriptOriginPtr = nullptr; >> scriptOriginPtr = new ScriptOrigin( >> String::NewFromTwoByte(isolate_, sourceName, >> NewStringType::kNormal).ToLocalChecked(), >> Integer::New(isolate_, 0), Integer::New(isolate_, 0)); >> ScriptCompiler::Source* source = nullptr; >> source = new ScriptCompiler::Source(sourceContent, *scriptOriginPtr); >> >> Local<Script> script; >> ScriptCompiler::Compile(context_, source, >> ScriptCompiler::CompileOptions::kEagerCompile).ToLocal(&script); >> >> ScriptCompiler::CachedData* data = >> ScriptCompiler::CreateCodeCache(script->GetUnboundScript()); >> >> return data; >> } >> ``` >> >> When I use these code, the value of data is nullptr. >> >> ``` >> function A() { >> "use asm" >> function R() {} >> return R >> } >> ``` >> >> When I use these code, the value of data isn't nullptr. >> >> ``` >> function A() { >> "use asm" >> function R() {}; >> return R >> } >> ``` >> >> What's the difference between these two JS codes? In V8? And In JS? >> >> -- >> -- >> v8-dev mailing list >> v8-...@googlegroups.com >> http://groups.google.com/group/v8-dev >> --- >> You received this message because you are subscribed to the Google Groups >> "v8-dev" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to v8-dev+un...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/v8-dev/5c6eaaa6-b0cc-4196-bd90-2d2dbe632f21n%40googlegroups.com >> >> <https://groups.google.com/d/msgid/v8-dev/5c6eaaa6-b0cc-4196-bd90-2d2dbe632f21n%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > > > -- > > Clemens Backes > > Software Engineer > > clem...@google.com > > Google Germany GmbH > > Erika-Mann-Straße 33 > > 80636 München > > Geschäftsführer: Paul Manicle, Liana Sebastian > > Registergericht und -nummer: Hamburg, HRB 86891 > > Sitz der Gesellschaft: Hamburg > > Diese E-Mail ist vertraulich. Falls sie diese fälschlicherweise erhalten > haben sollten, leiten Sie diese bitte nicht an jemand anderes weiter, > löschen Sie alle Kopien und Anhänge davon und lassen Sie mich bitte wissen, > dass die E-Mail an die falsche Person gesendet wurde. > > > This e-mail is confidential. If you received this communication by > mistake, please don't forward it to anyone else, please erase all copies > and attachments, and please let me know that it has gone to the wrong > person. > > > -- -- v8-dev mailing list v8-dev@googlegroups.com http://groups.google.com/group/v8-dev --- You received this message because you are subscribed to the Google Groups "v8-dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to v8-dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/v8-dev/05c51192-6fad-4a27-9ea7-82392845f5dcn%40googlegroups.com.