toolkit/devtools/server/actors/pretty-print-worker.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; js-indent-level: 2; -*- */
     2 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 /**
     8  * This file is meant to be loaded as a ChromeWorker. It accepts messages which
     9  * have data of the form:
    10  *
    11  *     { id, url, indent, source }
    12  *
    13  * Where `id` is a unique ID to identify this request, `url` is the url of the
    14  * source being pretty printed, `indent` is the number of spaces to indent the
    15  * code by, and `source` is the source text.
    16  *
    17  * On success, the worker responds with a message of the form:
    18  *
    19  *     { id, code, mappings }
    20  *
    21  * Where `id` is the same unique ID from the request, `code` is the pretty
    22  * printed source text, and `mappings` is an array or source mappings from the
    23  * pretty printed code back to the ugly source text.
    24  *
    25  * In the case of an error, the worker responds with a message of the form:
    26  *
    27  *     { id, error }
    28  */
    30 importScripts("resource://gre/modules/devtools/acorn/acorn.js");
    31 importScripts("resource://gre/modules/devtools/source-map.js");
    32 importScripts("resource://gre/modules/devtools/pretty-fast.js");
    34 self.onmessage = (event) => {
    35   const { data: { id, url, indent, source } } = event;
    36   try {
    37     const prettified = prettyFast(source, {
    38       url: url,
    39       indent: " ".repeat(indent)
    40     });
    42     self.postMessage({
    43       id: id,
    44       code: prettified.code,
    45       mappings: prettified.map._mappings
    46     });
    47   } catch (e) {
    48     self.postMessage({
    49       id: id,
    50       error: e.message + "\n" + e.stack
    51     });
    52   }
    53 };

mercurial