-
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.
feat: support generator, add eval5 benchmark, improve reporter (#23)
- Loading branch information
Showing
24 changed files
with
1,010 additions
and
521 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 @@ | ||
const { Interpreter } = require('eval5') | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
const interpreter = new Interpreter(global, {}) | ||
|
||
const script = fs.readFileSync(path.join(__dirname, 'cases/v8-7/_bundle.js'), 'utf8') | ||
interpreter.evaluate(script) |
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
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,65 @@ | ||
import { JSClassCall } from './class' | ||
import { Context } from './context' | ||
import { callFrame } from './executor' | ||
import { StackFrame, createStackFrame } from './frame' | ||
import { JSNewObjectFromCtor, JSObjectType, setObjectData } from './object' | ||
import { JSValue, JS_UNDEFINED, isExceptionValue } from './value' | ||
|
||
export const JS_CALL_ASYNC_YIELD = 1 | ||
export const JS_CALL_ASYNC_YIELD_STAR = 2 | ||
export const JS_CALL_ASYNC_RETURN = 3 | ||
export const JS_CALL_ASYNC_AWAIT = 4 | ||
|
||
export interface JSAsyncFunctionData {} | ||
|
||
export const enum JSGeneratorState { | ||
SUSPENDED_START, | ||
SUSPENDED_YIELD, | ||
SUSPENDED_YIELD_STAR, | ||
EXECUTING, | ||
COMPLETED, | ||
} | ||
|
||
export interface JSGeneratorData { | ||
funcState: JSAsyncLikeFunctionState | ||
state: JSGeneratorState | ||
} | ||
|
||
export interface JSAsyncLikeFunctionState { | ||
thisVal: JSValue | ||
throwFlag: boolean | ||
frame: StackFrame | ||
} | ||
|
||
export const generatorCallHandler: JSClassCall = (ctx, fnObj, thisObj, args, isNew) => { | ||
const data: JSGeneratorData = { | ||
state: JSGeneratorState.SUSPENDED_START, | ||
funcState: { | ||
thisVal: thisObj, | ||
throwFlag: false, | ||
frame: createStackFrame(ctx, fnObj, args), | ||
}, | ||
} | ||
|
||
// TODO: add initial step | ||
|
||
const obj = JSNewObjectFromCtor(ctx, fnObj, JSObjectType.Generator) | ||
if (isExceptionValue(obj)) { | ||
return obj | ||
} | ||
setObjectData(obj.value, data) | ||
|
||
return obj | ||
} | ||
|
||
export function JSAsyncLikeFunctionResume(ctx: Context, data: JSAsyncLikeFunctionState): JSValue { | ||
return callFrame(ctx, data.frame, data.thisVal, JS_UNDEFINED, data.throwFlag) | ||
} | ||
|
||
export function freeGeneratorData(ctx: Context, data: JSGeneratorData) { | ||
if (data.state === JSGeneratorState.COMPLETED) { | ||
return | ||
} | ||
data.state = JSGeneratorState.COMPLETED | ||
// TODO: remove funcState | ||
} |
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
Oops, something went wrong.