From e976b3e0414dc768624b77e431ee7f55b03b76a4 Mon Sep 17 00:00:00 2001 From: F001 Date: Wed, 12 Dec 2018 17:43:42 +0800 Subject: use byte array instead of string for code fetch (#1307) --- js/compiler.ts | 1 + js/os.ts | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'js') diff --git a/js/compiler.ts b/js/compiler.ts index e0bfb77bb..5031fb0bf 100644 --- a/js/compiler.ts +++ b/js/compiler.ts @@ -233,6 +233,7 @@ export class Compiler // We query Rust with a CodeFetch message. It will load the sourceCode, // and if there is any outputCode cached, will return that as well. const fetchResponse = this._os.codeFetch(moduleSpecifier, containingFile); + assert(fetchResponse != null, "fetchResponse is null"); moduleId = fetchResponse.moduleName; fileName = fetchResponse.filename; mediaType = fetchResponse.mediaType; diff --git a/js/os.ts b/js/os.ts index e56aab574..7fc37e46a 100644 --- a/js/os.ts +++ b/js/os.ts @@ -4,6 +4,7 @@ import { assert } from "./util"; import * as util from "./util"; import * as flatbuffers from "./flatbuffers"; import { sendSync } from "./dispatch"; +import { TextDecoder } from "./text_encoding"; interface CodeInfo { moduleName: string | undefined; @@ -45,13 +46,17 @@ export function codeFetch(specifier: string, referrer: string): CodeInfo { assert(baseRes!.inner(codeFetchRes) != null); // flatbuffers returns `null` for an empty value, this does not fit well with // idiomatic TypeScript under strict null checks, so converting to `undefined` + const sourceCode = codeFetchRes.sourceCodeArray() || undefined; + const outputCode = codeFetchRes.outputCodeArray() || undefined; + const sourceMap = codeFetchRes.sourceMapArray() || undefined; + const decoder = new TextDecoder(); return { moduleName: codeFetchRes.moduleName() || undefined, filename: codeFetchRes.filename() || undefined, mediaType: codeFetchRes.mediaType(), - sourceCode: codeFetchRes.sourceCode() || undefined, - outputCode: codeFetchRes.outputCode() || undefined, - sourceMap: codeFetchRes.sourceMap() || undefined + sourceCode: sourceCode && decoder.decode(sourceCode), + outputCode: outputCode && decoder.decode(outputCode), + sourceMap: sourceMap && decoder.decode(sourceMap) }; } -- cgit v1.2.3