-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example of using externref in assembly code (#15913)
See #15878
- Loading branch information
Showing
5 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <stdio.h> | ||
|
||
void log_externref(); | ||
void get_externref(); | ||
|
||
int main() { | ||
printf("in main\n"); | ||
log_externref(); | ||
get_externref(); | ||
printf("extenref stored\n"); | ||
log_externref(); | ||
printf("extenref logged\n"); | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
mergeInto(LibraryManager.library, { | ||
get_externref_js: function () { | ||
var test_object = { foo: 1 }; | ||
return test_object; | ||
}, | ||
|
||
log_externref_js: function (ref) { | ||
console.log('log_externref_js: ' + JSON.stringify(ref)); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
in main | ||
log_externref_js: null | ||
extenref stored | ||
log_externref_js: {"foo":1} | ||
extenref logged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Define a global of type `externref` | ||
|
||
.globaltype my_global, externref | ||
my_global: | ||
|
||
# Define a function that will call out to JS, passing the | ||
# externref to the JS function | ||
|
||
.functype log_externref_js (externref) -> () | ||
|
||
.globl log_externref | ||
log_externref: | ||
.functype log_externref () -> () | ||
global.get my_global | ||
call log_externref_js | ||
end_function | ||
|
||
# Define a function that will call out to JS to grab an | ||
# externref | ||
|
||
.functype get_externref_js () -> (externref) | ||
|
||
.globl get_externref | ||
get_externref: | ||
.functype get_externref () -> () | ||
call get_externref_js | ||
global.set my_global | ||
end_function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters