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 <kevinshihaoc...@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-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/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

cleme...@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/CAGO%3DqhAtVWQVYyFTQt3TaTMjfwaVviTcZEGYgp%3DvH9YvUr-ypw%40mail.gmail.com.

Reply via email to