Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two fixes to breakpoints and integration test #425

Merged
merged 3 commits into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
language: node_js
node_js:
"8"
install:
- yarn install
script:
- yarn run build
- (cd stopify-continuations-compiler && yarn run test)
- (cd stopify && yarn run test)
cache:
directories:
- node_modules
notifications:
email:false
addons:
chrome: stable
firefox: latest
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Stopify [![Build Status](http://35.207.24.48:5000/buildStatus/icon?job=stopify-build/master)](http://35.207.24.48:5000/blue/organizations/jenkins/stopify-build/activity?branch=master) [![Documentation Status](https://readthedocs.org/projects/stopify/badge/?version=latest)](http://stopify.readthedocs.io/en/latest/?badge=latest)
# Stopify [![Build Status](https://travis-ci.org/plasma-umass/Stopify.svg?branch=master)](https://travis-ci.org/plasma-umass/Stopify) [![Documentation Status](https://readthedocs.org/projects/stopify/badge/?version=latest)](http://stopify.readthedocs.io/en/latest/?badge=latest)

Stopify is a JavaScript-to-JavaScript compiler that makes JavaScript a better
target language for high-level languages and web-based programming tools.
Expand Down
2 changes: 2 additions & 0 deletions docs/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Stopify 0.6.0
estimator is introduced for Node.js programs, using a C++ extension to
Node.js to initialize a timer.

- Fixed several issues with breakpoints. See https://github.com/plasma-umass/Stopify/issues/424.

Stopify 0.5.0
=============

Expand Down
2 changes: 2 additions & 0 deletions stopify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"@types/tmp": "0.0.33",
"@types/webpack": "^3.0.5",
"browserify": "^16.1.0",
"chromedriver": "^2.46.0",
"geckodriver": "^1.16.0",
"glob": "^7.1.1",
"jest": "^20.0.4",
"jest-junit": "^3.1.0",
Expand Down
29 changes: 16 additions & 13 deletions stopify/src/runtime/abstractRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { RuntimeOpts, AsyncRun } from '../types';
import { Result, Runtime } from 'stopify-continuations';
import { RuntimeWithSuspend, badResume } from './suspend';
import { makeEstimator } from './makeEstimator';
import { setImmediate } from './setImmediate';

export enum EventProcessingMode {
Running,
Expand Down Expand Up @@ -55,17 +56,6 @@ export abstract class AbstractRunner implements AsyncRun {
return this.breakpoints.includes(n);
}

private onYieldRunning() {
if (this.mayYieldRunning()) {
this.onBreakpoint(this.suspendRTS.linenum!);
return false;
}
else {
this.onYield();
return true;
}
}

stopifyArray(arr: Array<any>) {
return this.higherOrderFunctions.stopifyArray(arr);
}
Expand Down Expand Up @@ -102,7 +92,20 @@ export abstract class AbstractRunner implements AsyncRun {
case 'pausedAndMayYield':
throw new Error('Internal error: onYield called while paused');
case 'resume':
return this.onYieldRunning();
if (this.mayYieldRunning()) {
this.onYieldFlag = {
kind: 'paused',
onPaused: this.onBreakpoint
};
this.eventMode = EventProcessingMode.Paused;
// Invoke the breakpoint handler on the next turn, after the stack
// is fully reified.
setImmediate(() =>
this.onBreakpoint(this.suspendRTS.linenum!));
return false;
}
this.onYield();
return true;
default: // Step
return !this.suspendRTS.mayYield();
}
Expand Down Expand Up @@ -181,7 +184,7 @@ export abstract class AbstractRunner implements AsyncRun {
else {
this.eventMode = EventProcessingMode.Running;
this.mayYieldFlag = { kind: 'resume' };
this.onYieldFlag = { kind: 'resume' }
this.onYieldFlag = { kind: 'resume' };
this.suspendRTS.resumeFromCaptured();
}
}
Expand Down
55 changes: 29 additions & 26 deletions stopify/src/stopify/suspendStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,37 @@ import { NodePath, Visitor } from 'babel-traverse';
import * as t from 'babel-types';
import { CompilerOpts } from 'stopify-continuations-compiler';

function insertSuspendHelper(body: t.Statement[], opts: CompilerOpts) {
const newBody: t.Statement[] = [];
(<any>newBody).suspends = false;
body.forEach((v, i) => {
const loc = v.loc;
let ln: number | null;
if (loc) {
ln = opts.sourceMap.getLine(loc.start.line, loc.start.column);
if (ln) {
newBody.push(
t.expressionStatement(t.assignmentExpression('=',
t.memberExpression(t.memberExpression(t.identifier('$S'), t.identifier('suspendRTS')), t.identifier('linenum')),
t.numericLiteral(ln))),
t.expressionStatement(
t.callExpression(t.memberExpression(t.identifier("$S"),
t.identifier("suspend")), [])),
v);
(<any>newBody).suspends = true;
} else {
newBody.push(v);
}
} else {
newBody.push(v);
}
});
return newBody;
}
const insertSuspend: Visitor = {
BlockStatement: {
exit(path: NodePath<t.BlockStatement>, s: { opts: CompilerOpts }): void {
const { body } = path.node;
const newBody: t.Statement[] = [];
(<any>newBody).suspends = false;
body.forEach((v, i) => {
const loc = v.loc;
let ln: number | null;
if (loc) {
ln = s.opts.sourceMap.getLine(loc.start.line, loc.start.column);
if (ln) {
newBody.push(
t.expressionStatement(t.assignmentExpression('=',
t.memberExpression(t.identifier('$__R'), t.identifier('linenum')),
t.numericLiteral(ln))),
t.expressionStatement(
t.callExpression(t.memberExpression(t.identifier("$S"),
t.identifier("suspend")), [])),
v);
(<any>newBody).suspends = true;
} else {
newBody.push(v);
}
} else {
newBody.push(v);
}
});
path.node.body = newBody;
path.node.body = insertSuspendHelper(path.node.body, s.opts);
}
},

Expand Down Expand Up @@ -75,6 +77,7 @@ const insertSuspend: Visitor = {
`Compile function expected top-level functionDeclaration`);
}
}
path.node.body = insertSuspendHelper(path.node.body, opts);
}
},
};
Expand Down
76 changes: 76 additions & 0 deletions stopify/test-data/integration/breakpoints.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<html>
<body>
<title>running</title>
<script src="../../dist/stopify-full.bundle.js"></script>
<script>
window.onerror = function() {
window.document.title = "error";
}

