Skip to content

Commit

Permalink
[js] Load the wasm part of source map handling from disk
Browse files Browse the repository at this point in the history
  • Loading branch information
pmurias committed Feb 25, 2019
1 parent 93470d6 commit c4030ec
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/vm/js/Operations.nqp
Expand Up @@ -899,8 +899,8 @@ class QAST::OperationsJS {

add_simple_op('newexception', $T_OBJ, [], :side_effects);

add_simple_op('backtracestrings', $T_OBJ, [$T_OBJ], :takes_hll);
add_simple_op('backtrace', $T_OBJ, [$T_OBJ], :takes_hll);
add_simple_op('backtracestrings', $T_OBJ, [$T_OBJ], :takes_hll, :await);
add_simple_op('backtrace', $T_OBJ, [$T_OBJ], :takes_hll, :await);

add_simple_op('findmethod', $T_OBJ, [$T_OBJ, $T_STR], :side_effects, :decont(0), :ctx, :await);
add_simple_op('tryfindmethod', $T_OBJ, [$T_OBJ, $T_STR], :side_effects, :decont(0), :ctx, :await);
Expand Down
17 changes: 10 additions & 7 deletions src/vm/js/nqp-runtime/core.js
Expand Up @@ -53,7 +53,7 @@ const unicodeCollationAlgorithm = require('unicode-collation-algorithm');

const unicodeData = require('nqp-unicode-data');

const resolveSourceMap = process.browser ? null : require('./resolve-sourcemap.js');
const resolveSourceMap = process.browser ? require('./resolve-sourcemap-browser.js') : require('./resolve-sourcemap.js');

const path = process.browser ? null : require('path');

Expand Down Expand Up @@ -1674,7 +1674,7 @@ op.getstaticcode = function(codeRef) {
return codeRef.staticCode;
};

function backtrace(exception) {
/*async*/ function backtrace(exception) {
if (exception.$$ctx) {
let ctx = exception.$$ctx.$$skipHandlers();

Expand Down Expand Up @@ -1719,11 +1719,14 @@ function backtrace(exception) {
}
} else {
if (file && resolveSourceMap) {
const resolved = resolveSourceMap(file);
const resolved = /*await*/ resolveSourceMap(file);
if (resolved !== null) {
const original = resolved.originalPositionFor({line: line, column: column});
if (original.source) {
file = original.source;

/* HACK - avoid parcel adding a ../ prefix */
file = file.replace(/^\.\.\/SETTING::/, 'SETTING::');
line = original.line;
column = original.column;
}
Expand Down Expand Up @@ -1752,14 +1755,14 @@ function backtrace(exception) {
}
};

op.backtrace = function(currentHLL, exception) {
return hll.list(currentHLL, backtrace(exception));
op.backtrace = /*async*/ function(currentHLL, exception) {
return hll.list(currentHLL, /*await*/ backtrace(exception));
};

op.backtracestrings = function(currentHLL, exception) {
op.backtracestrings = /*async*/ function(currentHLL, exception) {
const lines = [];
let first = true;
for (const row of backtrace(exception)) {
for (const row of /*await*/ backtrace(exception)) {
const annotations = row.$$atkey('annotations');
const sub = row.$$atkey('sub');
lines.push((first ? ' at ' : ' from ') + annotations.$$atkey('file').value + ':'+ annotations.$$atkey('line').value + ' (cuid ' + sub.cuid + ')');
Expand Down
29 changes: 29 additions & 0 deletions src/vm/js/nqp-runtime/resolve-sourcemap-browser.js
@@ -0,0 +1,29 @@
const SourceMapConsumer = require('source-map').SourceMapConsumer;


const cache = new Map();

const sourceMapInfo = [/*sourceMapInfo*/];

if ('/*async*/' === '/*asy' + 'nc*/' || typeof fetch == 'undefined') {
module.exports = null;
} else {
SourceMapConsumer.initialize({
'lib/mappings.wasm': require('./mappings-wasm-base64.js')
});

module.exports = async function(filename) {
if (cache.has(filename)) return cache.get(filename);

if (sourceMapInfo.length == 1) {
const response = await fetch(sourceMapInfo[0].mapUrl);

const json = await response.json();

const ret = new SourceMapConsumer(json);

cache.set(filename, ret);
return ret;
}
};
}

0 comments on commit c4030ec

Please sign in to comment.