From f5eb34466ecffac20a581e52557e481c3747d795 Mon Sep 17 00:00:00 2001 From: atanasovg Date: Fri, 22 Jan 2016 11:20:54 +0200 Subject: [PATCH] Some snapshot-specific fixes/improvements. --- console/console.ts | 5 +++++ globals/globals.ts | 45 ++++++++++++++++++++++++++++++++++----------- xml/xml.ts | 5 +++++ 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/console/console.ts b/console/console.ts index 2341b6872..955847c19 100644 --- a/console/console.ts +++ b/console/console.ts @@ -286,6 +286,11 @@ export class Console implements definition.Console { } private logMessage(message: string, messageType: number): void { + if (!global.android) { + // This case may be entered during heap snapshot where the global.android is not present + return; + } + var arrayToLog = []; if (message.length > 4000) { var i; diff --git a/globals/globals.ts b/globals/globals.ts index 753c88778..329588b3c 100644 --- a/globals/globals.ts +++ b/globals/globals.ts @@ -6,6 +6,9 @@ global.moduleMerge = function (sourceExports: any, destExports: any) { } } +import * as timerModule from "timer"; +import * as dialogsModule from "ui/dialogs"; + type ModuleLoader = () => any; const modules: Map = new Map(); @@ -54,16 +57,37 @@ function registerOnGlobalContext(name: string, module: string): void { }); } -registerOnGlobalContext("setTimeout", "timer"); -registerOnGlobalContext("clearTimeout", "timer"); -registerOnGlobalContext("setInterval", "timer"); -registerOnGlobalContext("clearInterval", "timer"); -registerOnGlobalContext("alert", "ui/dialogs"); -registerOnGlobalContext("confirm", "ui/dialogs"); -registerOnGlobalContext("prompt", "ui/dialogs"); -registerOnGlobalContext("XMLHttpRequest", "xhr"); -registerOnGlobalContext("FormData", "xhr"); -registerOnGlobalContext("fetch", "fetch"); +if (global.__snapshot) { + // when we have a snapshot, it is better to pre-populate these on the global context to get them saved within the blob + var timer: typeof timerModule = require("timer"); + global.setTimeout = timer.setTimeout; + global.clearTimeout = timer.clearTimeout; + global.setInterval = timer.setInterval; + global.clearInterval = timer.clearInterval; + + var dialogs: typeof dialogsModule = require("ui/dialogs"); + global.alert = dialogs.alert; + global.confirm = dialogs.confirm; + global.prompt = dialogs.prompt; + + var xhr = require("xhr"); + global.XMLHttpRequest = xhr.XMLHttpRequest; + global.FormData = xhr.FormData; + + var fetch = require("fetch"); + global.fetch = fetch.fetch; +} else { + registerOnGlobalContext("setTimeout", "timer"); + registerOnGlobalContext("clearTimeout", "timer"); + registerOnGlobalContext("setInterval", "timer"); + registerOnGlobalContext("clearInterval", "timer"); + registerOnGlobalContext("alert", "ui/dialogs"); + registerOnGlobalContext("confirm", "ui/dialogs"); + registerOnGlobalContext("prompt", "ui/dialogs"); + registerOnGlobalContext("XMLHttpRequest", "xhr"); + registerOnGlobalContext("FormData", "xhr"); + registerOnGlobalContext("fetch", "fetch"); +} import platform = require("platform"); import consoleModule = require("console"); @@ -107,7 +131,6 @@ export function Deprecated(target: Object, key?: string | symbol, descriptor?: a return descriptor; } else { - console.log(`${(target && (target).name || target)} is deprecated`); return target; } diff --git a/xml/xml.ts b/xml/xml.ts index 0094b1172..53f44c4ca 100644 --- a/xml/xml.ts +++ b/xml/xml.ts @@ -83,6 +83,11 @@ function _generateAmpMap(): any { return ampCodes; } +// android-specific implementation, which pre-populates the map to get it saved into the heap blob +if (global.__snapshot) { + _ampCodes = _generateAmpMap(); +} + function _HandleAmpEntities(found: string, decimalValue: string, hexValue: string, wordValue: string): string { if (wordValue) {