Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fast exceptions no sources #1097

Merged
merged 2 commits into from
Nov 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions js/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ export class DenoCompiler
let lastModule: ModuleMetaData | undefined;
sourceMaps.install({
installPrepareStackTrace: true,

getGeneratedContents: (fileName: string): string | RawSourceMap => {
this._log("compiler.getGeneratedContents", fileName);
if (fileName === "gen/bundle/main.js") {
Expand Down Expand Up @@ -419,6 +420,11 @@ export class DenoCompiler
}
}
});
// Pre-compute source maps for main.js.map. This will happen at compile-time
// as long as Compiler is instanciated before the snapshot is created..
const consumer = sourceMaps.loadConsumer("gen/bundle/main.js");
assert(consumer != null);
consumer!.computeColumnSpans();
}

private constructor() {
Expand Down
5 changes: 4 additions & 1 deletion js/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import { promiseErrorExaminer, promiseRejectHandler } from "./promise_util";
import { replLoop } from "./repl";
import { version } from "typescript";

// Instantiate compiler at the top-level so it decodes source maps for the main
// bundle during snapshot.
const compiler = DenoCompiler.instance();

function sendStart(): msg.StartRes {
const builder = flatbuffers.createBuilder();
msg.Start.startStart(builder);
Expand Down Expand Up @@ -44,7 +48,6 @@ export default function denoMain() {
libdeno.setGlobalErrorHandler(onGlobalError);
libdeno.setPromiseRejectHandler(promiseRejectHandler);
libdeno.setPromiseErrorExaminer(promiseErrorExaminer);
const compiler = DenoCompiler.instance();

// First we send an empty "Start" message to let the privileged side know we
// are ready. The response should be a "StartRes" message containing the CLI
Expand Down
9 changes: 4 additions & 5 deletions js/v8_source_maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function CallSiteToString(frame: CallSite): string {
// Regex for detecting source maps
const reSourceMap = /^data:application\/json[^,]+base64,/;

function loadConsumer(source: string): SourceMapConsumer | null {
export function loadConsumer(source: string): SourceMapConsumer | null {
let consumer = consumers.get(source);
if (consumer == null) {
const code = getGeneratedContents(source);
Expand All @@ -210,16 +210,15 @@ function loadConsumer(source: string): SourceMapConsumer | null {
sourceMapData = arrayToStr(ui8);
sourceMappingURL = source;
} else {
// Support source map URLs relative to the source URL
//sourceMappingURL = supportRelativeURL(source, sourceMappingURL);
// TODO Support source map URLs relative to the source URL
// sourceMappingURL = supportRelativeURL(source, sourceMappingURL);
sourceMapData = getGeneratedContents(sourceMappingURL);
}

const rawSourceMap =
typeof sourceMapData === "string"
? JSON.parse(sourceMapData)
: sourceMapData;
//console.log("sourceMapData", sourceMapData);
consumer = new SourceMapConsumer(rawSourceMap);
consumers.set(source, consumer);
}
Expand All @@ -242,7 +241,7 @@ function retrieveSourceMapURL(fileData: string): string | null {
return lastMatch[1];
}

function mapSourcePosition(position: Position): MappedPosition {
export function mapSourcePosition(position: Position): MappedPosition {
const consumer = loadConsumer(position.source);
if (consumer == null) {
return position;
Expand Down
14 changes: 7 additions & 7 deletions libdeno/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -521,13 +521,6 @@ void InitializeContext(v8::Isolate* isolate, v8::Local<v8::Context> context,
.FromJust());

{
auto source = deno::v8_str(js_source);
CHECK(
deno_val->Set(context, deno::v8_str("mainSource"), source).FromJust());

bool r = deno::ExecuteV8StringSource(context, js_filename, source);
CHECK(r);

if (source_map != nullptr) {
v8::TryCatch try_catch(isolate);
v8::ScriptOrigin origin(v8_str("set_source_map.js"));
Expand All @@ -551,6 +544,13 @@ void InitializeContext(v8::Isolate* isolate, v8::Local<v8::Context> context,
source_map_obj.ToLocalChecked())
.FromJust());
}

auto source = deno::v8_str(js_source);
CHECK(
deno_val->Set(context, deno::v8_str("mainSource"), source).FromJust());

bool r = deno::ExecuteV8StringSource(context, js_filename, source);
CHECK(r);
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"flatbuffers": "^1.9.0",
"magic-string": "^0.22.5",
"prettier": "^1.14.0",
"rollup": "^0.63.2",
"rollup": "0.67.0",
"rollup-plugin-alias": "^1.4.0",
"rollup-plugin-analyzer": "^2.1.0",
"rollup-plugin-commonjs": "^9.1.3",
Expand Down
23 changes: 15 additions & 8 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
import assert from "assert";
// @ts-check
import * as fs from "fs";
import path from "path";
import alias from "rollup-plugin-alias";
Expand Down Expand Up @@ -30,10 +30,14 @@ const tsconfigOverride = {
}
};

// this is a rollup plugin which will look for imports ending with `!string` and resolve
// them with a module that will inline the contents of the file as a string. Needed to
// support `js/assets.ts`.
function strings({ include, exclude } = {}) {
/** this is a rollup plugin which will look for imports ending with `!string` and resolve
* them with a module that will inline the contents of the file as a string. Needed to
* support `js/assets.ts`.
* @param {any} param0
*/
function strings(
{ include, exclude } = { include: undefined, exclude: undefined }
) {
if (!include) {
throw new Error("include option must be passed");
}
Expand Down Expand Up @@ -85,7 +89,9 @@ const osNodeToDeno = {
linux: "linux"
};

// Inject deno.platform.arch and deno.platform.os
/** Inject deno.platform.arch and deno.platform.os
* @param {any} param0
*/
function platform({ include, exclude } = {}) {
if (!include) {
throw new Error("include option must be passed");
Expand Down Expand Up @@ -132,7 +138,7 @@ function resolveGenerated() {
}

function generateDepFile({ outputFile, sourceFiles = [], configFiles = [] }) {
let timestamp = Date.now();
let timestamp = new Date();

// Save the depfile just before the node process exits.
process.once("beforeExit", () =>
Expand Down Expand Up @@ -209,7 +215,8 @@ export default function makeConfig(commandOptions) {
output: {
format: "iife",
name: "denoMain",
sourcemap: true
sourcemap: true,
sourcemapExcludeSources: true
},

plugins: [
Expand Down
4 changes: 2 additions & 2 deletions tests/error_004_missing_module.ts.out
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ NotFound: Cannot resolve module "bad-module.ts" from "[WILDCARD]/tests/error_004
at moduleNames.map.name ([WILDCARD]/js/compiler.ts:[WILDCARD])
at Array.map (<anonymous>)
at DenoCompiler.resolveModuleNames ([WILDCARD]/js/compiler.ts:[WILDCARD])
at Object.compilerHost.resolveModuleNames ([WILDCARD]/third_party/node_modules/typescript/lib/typescript.js:[WILDCARD])
at resolveModuleNamesWorker ([WILDCARD]/third_party/node_modules/typescript/lib/typescript.js:[WILDCARD])
at Object.compilerHost.resolveModuleNames (<anonymous>)
at resolveModuleNamesWorker (<anonymous>)
4 changes: 2 additions & 2 deletions tests/error_005_missing_dynamic_import.ts.out
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ NotFound: Cannot resolve module "bad-module.ts" from "[WILDCARD]/tests/error_005
at moduleNames.map.name ([WILDCARD]/js/compiler.ts:[WILDCARD])
at Array.map (<anonymous>)
at DenoCompiler.resolveModuleNames ([WILDCARD]/js/compiler.ts:[WILDCARD])
at Object.compilerHost.resolveModuleNames ([WILDCARD]/third_party/node_modules/typescript/lib/typescript.js:[WILDCARD])
at resolveModuleNamesWorker ([WILDCARD]/third_party/node_modules/typescript/lib/typescript.js:[WILDCARD])
at Object.compilerHost.resolveModuleNames (<anonymous>)
at resolveModuleNamesWorker (<anonymous>)
4 changes: 2 additions & 2 deletions tests/error_006_import_ext_failure.ts.out
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ NotFound: Cannot resolve module "./non-existent" from "[WILDCARD]/tests/error_00
at moduleNames.map.name ([WILDCARD]/js/compiler.ts:[WILDCARD])
at Array.map (<anonymous>)
at DenoCompiler.resolveModuleNames ([WILDCARD]/js/compiler.ts:[WILDCARD])
at Object.compilerHost.resolveModuleNames ([WILDCARD]/third_party/node_modules/typescript/lib/typescript.js:[WILDCARD])
at resolveModuleNamesWorker ([WILDCARD]/third_party/node_modules/typescript/lib/typescript.js:[WILDCARD])
at Object.compilerHost.resolveModuleNames (<anonymous>)
at resolveModuleNamesWorker (<anonymous>)