summaryrefslogtreecommitdiff
path: root/js/error_stack.ts
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2019-08-24 13:20:48 -0700
committerGitHub <noreply@github.com>2019-08-24 13:20:48 -0700
commit2235dd795d3cc6c24ff1bdd1bbdcd110b4b0bdfc (patch)
treea5811adc062cbb1c66f05c863c9be245cf4fd2d2 /js/error_stack.ts
parentbdc0a13261deaa3748f51d9948b4e7b92864c324 (diff)
Revert json ops (#2814)
* Revert "port more ops to JSON (#2809)" This reverts commit 137f33733d365026903d40e7cde6e34ac6c36dcf. * Revert "port ops to JSON: compiler, errors, fetch, files (#2804)" This reverts commit 79f82cf10ed1dbf91346994250d7311a4d74377a. * Revert "Port rest of os ops to JSON (#2802)" This reverts commit 5b2baa5c990fbeae747e952c5dcd7a5369e950b1.
Diffstat (limited to 'js/error_stack.ts')
-rw-r--r--js/error_stack.ts51
1 files changed, 37 insertions, 14 deletions
diff --git a/js/error_stack.ts b/js/error_stack.ts
index 7d41b9cf4..003717a72 100644
--- a/js/error_stack.ts
+++ b/js/error_stack.ts
@@ -1,8 +1,8 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
// Some of the code here is adapted directly from V8 and licensed under a BSD
// style license available here: https://github.com/v8/v8/blob/24886f2d1c565287d33d71e4109a53bf0b54b75c/LICENSE.v8
-import * as dispatch from "./dispatch";
-import { sendSync } from "./dispatch_json";
+
+import { sendSync, msg, flatbuffers } from "./dispatch_flatbuffers";
import { assert } from "./util";
export interface Location {
@@ -17,6 +17,40 @@ export interface Location {
column: number;
}
+function req(
+ filename: string,
+ line: number,
+ column: number
+): [flatbuffers.Builder, msg.Any.ApplySourceMap, flatbuffers.Offset] {
+ const builder = flatbuffers.createBuilder();
+ const filename_ = builder.createString(filename);
+ const inner = msg.ApplySourceMap.createApplySourceMap(
+ builder,
+ filename_,
+ // On this side, line/column are 1 based, but in the source maps, they are
+ // 0 based, so we have to convert back and forth
+ line - 1,
+ column - 1
+ );
+ return [builder, msg.Any.ApplySourceMap, inner];
+}
+
+function res(baseRes: msg.Base | null): Location {
+ assert(baseRes != null);
+ assert(baseRes!.innerType() === msg.Any.ApplySourceMap);
+ const res = new msg.ApplySourceMap();
+ assert(baseRes!.inner(res) != null);
+ const filename = res.filename()!;
+ assert(filename != null);
+ return {
+ filename,
+ // On this side, line/column are 1 based, but in the source maps, they are
+ // 0 based, so we have to convert back and forth
+ line: res.line() + 1,
+ column: res.column() + 1
+ };
+}
+
/** Given a current location in a module, lookup the source location and
* return it.
*
@@ -41,18 +75,7 @@ export interface Location {
*/
export function applySourceMap(location: Location): Location {
const { filename, line, column } = location;
- // On this side, line/column are 1 based, but in the source maps, they are
- // 0 based, so we have to convert back and forth
- const res = sendSync(dispatch.OP_APPLY_SOURCE_MAP, {
- filename,
- line: line - 1,
- column: column - 1
- });
- return {
- filename: res.filename,
- line: res.line + 1,
- column: res.column + 1
- };
+ return res(sendSync(...req(filename, line, column)));
}
/** Mutate the call site so that it returns the location, instead of its