forked from bellard/quickjs
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more wip, pulling inspect out of libc
- Loading branch information
Showing
18 changed files
with
148 additions
and
59 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,5 @@ | ||
print("print", 1, {}); | ||
console.log("console.log", 2, {}); | ||
console.warn("console.warn", 3, {}); | ||
console.error("console.error", 4, {}); | ||
console.info("console.info", 5, {}); |
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
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
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
This file was deleted.
Oops, something went wrong.
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
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
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
File renamed without changes.
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 @@ | ||
#include "quickjs-inspect.h" | ||
#include "quickjs-modulesys.h" | ||
|
||
extern const uint8_t qjsc_inspect[]; | ||
extern const uint32_t qjsc_inspect_size; | ||
|
||
int js_inspect_add_inspect_global(JSContext *ctx) | ||
{ | ||
return QJMS_EvalBinary(ctx, qjsc_inspect, qjsc_inspect_size, 0); | ||
} |
File renamed without changes.
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,9 @@ | ||
#ifndef QUICKJS_INSPECT_H | ||
#define QUICKJS_INSPECT_H | ||
|
||
#include "quickjs.h" | ||
|
||
/* Adds 'inspect' global */ | ||
int js_inspect_add_inspect_global(JSContext *ctx); | ||
|
||
#endif /* ifndef QUICKJS_INSPECT_H */ |
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,41 @@ | ||
// The C helper function for adding the global | ||
build({ | ||
output: builddir("intermediate/quickjs-inspect.host.o"), | ||
rule: "cc_host", | ||
inputs: [rel("quickjs-inspect.c")], | ||
}); | ||
|
||
build({ | ||
output: builddir("intermediate/quickjs-inspect.target.o"), | ||
rule: "cc_target", | ||
inputs: [rel("quickjs-inspect.c")], | ||
}); | ||
|
||
// C bytecode file generated from js | ||
const inspect_c = build({ | ||
output: builddir("intermediate/inspect.c"), | ||
rule: "qjsc", | ||
inputs: [rel("inspect.js")], | ||
ruleVariables: { | ||
qjsc_args: `-c -m`, | ||
}, | ||
}); | ||
|
||
// The compiled objects containing the bytecode | ||
build({ | ||
output: builddir("intermediate/inspect.host.o"), | ||
rule: "cc_host", | ||
inputs: [inspect_c], | ||
}); | ||
|
||
build({ | ||
output: builddir("intermediate/inspect.target.o"), | ||
rule: "cc_target", | ||
inputs: [inspect_c], | ||
}); | ||
|
||
build({ | ||
output: builddir("dts/quickjs-inspect.d.ts"), | ||
rule: "copy", | ||
inputs: [rel("quickjs-inspect.d.ts")], | ||
}); |
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
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
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
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,31 @@ | ||
import { spawn } from "first-base"; | ||
import { binDir, rootDir } from "./_utils"; | ||
|
||
test("inspect", async () => { | ||
const run = spawn(binDir("qjs"), [ | ||
"-e", | ||
` | ||
const obj = { | ||
something: { | ||
theSomething: true, | ||
} | ||
} | ||
print(inspect(obj)); | ||
`, | ||
]); | ||
await run.completion; | ||
expect(run.result).toMatchInlineSnapshot(` | ||
{ | ||
"code": 0, | ||
"error": false, | ||
"stderr": "", | ||
"stdout": "{ | ||
something: { | ||
theSomething: true | ||
} | ||
} | ||
", | ||
} | ||
`); | ||
}); |
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,20 @@ | ||
import { spawn } from "first-base"; | ||
import { binDir, rootDir } from "./_utils"; | ||
|
||
test("quickjs-print", async () => { | ||
const run = spawn(binDir("qjs"), [rootDir("examples/logging.js")]); | ||
await run.completion; | ||
expect(run.result).toMatchInlineSnapshot(` | ||
{ | ||
"code": 0, | ||
"error": false, | ||
"stderr": "console.warn 3 [object Object] | ||
console.error 4 [object Object] | ||
", | ||
"stdout": "print 1 [object Object] | ||
console.log 2 [object Object] | ||
console.info 5 [object Object] | ||
", | ||
} | ||
`); | ||
}); |