-
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
8 changed files
with
157 additions
and
52 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
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,8 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<body> | ||
<script> | ||
console.log('helloworld'); | ||
</script> | ||
</body> | ||
</html> |
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,25 @@ | ||
const jsdom = require("jsdom"); | ||
const { JSDOM } = jsdom; | ||
const Qjsc = require('./qjsc'); | ||
const { Wbc } = require('./wbc'); | ||
|
||
function parseAndConvertHTML(html, version = '1') { | ||
let dom = new JSDOM(html); | ||
const scripts = dom.window.document.querySelectorAll('script'); | ||
|
||
[].slice.call(scripts).forEach(script => { | ||
const textContent = script.textContent; | ||
if (textContent.length == 0) return; | ||
const qjsc = new Qjsc(); | ||
const wbc = new Wbc(); | ||
const buffer = qjsc.compile(textContent); | ||
let wbcBytecode = wbc.generateWbcBytecode(buffer); | ||
let code = wbcBytecode.toString('binary'); | ||
script.textContent = code; | ||
}) | ||
|
||
return dom.window.document.documentElement.outerHTML; | ||
} | ||
|
||
|
||
module.exports = parseAndConvertHTML; |
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,33 +1,24 @@ | ||
const supportedVersions = ['1']; | ||
const { Wbc } = require('./wbc'); | ||
const Qjsc = require('./qjsc'); | ||
const parseAndConvertHTML = require('./html_converter'); | ||
|
||
class Qjsc { | ||
constructor(options = {}) { | ||
let version = options.version || '1'; | ||
if (supportedVersions.indexOf(version) === -1) { | ||
throw new Error('Unsupported WBC version: ' + version); | ||
} | ||
this._bindings = require('node-gyp-build')(__dirname); | ||
} | ||
help() { | ||
console.log('Supported WBC versions: ' + supportedVersions.join(', ')); | ||
} | ||
|
||
getSupportedVersions() { | ||
return supportedVersions; | ||
} | ||
|
||
compile(code, options = {}) { | ||
let sourceURL = options.sourceURL || 'internal://'; | ||
return this._bindings.dumpByteCode(code, sourceURL); | ||
} | ||
function compileJavaScriptToWbc(code, version = '1') { | ||
const qjsc = new Qjsc({version: version}); | ||
const wbc = new Wbc(); | ||
const quickjsBuffer = qjsc.compile(code); | ||
let wbcBytecode = wbc.generateWbcBytecode(quickjsBuffer); | ||
return wbcBytecode; | ||
} | ||
|
||
get version() { | ||
return this._bindings.version; | ||
} | ||
function legacyCompileJavaScriptToKBC(code) { | ||
const qjsc = new Qjsc(); | ||
return qjsc.compile(code); | ||
} | ||
|
||
_evalByteCode(buffer) { | ||
return this._bindings.evalByteCode(buffer); | ||
} | ||
function transformInlineScriptToWbc(html, version = '1') { | ||
return parseAndConvertHTML(html, version); | ||
} | ||
|
||
module.exports = Qjsc; | ||
exports.compileJavaScriptToWbc = compileJavaScriptToWbc; | ||
exports.transformInlineScriptToWbc = transformInlineScriptToWbc; | ||
exports.legacyCompileJavaScriptToKBC = legacyCompileJavaScriptToKBC; |
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,33 @@ | ||
const supportedVersions = ['1']; | ||
|
||
class Qjsc { | ||
constructor(options = {}) { | ||
let version = options.version || '1'; | ||
if (supportedVersions.indexOf(version) === -1) { | ||
throw new Error('Unsupported WBC version: ' + version); | ||
} | ||
this._bindings = require('node-gyp-build')(__dirname); | ||
} | ||
help() { | ||
console.log('Supported WBC versions: ' + supportedVersions.join(', ')); | ||
} | ||
|
||
getSupportedVersions() { | ||
return supportedVersions; | ||
} | ||
|
||
compile(code, options = {}) { | ||
let sourceURL = options.sourceURL || 'internal://'; | ||
return this._bindings.dumpByteCode(code, sourceURL); | ||
} | ||
|
||
get version() { | ||
return this._bindings.version; | ||
} | ||
|
||
_evalByteCode(buffer) { | ||
return this._bindings.evalByteCode(buffer); | ||
} | ||
} | ||
|
||
module.exports = Qjsc; |
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