diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2019-08-26 14:50:21 +0200 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-08-26 08:50:21 -0400 |
commit | 520f9631e09aa720fd8c03513ee8ea967f5ed4b2 (patch) | |
tree | fc3d1bd5182452ca1865a5c2631355e0895af94c /js/error_stack.ts | |
parent | 017f88ee99b0fe40221e6af92e0b6a976fbaf2ad (diff) |
bring back json ops (#2815)
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 |