Skip to content

Commit

Permalink
no error if absent evt.data, see phetsims/scenery#825
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Jul 4, 2018
1 parent d0aac8f commit 5751148
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
22 changes: 12 additions & 10 deletions js/sim-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,18 @@ function onSimUnload() {

// handling messages from sims
window.addEventListener( 'message', function( evt ) {
var data = JSON.parse( evt.data );
if ( evt.data ) {
var data = JSON.parse( evt.data );

// Sent by Joist due to the postMessage* query parameters
if ( data.type === 'load' ) {
onSimLoad();
}
else if ( data.type === 'error' ) {
onSimError( data );
}
else if ( data.type === 'beforeUnload' ) {
onSimUnload();
// Sent by Joist due to the postMessage* query parameters
if ( data.type === 'load' ) {
onSimLoad();
}
else if ( data.type === 'error' ) {
onSimError( data );
}
else if ( data.type === 'beforeUnload' ) {
onSimUnload();
}
}
} );
13 changes: 8 additions & 5 deletions test-server/test-sims.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// Grab all query parameters to pass to the simulation, and add additional ones for receiving messages.

(function() {
( function() {
'use strict';
var simulationQueryString = window.location.search;

Expand All @@ -17,7 +17,7 @@
simulationQueryString += 'postMessageOnLoad&postMessageOnError';

var options = QueryStringMachine.getAll( {

// Whether the sim should be left open for the testDuration. If false, once a sim loads, it will change to the next sim.
testTask: {
type: 'boolean',
Expand Down Expand Up @@ -234,6 +234,9 @@

// handling messages from sims
window.addEventListener( 'message', function( evt ) {
if ( !evt.data ) {
return;
}
var data = JSON.parse( evt.data );

function simNameFromURL( url ) {
Expand All @@ -257,7 +260,7 @@
} );

// load the list of sims before kicking things off
(function() {
( function() {
var req = new XMLHttpRequest();
req.onload = function() {
var simListText = req.responseText;
Expand Down Expand Up @@ -296,6 +299,6 @@
// location of active sims
req.open( 'GET', '../../perennial/data/active-runnables', true );
req.send();
})();
} )();

})();
} )();

0 comments on commit 5751148

Please sign in to comment.