let breakAt = [];
let log = [];

const program = `
function app(f, x) {
var r = f(x);
return r;
}

function incr(y) {
return y + 10;
}

log(app(incr, 5));
log(app(incr, 10));
log('at breakpoint');
log('test');
`;

function arrayEquals(arr1, arr2) {
if (arr1.length !== arr2.length) {
return false;
}
for (let i = 0; i < arr1.length; i++) {
if (arr1[i] !== arr2[i]) {
return false;
}
}
return true;
}

const asyncRun = stopify.stopifyLocally(program,
// per-line instrumentation for breakpoints
{ debug: true },
// check each line for breakpoints
{estimator: 'countdown', yieldInterval: 1 });

asyncRun.g.log = (message) => log.push(message);

asyncRun.setBreakpoints([3, 13]);

asyncRun.run(
// on done handler
(result) => {
if (result.type !== 'normal') {
console.error('Result is ', result);
window.document.title = 'error';
}
else if (arrayEquals(breakAt, [3, 3, 13])) {
window.document.title = 'okay';
}
else {
console.log('Breakpoints hit at lines ', breakAt);
window.document.title = 'error';
}
},
// on yield handler
() => { },
// breakpoint handler
(line) => {
breakAt.push(line);
asyncRun.resume();
});

</script>
</body>
</html>
Loading