-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
engine262: runtime & agent, documentation, testing
- Loading branch information
Showing
11 changed files
with
352 additions
and
166 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
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,39 @@ | ||
'use strict'; | ||
|
||
const cp = require('child_process'); | ||
const fs = require('fs'); | ||
const runtimePath = require('../runtimePath'); | ||
const ConsoleAgent = require('../ConsoleAgent'); | ||
|
||
const isWindows = process.platform === 'win32' || | ||
process.env.OSTYPE === 'cygwin' || | ||
process.env.OSTYPE === 'msys'; | ||
|
||
class Engine262 extends ConsoleAgent { | ||
evalScript(code, options = {}) { | ||
if (options.module && this.args[0] !== '--module') { | ||
this.args.unshift('--module'); | ||
} | ||
|
||
if (!options.module && this.args[0] === '--module') { | ||
this.args.shift(); | ||
} | ||
|
||
return super.evalScript(code, options); | ||
} | ||
|
||
stop() { | ||
if (isWindows && this[Symbol.for('cp')]) { | ||
// This is necessary for killing a node.js .cmd process on windows | ||
this[Symbol.for('cp')].then(child => cp.exec(`taskkill -F -T -PID ${child.pid}`)); | ||
} else { | ||
super.stop(); | ||
} | ||
|
||
return Promise.resolve(); | ||
} | ||
} | ||
|
||
Engine262.runtime = fs.readFileSync(runtimePath.for('engine262'), 'utf8'); | ||
|
||
module.exports = Engine262; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* Engine262 exposes a "$" object to its runtime */ | ||
/* Using this["\x24"]; prevents overwrite by ConsoleAgent */ | ||
var engine262 = this["\x24"]; | ||
var $ = { | ||
global: engine262.global, | ||
realm: null, | ||
createRealm(options) { | ||
options = options || {}; | ||
options.globals = options.globals || {}; | ||
|
||
var realm = engine262.createRealm(); | ||
|
||
realm.evalScript(this.source); | ||
realm.getGlobal = this.getGlobal; | ||
realm.setGlobal = this.setGlobal; | ||
realm.source = this.source; | ||
realm.destroy = function () { | ||
if (options.destroy) { | ||
options.destroy(); | ||
} | ||
}; | ||
|
||
for (var glob in options.globals) { | ||
realm.global[glob] = options.globals[glob]; | ||
} | ||
|
||
this.realm = realm; | ||
|
||
return realm; | ||
}, | ||
evalScript(code) { | ||
try { | ||
(this.realm || engine262).evalScript(code); | ||
return { type: 'normal', value: undefined }; | ||
} catch (e) { | ||
return { type: 'throw', value: e }; | ||
} | ||
}, | ||
|
||
detachArrayBuffer: engine262.detachArrayBuffer, | ||
getGlobal(name) { | ||
return this.global[name]; | ||
}, | ||
setGlobal(name, value) { | ||
this.global[name] = value; | ||
}, | ||
destroy() { /* noop */ }, | ||
IsHTMLDDA() { return {}; }, | ||
source: $SOURCE | ||
}; |
Oops, something went wrong.