-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
279 additions
and
6 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,8 @@ | ||
# Apply the following rules to these file types | ||
[*] | ||
end_of_line = lf #Unix type line endings | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 2 | ||
trim_trailing_whitespace = true | ||
max_line_length = 120 |
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 |
---|---|---|
|
@@ -106,4 +106,5 @@ dist | |
compile_commands.json | ||
|
||
build/ | ||
.clangd | ||
.clangd | ||
.idea/ |
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 |
---|---|---|
@@ -1 +1,27 @@ | ||
var bindings = require('bindings')('qjsc_20210307.node'); | ||
const supportedVersion = ['20210307']; | ||
|
||
class Qjsc { | ||
constructor(version = '20210307') { | ||
if (supportedVersion.indexOf(version) === -1) { | ||
throw new Error('Unsupported quickjs version: ' + version); | ||
} | ||
this._bindings = require('bindings')(`qjsc_${version}.node`); | ||
} | ||
help() { | ||
console.log('supported version: ' + supportedVersion.join(', ')); | ||
} | ||
|
||
dumpByteCode(code) { | ||
return this._bindings.dumpByteCode(code); | ||
} | ||
|
||
version() { | ||
return this._bindings.version(); | ||
} | ||
|
||
evalByteCode(buffer) { | ||
return this._bindings.evalByteCode(buffer); | ||
} | ||
} | ||
|
||
module.exports = Qjsc; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const Qjsc = require('./index'); | ||
|
||
const qjsc = new Qjsc(); | ||
|
||
describe('qjsc', () => { | ||
it('throw error when empty arguments', () => { | ||
expect(() => qjsc.dumpByteCode()).toThrowError('1st arguments should be string.'); | ||
}); | ||
|
||
it('throw error when js syntax not correct', () => { | ||
const code = ` | ||
function f() { | ||
console.log(111; | ||
`; | ||
expect(() => qjsc.dumpByteCode(code)).toThrowError(); | ||
}); | ||
|
||
it('return bytecode binary', () => { | ||
const code = ` | ||
function f() { return 1 + '1234'; } | ||
f(); | ||
`; | ||
let buffer = qjsc.dumpByteCode(code); | ||
expect(qjsc.evalByteCode(buffer)).toBe('11234'); | ||
}); | ||
}); |