diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2019-08-24 15:02:42 +0200 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-08-24 06:02:42 -0700 |
commit | 79f82cf10ed1dbf91346994250d7311a4d74377a (patch) | |
tree | b00755d666198b9c66264a3c240f849096951e2f /js/error_stack.ts | |
parent | 5b2baa5c990fbeae747e952c5dcd7a5369e950b1 (diff) |
port ops to JSON: compiler, errors, fetch, files (#2804)
Diffstat (limited to 'js/error_stack.ts')
-rw-r--r-- | js/error_stack.ts | 51 |
1 files changed, 14 insertions, 37 deletions
diff --git a/js/error_stack.ts b/js/error_stack.ts index 003717a72..7d41b9cf4 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 { sendSync, msg, flatbuffers } from "./dispatch_flatbuffers"; +import * as dispatch from "./dispatch"; +import { sendSync } from "./dispatch_json"; import { assert } from "./util"; export interface Location { @@ -17,40 +17,6 @@ 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. * @@ -75,7 +41,18 @@ function res(baseRes: msg.Base | null): Location { */ export function applySourceMap(location: Location): Location { const { filename, line, column } = location; - return res(sendSync(...req(filename, line, column))); + // 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 + }; } /** Mutate the call site so that it returns the location, instead of its |