From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- devtools/shared/DevToolsUtils.js | 672 ++ devtools/shared/Loader.jsm | 244 + devtools/shared/Parser.jsm | 2451 +++++ devtools/shared/ThreadSafeDevToolsUtils.js | 334 + devtools/shared/acorn/LICENSE | 23 + devtools/shared/acorn/UPGRADING.md | 31 + devtools/shared/acorn/acorn.js | 3330 +++++++ devtools/shared/acorn/acorn_loose.js | 1302 +++ devtools/shared/acorn/moz.build | 13 + devtools/shared/acorn/tests/unit/head_acorn.js | 75 + .../shared/acorn/tests/unit/test_import_acorn.js | 18 + .../shared/acorn/tests/unit/test_lenient_parser.js | 62 + devtools/shared/acorn/tests/unit/test_same_ast.js | 37 + devtools/shared/acorn/tests/unit/xpcshell.ini | 10 + devtools/shared/acorn/walk.js | 377 + devtools/shared/apps/Devices.jsm | 53 + devtools/shared/apps/Simulator.jsm | 44 + devtools/shared/apps/app-actor-front.js | 840 ++ devtools/shared/apps/moz.build | 10 + devtools/shared/async-storage.js | 188 + devtools/shared/async-utils.js | 107 + devtools/shared/builtin-modules.js | 288 + devtools/shared/client/connection-manager.js | 382 + devtools/shared/client/main.js | 3123 +++++++ devtools/shared/client/moz.build | 10 + devtools/shared/content-observer.js | 71 + devtools/shared/css/color-db.js | 162 + devtools/shared/css/color.js | 1117 +++ .../shared/css/generated/generate-properties-db.js | 55 + devtools/shared/css/generated/mach_commands.py | 91 + devtools/shared/css/generated/moz.build | 9 + devtools/shared/css/generated/properties-db.js | 9367 ++++++++++++++++++++ devtools/shared/css/generated/properties-db.js.in | 20 + devtools/shared/css/lexer.js | 1240 +++ devtools/shared/css/moz.build | 17 + devtools/shared/css/parsing-utils.js | 1171 +++ devtools/shared/css/properties-db.js | 100 + devtools/shared/defer.js | 25 + devtools/shared/deprecated-sync-thenables.js | 119 + devtools/shared/discovery/discovery.js | 496 ++ devtools/shared/discovery/moz.build | 11 + .../shared/discovery/tests/unit/test_discovery.js | 161 + devtools/shared/discovery/tests/unit/xpcshell.ini | 7 + devtools/shared/dom-node-constants.js | 30 + devtools/shared/dom-node-filter-constants.js | 21 + devtools/shared/event-emitter.js | 250 + devtools/shared/flags.js | 21 + devtools/shared/fronts/actor-registry.js | 67 + devtools/shared/fronts/addons.js | 17 + devtools/shared/fronts/animation.js | 140 + devtools/shared/fronts/call-watcher.js | 226 + devtools/shared/fronts/canvas.js | 91 + devtools/shared/fronts/css-properties.js | 323 + devtools/shared/fronts/csscoverage.js | 125 + devtools/shared/fronts/device.js | 54 + devtools/shared/fronts/director-manager.js | 47 + devtools/shared/fronts/director-registry.js | 21 + devtools/shared/fronts/emulation.js | 24 + devtools/shared/fronts/eventlooplag.js | 15 + devtools/shared/fronts/framerate.js | 19 + devtools/shared/fronts/gcli.js | 40 + devtools/shared/fronts/highlighters.js | 34 + devtools/shared/fronts/inspector.js | 1007 +++ devtools/shared/fronts/layout.js | 30 + devtools/shared/fronts/memory.js | 92 + devtools/shared/fronts/moz.build | 41 + devtools/shared/fronts/performance-entries.js | 17 + devtools/shared/fronts/performance-recording.js | 152 + devtools/shared/fronts/performance.js | 148 + devtools/shared/fronts/preference.js | 31 + devtools/shared/fronts/profiler.js | 80 + devtools/shared/fronts/promises.js | 27 + devtools/shared/fronts/reflow.js | 29 + devtools/shared/fronts/settings.js | 29 + devtools/shared/fronts/storage.js | 32 + devtools/shared/fronts/string.js | 47 + devtools/shared/fronts/styleeditor.js | 113 + devtools/shared/fronts/styles.js | 421 + devtools/shared/fronts/stylesheets.js | 184 + devtools/shared/fronts/timeline.js | 25 + devtools/shared/fronts/webaudio.js | 83 + devtools/shared/fronts/webgl.js | 45 + devtools/shared/gcli/commands/addon.js | 320 + devtools/shared/gcli/commands/appcache.js | 186 + devtools/shared/gcli/commands/calllog.js | 219 + devtools/shared/gcli/commands/cmd.js | 178 + devtools/shared/gcli/commands/cookie.js | 300 + devtools/shared/gcli/commands/csscoverage.js | 201 + devtools/shared/gcli/commands/folder.js | 77 + devtools/shared/gcli/commands/highlight.js | 158 + devtools/shared/gcli/commands/index.js | 179 + devtools/shared/gcli/commands/inject.js | 86 + devtools/shared/gcli/commands/jsb.js | 134 + devtools/shared/gcli/commands/listen.js | 106 + devtools/shared/gcli/commands/mdn.js | 83 + devtools/shared/gcli/commands/measure.js | 112 + devtools/shared/gcli/commands/media.js | 56 + devtools/shared/gcli/commands/moz.build | 30 + devtools/shared/gcli/commands/pagemod.js | 276 + devtools/shared/gcli/commands/paintflashing.js | 201 + devtools/shared/gcli/commands/qsa.js | 24 + devtools/shared/gcli/commands/restart.js | 77 + devtools/shared/gcli/commands/rulers.js | 110 + devtools/shared/gcli/commands/screenshot.js | 579 ++ devtools/shared/gcli/commands/security.js | 328 + devtools/shared/gcli/moz.build | 23 + devtools/shared/gcli/source/LICENSE | 202 + devtools/shared/gcli/source/docs/design.md | 102 + .../shared/gcli/source/docs/developing-gcli.md | 213 + devtools/shared/gcli/source/docs/index.md | 150 + devtools/shared/gcli/source/docs/running-tests.md | 60 + .../shared/gcli/source/docs/writing-commands.md | 757 ++ devtools/shared/gcli/source/docs/writing-tests.md | 20 + devtools/shared/gcli/source/docs/writing-types.md | 106 + devtools/shared/gcli/source/lib/gcli/cli.js | 2209 +++++ .../shared/gcli/source/lib/gcli/commands/clear.js | 59 + .../gcli/source/lib/gcli/commands/commands.js | 570 ++ .../gcli/source/lib/gcli/commands/context.js | 62 + .../shared/gcli/source/lib/gcli/commands/help.js | 387 + .../shared/gcli/source/lib/gcli/commands/mocks.js | 68 + .../shared/gcli/source/lib/gcli/commands/moz.build | 16 + .../shared/gcli/source/lib/gcli/commands/pref.js | 93 + .../gcli/source/lib/gcli/commands/preflist.js | 214 + .../shared/gcli/source/lib/gcli/commands/test.js | 215 + .../gcli/source/lib/gcli/connectors/connectors.js | 157 + .../gcli/source/lib/gcli/connectors/moz.build | 9 + .../gcli/source/lib/gcli/converters/basic.js | 94 + .../gcli/source/lib/gcli/converters/converters.js | 280 + .../shared/gcli/source/lib/gcli/converters/html.js | 47 + .../gcli/source/lib/gcli/converters/moz.build | 12 + .../gcli/source/lib/gcli/converters/terminal.js | 56 + .../shared/gcli/source/lib/gcli/fields/delegate.js | 96 + .../shared/gcli/source/lib/gcli/fields/fields.js | 245 + .../shared/gcli/source/lib/gcli/fields/moz.build | 11 + .../gcli/source/lib/gcli/fields/selection.js | 124 + devtools/shared/gcli/source/lib/gcli/index.js | 29 + devtools/shared/gcli/source/lib/gcli/l10n.js | 74 + .../gcli/source/lib/gcli/languages/command.html | 14 + .../gcli/source/lib/gcli/languages/command.js | 563 ++ .../gcli/source/lib/gcli/languages/javascript.js | 86 + .../gcli/source/lib/gcli/languages/languages.js | 179 + .../gcli/source/lib/gcli/languages/moz.build | 12 + devtools/shared/gcli/source/lib/gcli/moz.build | 13 + .../shared/gcli/source/lib/gcli/mozui/completer.js | 151 + .../shared/gcli/source/lib/gcli/mozui/inputter.js | 657 ++ .../shared/gcli/source/lib/gcli/mozui/moz.build | 11 + .../shared/gcli/source/lib/gcli/mozui/tooltip.js | 298 + devtools/shared/gcli/source/lib/gcli/settings.js | 284 + devtools/shared/gcli/source/lib/gcli/system.js | 370 + .../shared/gcli/source/lib/gcli/types/array.js | 80 + .../shared/gcli/source/lib/gcli/types/boolean.js | 62 + .../shared/gcli/source/lib/gcli/types/command.js | 255 + devtools/shared/gcli/source/lib/gcli/types/date.js | 248 + .../shared/gcli/source/lib/gcli/types/delegate.js | 158 + devtools/shared/gcli/source/lib/gcli/types/file.js | 96 + .../gcli/source/lib/gcli/types/fileparser.js | 19 + .../gcli/source/lib/gcli/types/javascript.js | 522 ++ .../shared/gcli/source/lib/gcli/types/moz.build | 25 + devtools/shared/gcli/source/lib/gcli/types/node.js | 201 + .../shared/gcli/source/lib/gcli/types/number.js | 181 + .../shared/gcli/source/lib/gcli/types/resource.js | 270 + .../shared/gcli/source/lib/gcli/types/selection.js | 389 + .../shared/gcli/source/lib/gcli/types/setting.js | 62 + .../shared/gcli/source/lib/gcli/types/string.js | 92 + .../shared/gcli/source/lib/gcli/types/types.js | 1146 +++ .../shared/gcli/source/lib/gcli/types/union.js | 117 + devtools/shared/gcli/source/lib/gcli/types/url.js | 86 + devtools/shared/gcli/source/lib/gcli/ui/focus.js | 403 + devtools/shared/gcli/source/lib/gcli/ui/history.js | 71 + devtools/shared/gcli/source/lib/gcli/ui/intro.js | 90 + devtools/shared/gcli/source/lib/gcli/ui/menu.css | 69 + devtools/shared/gcli/source/lib/gcli/ui/menu.html | 20 + devtools/shared/gcli/source/lib/gcli/ui/menu.js | 328 + devtools/shared/gcli/source/lib/gcli/ui/moz.build | 15 + devtools/shared/gcli/source/lib/gcli/ui/view.js | 87 + .../gcli/source/lib/gcli/util/domtemplate.js | 20 + .../shared/gcli/source/lib/gcli/util/fileparser.js | 281 + .../shared/gcli/source/lib/gcli/util/filesystem.js | 130 + devtools/shared/gcli/source/lib/gcli/util/host.js | 230 + devtools/shared/gcli/source/lib/gcli/util/l10n.js | 80 + .../shared/gcli/source/lib/gcli/util/legacy.js | 147 + .../shared/gcli/source/lib/gcli/util/moz.build | 17 + devtools/shared/gcli/source/lib/gcli/util/prism.js | 361 + devtools/shared/gcli/source/lib/gcli/util/spell.js | 197 + devtools/shared/gcli/source/lib/gcli/util/util.js | 685 ++ devtools/shared/gcli/templater.js | 602 ++ devtools/shared/heapsnapshot/.gitattributes | 1 + devtools/shared/heapsnapshot/AutoMemMap.cpp | 64 + devtools/shared/heapsnapshot/AutoMemMap.h | 75 + devtools/shared/heapsnapshot/CensusUtils.js | 489 + devtools/shared/heapsnapshot/CoreDump.pb.cc | 2542 ++++++ devtools/shared/heapsnapshot/CoreDump.pb.h | 1893 ++++ devtools/shared/heapsnapshot/CoreDump.proto | 143 + devtools/shared/heapsnapshot/DeserializedNode.cpp | 150 + devtools/shared/heapsnapshot/DeserializedNode.h | 317 + devtools/shared/heapsnapshot/DominatorTree.cpp | 140 + devtools/shared/heapsnapshot/DominatorTree.h | 67 + devtools/shared/heapsnapshot/DominatorTreeNode.js | 336 + .../heapsnapshot/FileDescriptorOutputStream.cpp | 86 + .../heapsnapshot/FileDescriptorOutputStream.h | 41 + devtools/shared/heapsnapshot/HeapAnalysesClient.js | 277 + devtools/shared/heapsnapshot/HeapAnalysesWorker.js | 303 + devtools/shared/heapsnapshot/HeapSnapshot.cpp | 1652 ++++ devtools/shared/heapsnapshot/HeapSnapshot.h | 239 + .../shared/heapsnapshot/HeapSnapshotFileUtils.js | 95 + .../heapsnapshot/HeapSnapshotTempFileHelperChild.h | 32 + .../HeapSnapshotTempFileHelperParent.cpp | 53 + .../HeapSnapshotTempFileHelperParent.h | 35 + .../heapsnapshot/PHeapSnapshotTempFileHelper.ipdl | 35 + .../heapsnapshot/ZeroCopyNSIOutputStream.cpp | 100 + .../shared/heapsnapshot/ZeroCopyNSIOutputStream.h | 70 + devtools/shared/heapsnapshot/census-tree-node.js | 748 ++ .../heapsnapshot/generate-core-dump-sources.sh | 26 + devtools/shared/heapsnapshot/moz.build | 62 + devtools/shared/heapsnapshot/shortest-paths.js | 91 + .../tests/gtest/DeserializedNodeUbiNodes.cpp | 100 + .../gtest/DeserializedStackFrameUbiStackFrames.cpp | 91 + .../shared/heapsnapshot/tests/gtest/DevTools.h | 276 + .../tests/gtest/DoesCrossCompartmentBoundaries.cpp | 73 + .../gtest/DoesntCrossCompartmentBoundaries.cpp | 64 + .../tests/gtest/SerializesEdgeNames.cpp | 53 + .../gtest/SerializesEverythingInHeapGraphOnce.cpp | 37 + .../tests/gtest/SerializesTypeNames.cpp | 30 + devtools/shared/heapsnapshot/tests/gtest/moz.build | 31 + .../shared/heapsnapshot/tests/mochitest/chrome.ini | 8 + .../heapsnapshot/tests/mochitest/mochitest.ini | 6 + .../tests/mochitest/test_DominatorTree_01.html | 37 + .../tests/mochitest/test_SaveHeapSnapshot.html | 25 + .../mochitest/test_saveHeapSnapshot_e10s_01.html | 82 + .../shared/heapsnapshot/tests/unit/.eslintrc.js | 6 + devtools/shared/heapsnapshot/tests/unit/Census.jsm | 165 + devtools/shared/heapsnapshot/tests/unit/Match.jsm | 190 + .../tests/unit/dominator-tree-worker.js | 47 + .../heapsnapshot/tests/unit/head_heapsnapshot.js | 448 + .../tests/unit/heap-snapshot-worker.js | 46 + ...est_DominatorTreeNode_LabelAndShallowSize_01.js | 46 + ...est_DominatorTreeNode_LabelAndShallowSize_02.js | 45 + ...est_DominatorTreeNode_LabelAndShallowSize_03.js | 47 + ...est_DominatorTreeNode_LabelAndShallowSize_04.js | 53 + ...est_DominatorTreeNode_attachShortestPaths_01.js | 132 + ...st_DominatorTreeNode_getNodeByIdAlongPath_01.js | 44 + .../tests/unit/test_DominatorTreeNode_insert_01.js | 112 + .../tests/unit/test_DominatorTreeNode_insert_02.js | 30 + .../tests/unit/test_DominatorTreeNode_insert_03.js | 117 + .../test_DominatorTreeNode_partialTraversal_01.js | 164 + .../tests/unit/test_DominatorTree_01.js | 23 + .../tests/unit/test_DominatorTree_02.js | 40 + .../tests/unit/test_DominatorTree_03.js | 13 + .../tests/unit/test_DominatorTree_04.js | 22 + .../tests/unit/test_DominatorTree_05.js | 75 + .../tests/unit/test_DominatorTree_06.js | 56 + .../test_HeapAnalyses_computeDominatorTree_01.js | 22 + .../test_HeapAnalyses_computeDominatorTree_02.js | 23 + .../test_HeapAnalyses_deleteHeapSnapshot_01.js | 59 + .../test_HeapAnalyses_deleteHeapSnapshot_02.js | 22 + .../test_HeapAnalyses_deleteHeapSnapshot_03.js | 62 + .../test_HeapAnalyses_getCensusIndividuals_01.js | 89 + .../unit/test_HeapAnalyses_getCreationTime_01.js | 58 + .../unit/test_HeapAnalyses_getDominatorTree_01.js | 69 + .../unit/test_HeapAnalyses_getDominatorTree_02.js | 31 + ...test_HeapAnalyses_getImmediatelyDominated_01.js | 81 + .../unit/test_HeapAnalyses_readHeapSnapshot_01.js | 18 + .../unit/test_HeapAnalyses_takeCensusDiff_01.js | 54 + .../unit/test_HeapAnalyses_takeCensusDiff_02.js | 59 + .../tests/unit/test_HeapAnalyses_takeCensus_01.js | 27 + .../tests/unit/test_HeapAnalyses_takeCensus_02.js | 29 + .../tests/unit/test_HeapAnalyses_takeCensus_03.js | 48 + .../tests/unit/test_HeapAnalyses_takeCensus_04.js | 118 + .../tests/unit/test_HeapAnalyses_takeCensus_05.js | 44 + .../tests/unit/test_HeapAnalyses_takeCensus_06.js | 109 + .../tests/unit/test_HeapAnalyses_takeCensus_07.js | 52 + .../test_HeapSnapshot_computeShortestPaths_01.js | 69 + .../test_HeapSnapshot_computeShortestPaths_02.js | 47 + .../unit/test_HeapSnapshot_creationTime_01.js | 30 + .../tests/unit/test_HeapSnapshot_deepStack_01.js | 70 + .../unit/test_HeapSnapshot_describeNode_01.js | 42 + .../tests/unit/test_HeapSnapshot_takeCensus_01.js | 31 + .../tests/unit/test_HeapSnapshot_takeCensus_02.js | 57 + .../tests/unit/test_HeapSnapshot_takeCensus_03.js | 34 + .../tests/unit/test_HeapSnapshot_takeCensus_04.js | 36 + .../tests/unit/test_HeapSnapshot_takeCensus_05.js | 24 + .../tests/unit/test_HeapSnapshot_takeCensus_06.js | 125 + .../tests/unit/test_HeapSnapshot_takeCensus_07.js | 82 + .../tests/unit/test_HeapSnapshot_takeCensus_08.js | 82 + .../tests/unit/test_HeapSnapshot_takeCensus_09.js | 92 + .../tests/unit/test_HeapSnapshot_takeCensus_10.js | 68 + .../tests/unit/test_HeapSnapshot_takeCensus_11.js | 116 + .../tests/unit/test_HeapSnapshot_takeCensus_12.js | 50 + .../tests/unit/test_ReadHeapSnapshot.js | 20 + .../unit/test_ReadHeapSnapshot_with_allocations.js | 36 + .../tests/unit/test_ReadHeapSnapshot_worker.js | 40 + .../tests/unit/test_SaveHeapSnapshot.js | 82 + .../tests/unit/test_census-tree-node-01.js | 76 + .../tests/unit/test_census-tree-node-02.js | 136 + .../tests/unit/test_census-tree-node-03.js | 96 + .../tests/unit/test_census-tree-node-04.js | 159 + .../tests/unit/test_census-tree-node-05.js | 145 + .../tests/unit/test_census-tree-node-06.js | 200 + .../tests/unit/test_census-tree-node-07.js | 200 + .../tests/unit/test_census-tree-node-08.js | 142 + .../tests/unit/test_census-tree-node-09.js | 44 + .../tests/unit/test_census-tree-node-10.js | 43 + .../heapsnapshot/tests/unit/test_census_diff_01.js | 74 + .../heapsnapshot/tests/unit/test_census_diff_02.js | 25 + .../heapsnapshot/tests/unit/test_census_diff_03.js | 73 + .../heapsnapshot/tests/unit/test_census_diff_04.js | 63 + .../heapsnapshot/tests/unit/test_census_diff_05.js | 34 + .../heapsnapshot/tests/unit/test_census_diff_06.js | 137 + .../tests/unit/test_census_filtering_01.js | 105 + .../tests/unit/test_census_filtering_02.js | 124 + .../tests/unit/test_census_filtering_03.js | 59 + .../tests/unit/test_census_filtering_04.js | 102 + .../tests/unit/test_census_filtering_05.js | 71 + .../tests/unit/test_countToBucketBreakdown_01.js | 37 + .../tests/unit/test_deduplicatePaths_01.js | 113 + .../tests/unit/test_getCensusIndividuals_01.js | 60 + .../tests/unit/test_getReportLeaves_01.js | 114 + .../tests/unit/test_saveHeapSnapshot_e10s_01.js | 8 + .../shared/heapsnapshot/tests/unit/xpcshell.ini | 98 + devtools/shared/indentation.js | 160 + devtools/shared/inspector/css-logic.js | 325 + devtools/shared/inspector/moz.build | 9 + devtools/shared/jar.mn | 10 + devtools/shared/jsbeautify/UPGRADING.md | 37 + devtools/shared/jsbeautify/beautify.js | 7 + devtools/shared/jsbeautify/lib/moz.build | 10 + devtools/shared/jsbeautify/lib/sanitytest.js | 137 + .../shared/jsbeautify/lib/urlencode_unpacker.js | 73 + devtools/shared/jsbeautify/moz.build | 16 + devtools/shared/jsbeautify/src/beautify-css.js | 367 + devtools/shared/jsbeautify/src/beautify-html.js | 822 ++ devtools/shared/jsbeautify/src/beautify-js.js | 1662 ++++ devtools/shared/jsbeautify/src/beautify-tests.js | 2096 +++++ devtools/shared/jsbeautify/src/moz.build | 12 + .../jsbeautify/tests/unit/head_jsbeautify.js | 17 + devtools/shared/jsbeautify/tests/unit/test.js | 23 + devtools/shared/jsbeautify/tests/unit/xpcshell.ini | 8 + devtools/shared/l10n.js | 253 + devtools/shared/layout/moz.build | 9 + devtools/shared/layout/utils.js | 649 ++ devtools/shared/loader-plugin-raw.jsm | 42 + devtools/shared/locales/en-US/csscoverage.dtd | 47 + .../shared/locales/en-US/csscoverage.properties | 32 + devtools/shared/locales/en-US/debugger.properties | 59 + devtools/shared/locales/en-US/gcli.properties | 318 + .../shared/locales/en-US/gclicommands.properties | 1530 ++++ devtools/shared/locales/en-US/shared.properties | 6 + .../shared/locales/en-US/styleinspector.properties | 188 + devtools/shared/locales/jar.mn | 8 + devtools/shared/locales/moz.build | 7 + devtools/shared/moz.build | 67 + devtools/shared/node-properties/UPGRADING.md | 12 + devtools/shared/node-properties/moz.build | 9 + devtools/shared/node-properties/node-properties.js | 776 ++ devtools/shared/path.js | 28 + devtools/shared/performance/moz.build | 12 + devtools/shared/performance/recording-common.js | 97 + devtools/shared/performance/recording-utils.js | 628 ++ devtools/shared/performance/test/head.js | 7 + .../test/test_perf-utils-allocations-to-samples.js | 93 + devtools/shared/performance/test/xpcshell.ini | 8 + devtools/shared/platform/README.md | 13 + devtools/shared/platform/chrome/clipboard.js | 28 + devtools/shared/platform/chrome/moz.build | 10 + devtools/shared/platform/chrome/stack.js | 75 + devtools/shared/platform/content/.eslintrc.js | 12 + devtools/shared/platform/content/clipboard.js | 34 + devtools/shared/platform/content/moz.build | 16 + devtools/shared/platform/content/stack.js | 49 + devtools/shared/platform/content/test/.eslintrc.js | 6 + .../shared/platform/content/test/mochitest.ini | 5 + .../platform/content/test/test_clipboard.html | 53 + .../shared/platform/content/test/test_stack.js | 48 + devtools/shared/platform/content/test/xpcshell.ini | 7 + devtools/shared/platform/moz.build | 10 + devtools/shared/plural-form.js | 196 + devtools/shared/pretty-fast/UPGRADING.md | 11 + devtools/shared/pretty-fast/moz.build | 11 + devtools/shared/pretty-fast/pretty-fast.js | 873 ++ .../pretty-fast/tests/unit/head_pretty-fast.js | 49 + devtools/shared/pretty-fast/tests/unit/test.js | 572 ++ .../shared/pretty-fast/tests/unit/xpcshell.ini | 8 + devtools/shared/protocol.js | 1517 ++++ devtools/shared/qrcode/decoder/LICENSE | 201 + devtools/shared/qrcode/decoder/index.js | 2375 +++++ devtools/shared/qrcode/decoder/moz.build | 9 + devtools/shared/qrcode/encoder/LICENSE | 19 + devtools/shared/qrcode/encoder/index.js | 1674 ++++ devtools/shared/qrcode/encoder/moz.build | 9 + devtools/shared/qrcode/index.js | 116 + devtools/shared/qrcode/moz.build | 22 + devtools/shared/qrcode/tests/mochitest/chrome.ini | 5 + .../shared/qrcode/tests/mochitest/test_decode.html | 68 + devtools/shared/qrcode/tests/unit/test_encode.js | 27 + devtools/shared/qrcode/tests/unit/xpcshell.ini | 7 + devtools/shared/security/auth.js | 653 ++ devtools/shared/security/cert.js | 67 + devtools/shared/security/docs/wifi.md | 154 + devtools/shared/security/moz.build | 15 + devtools/shared/security/prompt.js | 179 + devtools/shared/security/socket.js | 793 ++ devtools/shared/security/tests/chrome/chrome.ini | 4 + .../tests/chrome/test_websocket-transport.html | 76 + devtools/shared/security/tests/unit/.eslintrc.js | 6 + devtools/shared/security/tests/unit/head_dbg.js | 96 + .../shared/security/tests/unit/test_encryption.js | 110 + .../security/tests/unit/test_oob_cert_auth.js | 261 + devtools/shared/security/tests/unit/testactors.js | 131 + devtools/shared/security/tests/unit/xpcshell.ini | 12 + devtools/shared/shims/Console.jsm | 35 + devtools/shared/shims/Loader.jsm | 38 + devtools/shared/shims/Simulator.jsm | 34 + devtools/shared/shims/dbg-client.jsm | 43 + devtools/shared/shims/event-emitter.js | 42 + devtools/shared/shims/moz.build | 31 + devtools/shared/sourcemap/UPGRADING.md | 13 + devtools/shared/sourcemap/moz.build | 11 + devtools/shared/sourcemap/source-map.js | 3006 +++++++ .../shared/sourcemap/tests/unit/head_sourcemap.js | 18 + devtools/shared/sourcemap/tests/unit/test_api.js | 3026 +++++++ .../shared/sourcemap/tests/unit/test_array_set.js | 683 ++ .../shared/sourcemap/tests/unit/test_base64.js | 163 + .../shared/sourcemap/tests/unit/test_base64_vlq.js | 301 + .../sourcemap/tests/unit/test_binary_search.js | 276 + .../sourcemap/tests/unit/test_dog_fooding.js | 2985 +++++++ .../shared/sourcemap/tests/unit/test_quick_sort.js | 228 + .../tests/unit/test_source_map_consumer.js | 4005 +++++++++ .../tests/unit/test_source_map_generator.js | 4039 +++++++++ .../sourcemap/tests/unit/test_source_node.js | 3908 ++++++++ devtools/shared/sourcemap/tests/unit/test_util.js | 651 ++ devtools/shared/sourcemap/tests/unit/xpcshell.ini | 16 + devtools/shared/specs/actor-registry.js | 43 + devtools/shared/specs/addons.js | 19 + devtools/shared/specs/animation.js | 151 + devtools/shared/specs/breakpoint.js | 16 + devtools/shared/specs/call-watcher.js | 79 + devtools/shared/specs/canvas.js | 131 + devtools/shared/specs/css-properties.js | 20 + devtools/shared/specs/csscoverage.js | 44 + devtools/shared/specs/device.js | 19 + devtools/shared/specs/director-manager.js | 190 + devtools/shared/specs/director-registry.js | 41 + devtools/shared/specs/emulation.js | 106 + devtools/shared/specs/environment.js | 27 + devtools/shared/specs/eventlooplag.js | 31 + devtools/shared/specs/frame.js | 14 + devtools/shared/specs/framerate.js | 34 + devtools/shared/specs/gcli.js | 86 + devtools/shared/specs/heap-snapshot-file.js | 20 + devtools/shared/specs/highlighters.js | 63 + devtools/shared/specs/inspector.js | 445 + devtools/shared/specs/layout.js | 33 + devtools/shared/specs/memory.js | 124 + devtools/shared/specs/moz.build | 50 + devtools/shared/specs/node.js | 67 + devtools/shared/specs/performance-entries.js | 25 + devtools/shared/specs/performance-recording.js | 12 + devtools/shared/specs/performance.js | 88 + devtools/shared/specs/preference.js | 47 + devtools/shared/specs/profiler.js | 121 + devtools/shared/specs/promises.js | 56 + devtools/shared/specs/reflow.js | 33 + devtools/shared/specs/script.js | 14 + devtools/shared/specs/settings.js | 31 + devtools/shared/specs/source.js | 40 + devtools/shared/specs/storage.js | 279 + devtools/shared/specs/string.js | 87 + devtools/shared/specs/styleeditor.js | 61 + devtools/shared/specs/styles.js | 206 + devtools/shared/specs/stylesheets.js | 120 + devtools/shared/specs/timeline.js | 118 + devtools/shared/specs/webaudio.js | 163 + devtools/shared/specs/webgl.js | 101 + devtools/shared/specs/worker.js | 78 + devtools/shared/sprintfjs/UPGRADING.md | 12 + devtools/shared/sprintfjs/moz.build | 9 + devtools/shared/sprintfjs/sprintf.js | 274 + devtools/shared/system.js | 339 + devtools/shared/task.js | 515 ++ devtools/shared/tests/browser/.eslintrc.js | 6 + devtools/shared/tests/browser/browser.ini | 8 + .../shared/tests/browser/browser_async_storage.js | 77 + .../tests/browser/browser_l10n_localizeMarkup.js | 54 + devtools/shared/tests/mochitest/chrome.ini | 7 + .../tests/mochitest/test_devtools_extensions.html | 117 + .../tests/mochitest/test_eventemitter_basic.html | 194 + devtools/shared/tests/unit/.eslintrc.js | 6 + devtools/shared/tests/unit/exposeLoader.js | 8 + devtools/shared/tests/unit/head_devtools.js | 60 + devtools/shared/tests/unit/test_assert.js | 36 + devtools/shared/tests/unit/test_async-utils.js | 157 + .../shared/tests/unit/test_console_filtering.js | 133 + .../shared/tests/unit/test_css-properties-db.js | 136 + devtools/shared/tests/unit/test_csslexer.js | 242 + devtools/shared/tests/unit/test_defer.js | 32 + .../tests/unit/test_defineLazyPrototypeGetter.js | 68 + devtools/shared/tests/unit/test_executeSoon.js | 48 + devtools/shared/tests/unit/test_fetch-bom.js | 76 + devtools/shared/tests/unit/test_fetch-chrome.js | 31 + devtools/shared/tests/unit/test_fetch-file.js | 104 + devtools/shared/tests/unit/test_fetch-http.js | 61 + devtools/shared/tests/unit/test_fetch-resource.js | 31 + devtools/shared/tests/unit/test_flatten.js | 24 + devtools/shared/tests/unit/test_indentation.js | 133 + .../shared/tests/unit/test_independent_loaders.js | 20 + .../shared/tests/unit/test_invisible_loader.js | 60 + devtools/shared/tests/unit/test_isSet.js | 25 + .../shared/tests/unit/test_pluralForm-english.js | 29 + .../tests/unit/test_pluralForm-makeGetter.js | 38 + devtools/shared/tests/unit/test_prettifyCSS.js | 68 + devtools/shared/tests/unit/test_require.js | 20 + devtools/shared/tests/unit/test_require_lazy.js | 32 + devtools/shared/tests/unit/test_require_raw.js | 19 + devtools/shared/tests/unit/test_safeErrorString.js | 58 + devtools/shared/tests/unit/test_stack.js | 45 + devtools/shared/tests/unit/xpcshell.ini | 40 + devtools/shared/touch/moz.build | 11 + devtools/shared/touch/simulator-content.js | 43 + devtools/shared/touch/simulator-core.js | 366 + devtools/shared/touch/simulator.js | 77 + devtools/shared/transport/moz.build | 14 + devtools/shared/transport/packets.js | 414 + devtools/shared/transport/stream-utils.js | 249 + devtools/shared/transport/tests/unit/.eslintrc.js | 6 + devtools/shared/transport/tests/unit/head_dbg.js | 278 + .../shared/transport/tests/unit/test_bulk_error.js | 92 + .../tests/unit/test_client_server_bulk.js | 271 + .../shared/transport/tests/unit/test_dbgsocket.js | 124 + .../tests/unit/test_dbgsocket_connection_drop.js | 81 + .../transport/tests/unit/test_delimited_read.js | 26 + .../shared/transport/tests/unit/test_no_bulk.js | 38 + .../shared/transport/tests/unit/test_packet.js | 21 + devtools/shared/transport/tests/unit/test_queue.js | 177 + .../transport/tests/unit/test_transport_bulk.js | 148 + .../transport/tests/unit/test_transport_events.js | 75 + .../transport/tests/unit/testactors-no-bulk.js | 27 + devtools/shared/transport/tests/unit/testactors.js | 131 + devtools/shared/transport/tests/unit/xpcshell.ini | 21 + devtools/shared/transport/transport.js | 908 ++ devtools/shared/transport/websocket-transport.js | 79 + devtools/shared/webconsole/client.js | 652 ++ devtools/shared/webconsole/js-property-provider.js | 538 ++ devtools/shared/webconsole/moz.build | 19 + devtools/shared/webconsole/network-helper.js | 814 ++ devtools/shared/webconsole/network-monitor.js | 2044 +++++ .../shared/webconsole/server-logger-monitor.js | 191 + devtools/shared/webconsole/server-logger.js | 514 ++ devtools/shared/webconsole/test/chrome.ini | 41 + devtools/shared/webconsole/test/common.js | 345 + .../shared/webconsole/test/console-test-worker.js | 16 + devtools/shared/webconsole/test/data.json | 3 + devtools/shared/webconsole/test/data.json^headers^ | 3 + .../shared/webconsole/test/helper_serviceworker.js | 19 + .../webconsole/test/network_requests_iframe.html | 61 + .../shared/webconsole/test/sandboxed_iframe.html | 8 + devtools/shared/webconsole/test/test_basics.html | 80 + .../test/test_bug819670_getter_throws.html | 76 + .../webconsole/test/test_cached_messages.html | 230 + .../webconsole/test/test_commands_other.html | 83 + .../test/test_commands_registration.html | 191 + .../test/test_console_serviceworker.html | 157 + .../test/test_console_serviceworker_cached.html | 117 + .../webconsole/test/test_console_styling.html | 126 + .../shared/webconsole/test/test_consoleapi.html | 233 + .../webconsole/test/test_consoleapi_innerID.html | 164 + devtools/shared/webconsole/test/test_file_uri.html | 106 + devtools/shared/webconsole/test/test_jsterm.html | 309 + .../webconsole/test/test_jsterm_autocomplete.html | 183 + .../webconsole/test/test_jsterm_cd_iframe.html | 223 + .../webconsole/test/test_jsterm_last_result.html | 130 + .../webconsole/test/test_jsterm_queryselector.html | 134 + .../shared/webconsole/test/test_network_get.html | 260 + .../webconsole/test/test_network_longstring.html | 293 + .../shared/webconsole/test/test_network_post.html | 272 + .../test/test_network_security-hpkp.html | 108 + .../test/test_network_security-hsts.html | 100 + .../webconsole/test/test_nsiconsolemessage.html | 74 + .../shared/webconsole/test/test_object_actor.html | 178 + .../test/test_object_actor_native_getters.html | 106 + ...t_object_actor_native_getters_lenient_this.html | 79 + .../shared/webconsole/test/test_page_errors.html | 186 + devtools/shared/webconsole/test/test_reflow.html | 94 + devtools/shared/webconsole/test/test_throw.html | 93 + devtools/shared/webconsole/test/unit/.eslintrc.js | 6 + .../test/unit/test_js_property_provider.js | 170 + .../webconsole/test/unit/test_network_helper.js | 47 + .../test/unit/test_security-info-certificate.js | 68 + .../test/unit/test_security-info-parser.js | 64 + .../unit/test_security-info-protocol-version.js | 54 + .../test/unit/test_security-info-state.js | 100 + .../test/unit/test_security-info-static-hpkp.js | 47 + .../unit/test_security-info-weakness-reasons.js | 47 + .../shared/webconsole/test/unit/test_throttle.js | 140 + devtools/shared/webconsole/test/unit/xpcshell.ini | 17 + devtools/shared/webconsole/throttle.js | 418 + devtools/shared/worker/helper.js | 133 + devtools/shared/worker/loader.js | 517 ++ devtools/shared/worker/moz.build | 13 + devtools/shared/worker/tests/browser/.eslintrc.js | 6 + devtools/shared/worker/tests/browser/browser.ini | 9 + .../worker/tests/browser/browser_worker-01.js | 45 + .../worker/tests/browser/browser_worker-02.js | 46 + .../worker/tests/browser/browser_worker-03.js | 52 + devtools/shared/worker/worker.js | 171 + 604 files changed, 138967 insertions(+) create mode 100644 devtools/shared/DevToolsUtils.js create mode 100644 devtools/shared/Loader.jsm create mode 100644 devtools/shared/Parser.jsm create mode 100644 devtools/shared/ThreadSafeDevToolsUtils.js create mode 100644 devtools/shared/acorn/LICENSE create mode 100644 devtools/shared/acorn/UPGRADING.md create mode 100644 devtools/shared/acorn/acorn.js create mode 100644 devtools/shared/acorn/acorn_loose.js create mode 100644 devtools/shared/acorn/moz.build create mode 100644 devtools/shared/acorn/tests/unit/head_acorn.js create mode 100644 devtools/shared/acorn/tests/unit/test_import_acorn.js create mode 100644 devtools/shared/acorn/tests/unit/test_lenient_parser.js create mode 100644 devtools/shared/acorn/tests/unit/test_same_ast.js create mode 100644 devtools/shared/acorn/tests/unit/xpcshell.ini create mode 100644 devtools/shared/acorn/walk.js create mode 100644 devtools/shared/apps/Devices.jsm create mode 100644 devtools/shared/apps/Simulator.jsm create mode 100644 devtools/shared/apps/app-actor-front.js create mode 100644 devtools/shared/apps/moz.build create mode 100644 devtools/shared/async-storage.js create mode 100644 devtools/shared/async-utils.js create mode 100644 devtools/shared/builtin-modules.js create mode 100644 devtools/shared/client/connection-manager.js create mode 100644 devtools/shared/client/main.js create mode 100644 devtools/shared/client/moz.build create mode 100644 devtools/shared/content-observer.js create mode 100644 devtools/shared/css/color-db.js create mode 100644 devtools/shared/css/color.js create mode 100644 devtools/shared/css/generated/generate-properties-db.js create mode 100644 devtools/shared/css/generated/mach_commands.py create mode 100644 devtools/shared/css/generated/moz.build create mode 100644 devtools/shared/css/generated/properties-db.js create mode 100644 devtools/shared/css/generated/properties-db.js.in create mode 100644 devtools/shared/css/lexer.js create mode 100644 devtools/shared/css/moz.build create mode 100644 devtools/shared/css/parsing-utils.js create mode 100644 devtools/shared/css/properties-db.js create mode 100644 devtools/shared/defer.js create mode 100644 devtools/shared/deprecated-sync-thenables.js create mode 100644 devtools/shared/discovery/discovery.js create mode 100644 devtools/shared/discovery/moz.build create mode 100644 devtools/shared/discovery/tests/unit/test_discovery.js create mode 100644 devtools/shared/discovery/tests/unit/xpcshell.ini create mode 100644 devtools/shared/dom-node-constants.js create mode 100644 devtools/shared/dom-node-filter-constants.js create mode 100644 devtools/shared/event-emitter.js create mode 100644 devtools/shared/flags.js create mode 100644 devtools/shared/fronts/actor-registry.js create mode 100644 devtools/shared/fronts/addons.js create mode 100644 devtools/shared/fronts/animation.js create mode 100644 devtools/shared/fronts/call-watcher.js create mode 100644 devtools/shared/fronts/canvas.js create mode 100644 devtools/shared/fronts/css-properties.js create mode 100644 devtools/shared/fronts/csscoverage.js create mode 100644 devtools/shared/fronts/device.js create mode 100644 devtools/shared/fronts/director-manager.js create mode 100644 devtools/shared/fronts/director-registry.js create mode 100644 devtools/shared/fronts/emulation.js create mode 100644 devtools/shared/fronts/eventlooplag.js create mode 100644 devtools/shared/fronts/framerate.js create mode 100644 devtools/shared/fronts/gcli.js create mode 100644 devtools/shared/fronts/highlighters.js create mode 100644 devtools/shared/fronts/inspector.js create mode 100644 devtools/shared/fronts/layout.js create mode 100644 devtools/shared/fronts/memory.js create mode 100644 devtools/shared/fronts/moz.build create mode 100644 devtools/shared/fronts/performance-entries.js create mode 100644 devtools/shared/fronts/performance-recording.js create mode 100644 devtools/shared/fronts/performance.js create mode 100644 devtools/shared/fronts/preference.js create mode 100644 devtools/shared/fronts/profiler.js create mode 100644 devtools/shared/fronts/promises.js create mode 100644 devtools/shared/fronts/reflow.js create mode 100644 devtools/shared/fronts/settings.js create mode 100644 devtools/shared/fronts/storage.js create mode 100644 devtools/shared/fronts/string.js create mode 100644 devtools/shared/fronts/styleeditor.js create mode 100644 devtools/shared/fronts/styles.js create mode 100644 devtools/shared/fronts/stylesheets.js create mode 100644 devtools/shared/fronts/timeline.js create mode 100644 devtools/shared/fronts/webaudio.js create mode 100644 devtools/shared/fronts/webgl.js create mode 100644 devtools/shared/gcli/commands/addon.js create mode 100644 devtools/shared/gcli/commands/appcache.js create mode 100644 devtools/shared/gcli/commands/calllog.js create mode 100644 devtools/shared/gcli/commands/cmd.js create mode 100644 devtools/shared/gcli/commands/cookie.js create mode 100644 devtools/shared/gcli/commands/csscoverage.js create mode 100644 devtools/shared/gcli/commands/folder.js create mode 100644 devtools/shared/gcli/commands/highlight.js create mode 100644 devtools/shared/gcli/commands/index.js create mode 100644 devtools/shared/gcli/commands/inject.js create mode 100644 devtools/shared/gcli/commands/jsb.js create mode 100644 devtools/shared/gcli/commands/listen.js create mode 100644 devtools/shared/gcli/commands/mdn.js create mode 100644 devtools/shared/gcli/commands/measure.js create mode 100644 devtools/shared/gcli/commands/media.js create mode 100644 devtools/shared/gcli/commands/moz.build create mode 100644 devtools/shared/gcli/commands/pagemod.js create mode 100644 devtools/shared/gcli/commands/paintflashing.js create mode 100644 devtools/shared/gcli/commands/qsa.js create mode 100644 devtools/shared/gcli/commands/restart.js create mode 100644 devtools/shared/gcli/commands/rulers.js create mode 100644 devtools/shared/gcli/commands/screenshot.js create mode 100644 devtools/shared/gcli/commands/security.js create mode 100644 devtools/shared/gcli/moz.build create mode 100644 devtools/shared/gcli/source/LICENSE create mode 100644 devtools/shared/gcli/source/docs/design.md create mode 100644 devtools/shared/gcli/source/docs/developing-gcli.md create mode 100644 devtools/shared/gcli/source/docs/index.md create mode 100644 devtools/shared/gcli/source/docs/running-tests.md create mode 100644 devtools/shared/gcli/source/docs/writing-commands.md create mode 100644 devtools/shared/gcli/source/docs/writing-tests.md create mode 100644 devtools/shared/gcli/source/docs/writing-types.md create mode 100644 devtools/shared/gcli/source/lib/gcli/cli.js create mode 100644 devtools/shared/gcli/source/lib/gcli/commands/clear.js create mode 100644 devtools/shared/gcli/source/lib/gcli/commands/commands.js create mode 100644 devtools/shared/gcli/source/lib/gcli/commands/context.js create mode 100644 devtools/shared/gcli/source/lib/gcli/commands/help.js create mode 100644 devtools/shared/gcli/source/lib/gcli/commands/mocks.js create mode 100644 devtools/shared/gcli/source/lib/gcli/commands/moz.build create mode 100644 devtools/shared/gcli/source/lib/gcli/commands/pref.js create mode 100644 devtools/shared/gcli/source/lib/gcli/commands/preflist.js create mode 100644 devtools/shared/gcli/source/lib/gcli/commands/test.js create mode 100644 devtools/shared/gcli/source/lib/gcli/connectors/connectors.js create mode 100644 devtools/shared/gcli/source/lib/gcli/connectors/moz.build create mode 100644 devtools/shared/gcli/source/lib/gcli/converters/basic.js create mode 100644 devtools/shared/gcli/source/lib/gcli/converters/converters.js create mode 100644 devtools/shared/gcli/source/lib/gcli/converters/html.js create mode 100644 devtools/shared/gcli/source/lib/gcli/converters/moz.build create mode 100644 devtools/shared/gcli/source/lib/gcli/converters/terminal.js create mode 100644 devtools/shared/gcli/source/lib/gcli/fields/delegate.js create mode 100644 devtools/shared/gcli/source/lib/gcli/fields/fields.js create mode 100644 devtools/shared/gcli/source/lib/gcli/fields/moz.build create mode 100644 devtools/shared/gcli/source/lib/gcli/fields/selection.js create mode 100644 devtools/shared/gcli/source/lib/gcli/index.js create mode 100644 devtools/shared/gcli/source/lib/gcli/l10n.js create mode 100644 devtools/shared/gcli/source/lib/gcli/languages/command.html create mode 100644 devtools/shared/gcli/source/lib/gcli/languages/command.js create mode 100644 devtools/shared/gcli/source/lib/gcli/languages/javascript.js create mode 100644 devtools/shared/gcli/source/lib/gcli/languages/languages.js create mode 100644 devtools/shared/gcli/source/lib/gcli/languages/moz.build create mode 100644 devtools/shared/gcli/source/lib/gcli/moz.build create mode 100644 devtools/shared/gcli/source/lib/gcli/mozui/completer.js create mode 100644 devtools/shared/gcli/source/lib/gcli/mozui/inputter.js create mode 100644 devtools/shared/gcli/source/lib/gcli/mozui/moz.build create mode 100644 devtools/shared/gcli/source/lib/gcli/mozui/tooltip.js create mode 100644 devtools/shared/gcli/source/lib/gcli/settings.js create mode 100644 devtools/shared/gcli/source/lib/gcli/system.js create mode 100644 devtools/shared/gcli/source/lib/gcli/types/array.js create mode 100644 devtools/shared/gcli/source/lib/gcli/types/boolean.js create mode 100644 devtools/shared/gcli/source/lib/gcli/types/command.js create mode 100644 devtools/shared/gcli/source/lib/gcli/types/date.js create mode 100644 devtools/shared/gcli/source/lib/gcli/types/delegate.js create mode 100644 devtools/shared/gcli/source/lib/gcli/types/file.js create mode 100644 devtools/shared/gcli/source/lib/gcli/types/fileparser.js create mode 100644 devtools/shared/gcli/source/lib/gcli/types/javascript.js create mode 100644 devtools/shared/gcli/source/lib/gcli/types/moz.build create mode 100644 devtools/shared/gcli/source/lib/gcli/types/node.js create mode 100644 devtools/shared/gcli/source/lib/gcli/types/number.js create mode 100644 devtools/shared/gcli/source/lib/gcli/types/resource.js create mode 100644 devtools/shared/gcli/source/lib/gcli/types/selection.js create mode 100644 devtools/shared/gcli/source/lib/gcli/types/setting.js create mode 100644 devtools/shared/gcli/source/lib/gcli/types/string.js create mode 100644 devtools/shared/gcli/source/lib/gcli/types/types.js create mode 100644 devtools/shared/gcli/source/lib/gcli/types/union.js create mode 100644 devtools/shared/gcli/source/lib/gcli/types/url.js create mode 100644 devtools/shared/gcli/source/lib/gcli/ui/focus.js create mode 100644 devtools/shared/gcli/source/lib/gcli/ui/history.js create mode 100644 devtools/shared/gcli/source/lib/gcli/ui/intro.js create mode 100644 devtools/shared/gcli/source/lib/gcli/ui/menu.css create mode 100644 devtools/shared/gcli/source/lib/gcli/ui/menu.html create mode 100644 devtools/shared/gcli/source/lib/gcli/ui/menu.js create mode 100644 devtools/shared/gcli/source/lib/gcli/ui/moz.build create mode 100644 devtools/shared/gcli/source/lib/gcli/ui/view.js create mode 100644 devtools/shared/gcli/source/lib/gcli/util/domtemplate.js create mode 100644 devtools/shared/gcli/source/lib/gcli/util/fileparser.js create mode 100644 devtools/shared/gcli/source/lib/gcli/util/filesystem.js create mode 100644 devtools/shared/gcli/source/lib/gcli/util/host.js create mode 100644 devtools/shared/gcli/source/lib/gcli/util/l10n.js create mode 100644 devtools/shared/gcli/source/lib/gcli/util/legacy.js create mode 100644 devtools/shared/gcli/source/lib/gcli/util/moz.build create mode 100644 devtools/shared/gcli/source/lib/gcli/util/prism.js create mode 100644 devtools/shared/gcli/source/lib/gcli/util/spell.js create mode 100644 devtools/shared/gcli/source/lib/gcli/util/util.js create mode 100644 devtools/shared/gcli/templater.js create mode 100644 devtools/shared/heapsnapshot/.gitattributes create mode 100644 devtools/shared/heapsnapshot/AutoMemMap.cpp create mode 100644 devtools/shared/heapsnapshot/AutoMemMap.h create mode 100644 devtools/shared/heapsnapshot/CensusUtils.js create mode 100644 devtools/shared/heapsnapshot/CoreDump.pb.cc create mode 100644 devtools/shared/heapsnapshot/CoreDump.pb.h create mode 100644 devtools/shared/heapsnapshot/CoreDump.proto create mode 100644 devtools/shared/heapsnapshot/DeserializedNode.cpp create mode 100644 devtools/shared/heapsnapshot/DeserializedNode.h create mode 100644 devtools/shared/heapsnapshot/DominatorTree.cpp create mode 100644 devtools/shared/heapsnapshot/DominatorTree.h create mode 100644 devtools/shared/heapsnapshot/DominatorTreeNode.js create mode 100644 devtools/shared/heapsnapshot/FileDescriptorOutputStream.cpp create mode 100644 devtools/shared/heapsnapshot/FileDescriptorOutputStream.h create mode 100644 devtools/shared/heapsnapshot/HeapAnalysesClient.js create mode 100644 devtools/shared/heapsnapshot/HeapAnalysesWorker.js create mode 100644 devtools/shared/heapsnapshot/HeapSnapshot.cpp create mode 100644 devtools/shared/heapsnapshot/HeapSnapshot.h create mode 100644 devtools/shared/heapsnapshot/HeapSnapshotFileUtils.js create mode 100644 devtools/shared/heapsnapshot/HeapSnapshotTempFileHelperChild.h create mode 100644 devtools/shared/heapsnapshot/HeapSnapshotTempFileHelperParent.cpp create mode 100644 devtools/shared/heapsnapshot/HeapSnapshotTempFileHelperParent.h create mode 100644 devtools/shared/heapsnapshot/PHeapSnapshotTempFileHelper.ipdl create mode 100644 devtools/shared/heapsnapshot/ZeroCopyNSIOutputStream.cpp create mode 100644 devtools/shared/heapsnapshot/ZeroCopyNSIOutputStream.h create mode 100644 devtools/shared/heapsnapshot/census-tree-node.js create mode 100755 devtools/shared/heapsnapshot/generate-core-dump-sources.sh create mode 100644 devtools/shared/heapsnapshot/moz.build create mode 100644 devtools/shared/heapsnapshot/shortest-paths.js create mode 100644 devtools/shared/heapsnapshot/tests/gtest/DeserializedNodeUbiNodes.cpp create mode 100644 devtools/shared/heapsnapshot/tests/gtest/DeserializedStackFrameUbiStackFrames.cpp create mode 100644 devtools/shared/heapsnapshot/tests/gtest/DevTools.h create mode 100644 devtools/shared/heapsnapshot/tests/gtest/DoesCrossCompartmentBoundaries.cpp create mode 100644 devtools/shared/heapsnapshot/tests/gtest/DoesntCrossCompartmentBoundaries.cpp create mode 100644 devtools/shared/heapsnapshot/tests/gtest/SerializesEdgeNames.cpp create mode 100644 devtools/shared/heapsnapshot/tests/gtest/SerializesEverythingInHeapGraphOnce.cpp create mode 100644 devtools/shared/heapsnapshot/tests/gtest/SerializesTypeNames.cpp create mode 100644 devtools/shared/heapsnapshot/tests/gtest/moz.build create mode 100644 devtools/shared/heapsnapshot/tests/mochitest/chrome.ini create mode 100644 devtools/shared/heapsnapshot/tests/mochitest/mochitest.ini create mode 100644 devtools/shared/heapsnapshot/tests/mochitest/test_DominatorTree_01.html create mode 100644 devtools/shared/heapsnapshot/tests/mochitest/test_SaveHeapSnapshot.html create mode 100644 devtools/shared/heapsnapshot/tests/mochitest/test_saveHeapSnapshot_e10s_01.html create mode 100644 devtools/shared/heapsnapshot/tests/unit/.eslintrc.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/Census.jsm create mode 100644 devtools/shared/heapsnapshot/tests/unit/Match.jsm create mode 100644 devtools/shared/heapsnapshot/tests/unit/dominator-tree-worker.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/head_heapsnapshot.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/heap-snapshot-worker.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_LabelAndShallowSize_01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_LabelAndShallowSize_02.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_LabelAndShallowSize_03.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_LabelAndShallowSize_04.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_attachShortestPaths_01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_getNodeByIdAlongPath_01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_insert_01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_insert_02.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_insert_03.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_partialTraversal_01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_DominatorTree_01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_DominatorTree_02.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_DominatorTree_03.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_DominatorTree_04.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_DominatorTree_05.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_DominatorTree_06.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_computeDominatorTree_01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_computeDominatorTree_02.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_deleteHeapSnapshot_01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_deleteHeapSnapshot_02.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_deleteHeapSnapshot_03.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_getCensusIndividuals_01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_getCreationTime_01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_getDominatorTree_01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_getDominatorTree_02.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_getImmediatelyDominated_01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_readHeapSnapshot_01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensusDiff_01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensusDiff_02.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_02.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_03.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_04.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_05.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_06.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_07.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_computeShortestPaths_01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_computeShortestPaths_02.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_creationTime_01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_deepStack_01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_describeNode_01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_02.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_03.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_04.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_05.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_06.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_07.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_08.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_09.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_10.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_11.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_12.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_ReadHeapSnapshot.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_ReadHeapSnapshot_with_allocations.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_ReadHeapSnapshot_worker.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_SaveHeapSnapshot.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-02.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-03.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-04.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-05.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-06.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-07.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-08.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-09.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-10.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_census_diff_01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_census_diff_02.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_census_diff_03.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_census_diff_04.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_census_diff_05.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_census_diff_06.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_census_filtering_01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_census_filtering_02.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_census_filtering_03.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_census_filtering_04.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_census_filtering_05.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_countToBucketBreakdown_01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_deduplicatePaths_01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_getCensusIndividuals_01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_getReportLeaves_01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/test_saveHeapSnapshot_e10s_01.js create mode 100644 devtools/shared/heapsnapshot/tests/unit/xpcshell.ini create mode 100644 devtools/shared/indentation.js create mode 100644 devtools/shared/inspector/css-logic.js create mode 100644 devtools/shared/inspector/moz.build create mode 100644 devtools/shared/jar.mn create mode 100644 devtools/shared/jsbeautify/UPGRADING.md create mode 100644 devtools/shared/jsbeautify/beautify.js create mode 100644 devtools/shared/jsbeautify/lib/moz.build create mode 100644 devtools/shared/jsbeautify/lib/sanitytest.js create mode 100644 devtools/shared/jsbeautify/lib/urlencode_unpacker.js create mode 100644 devtools/shared/jsbeautify/moz.build create mode 100644 devtools/shared/jsbeautify/src/beautify-css.js create mode 100644 devtools/shared/jsbeautify/src/beautify-html.js create mode 100644 devtools/shared/jsbeautify/src/beautify-js.js create mode 100644 devtools/shared/jsbeautify/src/beautify-tests.js create mode 100644 devtools/shared/jsbeautify/src/moz.build create mode 100644 devtools/shared/jsbeautify/tests/unit/head_jsbeautify.js create mode 100644 devtools/shared/jsbeautify/tests/unit/test.js create mode 100644 devtools/shared/jsbeautify/tests/unit/xpcshell.ini create mode 100644 devtools/shared/l10n.js create mode 100644 devtools/shared/layout/moz.build create mode 100644 devtools/shared/layout/utils.js create mode 100644 devtools/shared/loader-plugin-raw.jsm create mode 100644 devtools/shared/locales/en-US/csscoverage.dtd create mode 100644 devtools/shared/locales/en-US/csscoverage.properties create mode 100644 devtools/shared/locales/en-US/debugger.properties create mode 100644 devtools/shared/locales/en-US/gcli.properties create mode 100644 devtools/shared/locales/en-US/gclicommands.properties create mode 100644 devtools/shared/locales/en-US/shared.properties create mode 100644 devtools/shared/locales/en-US/styleinspector.properties create mode 100644 devtools/shared/locales/jar.mn create mode 100644 devtools/shared/locales/moz.build create mode 100644 devtools/shared/moz.build create mode 100644 devtools/shared/node-properties/UPGRADING.md create mode 100644 devtools/shared/node-properties/moz.build create mode 100644 devtools/shared/node-properties/node-properties.js create mode 100644 devtools/shared/path.js create mode 100644 devtools/shared/performance/moz.build create mode 100644 devtools/shared/performance/recording-common.js create mode 100644 devtools/shared/performance/recording-utils.js create mode 100644 devtools/shared/performance/test/head.js create mode 100644 devtools/shared/performance/test/test_perf-utils-allocations-to-samples.js create mode 100644 devtools/shared/performance/test/xpcshell.ini create mode 100644 devtools/shared/platform/README.md create mode 100644 devtools/shared/platform/chrome/clipboard.js create mode 100644 devtools/shared/platform/chrome/moz.build create mode 100644 devtools/shared/platform/chrome/stack.js create mode 100644 devtools/shared/platform/content/.eslintrc.js create mode 100644 devtools/shared/platform/content/clipboard.js create mode 100644 devtools/shared/platform/content/moz.build create mode 100644 devtools/shared/platform/content/stack.js create mode 100644 devtools/shared/platform/content/test/.eslintrc.js create mode 100644 devtools/shared/platform/content/test/mochitest.ini create mode 100644 devtools/shared/platform/content/test/test_clipboard.html create mode 100644 devtools/shared/platform/content/test/test_stack.js create mode 100644 devtools/shared/platform/content/test/xpcshell.ini create mode 100644 devtools/shared/platform/moz.build create mode 100644 devtools/shared/plural-form.js create mode 100644 devtools/shared/pretty-fast/UPGRADING.md create mode 100644 devtools/shared/pretty-fast/moz.build create mode 100644 devtools/shared/pretty-fast/pretty-fast.js create mode 100644 devtools/shared/pretty-fast/tests/unit/head_pretty-fast.js create mode 100644 devtools/shared/pretty-fast/tests/unit/test.js create mode 100644 devtools/shared/pretty-fast/tests/unit/xpcshell.ini create mode 100644 devtools/shared/protocol.js create mode 100644 devtools/shared/qrcode/decoder/LICENSE create mode 100644 devtools/shared/qrcode/decoder/index.js create mode 100644 devtools/shared/qrcode/decoder/moz.build create mode 100644 devtools/shared/qrcode/encoder/LICENSE create mode 100644 devtools/shared/qrcode/encoder/index.js create mode 100644 devtools/shared/qrcode/encoder/moz.build create mode 100644 devtools/shared/qrcode/index.js create mode 100644 devtools/shared/qrcode/moz.build create mode 100644 devtools/shared/qrcode/tests/mochitest/chrome.ini create mode 100644 devtools/shared/qrcode/tests/mochitest/test_decode.html create mode 100644 devtools/shared/qrcode/tests/unit/test_encode.js create mode 100644 devtools/shared/qrcode/tests/unit/xpcshell.ini create mode 100644 devtools/shared/security/auth.js create mode 100644 devtools/shared/security/cert.js create mode 100644 devtools/shared/security/docs/wifi.md create mode 100644 devtools/shared/security/moz.build create mode 100644 devtools/shared/security/prompt.js create mode 100644 devtools/shared/security/socket.js create mode 100644 devtools/shared/security/tests/chrome/chrome.ini create mode 100644 devtools/shared/security/tests/chrome/test_websocket-transport.html create mode 100644 devtools/shared/security/tests/unit/.eslintrc.js create mode 100644 devtools/shared/security/tests/unit/head_dbg.js create mode 100644 devtools/shared/security/tests/unit/test_encryption.js create mode 100644 devtools/shared/security/tests/unit/test_oob_cert_auth.js create mode 100644 devtools/shared/security/tests/unit/testactors.js create mode 100644 devtools/shared/security/tests/unit/xpcshell.ini create mode 100644 devtools/shared/shims/Console.jsm create mode 100644 devtools/shared/shims/Loader.jsm create mode 100644 devtools/shared/shims/Simulator.jsm create mode 100644 devtools/shared/shims/dbg-client.jsm create mode 100644 devtools/shared/shims/event-emitter.js create mode 100644 devtools/shared/shims/moz.build create mode 100644 devtools/shared/sourcemap/UPGRADING.md create mode 100644 devtools/shared/sourcemap/moz.build create mode 100644 devtools/shared/sourcemap/source-map.js create mode 100644 devtools/shared/sourcemap/tests/unit/head_sourcemap.js create mode 100644 devtools/shared/sourcemap/tests/unit/test_api.js create mode 100644 devtools/shared/sourcemap/tests/unit/test_array_set.js create mode 100644 devtools/shared/sourcemap/tests/unit/test_base64.js create mode 100644 devtools/shared/sourcemap/tests/unit/test_base64_vlq.js create mode 100644 devtools/shared/sourcemap/tests/unit/test_binary_search.js create mode 100644 devtools/shared/sourcemap/tests/unit/test_dog_fooding.js create mode 100644 devtools/shared/sourcemap/tests/unit/test_quick_sort.js create mode 100644 devtools/shared/sourcemap/tests/unit/test_source_map_consumer.js create mode 100644 devtools/shared/sourcemap/tests/unit/test_source_map_generator.js create mode 100644 devtools/shared/sourcemap/tests/unit/test_source_node.js create mode 100644 devtools/shared/sourcemap/tests/unit/test_util.js create mode 100644 devtools/shared/sourcemap/tests/unit/xpcshell.ini create mode 100644 devtools/shared/specs/actor-registry.js create mode 100644 devtools/shared/specs/addons.js create mode 100644 devtools/shared/specs/animation.js create mode 100644 devtools/shared/specs/breakpoint.js create mode 100644 devtools/shared/specs/call-watcher.js create mode 100644 devtools/shared/specs/canvas.js create mode 100644 devtools/shared/specs/css-properties.js create mode 100644 devtools/shared/specs/csscoverage.js create mode 100644 devtools/shared/specs/device.js create mode 100644 devtools/shared/specs/director-manager.js create mode 100644 devtools/shared/specs/director-registry.js create mode 100644 devtools/shared/specs/emulation.js create mode 100644 devtools/shared/specs/environment.js create mode 100644 devtools/shared/specs/eventlooplag.js create mode 100644 devtools/shared/specs/frame.js create mode 100644 devtools/shared/specs/framerate.js create mode 100644 devtools/shared/specs/gcli.js create mode 100644 devtools/shared/specs/heap-snapshot-file.js create mode 100644 devtools/shared/specs/highlighters.js create mode 100644 devtools/shared/specs/inspector.js create mode 100644 devtools/shared/specs/layout.js create mode 100644 devtools/shared/specs/memory.js create mode 100644 devtools/shared/specs/moz.build create mode 100644 devtools/shared/specs/node.js create mode 100644 devtools/shared/specs/performance-entries.js create mode 100644 devtools/shared/specs/performance-recording.js create mode 100644 devtools/shared/specs/performance.js create mode 100644 devtools/shared/specs/preference.js create mode 100644 devtools/shared/specs/profiler.js create mode 100644 devtools/shared/specs/promises.js create mode 100644 devtools/shared/specs/reflow.js create mode 100644 devtools/shared/specs/script.js create mode 100644 devtools/shared/specs/settings.js create mode 100644 devtools/shared/specs/source.js create mode 100644 devtools/shared/specs/storage.js create mode 100644 devtools/shared/specs/string.js create mode 100644 devtools/shared/specs/styleeditor.js create mode 100644 devtools/shared/specs/styles.js create mode 100644 devtools/shared/specs/stylesheets.js create mode 100644 devtools/shared/specs/timeline.js create mode 100644 devtools/shared/specs/webaudio.js create mode 100644 devtools/shared/specs/webgl.js create mode 100644 devtools/shared/specs/worker.js create mode 100644 devtools/shared/sprintfjs/UPGRADING.md create mode 100644 devtools/shared/sprintfjs/moz.build create mode 100644 devtools/shared/sprintfjs/sprintf.js create mode 100644 devtools/shared/system.js create mode 100644 devtools/shared/task.js create mode 100644 devtools/shared/tests/browser/.eslintrc.js create mode 100644 devtools/shared/tests/browser/browser.ini create mode 100644 devtools/shared/tests/browser/browser_async_storage.js create mode 100644 devtools/shared/tests/browser/browser_l10n_localizeMarkup.js create mode 100644 devtools/shared/tests/mochitest/chrome.ini create mode 100644 devtools/shared/tests/mochitest/test_devtools_extensions.html create mode 100644 devtools/shared/tests/mochitest/test_eventemitter_basic.html create mode 100644 devtools/shared/tests/unit/.eslintrc.js create mode 100644 devtools/shared/tests/unit/exposeLoader.js create mode 100644 devtools/shared/tests/unit/head_devtools.js create mode 100644 devtools/shared/tests/unit/test_assert.js create mode 100644 devtools/shared/tests/unit/test_async-utils.js create mode 100644 devtools/shared/tests/unit/test_console_filtering.js create mode 100644 devtools/shared/tests/unit/test_css-properties-db.js create mode 100644 devtools/shared/tests/unit/test_csslexer.js create mode 100644 devtools/shared/tests/unit/test_defer.js create mode 100644 devtools/shared/tests/unit/test_defineLazyPrototypeGetter.js create mode 100644 devtools/shared/tests/unit/test_executeSoon.js create mode 100644 devtools/shared/tests/unit/test_fetch-bom.js create mode 100644 devtools/shared/tests/unit/test_fetch-chrome.js create mode 100644 devtools/shared/tests/unit/test_fetch-file.js create mode 100644 devtools/shared/tests/unit/test_fetch-http.js create mode 100644 devtools/shared/tests/unit/test_fetch-resource.js create mode 100644 devtools/shared/tests/unit/test_flatten.js create mode 100644 devtools/shared/tests/unit/test_indentation.js create mode 100644 devtools/shared/tests/unit/test_independent_loaders.js create mode 100644 devtools/shared/tests/unit/test_invisible_loader.js create mode 100644 devtools/shared/tests/unit/test_isSet.js create mode 100644 devtools/shared/tests/unit/test_pluralForm-english.js create mode 100644 devtools/shared/tests/unit/test_pluralForm-makeGetter.js create mode 100644 devtools/shared/tests/unit/test_prettifyCSS.js create mode 100644 devtools/shared/tests/unit/test_require.js create mode 100644 devtools/shared/tests/unit/test_require_lazy.js create mode 100644 devtools/shared/tests/unit/test_require_raw.js create mode 100644 devtools/shared/tests/unit/test_safeErrorString.js create mode 100644 devtools/shared/tests/unit/test_stack.js create mode 100644 devtools/shared/tests/unit/xpcshell.ini create mode 100644 devtools/shared/touch/moz.build create mode 100644 devtools/shared/touch/simulator-content.js create mode 100644 devtools/shared/touch/simulator-core.js create mode 100644 devtools/shared/touch/simulator.js create mode 100644 devtools/shared/transport/moz.build create mode 100644 devtools/shared/transport/packets.js create mode 100644 devtools/shared/transport/stream-utils.js create mode 100644 devtools/shared/transport/tests/unit/.eslintrc.js create mode 100644 devtools/shared/transport/tests/unit/head_dbg.js create mode 100644 devtools/shared/transport/tests/unit/test_bulk_error.js create mode 100644 devtools/shared/transport/tests/unit/test_client_server_bulk.js create mode 100644 devtools/shared/transport/tests/unit/test_dbgsocket.js create mode 100644 devtools/shared/transport/tests/unit/test_dbgsocket_connection_drop.js create mode 100644 devtools/shared/transport/tests/unit/test_delimited_read.js create mode 100644 devtools/shared/transport/tests/unit/test_no_bulk.js create mode 100644 devtools/shared/transport/tests/unit/test_packet.js create mode 100644 devtools/shared/transport/tests/unit/test_queue.js create mode 100644 devtools/shared/transport/tests/unit/test_transport_bulk.js create mode 100644 devtools/shared/transport/tests/unit/test_transport_events.js create mode 100644 devtools/shared/transport/tests/unit/testactors-no-bulk.js create mode 100644 devtools/shared/transport/tests/unit/testactors.js create mode 100644 devtools/shared/transport/tests/unit/xpcshell.ini create mode 100644 devtools/shared/transport/transport.js create mode 100644 devtools/shared/transport/websocket-transport.js create mode 100644 devtools/shared/webconsole/client.js create mode 100644 devtools/shared/webconsole/js-property-provider.js create mode 100644 devtools/shared/webconsole/moz.build create mode 100644 devtools/shared/webconsole/network-helper.js create mode 100644 devtools/shared/webconsole/network-monitor.js create mode 100644 devtools/shared/webconsole/server-logger-monitor.js create mode 100644 devtools/shared/webconsole/server-logger.js create mode 100644 devtools/shared/webconsole/test/chrome.ini create mode 100644 devtools/shared/webconsole/test/common.js create mode 100644 devtools/shared/webconsole/test/console-test-worker.js create mode 100644 devtools/shared/webconsole/test/data.json create mode 100644 devtools/shared/webconsole/test/data.json^headers^ create mode 100644 devtools/shared/webconsole/test/helper_serviceworker.js create mode 100644 devtools/shared/webconsole/test/network_requests_iframe.html create mode 100644 devtools/shared/webconsole/test/sandboxed_iframe.html create mode 100644 devtools/shared/webconsole/test/test_basics.html create mode 100644 devtools/shared/webconsole/test/test_bug819670_getter_throws.html create mode 100644 devtools/shared/webconsole/test/test_cached_messages.html create mode 100644 devtools/shared/webconsole/test/test_commands_other.html create mode 100644 devtools/shared/webconsole/test/test_commands_registration.html create mode 100644 devtools/shared/webconsole/test/test_console_serviceworker.html create mode 100644 devtools/shared/webconsole/test/test_console_serviceworker_cached.html create mode 100644 devtools/shared/webconsole/test/test_console_styling.html create mode 100644 devtools/shared/webconsole/test/test_consoleapi.html create mode 100644 devtools/shared/webconsole/test/test_consoleapi_innerID.html create mode 100644 devtools/shared/webconsole/test/test_file_uri.html create mode 100644 devtools/shared/webconsole/test/test_jsterm.html create mode 100644 devtools/shared/webconsole/test/test_jsterm_autocomplete.html create mode 100644 devtools/shared/webconsole/test/test_jsterm_cd_iframe.html create mode 100644 devtools/shared/webconsole/test/test_jsterm_last_result.html create mode 100644 devtools/shared/webconsole/test/test_jsterm_queryselector.html create mode 100644 devtools/shared/webconsole/test/test_network_get.html create mode 100644 devtools/shared/webconsole/test/test_network_longstring.html create mode 100644 devtools/shared/webconsole/test/test_network_post.html create mode 100644 devtools/shared/webconsole/test/test_network_security-hpkp.html create mode 100644 devtools/shared/webconsole/test/test_network_security-hsts.html create mode 100644 devtools/shared/webconsole/test/test_nsiconsolemessage.html create mode 100644 devtools/shared/webconsole/test/test_object_actor.html create mode 100644 devtools/shared/webconsole/test/test_object_actor_native_getters.html create mode 100644 devtools/shared/webconsole/test/test_object_actor_native_getters_lenient_this.html create mode 100644 devtools/shared/webconsole/test/test_page_errors.html create mode 100644 devtools/shared/webconsole/test/test_reflow.html create mode 100644 devtools/shared/webconsole/test/test_throw.html create mode 100644 devtools/shared/webconsole/test/unit/.eslintrc.js create mode 100644 devtools/shared/webconsole/test/unit/test_js_property_provider.js create mode 100644 devtools/shared/webconsole/test/unit/test_network_helper.js create mode 100644 devtools/shared/webconsole/test/unit/test_security-info-certificate.js create mode 100644 devtools/shared/webconsole/test/unit/test_security-info-parser.js create mode 100644 devtools/shared/webconsole/test/unit/test_security-info-protocol-version.js create mode 100644 devtools/shared/webconsole/test/unit/test_security-info-state.js create mode 100644 devtools/shared/webconsole/test/unit/test_security-info-static-hpkp.js create mode 100644 devtools/shared/webconsole/test/unit/test_security-info-weakness-reasons.js create mode 100644 devtools/shared/webconsole/test/unit/test_throttle.js create mode 100644 devtools/shared/webconsole/test/unit/xpcshell.ini create mode 100644 devtools/shared/webconsole/throttle.js create mode 100644 devtools/shared/worker/helper.js create mode 100644 devtools/shared/worker/loader.js create mode 100644 devtools/shared/worker/moz.build create mode 100644 devtools/shared/worker/tests/browser/.eslintrc.js create mode 100644 devtools/shared/worker/tests/browser/browser.ini create mode 100644 devtools/shared/worker/tests/browser/browser_worker-01.js create mode 100644 devtools/shared/worker/tests/browser/browser_worker-02.js create mode 100644 devtools/shared/worker/tests/browser/browser_worker-03.js create mode 100644 devtools/shared/worker/worker.js (limited to 'devtools/shared') diff --git a/devtools/shared/DevToolsUtils.js b/devtools/shared/DevToolsUtils.js new file mode 100644 index 000000000..d44184fd6 --- /dev/null +++ b/devtools/shared/DevToolsUtils.js @@ -0,0 +1,672 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/* General utilities used throughout devtools. */ + +var { Ci, Cu, Cc, components } = require("chrome"); +var Services = require("Services"); +var promise = require("promise"); +var defer = require("devtools/shared/defer"); +var flags = require("./flags"); +var {getStack, callFunctionWithAsyncStack} = require("devtools/shared/platform/stack"); + +loader.lazyRequireGetter(this, "FileUtils", + "resource://gre/modules/FileUtils.jsm", true); + +// Re-export the thread-safe utils. +const ThreadSafeDevToolsUtils = require("./ThreadSafeDevToolsUtils.js"); +for (let key of Object.keys(ThreadSafeDevToolsUtils)) { + exports[key] = ThreadSafeDevToolsUtils[key]; +} + +/** + * Waits for the next tick in the event loop to execute a callback. + */ +exports.executeSoon = function executeSoon(aFn) { + if (isWorker) { + setImmediate(aFn); + } else { + let executor; + // Only enable async stack reporting when DEBUG_JS_MODULES is set + // (customized local builds) to avoid a performance penalty. + if (AppConstants.DEBUG_JS_MODULES || flags.testing) { + let stack = getStack(); + executor = () => { + callFunctionWithAsyncStack(aFn, stack, "DevToolsUtils.executeSoon"); + }; + } else { + executor = aFn; + } + Services.tm.mainThread.dispatch({ + run: exports.makeInfallible(executor) + }, Ci.nsIThread.DISPATCH_NORMAL); + } +}; + +/** + * Waits for the next tick in the event loop. + * + * @return Promise + * A promise that is resolved after the next tick in the event loop. + */ +exports.waitForTick = function waitForTick() { + let deferred = defer(); + exports.executeSoon(deferred.resolve); + return deferred.promise; +}; + +/** + * Waits for the specified amount of time to pass. + * + * @param number aDelay + * The amount of time to wait, in milliseconds. + * @return Promise + * A promise that is resolved after the specified amount of time passes. + */ +exports.waitForTime = function waitForTime(aDelay) { + let deferred = defer(); + setTimeout(deferred.resolve, aDelay); + return deferred.promise; +}; + +/** + * Like Array.prototype.forEach, but doesn't cause jankiness when iterating over + * very large arrays by yielding to the browser and continuing execution on the + * next tick. + * + * @param Array aArray + * The array being iterated over. + * @param Function aFn + * The function called on each item in the array. If a promise is + * returned by this function, iterating over the array will be paused + * until the respective promise is resolved. + * @returns Promise + * A promise that is resolved once the whole array has been iterated + * over, and all promises returned by the aFn callback are resolved. + */ +exports.yieldingEach = function yieldingEach(aArray, aFn) { + const deferred = defer(); + + let i = 0; + let len = aArray.length; + let outstanding = [deferred.promise]; + + (function loop() { + const start = Date.now(); + + while (i < len) { + // Don't block the main thread for longer than 16 ms at a time. To + // maintain 60fps, you have to render every frame in at least 16ms; we + // aren't including time spent in non-JS here, but this is Good + // Enough(tm). + if (Date.now() - start > 16) { + exports.executeSoon(loop); + return; + } + + try { + outstanding.push(aFn(aArray[i], i++)); + } catch (e) { + deferred.reject(e); + return; + } + } + + deferred.resolve(); + }()); + + return promise.all(outstanding); +}; + +/** + * Like XPCOMUtils.defineLazyGetter, but with a |this| sensitive getter that + * allows the lazy getter to be defined on a prototype and work correctly with + * instances. + * + * @param Object aObject + * The prototype object to define the lazy getter on. + * @param String aKey + * The key to define the lazy getter on. + * @param Function aCallback + * The callback that will be called to determine the value. Will be + * called with the |this| value of the current instance. + */ +exports.defineLazyPrototypeGetter = +function defineLazyPrototypeGetter(aObject, aKey, aCallback) { + Object.defineProperty(aObject, aKey, { + configurable: true, + get: function () { + const value = aCallback.call(this); + + Object.defineProperty(this, aKey, { + configurable: true, + writable: true, + value: value + }); + + return value; + } + }); +}; + +/** + * Safely get the property value from a Debugger.Object for a given key. Walks + * the prototype chain until the property is found. + * + * @param Debugger.Object aObject + * The Debugger.Object to get the value from. + * @param String aKey + * The key to look for. + * @return Any + */ +exports.getProperty = function getProperty(aObj, aKey) { + let root = aObj; + try { + do { + const desc = aObj.getOwnPropertyDescriptor(aKey); + if (desc) { + if ("value" in desc) { + return desc.value; + } + // Call the getter if it's safe. + return exports.hasSafeGetter(desc) ? desc.get.call(root).return : undefined; + } + aObj = aObj.proto; + } while (aObj); + } catch (e) { + // If anything goes wrong report the error and return undefined. + exports.reportException("getProperty", e); + } + return undefined; +}; + +/** + * Determines if a descriptor has a getter which doesn't call into JavaScript. + * + * @param Object aDesc + * The descriptor to check for a safe getter. + * @return Boolean + * Whether a safe getter was found. + */ +exports.hasSafeGetter = function hasSafeGetter(aDesc) { + // Scripted functions that are CCWs will not appear scripted until after + // unwrapping. + try { + let fn = aDesc.get.unwrap(); + return fn && fn.callable && fn.class == "Function" && fn.script === undefined; + } catch (e) { + // Avoid exception 'Object in compartment marked as invisible to Debugger' + return false; + } +}; + +/** + * Check if it is safe to read properties and execute methods from the given JS + * object. Safety is defined as being protected from unintended code execution + * from content scripts (or cross-compartment code). + * + * See bugs 945920 and 946752 for discussion. + * + * @type Object aObj + * The object to check. + * @return Boolean + * True if it is safe to read properties from aObj, or false otherwise. + */ +exports.isSafeJSObject = function isSafeJSObject(aObj) { + // If we are running on a worker thread, Cu is not available. In this case, + // we always return false, just to be on the safe side. + if (isWorker) { + return false; + } + + if (Cu.getGlobalForObject(aObj) == + Cu.getGlobalForObject(exports.isSafeJSObject)) { + return true; // aObj is not a cross-compartment wrapper. + } + + let principal = Cu.getObjectPrincipal(aObj); + if (Services.scriptSecurityManager.isSystemPrincipal(principal)) { + return true; // allow chrome objects + } + + return Cu.isXrayWrapper(aObj); +}; + +exports.dumpn = function dumpn(str) { + if (flags.wantLogging) { + dump("DBG-SERVER: " + str + "\n"); + } +}; + +/** + * A verbose logger for low-level tracing. + */ +exports.dumpv = function (msg) { + if (flags.wantVerbose) { + exports.dumpn(msg); + } +}; + +/** + * Defines a getter on a specified object that will be created upon first use. + * + * @param aObject + * The object to define the lazy getter on. + * @param aName + * The name of the getter to define on aObject. + * @param aLambda + * A function that returns what the getter should return. This will + * only ever be called once. + */ +exports.defineLazyGetter = function defineLazyGetter(aObject, aName, aLambda) { + Object.defineProperty(aObject, aName, { + get: function () { + delete aObject[aName]; + return aObject[aName] = aLambda.apply(aObject); + }, + configurable: true, + enumerable: true + }); +}; + +exports.defineLazyGetter(this, "AppConstants", () => { + if (isWorker) { + return {}; + } + const scope = {}; + Cu.import("resource://gre/modules/AppConstants.jsm", scope); + return scope.AppConstants; +}); + +/** + * No operation. The empty function. + */ +exports.noop = function () { }; + +let assertionFailureCount = 0; + +Object.defineProperty(exports, "assertionFailureCount", { + get() { + return assertionFailureCount; + } +}); + +function reallyAssert(condition, message) { + if (!condition) { + assertionFailureCount++; + const err = new Error("Assertion failure: " + message); + exports.reportException("DevToolsUtils.assert", err); + throw err; + } +} + +/** + * DevToolsUtils.assert(condition, message) + * + * @param Boolean condition + * @param String message + * + * Assertions are enabled when any of the following are true: + * - This is a DEBUG_JS_MODULES build + * - This is a DEBUG build + * - flags.testing is set to true + * + * If assertions are enabled, then `condition` is checked and if false-y, the + * assertion failure is logged and then an error is thrown. + * + * If assertions are not enabled, then this function is a no-op. + */ +Object.defineProperty(exports, "assert", { + get: () => (AppConstants.DEBUG || AppConstants.DEBUG_JS_MODULES || flags.testing) + ? reallyAssert + : exports.noop, +}); + +/** + * Defines a getter on a specified object for a module. The module will not + * be imported until first use. + * + * @param aObject + * The object to define the lazy getter on. + * @param aName + * The name of the getter to define on aObject for the module. + * @param aResource + * The URL used to obtain the module. + * @param aSymbol + * The name of the symbol exported by the module. + * This parameter is optional and defaults to aName. + */ +exports.defineLazyModuleGetter = function defineLazyModuleGetter(aObject, aName, + aResource, + aSymbol) +{ + this.defineLazyGetter(aObject, aName, function XPCU_moduleLambda() { + var temp = {}; + Cu.import(aResource, temp); + return temp[aSymbol || aName]; + }); +}; + +exports.defineLazyGetter(this, "NetUtil", () => { + return Cu.import("resource://gre/modules/NetUtil.jsm", {}).NetUtil; +}); + +exports.defineLazyGetter(this, "OS", () => { + return Cu.import("resource://gre/modules/osfile.jsm", {}).OS; +}); + +exports.defineLazyGetter(this, "TextDecoder", () => { + return Cu.import("resource://gre/modules/osfile.jsm", {}).TextDecoder; +}); + +exports.defineLazyGetter(this, "NetworkHelper", () => { + return require("devtools/shared/webconsole/network-helper"); +}); + +/** + * Performs a request to load the desired URL and returns a promise. + * + * @param aURL String + * The URL we will request. + * @param aOptions Object + * An object with the following optional properties: + * - loadFromCache: if false, will bypass the cache and + * always load fresh from the network (default: true) + * - policy: the nsIContentPolicy type to apply when fetching the URL + * (only works when loading from system principal) + * - window: the window to get the loadGroup from + * - charset: the charset to use if the channel doesn't provide one + * - principal: the principal to use, if omitted, the request is loaded + * with a codebase principal corresponding to the url being + * loaded, using the origin attributes of the window, if any. + * - cacheKey: when loading from cache, use this key to retrieve a cache + * specific to a given SHEntry. (Allows loading POST + * requests from cache) + * @returns Promise that resolves with an object with the following members on + * success: + * - content: the document at that URL, as a string, + * - contentType: the content type of the document + * + * If an error occurs, the promise is rejected with that error. + * + * XXX: It may be better to use nsITraceableChannel to get to the sources + * without relying on caching when we can (not for eval, etc.): + * http://www.softwareishard.com/blog/firebug/nsitraceablechannel-intercept-http-traffic/ + */ +function mainThreadFetch(aURL, aOptions = { loadFromCache: true, + policy: Ci.nsIContentPolicy.TYPE_OTHER, + window: null, + charset: null, + principal: null, + cacheKey: null }) { + // Create a channel. + let url = aURL.split(" -> ").pop(); + let channel; + try { + channel = newChannelForURL(url, aOptions); + } catch (ex) { + return promise.reject(ex); + } + + // Set the channel options. + channel.loadFlags = aOptions.loadFromCache + ? channel.LOAD_FROM_CACHE + : channel.LOAD_BYPASS_CACHE; + + // When loading from cache, the cacheKey allows us to target a specific + // SHEntry and offer ways to restore POST requests from cache. + if (aOptions.loadFromCache && + aOptions.cacheKey && channel instanceof Ci.nsICacheInfoChannel) { + channel.cacheKey = aOptions.cacheKey; + } + + if (aOptions.window) { + // Respect private browsing. + channel.loadGroup = aOptions.window.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIWebNavigation) + .QueryInterface(Ci.nsIDocumentLoader) + .loadGroup; + } + + let deferred = defer(); + let onResponse = (stream, status, request) => { + if (!components.isSuccessCode(status)) { + deferred.reject(new Error(`Failed to fetch ${url}. Code ${status}.`)); + return; + } + + try { + // We cannot use NetUtil to do the charset conversion as if charset + // information is not available and our default guess is wrong the method + // might fail and we lose the stream data. This means we can't fall back + // to using the locale default encoding (bug 1181345). + + // Read and decode the data according to the locale default encoding. + let available = stream.available(); + let source = NetUtil.readInputStreamToString(stream, available); + stream.close(); + + // We do our own BOM sniffing here because there's no convenient + // implementation of the "decode" algorithm + // (https://encoding.spec.whatwg.org/#decode) exposed to JS. + let bomCharset = null; + if (available >= 3 && source.codePointAt(0) == 0xef && + source.codePointAt(1) == 0xbb && source.codePointAt(2) == 0xbf) { + bomCharset = "UTF-8"; + source = source.slice(3); + } else if (available >= 2 && source.codePointAt(0) == 0xfe && + source.codePointAt(1) == 0xff) { + bomCharset = "UTF-16BE"; + source = source.slice(2); + } else if (available >= 2 && source.codePointAt(0) == 0xff && + source.codePointAt(1) == 0xfe) { + bomCharset = "UTF-16LE"; + source = source.slice(2); + } + + // If the channel or the caller has correct charset information, the + // content will be decoded correctly. If we have to fall back to UTF-8 and + // the guess is wrong, the conversion fails and convertToUnicode returns + // the input unmodified. Essentially we try to decode the data as UTF-8 + // and if that fails, we use the locale specific default encoding. This is + // the best we can do if the source does not provide charset info. + let charset = bomCharset || channel.contentCharset || aOptions.charset || "UTF-8"; + let unicodeSource = NetworkHelper.convertToUnicode(source, charset); + + deferred.resolve({ + content: unicodeSource, + contentType: request.contentType + }); + } catch (ex) { + let uri = request.originalURI; + if (ex.name === "NS_BASE_STREAM_CLOSED" && uri instanceof Ci.nsIFileURL) { + // Empty files cause NS_BASE_STREAM_CLOSED exception. Use OS.File to + // differentiate between empty files and other errors (bug 1170864). + // This can be removed when bug 982654 is fixed. + + uri.QueryInterface(Ci.nsIFileURL); + let result = OS.File.read(uri.file.path).then(bytes => { + // Convert the bytearray to a String. + let decoder = new TextDecoder(); + let content = decoder.decode(bytes); + + // We can't detect the contentType without opening a channel + // and that failed already. This is the best we can do here. + return { + content, + contentType: "text/plain" + }; + }); + + deferred.resolve(result); + } else { + deferred.reject(ex); + } + } + }; + + // Open the channel + try { + NetUtil.asyncFetch(channel, onResponse); + } catch (ex) { + return promise.reject(ex); + } + + return deferred.promise; +} + +/** + * Opens a channel for given URL. Tries a bit harder than NetUtil.newChannel. + * + * @param {String} url - The URL to open a channel for. + * @param {Object} options - The options object passed to @method fetch. + * @return {nsIChannel} - The newly created channel. Throws on failure. + */ +function newChannelForURL(url, { policy, window, principal }) { + var securityFlags = Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL; + + let uri; + try { + uri = Services.io.newURI(url, null, null); + } catch (e) { + // In the xpcshell tests, the script url is the absolute path of the test + // file, which will make a malformed URI error be thrown. Add the file + // scheme to see if it helps. + uri = Services.io.newURI("file://" + url, null, null); + } + let channelOptions = { + contentPolicyType: policy, + securityFlags: securityFlags, + uri: uri + }; + let prin = principal; + if (!prin) { + let oa = {}; + if (window) { + oa = window.document.nodePrincipal.originAttributes; + } + prin = Services.scriptSecurityManager + .createCodebasePrincipal(uri, oa); + } + // contentPolicyType is required when specifying a principal + if (!channelOptions.contentPolicyType) { + channelOptions.contentPolicyType = Ci.nsIContentPolicy.TYPE_OTHER; + } + channelOptions.loadingPrincipal = prin; + + try { + return NetUtil.newChannel(channelOptions); + } catch (e) { + // In xpcshell tests on Windows, nsExternalProtocolHandler::NewChannel() + // can throw NS_ERROR_UNKNOWN_PROTOCOL if the external protocol isn't + // supported by Windows, so we also need to handle the exception here if + // parsing the URL above doesn't throw. + return newChannelForURL("file://" + url, { policy, window, principal }); + } +} + +// Fetch is defined differently depending on whether we are on the main thread +// or a worker thread. +if (!this.isWorker) { + exports.fetch = mainThreadFetch; +} else { + // Services is not available in worker threads, nor is there any other way + // to fetch a URL. We need to enlist the help from the main thread here, by + // issuing an rpc request, to fetch the URL on our behalf. + exports.fetch = function (url, options) { + return rpc("fetch", url, options); + }; +} + +/** + * Open the file at the given path for reading. + * + * @param {String} filePath + * + * @returns Promise + */ +exports.openFileStream = function (filePath) { + return new Promise((resolve, reject) => { + const uri = NetUtil.newURI(new FileUtils.File(filePath)); + NetUtil.asyncFetch( + { uri, loadUsingSystemPrincipal: true }, + (stream, result) => { + if (!components.isSuccessCode(result)) { + reject(new Error(`Could not open "${filePath}": result = ${result}`)); + return; + } + + resolve(stream); + } + ); + }); +}; + +/* + * All of the flags have been moved to a different module. Make sure + * nobody is accessing them anymore, and don't write new code using + * them. We can remove this code after a while. + */ +function errorOnFlag(exports, name) { + Object.defineProperty(exports, name, { + get: () => { + const msg = `Cannot get the flag ${name}. ` + + `Use the "devtools/shared/flags" module instead`; + console.error(msg); + throw new Error(msg); + }, + set: () => { + const msg = `Cannot set the flag ${name}. ` + + `Use the "devtools/shared/flags" module instead`; + console.error(msg); + throw new Error(msg); + } + }); +} + +errorOnFlag(exports, "testing"); +errorOnFlag(exports, "wantLogging"); +errorOnFlag(exports, "wantVerbose"); + +// Calls the property with the given `name` on the given `object`, where +// `name` is a string, and `object` a Debugger.Object instance. +/// +// This function uses only the Debugger.Object API to call the property. It +// avoids the use of unsafeDeference. This is useful for example in workers, +// where unsafeDereference will return an opaque security wrapper to the +// referent. +function callPropertyOnObject(object, name) { + // Find the property. + let descriptor; + let proto = object; + do { + descriptor = proto.getOwnPropertyDescriptor(name); + if (descriptor !== undefined) { + break; + } + proto = proto.proto; + } while (proto !== null); + if (descriptor === undefined) { + throw new Error("No such property"); + } + let value = descriptor.value; + if (typeof value !== "object" || value === null || !("callable" in value)) { + throw new Error("Not a callable object."); + } + + // Call the property. + let result = value.call(object); + if (result === null) { + throw new Error("Code was terminated."); + } + if ("throw" in result) { + throw result.throw; + } + return result.return; +} + + +exports.callPropertyOnObject = callPropertyOnObject; diff --git a/devtools/shared/Loader.jsm b/devtools/shared/Loader.jsm new file mode 100644 index 000000000..6b31075ee --- /dev/null +++ b/devtools/shared/Loader.jsm @@ -0,0 +1,244 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * Manages the addon-sdk loader instance used to load the developer tools. + */ + +var { utils: Cu } = Components; +var { Services } = Cu.import("resource://gre/modules/Services.jsm", {}); +var { Loader, descriptor, resolveURI } = Cu.import("resource://gre/modules/commonjs/toolkit/loader.js", {}); +var { requireRawId } = Cu.import("resource://devtools/shared/loader-plugin-raw.jsm", {}); + +this.EXPORTED_SYMBOLS = ["DevToolsLoader", "devtools", "BuiltinProvider", + "require", "loader"]; + +/** + * Providers are different strategies for loading the devtools. + */ + +var sharedGlobalBlocklist = ["sdk/indexed-db"]; + +/** + * Used when the tools should be loaded from the Firefox package itself. + * This is the default case. + */ +function BuiltinProvider() {} +BuiltinProvider.prototype = { + load: function () { + const paths = { + // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ + "": "resource://gre/modules/commonjs/", + // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ + // Modules here are intended to have one implementation for + // chrome, and a separate implementation for content. Here we + // map the directory to the chrome subdirectory, but the content + // loader will map to the content subdirectory. See the + // README.md in devtools/shared/platform. + "devtools/shared/platform": "resource://devtools/shared/platform/chrome", + // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ + "devtools": "resource://devtools", + // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ + "gcli": "resource://devtools/shared/gcli/source/lib/gcli", + // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ + "acorn": "resource://devtools/shared/acorn", + // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ + "acorn/util/walk": "resource://devtools/shared/acorn/walk.js", + // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ + "source-map": "resource://devtools/shared/sourcemap/source-map.js", + // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ + // Allow access to xpcshell test items from the loader. + "xpcshell-test": "resource://test", + + // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ + // Allow access to locale data using paths closer to what is + // used in the source tree. + "devtools/client/locales": "chrome://devtools/locale", + "devtools/shared/locales": "chrome://devtools-shared/locale", + "toolkit/locales": "chrome://global/locale", + }; + // When creating a Loader invisible to the Debugger, we have to ensure + // using only modules and not depend on any JSM. As everything that is + // not loaded with Loader isn't going to respect `invisibleToDebugger`. + // But we have to keep using Promise.jsm for other loader to prevent + // breaking unhandled promise rejection in tests. + if (this.invisibleToDebugger) { + paths.promise = "resource://gre/modules/Promise-backend.js"; + } + this.loader = new Loader.Loader({ + id: "fx-devtools", + paths, + invisibleToDebugger: this.invisibleToDebugger, + sharedGlobal: true, + sharedGlobalBlocklist, + requireHook: (id, require) => { + if (id.startsWith("raw!")) { + return requireRawId(id, require); + } + return require(id); + }, + }); + }, + + unload: function (reason) { + Loader.unload(this.loader, reason); + delete this.loader; + }, +}; + +var gNextLoaderID = 0; + +/** + * The main devtools API. The standard instance of this loader is exported as + * |devtools| below, but if a fresh copy of the loader is needed, then a new + * one can also be created. + */ +this.DevToolsLoader = function DevToolsLoader() { + this.require = this.require.bind(this); + + Services.obs.addObserver(this, "devtools-unload", false); +}; + +DevToolsLoader.prototype = { + destroy: function (reason = "shutdown") { + Services.obs.removeObserver(this, "devtools-unload"); + + if (this._provider) { + this._provider.unload(reason); + delete this._provider; + } + }, + + get provider() { + if (!this._provider) { + this._loadProvider(); + } + return this._provider; + }, + + _provider: null, + + get id() { + if (this._id) { + return this._id; + } + this._id = ++gNextLoaderID; + return this._id; + }, + + /** + * A dummy version of require, in case a provider hasn't been chosen yet when + * this is first called. This will then be replaced by the real version. + * @see setProvider + */ + require: function () { + if (!this._provider) { + this._loadProvider(); + } + return this.require.apply(this, arguments); + }, + + /** + * Return true if |id| refers to something requiring help from a + * loader plugin. + */ + isLoaderPluginId: function (id) { + return id.startsWith("raw!"); + }, + + /** + * Override the provider used to load the tools. + */ + setProvider: function (provider) { + if (provider === this._provider) { + return; + } + + if (this._provider) { + delete this.require; + this._provider.unload("newprovider"); + } + this._provider = provider; + + // Pass through internal loader settings specific to this loader instance + this._provider.invisibleToDebugger = this.invisibleToDebugger; + + this._provider.load(); + this.require = Loader.Require(this._provider.loader, { id: "devtools" }); + + // Fetch custom pseudo modules and globals + let { modules, globals } = this.require("devtools/shared/builtin-modules"); + + // When creating a Loader for the browser toolbox, we have to use + // Promise-backend.js, as a Loader module. Instead of Promise.jsm which + // can't be flagged as invisible to debugger. + if (this.invisibleToDebugger) { + delete modules.promise; + } + + // Register custom pseudo modules to the current loader instance + let loader = this._provider.loader; + for (let id in modules) { + let exports = modules[id]; + let uri = resolveURI(id, loader.mapping); + loader.modules[uri] = { exports }; + } + + // Register custom globals to the current loader instance + globals.loader.id = this.id; + Object.defineProperties(loader.globals, descriptor(globals)); + + // Expose lazy helpers on loader + this.lazyGetter = globals.loader.lazyGetter; + this.lazyImporter = globals.loader.lazyImporter; + this.lazyServiceGetter = globals.loader.lazyServiceGetter; + this.lazyRequireGetter = globals.loader.lazyRequireGetter; + }, + + /** + * Choose a default tools provider based on the preferences. + */ + _loadProvider: function () { + this.setProvider(new BuiltinProvider()); + }, + + /** + * Handles "devtools-unload" event + * + * @param String data + * reason passed to modules when unloaded + */ + observe: function (subject, topic, data) { + if (topic != "devtools-unload") { + return; + } + this.destroy(data); + }, + + /** + * Sets whether the compartments loaded by this instance should be invisible + * to the debugger. Invisibility is needed for loaders that support debugging + * of chrome code. This is true of remote target environments, like Fennec or + * B2G. It is not the default case for desktop Firefox because we offer the + * Browser Toolbox for chrome debugging there, which uses its own, separate + * loader instance. + * @see devtools/client/framework/ToolboxProcess.jsm + */ + invisibleToDebugger: Services.appinfo.name !== "Firefox" +}; + +// Export the standard instance of DevToolsLoader used by the tools. +this.devtools = this.loader = new DevToolsLoader(); + +this.require = this.devtools.require.bind(this.devtools); + +// For compatibility reasons, expose these symbols on "devtools": +Object.defineProperty(this.devtools, "Toolbox", { + get: () => this.require("devtools/client/framework/toolbox").Toolbox +}); +Object.defineProperty(this.devtools, "TargetFactory", { + get: () => this.require("devtools/client/framework/target").TargetFactory +}); diff --git a/devtools/shared/Parser.jsm b/devtools/shared/Parser.jsm new file mode 100644 index 000000000..4bd635383 --- /dev/null +++ b/devtools/shared/Parser.jsm @@ -0,0 +1,2451 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const Cu = Components.utils; + +const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {}); +const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm"); +const { console } = require("resource://gre/modules/Console.jsm"); +const DevToolsUtils = require("devtools/shared/DevToolsUtils"); + +XPCOMUtils.defineLazyModuleGetter(this, + "Reflect", "resource://gre/modules/reflect.jsm"); + +this.EXPORTED_SYMBOLS = ["Parser", "ParserHelpers", "SyntaxTreeVisitor"]; + +/** + * A JS parser using the reflection API. + */ +this.Parser = function Parser() { + this._cache = new Map(); + this.errors = []; + this.logExceptions = true; +}; + +Parser.prototype = { + /** + * Gets a collection of parser methods for a specified source. + * + * @param string source + * The source text content. + * @param string url [optional] + * The source url. The AST nodes will be cached, so you can use this + * identifier to avoid parsing the whole source again. + */ + get(source, url = "") { + // Try to use the cached AST nodes, to avoid useless parsing operations. + if (this._cache.has(url)) { + return this._cache.get(url); + } + + // The source may not necessarily be JS, in which case we need to extract + // all the scripts. Fastest/easiest way is with a regular expression. + // Don't worry, the rules of using a + + + +
+
+
+ + diff --git a/devtools/shared/heapsnapshot/tests/mochitest/test_SaveHeapSnapshot.html b/devtools/shared/heapsnapshot/tests/mochitest/test_SaveHeapSnapshot.html new file mode 100644 index 000000000..f150a99c7 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/mochitest/test_SaveHeapSnapshot.html @@ -0,0 +1,25 @@ + + + + + + ChromeUtils.saveHeapSnapshot test + + + + +
+
+
+ + diff --git a/devtools/shared/heapsnapshot/tests/mochitest/test_saveHeapSnapshot_e10s_01.html b/devtools/shared/heapsnapshot/tests/mochitest/test_saveHeapSnapshot_e10s_01.html new file mode 100644 index 000000000..15f88f8e0 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/mochitest/test_saveHeapSnapshot_e10s_01.html @@ -0,0 +1,82 @@ + + + + + saveHeapSnapshot in e10s child processes + + + + + + diff --git a/devtools/shared/heapsnapshot/tests/unit/.eslintrc.js b/devtools/shared/heapsnapshot/tests/unit/.eslintrc.js new file mode 100644 index 000000000..59adf410a --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/.eslintrc.js @@ -0,0 +1,6 @@ +"use strict"; + +module.exports = { + // Extend from the common devtools xpcshell eslintrc config. + "extends": "../../../../.eslintrc.xpcshell.js" +}; diff --git a/devtools/shared/heapsnapshot/tests/unit/Census.jsm b/devtools/shared/heapsnapshot/tests/unit/Census.jsm new file mode 100644 index 000000000..f8fb1ce44 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/Census.jsm @@ -0,0 +1,165 @@ +// Functions for checking results returned by +// Debugger.Memory.prototype.takeCensus and +// HeapSnapshot.prototype.takeCensus. Adapted from js/src/jit-test/lib/census.js. + +this.EXPORTED_SYMBOLS = ["Census"]; + +this.Census = (function () { + const Census = {}; + + function dumpn(msg) { + dump("DBG-TEST: Census.jsm: " + msg + "\n"); + } + + // Census.walkCensus(subject, name, walker) + // + // Use |walker| to check |subject|, a census object of the sort returned by + // Debugger.Memory.prototype.takeCensus: a tree of objects with integers at the + // leaves. Use |name| as the name for |subject| in diagnostic messages. Return + // the number of leaves of |subject| we visited. + // + // A walker is an object with three methods: + // + // - enter(prop): Return the walker we should use to check the property of the + // subject census named |prop|. This is for recursing into the subobjects of + // the subject. + // + // - done(): Called after we have called 'enter' on every property of the + // subject. + // + // - check(value): Check |value|, a leaf in the subject. + // + // Walker methods are expected to simply throw if a node we visit doesn't look + // right. + Census.walkCensus = (subject, name, walker) => walk(subject, name, walker, 0); + function walk(subject, name, walker, count) { + if (typeof subject === "object") { + dumpn(name); + for (let prop in subject) { + count = walk(subject[prop], + name + "[" + uneval(prop) + "]", + walker.enter(prop), + count); + } + walker.done(); + } else { + dumpn(name + " = " + uneval(subject)); + walker.check(subject); + count++; + } + + return count; + } + + // A walker that doesn't check anything. + Census.walkAnything = { + enter: () => Census.walkAnything, + done: () => undefined, + check: () => undefined + }; + + // A walker that requires all leaves to be zeros. + Census.assertAllZeros = { + enter: () => Census.assertAllZeros, + done: () => undefined, + check: elt => { if (elt !== 0) throw new Error("Census mismatch: expected zero, found " + elt); } + }; + + function expectedObject() { + throw new Error("Census mismatch: subject has leaf where basis has nested object"); + } + + function expectedLeaf() { + throw new Error("Census mismatch: subject has nested object where basis has leaf"); + } + + // Return a function that, given a 'basis' census, returns a census walker that + // compares the subject census against the basis. The returned walker calls the + // given |compare|, |missing|, and |extra| functions as follows: + // + // - compare(subjectLeaf, basisLeaf): Check a leaf of the subject against the + // corresponding leaf of the basis. + // + // - missing(prop, value): Called when the subject is missing a property named + // |prop| which is present in the basis with value |value|. + // + // - extra(prop): Called when the subject has a property named |prop|, but the + // basis has no such property. This should return a walker that can check + // the subject's value. + function makeBasisChecker({compare, missing, extra}) { + return function makeWalker(basis) { + if (typeof basis === "object") { + var unvisited = new Set(Object.getOwnPropertyNames(basis)); + return { + enter: prop => { + unvisited.delete(prop); + if (prop in basis) { + return makeWalker(basis[prop]); + } else { + return extra(prop); + } + }, + + done: () => unvisited.forEach(prop => missing(prop, basis[prop])), + check: expectedObject + }; + } else { + return { + enter: expectedLeaf, + done: expectedLeaf, + check: elt => compare(elt, basis) + }; + } + }; + } + + function missingProp(prop) { + throw new Error("Census mismatch: subject lacks property present in basis: " + prop); + } + + function extraProp(prop) { + throw new Error("Census mismatch: subject has property not present in basis: " + prop); + } + + // Return a walker that checks that the subject census has counts all equal to + // |basis|. + Census.assertAllEqual = makeBasisChecker({ + compare: (a, b) => { if (a !== b) throw new Error("Census mismatch: expected " + a + " got " + b);}, + missing: missingProp, + extra: extraProp + }); + + function ok(val) { + if (!val) { + throw new Error("Census mismatch: expected truthy, got " + val); + } + } + + // Return a walker that checks that the subject census has at least as many + // items of each category as |basis|. + Census.assertAllNotLessThan = makeBasisChecker({ + compare: (subject, basis) => ok(subject >= basis), + missing: missingProp, + extra: () => Census.walkAnything + }); + + // Return a walker that checks that the subject census has at most as many + // items of each category as |basis|. + Census.assertAllNotMoreThan = makeBasisChecker({ + compare: (subject, basis) => ok(subject <= basis), + missing: missingProp, + extra: () => Census.walkAnything + }); + + // Return a walker that checks that the subject census has within |fudge| + // items of each category of the count in |basis|. + Census.assertAllWithin = function (fudge, basis) { + return makeBasisChecker({ + compare: (subject, basis) => ok(Math.abs(subject - basis) <= fudge), + missing: missingProp, + extra: () => Census.walkAnything + })(basis); + }; + + return Census; +}()); diff --git a/devtools/shared/heapsnapshot/tests/unit/Match.jsm b/devtools/shared/heapsnapshot/tests/unit/Match.jsm new file mode 100644 index 000000000..c29e6484e --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/Match.jsm @@ -0,0 +1,190 @@ +// A little pattern-matching library. +// +// Ported from js/src/tests/js1_8_5/reflect-parse/Match.js for use with devtools +// server xpcshell tests. + +this.EXPORTED_SYMBOLS = ["Match"]; + +this.Match = (function() { + + function Pattern(template) { + // act like a constructor even as a function + if (!(this instanceof Pattern)) + return new Pattern(template); + + this.template = template; + } + + Pattern.prototype = { + match: function(act) { + return match(act, this.template); + }, + + matches: function(act) { + try { + return this.match(act); + } + catch (e if e instanceof MatchError) { + return false; + } + }, + + assert: function(act, message) { + try { + return this.match(act); + } + catch (e if e instanceof MatchError) { + throw new Error((message || "failed match") + ": " + e.message); + } + }, + + toString: () => "[object Pattern]" + }; + + Pattern.ANY = new Pattern; + Pattern.ANY.template = Pattern.ANY; + + Pattern.NUMBER = new Pattern; + Pattern.NUMBER.match = function (act) { + if (typeof act !== 'number') { + throw new MatchError("Expected number, got: " + quote(act)); + } + } + + Pattern.NATURAL = new Pattern + Pattern.NATURAL.match = function (act) { + if (typeof act !== 'number' || act !== Math.floor(act) || act < 0) { + throw new MatchError("Expected natural number, got: " + quote(act)); + } + } + + var quote = uneval; + + function MatchError(msg) { + this.message = msg; + } + + MatchError.prototype = { + toString: function() { + return "match error: " + this.message; + } + }; + + function isAtom(x) { + return (typeof x === "number") || + (typeof x === "string") || + (typeof x === "boolean") || + (x === null) || + (typeof x === "object" && x instanceof RegExp); + } + + function isObject(x) { + return (x !== null) && (typeof x === "object"); + } + + function isFunction(x) { + return typeof x === "function"; + } + + function isArrayLike(x) { + return isObject(x) && ("length" in x); + } + + function matchAtom(act, exp) { + if ((typeof exp) === "number" && isNaN(exp)) { + if ((typeof act) !== "number" || !isNaN(act)) + throw new MatchError("expected NaN, got: " + quote(act)); + return true; + } + + if (exp === null) { + if (act !== null) + throw new MatchError("expected null, got: " + quote(act)); + return true; + } + + if (exp instanceof RegExp) { + if (!(act instanceof RegExp) || exp.source !== act.source) + throw new MatchError("expected " + quote(exp) + ", got: " + quote(act)); + return true; + } + + switch (typeof exp) { + case "string": + if (act !== exp) + throw new MatchError("expected " + quote(exp) + ", got " + quote(act)); + return true; + case "boolean": + case "number": + if (exp !== act) + throw new MatchError("expected " + exp + ", got " + quote(act)); + return true; + } + + throw new Error("bad pattern: " + exp.toSource()); + } + + function matchObject(act, exp) { + if (!isObject(act)) + throw new MatchError("expected object, got " + quote(act)); + + for (var key in exp) { + if (!(key in act)) + throw new MatchError("expected property " + quote(key) + " not found in " + quote(act)); + match(act[key], exp[key]); + } + + return true; + } + + function matchFunction(act, exp) { + if (!isFunction(act)) + throw new MatchError("expected function, got " + quote(act)); + + if (act !== exp) + throw new MatchError("expected function: " + exp + + "\nbut got different function: " + act); + } + + function matchArray(act, exp) { + if (!isObject(act) || !("length" in act)) + throw new MatchError("expected array-like object, got " + quote(act)); + + var length = exp.length; + if (act.length !== exp.length) + throw new MatchError("expected array-like object of length " + length + ", got " + quote(act)); + + for (var i = 0; i < length; i++) { + if (i in exp) { + if (!(i in act)) + throw new MatchError("expected array property " + i + " not found in " + quote(act)); + match(act[i], exp[i]); + } + } + + return true; + } + + function match(act, exp) { + if (exp === Pattern.ANY) + return true; + + if (exp instanceof Pattern) + return exp.match(act); + + if (isAtom(exp)) + return matchAtom(act, exp); + + if (isArrayLike(exp)) + return matchArray(act, exp); + + if (isFunction(exp)) + return matchFunction(act, exp); + + return matchObject(act, exp); + } + + return { Pattern: Pattern, + MatchError: MatchError }; + +})(); diff --git a/devtools/shared/heapsnapshot/tests/unit/dominator-tree-worker.js b/devtools/shared/heapsnapshot/tests/unit/dominator-tree-worker.js new file mode 100644 index 000000000..1f49ca841 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/dominator-tree-worker.js @@ -0,0 +1,47 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +console.log("Initializing worker."); + +self.onmessage = e => { + console.log("Starting test."); + try { + const path = ThreadSafeChromeUtils.saveHeapSnapshot({ runtime: true }); + const snapshot = ThreadSafeChromeUtils.readHeapSnapshot(path); + + const dominatorTree = snapshot.computeDominatorTree(); + ok(dominatorTree); + ok(dominatorTree instanceof DominatorTree); + + let threw = false; + try { + new DominatorTree(); + } catch (e) { + threw = true; + } + ok(threw, "Constructor shouldn't be usable"); + } catch (e) { + ok(false, "Unexpected error inside worker:\n" + e.toString() + "\n" + e.stack); + } finally { + done(); + } +}; + +// Proxy assertions to the main thread. +function ok(val, msg) { + console.log("ok(" + !!val + ", \"" + msg + "\")"); + self.postMessage({ + type: "assertion", + passed: !!val, + msg, + stack: Error().stack + }); +} + +// Tell the main thread we are done with the tests. +function done() { + console.log("done()"); + self.postMessage({ + type: "done" + }); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/head_heapsnapshot.js b/devtools/shared/heapsnapshot/tests/unit/head_heapsnapshot.js new file mode 100644 index 000000000..3171c8a6f --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/head_heapsnapshot.js @@ -0,0 +1,448 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cu = Components.utils; +var Cr = Components.results; +var CC = Components.Constructor; + +const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {}); +const { Match } = Cu.import("resource://test/Match.jsm", {}); +const { Census } = Cu.import("resource://test/Census.jsm", {}); +const { addDebuggerToGlobal } = + Cu.import("resource://gre/modules/jsdebugger.jsm", {}); +const { Task } = require("devtools/shared/task"); + +const DevToolsUtils = require("devtools/shared/DevToolsUtils"); +const flags = require("devtools/shared/flags"); +const HeapAnalysesClient = + require("devtools/shared/heapsnapshot/HeapAnalysesClient"); +const Services = require("Services"); +const { censusReportToCensusTreeNode } = require("devtools/shared/heapsnapshot/census-tree-node"); +const CensusUtils = require("devtools/shared/heapsnapshot/CensusUtils"); +const DominatorTreeNode = require("devtools/shared/heapsnapshot/DominatorTreeNode"); +const { deduplicatePaths } = require("devtools/shared/heapsnapshot/shortest-paths"); +const { LabelAndShallowSizeVisitor } = DominatorTreeNode; + + +// Always log packets when running tests. runxpcshelltests.py will throw +// the output away anyway, unless you give it the --verbose flag. +if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_DEFAULT) { + Services.prefs.setBoolPref("devtools.debugger.log", true); +} +flags.wantLogging = true; + +const SYSTEM_PRINCIPAL = Cc["@mozilla.org/systemprincipal;1"] + .createInstance(Ci.nsIPrincipal); + +function dumpn(msg) { + dump("HEAPSNAPSHOT-TEST: " + msg + "\n"); +} + +function addTestingFunctionsToGlobal(global) { + global.eval( + ` + const testingFunctions = Components.utils.getJSTestingFunctions(); + for (let k in testingFunctions) { + this[k] = testingFunctions[k]; + } + ` + ); + if (!global.print) { + global.print = do_print; + } + if (!global.newGlobal) { + global.newGlobal = newGlobal; + } + if (!global.Debugger) { + addDebuggerToGlobal(global); + } +} + +addTestingFunctionsToGlobal(this); + +/** + * Create a new global, with all the JS shell testing functions. Similar to the + * newGlobal function exposed to JS shells, and useful for porting JS shell + * tests to xpcshell tests. + */ +function newGlobal() { + const global = new Cu.Sandbox(SYSTEM_PRINCIPAL, { freshZone: true }); + addTestingFunctionsToGlobal(global); + return global; +} + +function assertThrowsValue(f, val, msg) { + var fullmsg; + try { + f(); + } catch (exc) { + if ((exc === val) === (val === val) && (val !== 0 || 1 / exc === 1 / val)) + return; + fullmsg = "Assertion failed: expected exception " + val + ", got " + exc; + } + if (fullmsg === undefined) + fullmsg = "Assertion failed: expected exception " + val + ", no exception thrown"; + if (msg !== undefined) + fullmsg += " - " + msg; + throw new Error(fullmsg); +} + +/** + * Returns the full path of the file with the specified name in a + * platform-independent and URL-like form. + */ +function getFilePath(aName, aAllowMissing = false, aUsePlatformPathSeparator = false) +{ + let file = do_get_file(aName, aAllowMissing); + let path = Services.io.newFileURI(file).spec; + let filePrePath = "file://"; + if ("nsILocalFileWin" in Ci && + file instanceof Ci.nsILocalFileWin) { + filePrePath += "/"; + } + + path = path.slice(filePrePath.length); + + if (aUsePlatformPathSeparator && path.match(/^\w:/)) { + path = path.replace(/\//g, "\\"); + } + + return path; +} + +function saveNewHeapSnapshot(opts = { runtime: true }) { + const filePath = ChromeUtils.saveHeapSnapshot(opts); + ok(filePath, "Should get a file path to save the core dump to."); + ok(true, "Saved a heap snapshot to " + filePath); + return filePath; +} + +function readHeapSnapshot(filePath) { + const snapshot = ChromeUtils.readHeapSnapshot(filePath); + ok(snapshot, "Should have read a heap snapshot back from " + filePath); + ok(snapshot instanceof HeapSnapshot, "snapshot should be an instance of HeapSnapshot"); + return snapshot; +} + +/** + * Save a heap snapshot to the file with the given name in the current + * directory, read it back as a HeapSnapshot instance, and then take a census of + * the heap snapshot's serialized heap graph with the provided census options. + * + * @param {Object|undefined} censusOptions + * Options that should be passed through to the takeCensus method. See + * js/src/doc/Debugger/Debugger.Memory.md for details. + * + * @param {Debugger|null} dbg + * If a Debugger object is given, only serialize the subgraph covered by + * the Debugger's debuggees. If null, serialize the whole heap graph. + * + * @param {String} fileName + * The file name to save the heap snapshot's core dump file to, within + * the current directory. + * + * @returns Census + */ +function saveHeapSnapshotAndTakeCensus(dbg = null, censusOptions = undefined) { + const snapshotOptions = dbg ? { debugger: dbg } : { runtime: true }; + const filePath = saveNewHeapSnapshot(snapshotOptions); + const snapshot = readHeapSnapshot(filePath); + + equal(typeof snapshot.takeCensus, "function", "snapshot should have a takeCensus method"); + + return snapshot.takeCensus(censusOptions); +} + +/** + * Save a heap snapshot to disk, read it back as a HeapSnapshot instance, and + * then compute its dominator tree. + * + * @param {Debugger|null} dbg + * If a Debugger object is given, only serialize the subgraph covered by + * the Debugger's debuggees. If null, serialize the whole heap graph. + * + * @returns {DominatorTree} + */ +function saveHeapSnapshotAndComputeDominatorTree(dbg = null) { + const snapshotOptions = dbg ? { debugger: dbg } : { runtime: true }; + const filePath = saveNewHeapSnapshot(snapshotOptions); + const snapshot = readHeapSnapshot(filePath); + + equal(typeof snapshot.computeDominatorTree, "function", + "snapshot should have a `computeDominatorTree` method"); + + const dominatorTree = snapshot.computeDominatorTree(); + + ok(dominatorTree, "Should be able to compute a dominator tree"); + ok(dominatorTree instanceof DominatorTree, "Should be an instance of DominatorTree"); + + return dominatorTree; +} + +function isSavedFrame(obj) { + return Object.prototype.toString.call(obj) === "[object SavedFrame]"; +} + +function savedFrameReplacer(key, val) { + if (isSavedFrame(val)) { + return ``; + } else { + return val; + } +} + +/** + * Assert that creating a CensusTreeNode from the given `report` with the + * specified `breakdown` creates the given `expected` CensusTreeNode. + * + * @param {Object} breakdown + * The census breakdown. + * + * @param {Object} report + * The census report. + * + * @param {Object} expected + * The expected CensusTreeNode result. + * + * @param {Object} options + * The options to pass through to `censusReportToCensusTreeNode`. + */ +function compareCensusViewData(breakdown, report, expected, options) { + dumpn("Generating CensusTreeNode from report:"); + dumpn("breakdown: " + JSON.stringify(breakdown, null, 4)); + dumpn("report: " + JSON.stringify(report, null, 4)); + dumpn("expected: " + JSON.stringify(expected, savedFrameReplacer, 4)); + + const actual = censusReportToCensusTreeNode(breakdown, report, options); + dumpn("actual: " + JSON.stringify(actual, savedFrameReplacer, 4)); + + assertStructurallyEquivalent(actual, expected); +} + +// Deep structural equivalence that can handle Map objects in addition to plain +// objects. +function assertStructurallyEquivalent(actual, expected, path = "root") { + if (actual === expected) { + equal(actual, expected, "actual and expected are the same"); + return; + } + + equal(typeof actual, typeof expected, `${path}: typeof should be the same`); + + if (actual && typeof actual === "object") { + const actualProtoString = Object.prototype.toString.call(actual); + const expectedProtoString = Object.prototype.toString.call(expected); + equal(actualProtoString, expectedProtoString, + `${path}: Object.prototype.toString.call() should be the same`); + + if (actualProtoString === "[object Map]") { + const expectedKeys = new Set([...expected.keys()]); + + for (let key of actual.keys()) { + ok(expectedKeys.has(key), + `${path}: every key in actual should exist in expected: ${String(key).slice(0, 10)}`); + expectedKeys.delete(key); + + assertStructurallyEquivalent(actual.get(key), expected.get(key), + path + ".get(" + String(key).slice(0, 20) + ")"); + } + + equal(expectedKeys.size, 0, + `${path}: every key in expected should also exist in actual, did not see ${[...expectedKeys]}`); + } else if (actualProtoString === "[object Set]") { + const expectedItems = new Set([...expected]); + + for (let item of actual) { + ok(expectedItems.has(item), + `${path}: every set item in actual should exist in expected: ${item}`); + expectedItems.delete(item); + } + + equal(expectedItems.size, 0, + `${path}: every set item in expected should also exist in actual, did not see ${[...expectedItems]}`); + } else { + const expectedKeys = new Set(Object.keys(expected)); + + for (let key of Object.keys(actual)) { + ok(expectedKeys.has(key), + `${path}: every key in actual should exist in expected: ${key}`); + expectedKeys.delete(key); + + assertStructurallyEquivalent(actual[key], expected[key], path + "." + key); + } + + equal(expectedKeys.size, 0, + `${path}: every key in expected should also exist in actual, did not see ${[...expectedKeys]}`); + } + } else { + equal(actual, expected, `${path}: primitives should be equal`); + } +} + +/** + * Assert that creating a diff of the `first` and `second` census reports + * creates the `expected` delta-report. + * + * @param {Object} breakdown + * The census breakdown. + * + * @param {Object} first + * The first census report. + * + * @param {Object} second + * The second census report. + * + * @param {Object} expected + * The expected delta-report. + */ +function assertDiff(breakdown, first, second, expected) { + dumpn("Diffing census reports:"); + dumpn("Breakdown: " + JSON.stringify(breakdown, null, 4)); + dumpn("First census report: " + JSON.stringify(first, null, 4)); + dumpn("Second census report: " + JSON.stringify(second, null, 4)); + dumpn("Expected delta-report: " + JSON.stringify(expected, null, 4)); + + const actual = CensusUtils.diff(breakdown, first, second); + dumpn("Actual delta-report: " + JSON.stringify(actual, null, 4)); + + assertStructurallyEquivalent(actual, expected); +} + +/** + * Assert that creating a label and getting a shallow size from the given node + * description with the specified breakdown is as expected. + * + * @param {Object} breakdown + * @param {Object} givenDescription + * @param {Number} expectedShallowSize + * @param {Object} expectedLabel + */ +function assertLabelAndShallowSize(breakdown, givenDescription, expectedShallowSize, expectedLabel) { + dumpn("Computing label and shallow size from node description:"); + dumpn("Breakdown: " + JSON.stringify(breakdown, null, 4)); + dumpn("Given description: " + JSON.stringify(givenDescription, null, 4)); + + const visitor = new LabelAndShallowSizeVisitor(); + CensusUtils.walk(breakdown, description, visitor); + + dumpn("Expected shallow size: " + expectedShallowSize); + dumpn("Actual shallow size: " + visitor.shallowSize()); + equal(visitor.shallowSize(), expectedShallowSize, "Shallow size should be correct"); + + dumpn("Expected label: " + JSON.stringify(expectedLabel, null, 4)); + dumpn("Actual label: " + JSON.stringify(visitor.label(), null, 4)); + assertStructurallyEquivalent(visitor.label(), expectedLabel); +} + +// Counter for mock DominatorTreeNode ids. +let TEST_NODE_ID_COUNTER = 0; + +/** + * Create a mock DominatorTreeNode for testing, with sane defaults. Override any + * property by providing it on `opts`. Optionally pass child nodes as well. + * + * @param {Object} opts + * @param {Array?} children + * + * @returns {DominatorTreeNode} + */ +function makeTestDominatorTreeNode(opts, children) { + const nodeId = TEST_NODE_ID_COUNTER++; + + const node = Object.assign({ + nodeId, + label: undefined, + shallowSize: 1, + retainedSize: (children || []).reduce((size, c) => size + c.retainedSize, 1), + parentId: undefined, + children, + moreChildrenAvailable: true, + }, opts); + + if (children && children.length) { + children.map(c => c.parentId = node.nodeId); + } + + return node; +} + +/** + * Insert `newChildren` into the given dominator `tree` as specified by the + * `path` from the root to the node the `newChildren` should be inserted + * beneath. Assert that the resulting tree matches `expected`. + */ +function assertDominatorTreeNodeInsertion(tree, path, newChildren, moreChildrenAvailable, expected) { + dumpn("Inserting new children into a dominator tree:"); + dumpn("Dominator tree: " + JSON.stringify(tree, null, 2)); + dumpn("Path: " + JSON.stringify(path, null, 2)); + dumpn("New children: " + JSON.stringify(newChildren, null, 2)); + dumpn("Expected resulting tree: " + JSON.stringify(expected, null, 2)); + + const actual = DominatorTreeNode.insert(tree, path, newChildren, moreChildrenAvailable); + dumpn("Actual resulting tree: " + JSON.stringify(actual, null, 2)); + + assertStructurallyEquivalent(actual, expected); +} + +function assertDeduplicatedPaths({ target, paths, expectedNodes, expectedEdges }) { + dumpn("Deduplicating paths:"); + dumpn("target = " + target); + dumpn("paths = " + JSON.stringify(paths, null, 2)); + dumpn("expectedNodes = " + expectedNodes); + dumpn("expectedEdges = " + JSON.stringify(expectedEdges, null, 2)); + + const { nodes, edges } = deduplicatePaths(target, paths); + + dumpn("Actual nodes = " + nodes); + dumpn("Actual edges = " + JSON.stringify(edges, null, 2)); + + equal(nodes.length, expectedNodes.length, + "actual number of nodes is equal to the expected number of nodes"); + + equal(edges.length, expectedEdges.length, + "actual number of edges is equal to the expected number of edges"); + + const expectedNodeSet = new Set(expectedNodes); + const nodeSet = new Set(nodes); + ok(nodeSet.size === nodes.length, + "each returned node should be unique"); + + for (let node of nodes) { + ok(expectedNodeSet.has(node), `the ${node} node was expected`); + } + + for (let expectedEdge of expectedEdges) { + let count = 0; + for (let edge of edges) { + if (edge.from === expectedEdge.from && + edge.to === expectedEdge.to && + edge.name === expectedEdge.name) { + count++; + } + } + equal(count, 1, + "should have exactly one matching edge for the expected edge = " + JSON.stringify(edge)); + } +} + +function assertCountToBucketBreakdown(breakdown, expected) { + dumpn("count => bucket breakdown"); + dumpn("Initial breakdown = ", JSON.stringify(breakdown, null, 2)); + dumpn("Expected results = ", JSON.stringify(expected, null, 2)); + + const actual = CensusUtils.countToBucketBreakdown(breakdown); + dumpn("Actual results = ", JSON.stringify(actual, null, 2)); + + assertStructurallyEquivalent(actual, expected); +} + +/** + * Create a mock path entry for the given predecessor and edge. + */ +function pathEntry(predecessor, edge) { + return { predecessor, edge }; +} diff --git a/devtools/shared/heapsnapshot/tests/unit/heap-snapshot-worker.js b/devtools/shared/heapsnapshot/tests/unit/heap-snapshot-worker.js new file mode 100644 index 000000000..10ee70cec --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/heap-snapshot-worker.js @@ -0,0 +1,46 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +console.log("Initializing worker."); + +self.onmessage = e => { + console.log("Starting test."); + try { + ok(typeof ChromeUtils === "undefined", + "Should not have access to ChromeUtils in a worker."); + ok(ThreadSafeChromeUtils, + "Should have access to ThreadSafeChromeUtils in a worker."); + ok(HeapSnapshot, + "Should have access to HeapSnapshot in a worker."); + + const filePath = ThreadSafeChromeUtils.saveHeapSnapshot({ globals: [this] }); + ok(true, "Should be able to save a snapshot."); + + const snapshot = ThreadSafeChromeUtils.readHeapSnapshot(filePath); + ok(snapshot, "Should be able to read a heap snapshot"); + ok(snapshot instanceof HeapSnapshot, "Should be an instanceof HeapSnapshot"); + } catch (e) { + ok(false, "Unexpected error inside worker:\n" + e.toString() + "\n" + e.stack); + } finally { + done(); + } +}; + +// Proxy assertions to the main thread. +function ok(val, msg) { + console.log("ok(" + !!val + ", \"" + msg + "\")"); + self.postMessage({ + type: "assertion", + passed: !!val, + msg, + stack: Error().stack + }); +} + +// Tell the main thread we are done with the tests. +function done() { + console.log("done()"); + self.postMessage({ + type: "done" + }); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_LabelAndShallowSize_01.js b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_LabelAndShallowSize_01.js new file mode 100644 index 000000000..845a0d263 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_LabelAndShallowSize_01.js @@ -0,0 +1,46 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that we can generate label structures from node description reports. + +const breakdown = { + by: "coarseType", + objects: { + by: "objectClass", + then: { by: "count", count: true, bytes: true }, + other: { by: "count", count: true, bytes: true }, + }, + strings: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + scripts: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + other: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, +}; + +const description = { + objects: { + Function: { count: 1, bytes: 32 }, + other: { count: 0, bytes: 0 } + }, + strings: {}, + scripts: {}, + other: {} +}; + +const expected = [ + "objects", + "Function" +]; + +const shallowSize = 32; + +function run_test() { + assertLabelAndShallowSize(breakdown, description, shallowSize, expected); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_LabelAndShallowSize_02.js b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_LabelAndShallowSize_02.js new file mode 100644 index 000000000..e1f32de58 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_LabelAndShallowSize_02.js @@ -0,0 +1,45 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that we can generate label structures from node description reports. + +const breakdown = { + by: "coarseType", + objects: { + by: "objectClass", + then: { by: "count", count: true, bytes: true }, + other: { by: "count", count: true, bytes: true }, + }, + strings: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + scripts: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + other: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, +}; + +const description = { + objects: { + other: { count: 1, bytes: 10 } + }, + strings: {}, + scripts: {}, + other: {} +}; + +const expected = [ + "objects", + "other" +]; + +const shallowSize = 10; + +function run_test() { + assertLabelAndShallowSize(breakdown, description, shallowSize, expected); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_LabelAndShallowSize_03.js b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_LabelAndShallowSize_03.js new file mode 100644 index 000000000..ad35dcec1 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_LabelAndShallowSize_03.js @@ -0,0 +1,47 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that we can generate label structures from node description reports. + +const breakdown = { + by: "coarseType", + objects: { + by: "objectClass", + then: { by: "count", count: true, bytes: true }, + other: { by: "count", count: true, bytes: true }, + }, + strings: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + scripts: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + other: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, +}; + +const description = { + objects: { + other: { count: 0, bytes: 0 } + }, + strings: { + "JSString": { count: 1, bytes: 42 }, + }, + scripts: {}, + other: {} +}; + +const expected = [ + "strings", + "JSString" +]; + +const shallowSize = 42; + +function run_test() { + assertLabelAndShallowSize(breakdown, description, shallowSize, expected); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_LabelAndShallowSize_04.js b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_LabelAndShallowSize_04.js new file mode 100644 index 000000000..566ad0dab --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_LabelAndShallowSize_04.js @@ -0,0 +1,53 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that we can generate label structures from node description reports. + +const breakdown = { + by: "coarseType", + objects: { + by: "objectClass", + then: { + by: "allocationStack", + then: { by: "count", count: true, bytes: true }, + noStack: { by: "count", count: true, bytes: true }, + }, + other: { by: "count", count: true, bytes: true }, + }, + strings: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + scripts: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + other: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, +}; + +const stack = saveStack(); + +const description = { + objects: { + Array: new Map([[stack, { count: 1, bytes: 512 }]]), + other: { count: 0, bytes: 0 } + }, + strings: {}, + scripts: {}, + other: {} +}; + +const expected = [ + "objects", + "Array", + stack +]; + +const shallowSize = 512; + +function run_test() { + assertLabelAndShallowSize(breakdown, description, shallowSize, expected); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_attachShortestPaths_01.js b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_attachShortestPaths_01.js new file mode 100644 index 000000000..24e8e2eb5 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_attachShortestPaths_01.js @@ -0,0 +1,132 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +// Test that the DominatorTreeNode.attachShortestPaths function can correctly +// attach the deduplicated shortest retaining paths for each node it is given. + +const startNodeId = 9999; +const maxNumPaths = 2; + +// Mock data mapping node id to shortest paths to that node id. +const shortestPaths = new Map([ + [1000, [ + [pathEntry(1100, "a"), pathEntry(1200, "b")], + [pathEntry(1100, "c"), pathEntry(1300, "d")], + ]], + [2000, [ + [pathEntry(2100, "e"), pathEntry(2200, "f"), pathEntry(2300, "g")] + ]], + [3000, [ + [pathEntry(3100, "h")], + [pathEntry(3100, "i")], + [pathEntry(3100, "j")], + [pathEntry(3200, "k")], + [pathEntry(3300, "l")], + [pathEntry(3400, "m")], + ]], +]); + +const actual = [ + makeTestDominatorTreeNode({ nodeId: 1000 }), + makeTestDominatorTreeNode({ nodeId: 2000 }), + makeTestDominatorTreeNode({ nodeId: 3000 }), +]; + +const expected = [ + makeTestDominatorTreeNode({ + nodeId: 1000, + shortestPaths: { + nodes: [ + { id: 1000, label: ["SomeType-1000"] }, + { id: 1100, label: ["SomeType-1100"] }, + { id: 1200, label: ["SomeType-1200"] }, + { id: 1300, label: ["SomeType-1300"] }, + ], + edges: [ + { from: 1100, to: 1200, name: "a" }, + { from: 1100, to: 1300, name: "c" }, + { from: 1200, to: 1000, name: "b" }, + { from: 1300, to: 1000, name: "d" }, + ] + } + }), + + makeTestDominatorTreeNode({ + nodeId: 2000, + shortestPaths: { + nodes: [ + { id: 2000, label: ["SomeType-2000"] }, + { id: 2100, label: ["SomeType-2100"] }, + { id: 2200, label: ["SomeType-2200"] }, + { id: 2300, label: ["SomeType-2300"] }, + ], + edges: [ + { from: 2100, to: 2200, name: "e" }, + { from: 2200, to: 2300, name: "f" }, + { from: 2300, to: 2000, name: "g" }, + ] + } + }), + + makeTestDominatorTreeNode({ nodeId: 3000, + shortestPaths: { + nodes: [ + { id: 3000, label: ["SomeType-3000"] }, + { id: 3100, label: ["SomeType-3100"] }, + { id: 3200, label: ["SomeType-3200"] }, + { id: 3300, label: ["SomeType-3300"] }, + { id: 3400, label: ["SomeType-3400"] }, + ], + edges: [ + { from: 3100, to: 3000, name: "h" }, + { from: 3100, to: 3000, name: "i" }, + { from: 3100, to: 3000, name: "j" }, + { from: 3200, to: 3000, name: "k" }, + { from: 3300, to: 3000, name: "l" }, + { from: 3400, to: 3000, name: "m" }, + ] + } + }), +]; + +const breakdown = { + by: "internalType", + then: { by: "count", count: true, bytes: true } +}; + +const mockSnapshot = { + computeShortestPaths: (start, nodeIds, max) => { + equal(start, startNodeId); + equal(max, maxNumPaths); + + return new Map(nodeIds.map(nodeId => { + const paths = shortestPaths.get(nodeId); + ok(paths, "Expected computeShortestPaths call for node id = " + nodeId); + return [nodeId, paths]; + })); + }, + + describeNode: (bd, nodeId) => { + equal(bd, breakdown); + return { + ["SomeType-" + nodeId]: { + count: 1, + bytes: 10, + } + }; + }, +}; + +function run_test() { + DominatorTreeNode.attachShortestPaths(mockSnapshot, + breakdown, + startNodeId, + actual, + maxNumPaths); + + dumpn("Expected = " + JSON.stringify(expected, null, 2)); + dumpn("Actual = " + JSON.stringify(actual, null, 2)); + + assertStructurallyEquivalent(expected, actual); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_getNodeByIdAlongPath_01.js b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_getNodeByIdAlongPath_01.js new file mode 100644 index 000000000..de2907809 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_getNodeByIdAlongPath_01.js @@ -0,0 +1,44 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that we can find the node with the given id along the specified path. + +const node3000 = makeTestDominatorTreeNode({ nodeId: 3000 }); + +const node2000 = makeTestDominatorTreeNode({ nodeId: 2000 }, [ + makeTestDominatorTreeNode({}), + node3000, + makeTestDominatorTreeNode({}), +]); + +const node1000 = makeTestDominatorTreeNode({ nodeId: 1000 }, [ + makeTestDominatorTreeNode({}), + node2000, + makeTestDominatorTreeNode({}), +]); + +const tree = node1000; + +const path = [1000, 2000, 3000]; + +const tests = [ + { id: 1000, expected: node1000 }, + { id: 2000, expected: node2000 }, + { id: 3000, expected: node3000 }, +]; + +function run_test() { + for (let { id, expected } of tests) { + const actual = DominatorTreeNode.getNodeByIdAlongPath(id, tree, path); + equal(actual, expected, `We should have got the node with id = ${id}`); + } + + equal(null, + DominatorTreeNode.getNodeByIdAlongPath(999999999999, tree, path), + "null is returned for nodes that are not even in the tree"); + + const lastNodeId = tree.children[tree.children.length - 1].nodeId; + equal(null, + DominatorTreeNode.getNodeByIdAlongPath(lastNodeId, tree, path), + "null is returned for nodes that are not along the path"); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_insert_01.js b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_insert_01.js new file mode 100644 index 000000000..979232ff4 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_insert_01.js @@ -0,0 +1,112 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that we can insert new children into an existing DominatorTreeNode tree. + +const tree = makeTestDominatorTreeNode({ nodeId: 1000 }, [ + makeTestDominatorTreeNode({}), + makeTestDominatorTreeNode({ nodeId: 2000 }, [ + makeTestDominatorTreeNode({}), + makeTestDominatorTreeNode({ nodeId: 3000 }), + makeTestDominatorTreeNode({}), + ]), + makeTestDominatorTreeNode({}), +]); + +const path = [1000, 2000, 3000]; + +const newChildren = [ + makeTestDominatorTreeNode({ parentId: 3000 }), + makeTestDominatorTreeNode({ parentId: 3000 }), +]; + +const moreChildrenAvailable = false; + +const expected = { + nodeId: 1000, + parentId: undefined, + label: undefined, + shallowSize: 1, + retainedSize: 7, + children: [ + { + nodeId: 0, + label: undefined, + shallowSize: 1, + retainedSize: 1, + parentId: 1000, + moreChildrenAvailable: true, + children: undefined, + }, + { + nodeId: 2000, + label: undefined, + shallowSize: 1, + retainedSize: 4, + parentId: 1000, + children: [ + { + nodeId: 1, + label: undefined, + shallowSize: 1, + retainedSize: 1, + parentId: 2000, + moreChildrenAvailable: true, + children: undefined, + }, + { + nodeId: 3000, + label: undefined, + shallowSize: 1, + retainedSize: 1, + parentId: 2000, + children: [ + { + nodeId: 7, + parentId: 3000, + label: undefined, + shallowSize: 1, + retainedSize: 1, + moreChildrenAvailable: true, + children: undefined, + }, + { + nodeId: 8, + parentId: 3000, + label: undefined, + shallowSize: 1, + retainedSize: 1, + moreChildrenAvailable: true, + children: undefined, + }, + ], + moreChildrenAvailable: false + }, + { + nodeId: 3, + label: undefined, + shallowSize: 1, + retainedSize: 1, + parentId: 2000, + moreChildrenAvailable: true, + children: undefined, + }, + ], + moreChildrenAvailable: true + }, + { + nodeId: 5, + label: undefined, + shallowSize: 1, + retainedSize: 1, + parentId: 1000, + moreChildrenAvailable: true, + children: undefined, + } + ], + moreChildrenAvailable: true +}; + +function run_test() { + assertDominatorTreeNodeInsertion(tree, path, newChildren, moreChildrenAvailable, expected); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_insert_02.js b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_insert_02.js new file mode 100644 index 000000000..9a8d11d0b --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_insert_02.js @@ -0,0 +1,30 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test attempting to insert new children into an existing DominatorTreeNode +// tree with a bad path. + +const tree = makeTestDominatorTreeNode({}, [ + makeTestDominatorTreeNode({}), + makeTestDominatorTreeNode({}, [ + makeTestDominatorTreeNode({}), + makeTestDominatorTreeNode({}), + makeTestDominatorTreeNode({}), + ]), + makeTestDominatorTreeNode({}), +]); + +const path = [111111, 222222, 333333]; + +const newChildren = [ + makeTestDominatorTreeNode({ parentId: 333333 }), + makeTestDominatorTreeNode({ parentId: 333333 }), +]; + +const moreChildrenAvailable = false; + +const expected = tree; + +function run_test() { + assertDominatorTreeNodeInsertion(tree, path, newChildren, moreChildrenAvailable, expected); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_insert_03.js b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_insert_03.js new file mode 100644 index 000000000..f8cb5eec3 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_insert_03.js @@ -0,0 +1,117 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test inserting new children into an existing DominatorTreeNode at the root. + +const tree = makeTestDominatorTreeNode({ nodeId: 666 }, [ + makeTestDominatorTreeNode({}), + makeTestDominatorTreeNode({}, [ + makeTestDominatorTreeNode({}), + makeTestDominatorTreeNode({}), + makeTestDominatorTreeNode({}), + ]), + makeTestDominatorTreeNode({}), +]); + +const path = [666]; + +const newChildren = [ + makeTestDominatorTreeNode({ + nodeId: 777, + parentId: 666 + }), + makeTestDominatorTreeNode({ + nodeId: 888, + parentId: 666 + }), +]; + +const moreChildrenAvailable = false; + +const expected = { + nodeId: 666, + label: undefined, + parentId: undefined, + shallowSize: 1, + retainedSize: 7, + children: [ + { + nodeId: 0, + label: undefined, + shallowSize: 1, + retainedSize: 1, + parentId: 666, + moreChildrenAvailable: true, + children: undefined + }, + { + nodeId: 4, + label: undefined, + shallowSize: 1, + retainedSize: 4, + parentId: 666, + children: [ + { + nodeId: 1, + label: undefined, + shallowSize: 1, + retainedSize: 1, + parentId: 4, + moreChildrenAvailable: true, + children: undefined + }, + { + nodeId: 2, + label: undefined, + shallowSize: 1, + retainedSize: 1, + parentId: 4, + moreChildrenAvailable: true, + children: undefined + }, + { + nodeId: 3, + label: undefined, + shallowSize: 1, + retainedSize: 1, + parentId: 4, + moreChildrenAvailable: true, + children: undefined + } + ], + moreChildrenAvailable: true + }, + { + nodeId: 5, + label: undefined, + shallowSize: 1, + retainedSize: 1, + parentId: 666, + moreChildrenAvailable: true, + children: undefined + }, + { + nodeId: 777, + label: undefined, + shallowSize: 1, + retainedSize: 1, + parentId: 666, + moreChildrenAvailable: true, + children: undefined + }, + { + nodeId: 888, + label: undefined, + shallowSize: 1, + retainedSize: 1, + parentId: 666, + moreChildrenAvailable: true, + children: undefined + } + ], + moreChildrenAvailable: false +}; + +function run_test() { + assertDominatorTreeNodeInsertion(tree, path, newChildren, moreChildrenAvailable, expected); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_partialTraversal_01.js b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_partialTraversal_01.js new file mode 100644 index 000000000..78ec47b64 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTreeNode_partialTraversal_01.js @@ -0,0 +1,164 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that we correctly set `moreChildrenAvailable` when doing a partial +// traversal of a dominator tree to create the initial incrementally loaded +// `DominatorTreeNode` tree. + +// `tree` maps parent to children: +// +// 100 +// |- 200 +// | |- 500 +// | |- 600 +// | `- 700 +// |- 300 +// | |- 800 +// | |- 900 +// `- 400 +// |- 1000 +// |- 1100 +// `- 1200 +const tree = new Map([ + [100, [200, 300, 400]], + [200, [500, 600, 700]], + [300, [800, 900]], + [400, [1000, 1100, 1200]] +]); + +const mockDominatorTree = { + root: 100, + getRetainedSize: _ => 10, + getImmediatelyDominated: id => (tree.get(id) || []).slice() +}; + +const mockSnapshot = { + describeNode: _ => ({ + objects: { count: 0, bytes: 0 }, + strings: { count: 0, bytes: 0 }, + scripts: { count: 0, bytes: 0 }, + other: { SomeType: { count: 1, bytes: 10 } } + }) +}; + +const breakdown = { + by: "coarseType", + objects: { by: "count", count: true, bytes: true }, + strings: { by: "count", count: true, bytes: true }, + scripts: { by: "count", count: true, bytes: true }, + other: { + by: "internalType", + then: { by: "count", count: true, bytes: true } + }, +}; + +const expected = { + nodeId: 100, + label: [ + "other", + "SomeType" + ], + shallowSize: 10, + retainedSize: 10, + shortestPaths: undefined, + children: [ + { + nodeId: 200, + label: [ + "other", + "SomeType" + ], + shallowSize: 10, + retainedSize: 10, + parentId: 100, + shortestPaths: undefined, + children: [ + { + nodeId: 500, + label: [ + "other", + "SomeType" + ], + shallowSize: 10, + retainedSize: 10, + parentId: 200, + moreChildrenAvailable: false, + shortestPaths: undefined, + children: undefined + }, + { + nodeId: 600, + label: [ + "other", + "SomeType" + ], + shallowSize: 10, + retainedSize: 10, + parentId: 200, + moreChildrenAvailable: false, + shortestPaths: undefined, + children: undefined + } + ], + moreChildrenAvailable: true + }, + { + nodeId: 300, + label: [ + "other", + "SomeType" + ], + shallowSize: 10, + retainedSize: 10, + parentId: 100, + shortestPaths: undefined, + children: [ + { + nodeId: 800, + label: [ + "other", + "SomeType" + ], + shallowSize: 10, + retainedSize: 10, + parentId: 300, + moreChildrenAvailable: false, + shortestPaths: undefined, + children: undefined + }, + { + nodeId: 900, + label: [ + "other", + "SomeType" + ], + shallowSize: 10, + retainedSize: 10, + parentId: 300, + moreChildrenAvailable: false, + shortestPaths: undefined, + children: undefined + } + ], + moreChildrenAvailable: false + } + ], + moreChildrenAvailable: true, + parentId: undefined, +}; + +function run_test() { + // Traverse the whole depth of the test tree, but one short of the number of + // siblings. This will exercise the moreChildrenAvailable handling for + // siblings. + const actual = DominatorTreeNode.partialTraversal(mockDominatorTree, + mockSnapshot, + breakdown, + /* maxDepth = */ 4, + /* siblings = */ 2); + + dumpn("Expected = " + JSON.stringify(expected, null, 2)); + dumpn("Actual = " + JSON.stringify(actual, null, 2)); + + assertStructurallyEquivalent(expected, actual); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_DominatorTree_01.js b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTree_01.js new file mode 100644 index 000000000..e8145f658 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTree_01.js @@ -0,0 +1,23 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Sanity test that we can compute dominator trees. + +function run_test() { + const path = ChromeUtils.saveHeapSnapshot({ runtime: true }); + const snapshot = ChromeUtils.readHeapSnapshot(path); + + const dominatorTree = snapshot.computeDominatorTree(); + ok(dominatorTree); + ok(dominatorTree instanceof DominatorTree); + + let threw = false; + try { + new DominatorTree(); + } catch (e) { + threw = true; + } + ok(threw, "Constructor shouldn't be usable"); + + do_test_finished(); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_DominatorTree_02.js b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTree_02.js new file mode 100644 index 000000000..a518f8a27 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTree_02.js @@ -0,0 +1,40 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that we can compute dominator trees from a snapshot in a worker. + +add_task(function* () { + const worker = new ChromeWorker("resource://test/dominator-tree-worker.js"); + worker.postMessage({}); + + let assertionCount = 0; + worker.onmessage = e => { + if (e.data.type !== "assertion") { + return; + } + + ok(e.data.passed, e.data.msg + "\n" + e.data.stack); + assertionCount++; + }; + + yield waitForDone(worker); + + ok(assertionCount > 0); + worker.terminate(); +}); + +function waitForDone(w) { + return new Promise((resolve, reject) => { + w.onerror = e => { + reject(); + ok(false, "Error in worker: " + e); + }; + + w.addEventListener("message", function listener(e) { + if (e.data.type === "done") { + w.removeEventListener("message", listener, false); + resolve(); + } + }, false); + }); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_DominatorTree_03.js b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTree_03.js new file mode 100644 index 000000000..0a14ce53d --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTree_03.js @@ -0,0 +1,13 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that we can get the root of dominator trees. + +function run_test() { + const dominatorTree = saveHeapSnapshotAndComputeDominatorTree(); + equal(typeof dominatorTree.root, "number", "root should be a number"); + equal(Math.floor(dominatorTree.root), dominatorTree.root, "root should be an integer"); + ok(dominatorTree.root >= 0, "root should be positive"); + ok(dominatorTree.root <= Math.pow(2, 48), "root should be less than or equal to 2^48"); + do_test_finished(); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_DominatorTree_04.js b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTree_04.js new file mode 100644 index 000000000..e5aef3fec --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTree_04.js @@ -0,0 +1,22 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that we can get the retained sizes of dominator trees. + +function run_test() { + const dominatorTree = saveHeapSnapshotAndComputeDominatorTree(); + equal(typeof dominatorTree.getRetainedSize, "function", + "getRetainedSize should be a function"); + + const size = dominatorTree.getRetainedSize(dominatorTree.root); + ok(size, "should get a size for the root"); + equal(typeof size, "number", "retained sizes should be a number"); + equal(Math.floor(size), size, "size should be an integer"); + ok(size > 0, "size should be positive"); + ok(size <= Math.pow(2, 64), "size should be less than or equal to 2^64"); + + const bad = dominatorTree.getRetainedSize(1); + equal(bad, null, "null is returned for unknown node ids"); + + do_test_finished(); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_DominatorTree_05.js b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTree_05.js new file mode 100644 index 000000000..c07cee994 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTree_05.js @@ -0,0 +1,75 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that we can get the set of immediately dominated nodes for any given +// node and that this forms a tree. + +function run_test() { + var dominatorTree = saveHeapSnapshotAndComputeDominatorTree(); + equal(typeof dominatorTree.getImmediatelyDominated, "function", + "getImmediatelyDominated should be a function"); + + // Do a traversal of the dominator tree. + // + // Note that we don't assert directly, only if we get an unexpected + // value. There are just way too many nodes in the heap graph to assert for + // every one. This test would constantly time out and assertion messages would + // overflow the log size. + + var root = dominatorTree.root; + equal(dominatorTree.getImmediateDominator(root), null, + "The root should not have a parent"); + + var seen = new Set(); + var stack = [root]; + while (stack.length > 0) { + var top = stack.pop(); + + if (seen.has(top)) { + ok(false, + "This is a tree, not a graph: we shouldn't have multiple edges to the same node"); + } + seen.add(top); + if (seen.size % 1000 === 0) { + dumpn("Progress update: seen size = " + seen.size); + } + + var newNodes = dominatorTree.getImmediatelyDominated(top); + if (Object.prototype.toString.call(newNodes) !== "[object Array]") { + ok(false, "getImmediatelyDominated should return an array for known node ids"); + } + + var topSize = dominatorTree.getRetainedSize(top); + + var lastSize = Infinity; + for (var i = 0; i < newNodes.length; i++) { + if (typeof newNodes[i] !== "number") { + ok(false, "Every dominated id should be a number"); + } + + if (dominatorTree.getImmediateDominator(newNodes[i]) !== top) { + ok(false, "child's parent should be the expected parent"); + } + + var thisSize = dominatorTree.getRetainedSize(newNodes[i]); + + if (thisSize >= topSize) { + ok(false, "the size of children in the dominator tree should always be less than that of their parent"); + } + + if (thisSize > lastSize) { + ok(false, + "children should be sorted by greatest to least retained size, " + + "lastSize = " + lastSize + ", thisSize = " + thisSize); + } + + lastSize = thisSize; + stack.push(newNodes[i]); + } + } + + ok(true, "Successfully walked the tree"); + dumpn("Walked " + seen.size + " nodes"); + + do_test_finished(); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_DominatorTree_06.js b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTree_06.js new file mode 100644 index 000000000..680478623 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_DominatorTree_06.js @@ -0,0 +1,56 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that the retained size of a node is the sum of its children retained +// sizes plus its shallow size. + +// Note that we don't assert directly, only if we get an unexpected +// value. There are just way too many nodes in the heap graph to assert for +// every one. This test would constantly time out and assertion messages would +// overflow the log size. +function fastAssert(cond, msg) { + if (!cond) { + ok(false, msg); + } +} + +var COUNT = { by: "count", count: false, bytes: true }; + +function run_test() { + var path = saveNewHeapSnapshot(); + var snapshot = ChromeUtils.readHeapSnapshot(path); + var dominatorTree = snapshot.computeDominatorTree(); + + // Do a traversal of the dominator tree and assert the relationship between + // retained size, shallow size, and children's retained sizes. + + var root = dominatorTree.root; + var stack = [root]; + while (stack.length > 0) { + var top = stack.pop(); + + var children = dominatorTree.getImmediatelyDominated(top); + + var topRetainedSize = dominatorTree.getRetainedSize(top); + var topShallowSize = snapshot.describeNode(COUNT, top).bytes; + fastAssert(topShallowSize <= topRetainedSize, + "The shallow size should be less than or equal to the " + + "retained size"); + + var sumOfChildrensRetainedSizes = 0; + for (var i = 0; i < children.length; i++) { + sumOfChildrensRetainedSizes += dominatorTree.getRetainedSize(children[i]); + stack.push(children[i]); + } + + fastAssert(sumOfChildrensRetainedSizes <= topRetainedSize, + "The sum of the children's retained sizes should be less than " + + "or equal to the retained size"); + fastAssert(sumOfChildrensRetainedSizes + topShallowSize === topRetainedSize, + "The sum of the children's retained sizes plus the shallow " + + "size should be equal to the retained size"); + } + + ok(true, "Successfully walked the tree"); + do_test_finished(); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_computeDominatorTree_01.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_computeDominatorTree_01.js new file mode 100644 index 000000000..0114e0b69 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_computeDominatorTree_01.js @@ -0,0 +1,22 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test the HeapAnalyses{Client,Worker} "computeDominatorTree" request. + +function run_test() { + run_next_test(); +} + +add_task(function* () { + const client = new HeapAnalysesClient(); + + const snapshotFilePath = saveNewHeapSnapshot(); + yield client.readHeapSnapshot(snapshotFilePath); + ok(true, "Should have read the heap snapshot"); + + const dominatorTreeId = yield client.computeDominatorTree(snapshotFilePath); + equal(typeof dominatorTreeId, "number", + "should get a dominator tree id, and it should be a number"); + + client.destroy(); +}); diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_computeDominatorTree_02.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_computeDominatorTree_02.js new file mode 100644 index 000000000..6e3f5b257 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_computeDominatorTree_02.js @@ -0,0 +1,23 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test the HeapAnalyses{Client,Worker} "computeDominatorTree" request with bad +// file paths. + +function run_test() { + run_next_test(); +} + +add_task(function* () { + const client = new HeapAnalysesClient(); + + let threw = false; + try { + yield client.computeDominatorTree("/etc/passwd"); + } catch (_) { + threw = true; + } + ok(threw, "should throw when given a bad path"); + + client.destroy(); +}); diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_deleteHeapSnapshot_01.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_deleteHeapSnapshot_01.js new file mode 100644 index 000000000..7708de93c --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_deleteHeapSnapshot_01.js @@ -0,0 +1,59 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that the HeapAnalyses{Client,Worker} can delete heap snapshots. + +function run_test() { + run_next_test(); +} + +const breakdown = { + by: "coarseType", + objects: { by: "count", count: true, bytes: true }, + scripts: { by: "count", count: true, bytes: true }, + strings: { by: "count", count: true, bytes: true }, + other: { by: "count", count: true, bytes: true }, +}; + +add_task(function* () { + const client = new HeapAnalysesClient(); + + const snapshotFilePath = saveNewHeapSnapshot(); + yield client.readHeapSnapshot(snapshotFilePath); + ok(true, "Should have read the heap snapshot"); + + let dominatorTreeId = yield client.computeDominatorTree(snapshotFilePath); + ok(true, "Should have computed the dominator tree"); + + yield client.deleteHeapSnapshot(snapshotFilePath); + ok(true, "Should have deleted the snapshot"); + + let threw = false; + try { + yield client.getDominatorTree({ + dominatorTreeId: dominatorTreeId, + breakdown + }); + } catch (_) { + threw = true; + } + ok(threw, "getDominatorTree on deleted tree should throw an error"); + + threw = false; + try { + yield client.computeDominatorTree(snapshotFilePath); + } catch (_) { + threw = true; + } + ok(threw, "computeDominatorTree on deleted snapshot should throw an error"); + + threw = false; + try { + yield client.takeCensus(snapshotFilePath); + } catch (_) { + threw = true; + } + ok(threw, "takeCensus on deleted tree should throw an error"); + + client.destroy(); +}); diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_deleteHeapSnapshot_02.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_deleteHeapSnapshot_02.js new file mode 100644 index 000000000..3e25ddac4 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_deleteHeapSnapshot_02.js @@ -0,0 +1,22 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test deleteHeapSnapshot is a noop if the provided path matches no snapshot + +function run_test() { + run_next_test(); +} + +add_task(function* () { + const client = new HeapAnalysesClient(); + + let threw = false; + try { + yield client.deleteHeapSnapshot("path-does-not-exist"); + } catch (_) { + threw = true; + } + ok(threw, "deleteHeapSnapshot on non-existant path should throw an error"); + + client.destroy(); +}); diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_deleteHeapSnapshot_03.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_deleteHeapSnapshot_03.js new file mode 100644 index 000000000..e648c9407 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_deleteHeapSnapshot_03.js @@ -0,0 +1,62 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test other dominatorTrees can still be retrieved after deleting a snapshot + +function run_test() { + run_next_test(); +} + +const breakdown = { + by: "coarseType", + objects: { by: "count", count: true, bytes: true }, + scripts: { by: "count", count: true, bytes: true }, + strings: { by: "count", count: true, bytes: true }, + other: { by: "count", count: true, bytes: true }, +}; + +function* createSnapshotAndDominatorTree(client) { + let snapshotFilePath = saveNewHeapSnapshot(); + yield client.readHeapSnapshot(snapshotFilePath); + let dominatorTreeId = yield client.computeDominatorTree(snapshotFilePath); + return { dominatorTreeId, snapshotFilePath }; +} + +add_task(function* () { + const client = new HeapAnalysesClient(); + + let savedSnapshots = [ + yield createSnapshotAndDominatorTree(client), + yield createSnapshotAndDominatorTree(client), + yield createSnapshotAndDominatorTree(client) + ]; + ok(true, "Create 3 snapshots and dominator trees"); + + yield client.deleteHeapSnapshot(savedSnapshots[1].snapshotFilePath); + ok(true, "Snapshot deleted"); + + let tree = yield client.getDominatorTree({ + dominatorTreeId: savedSnapshots[0].dominatorTreeId, + breakdown + }); + ok(tree, "Should get a valid tree for first snapshot"); + + let threw = false; + try { + yield client.getDominatorTree({ + dominatorTreeId: savedSnapshots[1].dominatorTreeId, + breakdown + }); + } catch (_) { + threw = true; + } + ok(threw, "getDominatorTree on a deleted snapshot should throw an error"); + + tree = yield client.getDominatorTree({ + dominatorTreeId: savedSnapshots[2].dominatorTreeId, + breakdown + }); + ok(tree, "Should get a valid tree for third snapshot"); + + client.destroy(); +}); diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_getCensusIndividuals_01.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_getCensusIndividuals_01.js new file mode 100644 index 000000000..b63ad4230 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_getCensusIndividuals_01.js @@ -0,0 +1,89 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that the HeapAnalyses{Client,Worker} can get census individuals. + +function run_test() { + run_next_test(); +} + +const COUNT = { by: "count", count: true, bytes: true }; + +const CENSUS_BREAKDOWN = { + by: "coarseType", + objects: COUNT, + strings: COUNT, + scripts: COUNT, + other: COUNT, +}; + +const LABEL_BREAKDOWN = { + by: "internalType", + then: COUNT, +}; + +const MAX_INDIVIDUALS = 10; + +add_task(function* () { + const client = new HeapAnalysesClient(); + + const snapshotFilePath = saveNewHeapSnapshot(); + yield client.readHeapSnapshot(snapshotFilePath); + ok(true, "Should have read the heap snapshot"); + + const dominatorTreeId = yield client.computeDominatorTree(snapshotFilePath); + ok(true, "Should have computed dominator tree"); + + const { report } = yield client.takeCensus(snapshotFilePath, + { breakdown: CENSUS_BREAKDOWN }, + { asTreeNode: true }); + ok(report, "Should get a report"); + + let nodesWithLeafIndicesFound = 0; + + yield* (function* assertCanGetIndividuals(censusNode) { + if (censusNode.reportLeafIndex !== undefined) { + nodesWithLeafIndicesFound++; + + const response = yield client.getCensusIndividuals({ + dominatorTreeId, + indices: DevToolsUtils.isSet(censusNode.reportLeafIndex) + ? censusNode.reportLeafIndex + : new Set([censusNode.reportLeafIndex]), + censusBreakdown: CENSUS_BREAKDOWN, + labelBreakdown: LABEL_BREAKDOWN, + maxRetainingPaths: 1, + maxIndividuals: MAX_INDIVIDUALS, + }); + + dumpn(`response = ${JSON.stringify(response, null, 4)}`); + + equal(response.nodes.length, Math.min(MAX_INDIVIDUALS, censusNode.count), + "response.nodes.length === Math.min(MAX_INDIVIDUALS, censusNode.count)"); + + let lastRetainedSize = Infinity; + for (let individual of response.nodes) { + equal(typeof individual.nodeId, "number", + "individual.nodeId should be a number"); + ok(individual.retainedSize <= lastRetainedSize, + "individual.retainedSize <= lastRetainedSize"); + lastRetainedSize = individual.retainedSize; + ok(individual.shallowSize, "individual.shallowSize should exist and be non-zero"); + ok(individual.shortestPaths, "individual.shortestPaths should exist"); + ok(individual.shortestPaths.nodes, "individual.shortestPaths.nodes should exist"); + ok(individual.shortestPaths.edges, "individual.shortestPaths.edges should exist"); + ok(individual.label, "individual.label should exist"); + } + } + + if (censusNode.children) { + for (let child of censusNode.children) { + yield* assertCanGetIndividuals(child); + } + } + }(report)); + + equal(nodesWithLeafIndicesFound, 4, "Should have found a leaf for each coarse type"); + + client.destroy(); +}); diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_getCreationTime_01.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_getCreationTime_01.js new file mode 100644 index 000000000..5df79de7a --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_getCreationTime_01.js @@ -0,0 +1,58 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that the HeapAnalyses{Client,Worker} can get a HeapSnapshot's +// creation time. + +function waitForThirtyMilliseconds() { + const start = Date.now(); + while (Date.now() - start < 30) ; +} + +function run_test() { + run_next_test(); +} + +const BREAKDOWN = { + by: "internalType", + then: { by: "count", count: true, bytes: true } +}; + +add_task(function* () { + const client = new HeapAnalysesClient(); + const start = Date.now() * 1000; + + // Because Date.now() is less precise than the snapshot's time stamp, give it + // a little bit of head room. Additionally, WinXP's timers have a granularity + // of only +/-15 ms. + waitForThirtyMilliseconds(); + const snapshotFilePath = saveNewHeapSnapshot(); + waitForThirtyMilliseconds(); + const end = Date.now() * 1000; + + yield client.readHeapSnapshot(snapshotFilePath); + ok(true, "Should have read the heap snapshot"); + + let threw = false; + try { + yield client.getCreationTime("/not/a/real/path", { + breakdown: BREAKDOWN + }); + } catch (_) { + threw = true; + } + ok(threw, "getCreationTime should throw when snapshot does not exist"); + + let time = yield client.getCreationTime(snapshotFilePath, { + breakdown: BREAKDOWN + }); + + dumpn("Start = " + start); + dumpn("End = " + end); + dumpn("Time = " + time); + + ok(time >= start, "creation time occurred after start"); + ok(time <= end, "creation time occurred before end"); + + client.destroy(); +}); diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_getDominatorTree_01.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_getDominatorTree_01.js new file mode 100644 index 000000000..cedea5375 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_getDominatorTree_01.js @@ -0,0 +1,69 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test the HeapAnalyses{Client,Worker} "getDominatorTree" request. + +function run_test() { + run_next_test(); +} + +const breakdown = { + by: "coarseType", + objects: { by: "count", count: true, bytes: true }, + scripts: { by: "count", count: true, bytes: true }, + strings: { by: "count", count: true, bytes: true }, + other: { by: "count", count: true, bytes: true }, +}; + +add_task(function* () { + const client = new HeapAnalysesClient(); + + const snapshotFilePath = saveNewHeapSnapshot(); + yield client.readHeapSnapshot(snapshotFilePath); + ok(true, "Should have read the heap snapshot"); + + const dominatorTreeId = yield client.computeDominatorTree(snapshotFilePath); + equal(typeof dominatorTreeId, "number", + "should get a dominator tree id, and it should be a number"); + + const partialTree = yield client.getDominatorTree({ + dominatorTreeId, + breakdown + }); + ok(partialTree, "Should get a partial tree"); + equal(typeof partialTree, "object", + "partialTree should be an object"); + + function checkTree(node) { + equal(typeof node.nodeId, "number", "each node should have an id"); + + if (node === partialTree) { + equal(node.parentId, undefined, "the root has no parent"); + } else { + equal(typeof node.parentId, "number", "each node should have a parent id"); + } + + equal(typeof node.retainedSize, "number", + "each node should have a retained size"); + + ok(node.children === undefined || Array.isArray(node.children), + "each node either has a list of children, or undefined meaning no children loaded"); + equal(typeof node.moreChildrenAvailable, "boolean", + "each node should indicate if there are more children available or not"); + + equal(typeof node.shortestPaths, "object", + "Should have shortest paths"); + equal(typeof node.shortestPaths.nodes, "object", + "Should have shortest paths' nodes"); + equal(typeof node.shortestPaths.edges, "object", + "Should have shortest paths' edges"); + + if (node.children) { + node.children.forEach(checkTree); + } + } + + checkTree(partialTree); + + client.destroy(); +}); diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_getDominatorTree_02.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_getDominatorTree_02.js new file mode 100644 index 000000000..fd29beece --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_getDominatorTree_02.js @@ -0,0 +1,31 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test the HeapAnalyses{Client,Worker} "getDominatorTree" request with bad +// dominator tree ids. + +function run_test() { + run_next_test(); +} + +const breakdown = { + by: "coarseType", + objects: { by: "count", count: true, bytes: true }, + scripts: { by: "count", count: true, bytes: true }, + strings: { by: "count", count: true, bytes: true }, + other: { by: "count", count: true, bytes: true }, +}; + +add_task(function* () { + const client = new HeapAnalysesClient(); + + let threw = false; + try { + yield client.getDominatorTree({ dominatorTreeId: 42, breakdown }); + } catch (_) { + threw = true; + } + ok(threw, "should throw when given a bad id"); + + client.destroy(); +}); diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_getImmediatelyDominated_01.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_getImmediatelyDominated_01.js new file mode 100644 index 000000000..caf1c2056 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_getImmediatelyDominated_01.js @@ -0,0 +1,81 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test the HeapAnalyses{Client,Worker} "getImmediatelyDominated" request. + +function run_test() { + run_next_test(); +} + +const breakdown = { + by: "coarseType", + objects: { by: "count", count: true, bytes: true }, + scripts: { by: "count", count: true, bytes: true }, + strings: { by: "count", count: true, bytes: true }, + other: { by: "count", count: true, bytes: true }, +}; + +add_task(function* () { + const client = new HeapAnalysesClient(); + + const snapshotFilePath = saveNewHeapSnapshot(); + yield client.readHeapSnapshot(snapshotFilePath); + const dominatorTreeId = yield client.computeDominatorTree(snapshotFilePath); + + const partialTree = yield client.getDominatorTree({ + dominatorTreeId, + breakdown + }); + ok(partialTree.children.length > 0, + "root should immediately dominate some nodes"); + + // First, test getting a subset of children available. + const response = yield client.getImmediatelyDominated({ + dominatorTreeId, + breakdown, + nodeId: partialTree.nodeId, + startIndex: 0, + maxCount: partialTree.children.length - 1 + }); + + ok(Array.isArray(response.nodes)); + ok(response.nodes.every(node => node.parentId === partialTree.nodeId)); + ok(response.moreChildrenAvailable); + equal(response.path.length, 1); + equal(response.path[0], partialTree.nodeId); + + for (let node of response.nodes) { + equal(typeof node.shortestPaths, "object", + "Should have shortest paths"); + equal(typeof node.shortestPaths.nodes, "object", + "Should have shortest paths' nodes"); + equal(typeof node.shortestPaths.edges, "object", + "Should have shortest paths' edges"); + } + + // Next, test getting a subset of children available. + const secondResponse = yield client.getImmediatelyDominated({ + dominatorTreeId, + breakdown, + nodeId: partialTree.nodeId, + startIndex: 0, + maxCount: Infinity + }); + + ok(Array.isArray(secondResponse.nodes)); + ok(secondResponse.nodes.every(node => node.parentId === partialTree.nodeId)); + ok(!secondResponse.moreChildrenAvailable); + equal(secondResponse.path.length, 1); + equal(secondResponse.path[0], partialTree.nodeId); + + for (let node of secondResponse.nodes) { + equal(typeof node.shortestPaths, "object", + "Should have shortest paths"); + equal(typeof node.shortestPaths.nodes, "object", + "Should have shortest paths' nodes"); + equal(typeof node.shortestPaths.edges, "object", + "Should have shortest paths' edges"); + } + + client.destroy(); +}); diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_readHeapSnapshot_01.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_readHeapSnapshot_01.js new file mode 100644 index 000000000..0d0d58bef --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_readHeapSnapshot_01.js @@ -0,0 +1,18 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that the HeapAnalyses{Client,Worker} can read heap snapshots. + +function run_test() { + run_next_test(); +} + +add_task(function* () { + const client = new HeapAnalysesClient(); + + const snapshotFilePath = saveNewHeapSnapshot(); + yield client.readHeapSnapshot(snapshotFilePath); + ok(true, "Should have read the heap snapshot"); + + client.destroy(); +}); diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensusDiff_01.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensusDiff_01.js new file mode 100644 index 000000000..6f22cbad3 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensusDiff_01.js @@ -0,0 +1,54 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that the HeapAnalyses{Client,Worker} can take diffs between censuses. + +function run_test() { + run_next_test(); +} + +const BREAKDOWN = { + by: "objectClass", + then: { by: "count", count: true, bytes: false }, + other: { by: "count", count: true, bytes: false }, +}; + +add_task(function* () { + const client = new HeapAnalysesClient(); + + const markers = [allocationMarker()]; + + const firstSnapshotFilePath = saveNewHeapSnapshot(); + + // Allocate and hold an additional AllocationMarker object so we can see it in + // the next heap snapshot. + markers.push(allocationMarker()); + + const secondSnapshotFilePath = saveNewHeapSnapshot(); + + yield client.readHeapSnapshot(firstSnapshotFilePath); + yield client.readHeapSnapshot(secondSnapshotFilePath); + ok(true, "Should have read both heap snapshot files"); + + const { delta } = yield client.takeCensusDiff(firstSnapshotFilePath, + secondSnapshotFilePath, + { breakdown: BREAKDOWN }); + + equal(delta.AllocationMarker.count, 1, + "There exists one new AllocationMarker in the second heap snapshot"); + + const { delta: deltaTreeNode } = yield client.takeCensusDiff(firstSnapshotFilePath, + secondSnapshotFilePath, + { breakdown: BREAKDOWN }, + { asTreeNode: true }); + + // Have to manually set these because symbol properties aren't structured + // cloned. + delta[CensusUtils.basisTotalBytes] = deltaTreeNode.totalBytes; + delta[CensusUtils.basisTotalCount] = deltaTreeNode.totalCount; + + compareCensusViewData(BREAKDOWN, delta, deltaTreeNode, + "Returning delta-census as a tree node represents same data as the report"); + + client.destroy(); +}); diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensusDiff_02.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensusDiff_02.js new file mode 100644 index 000000000..f1ba9ce84 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensusDiff_02.js @@ -0,0 +1,59 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that the HeapAnalyses{Client,Worker} can take diffs between censuses as +// inverted trees. + +function run_test() { + run_next_test(); +} + +const BREAKDOWN = { + by: "coarseType", + objects: { + by: "objectClass", + then: { by: "count", count: true, bytes: true }, + other: { by: "count", count: true, bytes: true }, + }, + scripts: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + strings: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + other: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, +}; + +add_task(function* () { + const firstSnapshotFilePath = saveNewHeapSnapshot(); + const secondSnapshotFilePath = saveNewHeapSnapshot(); + + const client = new HeapAnalysesClient(); + yield client.readHeapSnapshot(firstSnapshotFilePath); + yield client.readHeapSnapshot(secondSnapshotFilePath); + + ok(true, "Should have read both heap snapshot files"); + + const { delta } = yield client.takeCensusDiff(firstSnapshotFilePath, + secondSnapshotFilePath, + { breakdown: BREAKDOWN }); + + const { delta: deltaTreeNode } = yield client.takeCensusDiff(firstSnapshotFilePath, + secondSnapshotFilePath, + { breakdown: BREAKDOWN }, + { asInvertedTreeNode: true }); + + // Have to manually set these because symbol properties aren't structured + // cloned. + delta[CensusUtils.basisTotalBytes] = deltaTreeNode.totalBytes; + delta[CensusUtils.basisTotalCount] = deltaTreeNode.totalCount; + + compareCensusViewData(BREAKDOWN, delta, deltaTreeNode, { invert: true }); + + client.destroy(); +}); diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_01.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_01.js new file mode 100644 index 000000000..e26981db4 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_01.js @@ -0,0 +1,27 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that the HeapAnalyses{Client,Worker} can take censuses. + +function run_test() { + run_next_test(); +} + +add_task(function* () { + const client = new HeapAnalysesClient(); + + const snapshotFilePath = saveNewHeapSnapshot(); + yield client.readHeapSnapshot(snapshotFilePath); + ok(true, "Should have read the heap snapshot"); + + const { report } = yield client.takeCensus(snapshotFilePath); + ok(report, "Should get a report"); + equal(typeof report, "object", "report should be an object"); + + ok(report.objects); + ok(report.scripts); + ok(report.strings); + ok(report.other); + + client.destroy(); +}); diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_02.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_02.js new file mode 100644 index 000000000..34494af70 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_02.js @@ -0,0 +1,29 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that the HeapAnalyses{Client,Worker} can take censuses with breakdown +// options. + +function run_test() { + run_next_test(); +} + +add_task(function* () { + const client = new HeapAnalysesClient(); + + const snapshotFilePath = saveNewHeapSnapshot(); + yield client.readHeapSnapshot(snapshotFilePath); + ok(true, "Should have read the heap snapshot"); + + const { report } = yield client.takeCensus(snapshotFilePath, { + breakdown: { by: "count", count: true, bytes: true } + }); + + ok(report, "Should get a report"); + equal(typeof report, "object", "report should be an object"); + + ok(report.count); + ok(report.bytes); + + client.destroy(); +}); diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_03.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_03.js new file mode 100644 index 000000000..486e250b5 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_03.js @@ -0,0 +1,48 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that the HeapAnalyses{Client,Worker} bubbles errors properly when things +// go wrong. + +function run_test() { + run_next_test(); +} + +add_task(function* () { + const client = new HeapAnalysesClient(); + + // Snapshot file path to a file that doesn't exist. + let failed = false; + try { + yield client.readHeapSnapshot(getFilePath("foo-bar-baz" + Math.random(), true)); + } catch (e) { + failed = true; + } + ok(failed, "should not read heap snapshots that do not exist"); + + // Snapshot file path to a file that is not a heap snapshot. + failed = false; + try { + yield client.readHeapSnapshot(getFilePath("test_HeapAnalyses_takeCensus_03.js")); + } catch (e) { + failed = true; + } + ok(failed, "should not be able to read a file that is not a heap snapshot as a heap snapshot"); + + const snapshotFilePath = saveNewHeapSnapshot(); + yield client.readHeapSnapshot(snapshotFilePath); + ok(true, "Should have read the heap snapshot"); + + // Bad census breakdown options. + failed = false; + try { + yield client.takeCensus(snapshotFilePath, { + breakdown: { by: "some classification that we do not have" } + }); + } catch (e) { + failed = true; + } + ok(failed, "should not be able to breakdown by an unknown classification"); + + client.destroy(); +}); diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_04.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_04.js new file mode 100644 index 000000000..769a2d99d --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_04.js @@ -0,0 +1,118 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that the HeapAnalyses{Client,Worker} can send SavedFrame stacks from +// by-allocation-stack reports from the worker. + +function run_test() { + run_next_test(); +} + +add_task(function* test() { + const client = new HeapAnalysesClient(); + + // Track some allocation stacks. + + const g = newGlobal(); + const dbg = new Debugger(g); + g.eval(` // 1 + this.log = []; // 2 + function f() { this.log.push(allocationMarker()); } // 3 + function g() { this.log.push(allocationMarker()); } // 4 + function h() { this.log.push(allocationMarker()); } // 5 + `); // 6 + + // Create one allocationMarker with tracking turned off, + // so it will have no associated stack. + g.f(); + + dbg.memory.allocationSamplingProbability = 1; + + for (let [func, n] of [ [g.f, 20], + [g.g, 10], + [g.h, 5] ]) { + for (let i = 0; i < n; i++) { + dbg.memory.trackingAllocationSites = true; + // All allocations of allocationMarker occur with this line as the oldest + // stack frame. + func(); + dbg.memory.trackingAllocationSites = false; + } + } + + // Take a heap snapshot. + + const snapshotFilePath = saveNewHeapSnapshot({ debugger: dbg }); + yield client.readHeapSnapshot(snapshotFilePath); + ok(true, "Should have read the heap snapshot"); + + // Run a census broken down by class name -> allocation stack so we can grab + // only the AllocationMarker objects we have complete control over. + + const { report } = yield client.takeCensus(snapshotFilePath, { + breakdown: { by: "objectClass", + then: { by: "allocationStack", + then: { by: "count", + bytes: true, + count: true + }, + noStack: { by: "count", + bytes: true, + count: true + } + } + } + }); + + // Test the generated report. + + ok(report, "Should get a report"); + + const map = report.AllocationMarker; + ok(map, "Should get AllocationMarkers in the report."); + // From a module with a different global, and therefore a different Map + // constructor, so we can't use instanceof. + equal(map.__proto__.constructor.name, "Map"); + + equal(map.size, 4, "Should have 4 allocation stacks (including the lack of a stack)"); + + // Gather the stacks we are expecting to appear as keys, and + // check that there are no unexpected keys. + let stacks = {}; + + map.forEach((v, k) => { + if (k === "noStack") { + // No need to save this key. + } else if (k.functionDisplayName === "f" && + k.parent.functionDisplayName === "test") { + stacks.f = k; + } else if (k.functionDisplayName === "g" && + k.parent.functionDisplayName === "test") { + stacks.g = k; + } else if (k.functionDisplayName === "h" && + k.parent.functionDisplayName === "test") { + stacks.h = k; + } else { + dumpn("Unexpected allocation stack:"); + k.toString().split(/\n/g).forEach(s => dumpn(s)); + ok(false); + } + }); + + ok(map.get("noStack")); + equal(map.get("noStack").count, 1); + + ok(stacks.f); + ok(map.get(stacks.f)); + equal(map.get(stacks.f).count, 20); + + ok(stacks.g); + ok(map.get(stacks.g)); + equal(map.get(stacks.g).count, 10); + + ok(stacks.h); + ok(map.get(stacks.h)); + equal(map.get(stacks.h).count, 5); + + client.destroy(); +}); diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_05.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_05.js new file mode 100644 index 000000000..7e16d9f00 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_05.js @@ -0,0 +1,44 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that the HeapAnalyses{Client,Worker} can take censuses and return +// a CensusTreeNode. + +function run_test() { + run_next_test(); +} + +const BREAKDOWN = { + by: "internalType", + then: { by: "count", count: true, bytes: true } +}; + +add_task(function* () { + const client = new HeapAnalysesClient(); + + const snapshotFilePath = saveNewHeapSnapshot(); + yield client.readHeapSnapshot(snapshotFilePath); + ok(true, "Should have read the heap snapshot"); + + const { report } = yield client.takeCensus(snapshotFilePath, { + breakdown: BREAKDOWN + }); + + const { report: treeNode } = yield client.takeCensus(snapshotFilePath, { + breakdown: BREAKDOWN + }, { + asTreeNode: true + }); + + ok(treeNode.children.length > 0, "treeNode has children"); + ok(treeNode.children.every(type => { + return "name" in type && + "bytes" in type && + "count" in type; + }), "all of tree node's children have name, bytes, count"); + + compareCensusViewData(BREAKDOWN, report, treeNode, + "Returning census as a tree node represents same data as the report"); + + client.destroy(); +}); diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_06.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_06.js new file mode 100644 index 000000000..7795a9700 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_06.js @@ -0,0 +1,109 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that the HeapAnalyses{Client,Worker} can take censuses by +// "allocationStack" and return a CensusTreeNode. + +function run_test() { + run_next_test(); +} + +const BREAKDOWN = { + by: "objectClass", + then: { + by: "allocationStack", + then: { by: "count", count: true, bytes: true }, + noStack: { by: "count", count: true, bytes: true } + }, + other: { by: "count", count: true, bytes: true } +}; + +add_task(function* () { + const g = newGlobal(); + const dbg = new Debugger(g); + + // 5 allocation markers with no stack. + g.eval(` + this.markers = []; + for (var i = 0; i < 5; i++) { + markers.push(allocationMarker()); + } + `); + + dbg.memory.allocationSamplingProbability = 1; + dbg.memory.trackingAllocationSites = true; + + // 5 allocation markers at 5 stacks. + g.eval(` + (function shouldHaveCountOfOne() { + markers.push(allocationMarker()); + markers.push(allocationMarker()); + markers.push(allocationMarker()); + markers.push(allocationMarker()); + markers.push(allocationMarker()); + }()); + `); + + // 5 allocation markers at 1 stack. + g.eval(` + (function shouldHaveCountOfFive() { + for (var i = 0; i < 5; i++) { + markers.push(allocationMarker()); + } + }()); + `); + + const snapshotFilePath = saveNewHeapSnapshot({ debugger: dbg }); + + const client = new HeapAnalysesClient(); + yield client.readHeapSnapshot(snapshotFilePath); + ok(true, "Should have read the heap snapshot"); + + const { report } = yield client.takeCensus(snapshotFilePath, { + breakdown: BREAKDOWN + }); + + const { report: treeNode } = yield client.takeCensus(snapshotFilePath, { + breakdown: BREAKDOWN + }, { + asTreeNode: true + }); + + const markers = treeNode.children.find(c => c.name === "AllocationMarker"); + ok(markers); + + const noStack = markers.children.find(c => c.name === "noStack"); + equal(noStack.count, 5); + + let numShouldHaveFiveFound = 0; + let numShouldHaveOneFound = 0; + + function walk(node) { + if (node.children) { + node.children.forEach(walk); + } + + if (!isSavedFrame(node.name)) { + return; + } + + if (node.name.functionDisplayName === "shouldHaveCountOfFive") { + equal(node.count, 5, "shouldHaveCountOfFive should have count of five"); + numShouldHaveFiveFound++; + } + + if (node.name.functionDisplayName === "shouldHaveCountOfOne") { + equal(node.count, 1, "shouldHaveCountOfOne should have count of one"); + numShouldHaveOneFound++; + } + } + markers.children.forEach(walk); + + equal(numShouldHaveFiveFound, 1); + equal(numShouldHaveOneFound, 5); + + compareCensusViewData(BREAKDOWN, report, treeNode, + "Returning census as a tree node represents same data as the report"); + + client.destroy(); +}); diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_07.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_07.js new file mode 100644 index 000000000..986b3aaa8 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_07.js @@ -0,0 +1,52 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that the HeapAnalyses{Client,Worker} can take censuses and return +// an inverted CensusTreeNode. + +function run_test() { + run_next_test(); +} + +const BREAKDOWN = { + by: "coarseType", + objects: { + by: "objectClass", + then: { by: "count", count: true, bytes: true }, + other: { by: "count", count: true, bytes: true }, + }, + scripts: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + strings: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + other: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, +}; + +add_task(function* () { + const client = new HeapAnalysesClient(); + + const snapshotFilePath = saveNewHeapSnapshot(); + yield client.readHeapSnapshot(snapshotFilePath); + ok(true, "Should have read the heap snapshot"); + + const { report } = yield client.takeCensus(snapshotFilePath, { + breakdown: BREAKDOWN + }); + + const { report: treeNode } = yield client.takeCensus(snapshotFilePath, { + breakdown: BREAKDOWN + }, { + asInvertedTreeNode: true + }); + + compareCensusViewData(BREAKDOWN, report, treeNode, { invert: true }); + + client.destroy(); +}); diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_computeShortestPaths_01.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_computeShortestPaths_01.js new file mode 100644 index 000000000..2ec577bd0 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_computeShortestPaths_01.js @@ -0,0 +1,69 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Sanity test that we can compute shortest paths. +// +// Because the actual heap graph is too unpredictable and likely to drastically +// change as various implementation bits change, we don't test exact paths +// here. See js/src/jsapi-tests/testUbiNode.cpp for such tests, where we can +// control the specific graph shape and structure and so testing exact paths is +// reliable. + +function run_test() { + const path = ChromeUtils.saveHeapSnapshot({ runtime: true }); + const snapshot = ChromeUtils.readHeapSnapshot(path); + + const dominatorTree = snapshot.computeDominatorTree(); + const dominatedByRoot = dominatorTree.getImmediatelyDominated(dominatorTree.root) + .slice(0, 10); + ok(dominatedByRoot); + ok(dominatedByRoot.length); + + const targetSet = new Set(dominatedByRoot); + + const shortestPaths = snapshot.computeShortestPaths(dominatorTree.root, dominatedByRoot, 2); + ok(shortestPaths); + ok(shortestPaths instanceof Map); + ok(shortestPaths.size === targetSet.size); + + for (let [target, paths] of shortestPaths) { + ok(targetSet.has(target), + "We should only get paths for our targets"); + targetSet.delete(target); + + ok(paths.length > 0, + "We must have at least one path, since the target is dominated by the root"); + ok(paths.length <= 2, + "Should not have recorded more paths than the max requested"); + + dumpn("---------------------"); + dumpn("Shortest paths for 0x" + target.toString(16) + ":"); + for (let path of paths) { + dumpn(" path ="); + for (let part of path) { + dumpn(" predecessor: 0x" + part.predecessor.toString(16) + + "; edge: " + part.edge); + } + } + dumpn("---------------------"); + + for (let path of paths) { + ok(path.length > 0, "Cannot have zero length paths"); + ok(path[0].predecessor === dominatorTree.root, + "The first predecessor is always our start node"); + + for (let part of path) { + ok(part.predecessor, "Each part of a path has a predecessor"); + ok(!!snapshot.describeNode({ by: "count", count: true, bytes: true}, + part.predecessor), + "The predecessor is in the heap snapshot"); + ok("edge" in part, "Each part has an (potentially null) edge property"); + } + } + } + + ok(targetSet.size === 0, + "We found paths for all of our targets"); + + do_test_finished(); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_computeShortestPaths_02.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_computeShortestPaths_02.js new file mode 100644 index 000000000..04fe58733 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_computeShortestPaths_02.js @@ -0,0 +1,47 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test computing shortest paths with invalid arguments. + +function run_test() { + const path = ChromeUtils.saveHeapSnapshot({ runtime: true }); + const snapshot = ChromeUtils.readHeapSnapshot(path); + + const dominatorTree = snapshot.computeDominatorTree(); + const target = dominatorTree.getImmediatelyDominated(dominatorTree.root).pop(); + ok(target); + + let threw = false; + try { + snapshot.computeShortestPaths(0, [target], 2); + } catch (_) { + threw = true; + } + ok(threw, "invalid start node should throw"); + + threw = false; + try { + snapshot.computeShortestPaths(dominatorTree.root, [0], 2); + } catch (_) { + threw = true; + } + ok(threw, "invalid target nodes should throw"); + + threw = false; + try { + snapshot.computeShortestPaths(dominatorTree.root, [], 2); + } catch (_) { + threw = true; + } + ok(threw, "empty target nodes should throw"); + + threw = false; + try { + snapshot.computeShortestPaths(dominatorTree.root, [target], 0); + } catch (_) { + threw = true; + } + ok(threw, "0 max paths should throw"); + + do_test_finished(); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_creationTime_01.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_creationTime_01.js new file mode 100644 index 000000000..0d08fea16 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_creationTime_01.js @@ -0,0 +1,30 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// HeapSnapshot.prototype.creationTime returns the expected time. + +function waitForThirtyMilliseconds() { + const start = Date.now(); + while (Date.now() - start < 30) ; +} + +function run_test() { + const start = Date.now() * 1000; + do_print("start = " + start); + + // Because Date.now() is less precise than the snapshot's time stamp, give it + // a little bit of head room. Additionally, WinXP's timer only has granularity + // of +/- 15ms. + waitForThirtyMilliseconds(); + const path = ChromeUtils.saveHeapSnapshot({ runtime: true }); + waitForThirtyMilliseconds(); + + const end = Date.now() * 1000; + do_print("end = " + end); + + const snapshot = ChromeUtils.readHeapSnapshot(path); + do_print("snapshot.creationTime = " + snapshot.creationTime); + + ok(snapshot.creationTime >= start); + ok(snapshot.creationTime <= end); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_deepStack_01.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_deepStack_01.js new file mode 100644 index 000000000..9eb11d9af --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_deepStack_01.js @@ -0,0 +1,70 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that we can save a core dump with very deep allocation stacks and read +// it back into a HeapSnapshot. + +function stackDepth(stack) { + return stack ? 1 + stackDepth(stack.parent) : 0; +} + +function run_test() { + // Create a Debugger observing a debuggee's allocations. + const debuggee = new Cu.Sandbox(null); + const dbg = new Debugger(debuggee); + dbg.memory.trackingAllocationSites = true; + + // Allocate some objects in the debuggee that will have their allocation + // stacks recorded by the Debugger. + + debuggee.eval("this.objects = []"); + debuggee.eval( + (function recursiveAllocate(n) { + if (n <= 0) + return; + + // Make sure to recurse before pushing the object so that when TCO is + // implemented sometime in the future, it doesn't invalidate this test. + recursiveAllocate(n - 1); + this.objects.push({}); + }).toString() + ); + debuggee.eval("recursiveAllocate = recursiveAllocate.bind(this);"); + debuggee.eval("recursiveAllocate(200);"); + + // Now save a snapshot that will include the allocation stacks and read it + // back again. + + const filePath = ChromeUtils.saveHeapSnapshot({ runtime: true }); + ok(true, "Should be able to save a snapshot."); + + const snapshot = ChromeUtils.readHeapSnapshot(filePath); + ok(snapshot, "Should be able to read a heap snapshot"); + ok(snapshot instanceof HeapSnapshot, "Should be an instanceof HeapSnapshot"); + + const report = snapshot.takeCensus({ + breakdown: { by: "allocationStack", + then: { by: "count", bytes: true, count: true }, + noStack: { by: "count", bytes: true, count: true } + } + }); + + // Keep this synchronized with `HeapSnapshot::MAX_STACK_DEPTH`! + const MAX_STACK_DEPTH = 60; + + let foundStacks = false; + report.forEach((v, k) => { + if (k === "noStack") { + return; + } + + foundStacks = true; + const depth = stackDepth(k); + dumpn("Stack depth is " + depth); + ok(depth <= MAX_STACK_DEPTH, + "Every stack should have depth less than or equal to the maximum stack depth"); + }); + ok(foundStacks); + + do_test_finished(); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_describeNode_01.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_describeNode_01.js new file mode 100644 index 000000000..d79cb5a7b --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_describeNode_01.js @@ -0,0 +1,42 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that we can describe nodes with a breakdown. + +function run_test() { + const path = saveNewHeapSnapshot(); + const snapshot = ChromeUtils.readHeapSnapshot(path); + ok(snapshot.describeNode); + equal(typeof snapshot.describeNode, "function"); + + const dt = snapshot.computeDominatorTree(); + + let threw = false; + try { + snapshot.describeNode(undefined, dt.root); + } catch (_) { + threw = true; + } + ok(threw, "Should require a breakdown"); + + const breakdown = { + by: "coarseType", + objects: { by: "objectClass" }, + scripts: { by: "internalType" }, + strings: { by: "internalType" }, + other: { by: "internalType" } + }; + + threw = false; + try { + snapshot.describeNode(breakdown, 0); + } catch (_) { + threw = true; + } + ok(threw, "Should throw when given an invalid node id"); + + const description = snapshot.describeNode(breakdown, dt.root); + ok(description); + ok(description.other); + ok(description.other["JS::ubi::RootList"]); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_01.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_01.js new file mode 100644 index 000000000..f3b3090b0 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_01.js @@ -0,0 +1,31 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// HeapSnapshot.prototype.takeCensus returns a value of an appropriate +// shape. Ported from js/src/jit-tests/debug/Memory-takeCensus-01.js + +function run_test() { + var dbg = new Debugger; + + function checkProperties(census) { + equal(typeof census, "object"); + for (prop of Object.getOwnPropertyNames(census)) { + var desc = Object.getOwnPropertyDescriptor(census, prop); + equal(desc.enumerable, true); + equal(desc.configurable, true); + equal(desc.writable, true); + if (typeof desc.value === "object") + checkProperties(desc.value); + else + equal(typeof desc.value, "number"); + } + } + + checkProperties(saveHeapSnapshotAndTakeCensus(dbg)); + + var g = newGlobal(); + dbg.addDebuggee(g); + checkProperties(saveHeapSnapshotAndTakeCensus(dbg)); + + do_test_finished(); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_02.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_02.js new file mode 100644 index 000000000..680ac9b58 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_02.js @@ -0,0 +1,57 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// HeapSnapshot.prototype.takeCensus behaves plausibly as we allocate objects. +// +// Exact object counts vary in ways we can't predict. For example, +// BaselineScripts can hold onto "template objects", which exist only to hold +// the shape and type for newly created objects. When BaselineScripts are +// discarded, these template objects go with them. +// +// So instead of expecting precise counts, we expect counts that are at least as +// many as we would expect given the object graph we've built. +// +// Ported from js/src/jit-tests/debug/Memory-takeCensus-02.js + +function run_test() { + // A Debugger with no debuggees had better not find anything. + var dbg = new Debugger; + var census0 = saveHeapSnapshotAndTakeCensus(dbg); + Census.walkCensus(census0, "census0", Census.assertAllZeros); + + function newGlobalWithDefs() { + var g = newGlobal(); + g.eval(` + function times(n, fn) { + var a=[]; + for (var i = 0; i ({}));"); + g.eval("var rxs = times(200, () => /foo/);"); + g.eval("var ars = times(400, () => []);"); + g.eval("var fns = times(800, () => () => {});"); + + var census1 = dbg.memory.takeCensus(dbg); + Census.walkCensus(census1, "census1", + Census.assertAllNotLessThan( + { "objects": + { "Object": { count: 100 }, + "RegExp": { count: 200 }, + "Array": { count: 400 }, + "Function": { count: 800 } + } + })); + + do_test_finished(); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_03.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_03.js new file mode 100644 index 000000000..25f2c3791 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_03.js @@ -0,0 +1,34 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// HeapSnapshot.prototype.takeCensus behaves plausibly as we add and remove +// debuggees. +// +// Ported from js/src/jit-test/tests/debug/Memory-takeCensus-03.js + +function run_test() { + var dbg = new Debugger; + + var census0 = saveHeapSnapshotAndTakeCensus(dbg); + Census.walkCensus(census0, "census0", Census.assertAllZeros); + + var g1 = newGlobal(); + dbg.addDebuggee(g1); + var census1 = saveHeapSnapshotAndTakeCensus(dbg); + Census.walkCensus(census1, "census1", Census.assertAllNotLessThan(census0)); + + var g2 = newGlobal(); + dbg.addDebuggee(g2); + var census2 = saveHeapSnapshotAndTakeCensus(dbg); + Census.walkCensus(census2, "census2", Census.assertAllNotLessThan(census1)); + + dbg.removeDebuggee(g2); + var census3 = saveHeapSnapshotAndTakeCensus(dbg); + Census.walkCensus(census3, "census3", Census.assertAllEqual(census1)); + + dbg.removeDebuggee(g1); + var census4 = saveHeapSnapshotAndTakeCensus(dbg); + Census.walkCensus(census4, "census4", Census.assertAllEqual(census0)); + + do_test_finished(); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_04.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_04.js new file mode 100644 index 000000000..799844cde --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_04.js @@ -0,0 +1,36 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that HeapSnapshot.prototype.takeCensus finds GC roots that are on the +// stack. +// +// Ported from js/src/jit-test/tests/debug/Memory-takeCensus-04.js + +function run_test() { + var g = newGlobal(); + var dbg = new Debugger(g); + + g.eval(` +function withAllocationMarkerOnStack(f) { + (function () { + var onStack = allocationMarker(); + f(); + }()); +} +`); + + equal("AllocationMarker" in saveHeapSnapshotAndTakeCensus(dbg).objects, false, + "There shouldn't exist any allocation markers in the census."); + + var allocationMarkerCount; + g.withAllocationMarkerOnStack(() => { + const census = saveHeapSnapshotAndTakeCensus(dbg); + allocationMarkerCount = census.objects.AllocationMarker.count; + }); + + equal(allocationMarkerCount, 1, + "Should have one allocation marker in the census, because there " + + "was one on the stack."); + + do_test_finished(); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_05.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_05.js new file mode 100644 index 000000000..da6067624 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_05.js @@ -0,0 +1,24 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that HeapSnapshot.prototype.takeCensus finds cross compartment +// wrapper GC roots. +// +// Ported from js/src/jit-test/tests/debug/Memory-takeCensus-05.js + +function run_test() { + var g = newGlobal(); + var dbg = new Debugger(g); + + equal("AllocationMarker" in saveHeapSnapshotAndTakeCensus(dbg).objects, false, + "No allocation markers should exist in the census."); + + this.ccw = g.allocationMarker(); + + const census = saveHeapSnapshotAndTakeCensus(dbg); + equal(census.objects.AllocationMarker.count, 1, + "Should have one allocation marker in the census, because there " + + "is one cross-compartment wrapper referring to it."); + + do_test_finished(); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_06.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_06.js new file mode 100644 index 000000000..0412410c0 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_06.js @@ -0,0 +1,125 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Check HeapSnapshot.prototype.takeCensus handling of 'breakdown' argument. +// +// Ported from js/src/jit-test/tests/debug/Memory-takeCensus-06.js + +function run_test() { + var Pattern = Match.Pattern; + + var g = newGlobal(); + var dbg = new Debugger(g); + + Pattern({ count: Pattern.NATURAL, + bytes: Pattern.NATURAL }) + .assert(saveHeapSnapshotAndTakeCensus(dbg, { breakdown: { by: "count" } })); + + let census = saveHeapSnapshotAndTakeCensus(dbg, { breakdown: { by: "count", count: false, bytes: false } }); + equal("count" in census, false); + equal("bytes" in census, false); + + census = saveHeapSnapshotAndTakeCensus(dbg, { breakdown: { by: "count", count: true, bytes: false } }); + equal("count" in census, true); + equal("bytes" in census, false); + + census = saveHeapSnapshotAndTakeCensus(dbg, { breakdown: { by: "count", count: false, bytes: true } }); + equal("count" in census, false); + equal("bytes" in census, true); + + census = saveHeapSnapshotAndTakeCensus(dbg, { breakdown: { by: "count", count: true, bytes: true } }); + equal("count" in census, true); + equal("bytes" in census, true); + + + // Pattern doesn't mind objects with extra properties, so we'll restrict this + // list to the object classes we're pretty sure are going to stick around for + // the forseeable future. + Pattern({ + Function: { count: Pattern.NATURAL }, + Object: { count: Pattern.NATURAL }, + Debugger: { count: Pattern.NATURAL }, + Sandbox: { count: Pattern.NATURAL }, + + // The below are all Debugger prototype objects. + Source: { count: Pattern.NATURAL }, + Environment: { count: Pattern.NATURAL }, + Script: { count: Pattern.NATURAL }, + Memory: { count: Pattern.NATURAL }, + Frame: { count: Pattern.NATURAL } + }) + .assert(saveHeapSnapshotAndTakeCensus(dbg, { breakdown: { by: "objectClass" } })); + + Pattern({ + objects: { count: Pattern.NATURAL }, + scripts: { count: Pattern.NATURAL }, + strings: { count: Pattern.NATURAL }, + other: { count: Pattern.NATURAL } + }) + .assert(saveHeapSnapshotAndTakeCensus(dbg, { breakdown: { by: "coarseType" } })); + + // As for { by: 'objectClass' }, restrict our pattern to the types + // we predict will stick around for a long time. + Pattern({ + JSString: { count: Pattern.NATURAL }, + "js::Shape": { count: Pattern.NATURAL }, + JSObject: { count: Pattern.NATURAL }, + JSScript: { count: Pattern.NATURAL } + }) + .assert(saveHeapSnapshotAndTakeCensus(dbg, { breakdown: { by: "internalType" } })); + + + // Nested breakdowns. + + let coarseTypePattern = { + objects: { count: Pattern.NATURAL }, + scripts: { count: Pattern.NATURAL }, + strings: { count: Pattern.NATURAL }, + other: { count: Pattern.NATURAL } + }; + + Pattern({ + JSString: coarseTypePattern, + "js::Shape": coarseTypePattern, + JSObject: coarseTypePattern, + JSScript: coarseTypePattern, + }) + .assert(saveHeapSnapshotAndTakeCensus(dbg, { + breakdown: { by: "internalType", + then: { by: "coarseType" } + } + })); + + Pattern({ + Function: { count: Pattern.NATURAL }, + Object: { count: Pattern.NATURAL }, + Debugger: { count: Pattern.NATURAL }, + Sandbox: { count: Pattern.NATURAL }, + other: coarseTypePattern + }) + .assert(saveHeapSnapshotAndTakeCensus(dbg, { + breakdown: { + by: "objectClass", + then: { by: "count" }, + other: { by: "coarseType" } + } + })); + + Pattern({ + objects: { count: Pattern.NATURAL, label: "object" }, + scripts: { count: Pattern.NATURAL, label: "scripts" }, + strings: { count: Pattern.NATURAL, label: "strings" }, + other: { count: Pattern.NATURAL, label: "other" } + }) + .assert(saveHeapSnapshotAndTakeCensus(dbg, { + breakdown: { + by: "coarseType", + objects: { by: "count", label: "object" }, + scripts: { by: "count", label: "scripts" }, + strings: { by: "count", label: "strings" }, + other: { by: "count", label: "other" } + } + })); + + do_test_finished(); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_07.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_07.js new file mode 100644 index 000000000..f5c36056f --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_07.js @@ -0,0 +1,82 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// HeapSnapshot.prototype.takeCensus breakdown: check error handling on property +// gets. +// +// Ported from js/src/jit-test/tests/debug/Memory-takeCensus-07.js + +function run_test() { + var g = newGlobal(); + var dbg = new Debugger(g); + + assertThrowsValue(() => { + saveHeapSnapshotAndTakeCensus(dbg, { + breakdown: { get by() { throw "ಠ_ಠ"; } } + }); + }, "ಠ_ಠ"); + + + + assertThrowsValue(() => { + saveHeapSnapshotAndTakeCensus(dbg, { + breakdown: { by: "count", get count() { throw "ಠ_ಠ"; } } + }); + }, "ಠ_ಠ"); + + assertThrowsValue(() => { + saveHeapSnapshotAndTakeCensus(dbg, { + breakdown: { by: "count", get bytes() { throw "ಠ_ಠ"; } } + }); + }, "ಠ_ಠ"); + + + + assertThrowsValue(() => { + saveHeapSnapshotAndTakeCensus(dbg, { + breakdown: { by: "objectClass", get then() { throw "ಠ_ಠ"; } } + }); + }, "ಠ_ಠ"); + + assertThrowsValue(() => { + saveHeapSnapshotAndTakeCensus(dbg, { + breakdown: { by: "objectClass", get other() { throw "ಠ_ಠ"; } } + }); + }, "ಠ_ಠ"); + + + + assertThrowsValue(() => { + saveHeapSnapshotAndTakeCensus(dbg, { + breakdown: { by: "coarseType", get objects() { throw "ಠ_ಠ"; } } + }); + }, "ಠ_ಠ"); + + assertThrowsValue(() => { + saveHeapSnapshotAndTakeCensus(dbg, { + breakdown: { by: "coarseType", get scripts() { throw "ಠ_ಠ"; } } + }); + }, "ಠ_ಠ"); + + assertThrowsValue(() => { + saveHeapSnapshotAndTakeCensus(dbg, { + breakdown: { by: "coarseType", get strings() { throw "ಠ_ಠ"; } } + }); + }, "ಠ_ಠ"); + + assertThrowsValue(() => { + saveHeapSnapshotAndTakeCensus(dbg, { + breakdown: { by: "coarseType", get other() { throw "ಠ_ಠ"; } } + }); + }, "ಠ_ಠ"); + + + + assertThrowsValue(() => { + saveHeapSnapshotAndTakeCensus(dbg, { + breakdown: { by: "internalType", get then() { throw "ಠ_ಠ"; } } + }); + }, "ಠ_ಠ"); + + do_test_finished(); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_08.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_08.js new file mode 100644 index 000000000..5934aa919 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_08.js @@ -0,0 +1,82 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// HeapSnapshot.prototype.takeCensus: test by: 'count' breakdown +// +// Ported from js/src/jit-test/tests/debug/Memory-takeCensus-08.js + +function run_test() { + let g = newGlobal(); + let dbg = new Debugger(g); + + g.eval(` + var stuff = []; + function add(n, c) { + for (let i = 0; i < n; i++) + stuff.push(c()); + } + + let count = 0; + + function obj() { return { count: count++ }; } + obj.factor = 1; + + // This creates a closure (a function JSObject) that has captured + // a Call object. So each call creates two items. + function fun() { let v = count; return () => { return v; } } + fun.factor = 2; + + function str() { return 'perambulator' + count++; } + str.factor = 1; + + // Eval a fresh text each time, allocating: + // - a fresh ScriptSourceObject + // - a new JSScripts, not an eval cache hits + // - a fresh prototype object + // - a fresh Call object, since the eval makes 'ev' heavyweight + // - the new function itself + function ev() { + return eval(\`(function () { return \${ count++ } })\`); + } + ev.factor = 5; + + // A new object (1) with a new shape (2) with a new atom (3) + function shape() { return { [ 'theobroma' + count++ ]: count }; } + shape.factor = 3; + `); + + let baseline = 0; + function countIncreasedByAtLeast(n) { + let oldBaseline = baseline; + + // Since a census counts only reachable objects, one might assume that calling + // GC here would have no effect on the census results. But GC also throws away + // JIT code and any objects it might be holding (template objects, say); + // takeCensus reaches those. Shake everything loose that we can, to make the + // census approximate reachability a bit more closely, and make our results a + // bit more predictable. + gc(g, "shrinking"); + + baseline = saveHeapSnapshotAndTakeCensus(dbg, { breakdown: { by: "count" } }).count; + return baseline >= oldBaseline + n; + } + + countIncreasedByAtLeast(0); + + g.add(100, g.obj); + ok(countIncreasedByAtLeast(g.obj.factor * 100)); + + g.add(100, g.fun); + ok(countIncreasedByAtLeast(g.fun.factor * 100)); + + g.add(100, g.str); + ok(countIncreasedByAtLeast(g.str.factor * 100)); + + g.add(100, g.ev); + ok(countIncreasedByAtLeast(g.ev.factor * 100)); + + g.add(100, g.shape); + ok(countIncreasedByAtLeast(g.shape.factor * 100)); + + do_test_finished(); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_09.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_09.js new file mode 100644 index 000000000..bbacccc8d --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_09.js @@ -0,0 +1,92 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// HeapSnapshot.prototype.takeCensus: by: allocationStack breakdown +// +// Ported from js/src/jit-test/tests/debug/Memory-takeCensus-09.js + +function run_test() { + var g = newGlobal(); + var dbg = new Debugger(g); + + g.eval(` // 1 + var log = []; // 2 + function f() { log.push(allocationMarker()); } // 3 + function g() { f(); } // 4 + function h() { f(); } // 5 + `); // 6 + + // Create one allocationMarker with tracking turned off, + // so it will have no associated stack. + g.f(); + + dbg.memory.allocationSamplingProbability = 1; + + for ([func, n] of [[g.f, 20], [g.g, 10], [g.h, 5]]) { + for (let i = 0; i < n; i++) { + dbg.memory.trackingAllocationSites = true; + // All allocations of allocationMarker occur with this line as the oldest + // stack frame. + func(); + dbg.memory.trackingAllocationSites = false; + } + } + + let census = saveHeapSnapshotAndTakeCensus(dbg, { breakdown: { by: "objectClass", + then: { by: "allocationStack", + then: { by: "count", + label: "haz stack" + }, + noStack: { by: "count", + label: "no haz stack" + } + } + } + }); + + let map = census.AllocationMarker; + ok(map instanceof Map, "Should be a Map instance"); + equal(map.size, 4, "Should have 4 allocation stacks (including the lack of a stack)"); + + // Gather the stacks we are expecting to appear as keys, and + // check that there are no unexpected keys. + let stacks = { }; + + map.forEach((v, k) => { + if (k === "noStack") { + // No need to save this key. + } else if (k.functionDisplayName === "f" && + k.parent.functionDisplayName === "run_test") { + stacks.f = k; + } else if (k.functionDisplayName === "f" && + k.parent.functionDisplayName === "g" && + k.parent.parent.functionDisplayName === "run_test") { + stacks.fg = k; + } else if (k.functionDisplayName === "f" && + k.parent.functionDisplayName === "h" && + k.parent.parent.functionDisplayName === "run_test") { + stacks.fh = k; + } else { + dumpn("Unexpected allocation stack:"); + k.toString().split(/\n/g).forEach(s => dumpn(s)); + ok(false); + } + }); + + equal(map.get("noStack").label, "no haz stack"); + equal(map.get("noStack").count, 1); + + ok(stacks.f); + equal(map.get(stacks.f).label, "haz stack"); + equal(map.get(stacks.f).count, 20); + + ok(stacks.fg); + equal(map.get(stacks.fg).label, "haz stack"); + equal(map.get(stacks.fg).count, 10); + + ok(stacks.fh); + equal(map.get(stacks.fh).label, "haz stack"); + equal(map.get(stacks.fh).count, 5); + + do_test_finished(); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_10.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_10.js new file mode 100644 index 000000000..a7f987f5a --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_10.js @@ -0,0 +1,68 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Check byte counts produced by takeCensus. +// +// Ported from js/src/jit-test/tests/debug/Memory-take Census-10.js + +function run_test() { + let g = newGlobal(); + let dbg = new Debugger(g); + + let sizeOfAM = byteSize(allocationMarker()); + + // Allocate a single allocation marker, and check that we can find it. + g.eval("var hold = allocationMarker();"); + let census = saveHeapSnapshotAndTakeCensus(dbg, { breakdown: { by: "objectClass" } }); + equal(census.AllocationMarker.count, 1); + equal(census.AllocationMarker.bytes, sizeOfAM); + g.hold = null; + + g.eval(` // 1 + var objs = []; // 2 + function fnerd() { // 3 + objs.push(allocationMarker()); // 4 + for (let i = 0; i < 10; i++) // 5 + objs.push(allocationMarker()); // 6 + } // 7 + `); // 8 + + dbg.memory.allocationSamplingProbability = 1; + dbg.memory.trackingAllocationSites = true; + g.fnerd(); + dbg.memory.trackingAllocationSites = false; + + census = saveHeapSnapshotAndTakeCensus(dbg, { + breakdown: { by: "objectClass", + then: { by: "allocationStack" } + } + }); + + let seen = 0; + census.AllocationMarker.forEach((v, k) => { + equal(k.functionDisplayName, "fnerd"); + switch (k.line) { + case 4: + equal(v.count, 1); + equal(v.bytes, sizeOfAM); + seen++; + break; + + case 6: + equal(v.count, 10); + equal(v.bytes, 10 * sizeOfAM); + seen++; + break; + + default: + dumpn("Unexpected stack:"); + k.toString().split(/\n/g).forEach(s => dumpn(s)); + ok(false); + break; + } + }); + + equal(seen, 2); + + do_test_finished(); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_11.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_11.js new file mode 100644 index 000000000..3d898b2d1 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_11.js @@ -0,0 +1,116 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that Debugger.Memory.prototype.takeCensus and +// HeapSnapshot.prototype.takeCensus return the same data for the same heap +// graph. + +function doLiveAndOfflineCensus(g, dbg, opts) { + dbg.memory.allocationSamplingProbability = 1; + dbg.memory.trackingAllocationSites = true; + g.eval(` // 1 + (function unsafeAtAnySpeed() { // 2 + for (var i = 0; i < 100; i++) { // 3 + this.markers.push(allocationMarker()); // 4 + } // 5 + }()); // 6 + `); // 7 + dbg.memory.trackingAllocationSites = false; + + return { + live: dbg.memory.takeCensus(opts), + offline: saveHeapSnapshotAndTakeCensus(dbg, opts) + }; +} + +function run_test() { + var g = newGlobal(); + var dbg = new Debugger(g); + + g.eval("this.markers = []"); + const markerSize = byteSize(allocationMarker()); + + // First, test that we get the same counts and sizes as we allocate and retain + // more things. + + let prevCount = 0; + let prevBytes = 0; + + for (var i = 0; i < 10; i++) { + const { live, offline } = doLiveAndOfflineCensus(g, dbg, { + breakdown: { by: "objectClass", + then: { by: "count"} } + }); + + equal(live.AllocationMarker.count, offline.AllocationMarker.count); + equal(live.AllocationMarker.bytes, offline.AllocationMarker.bytes); + equal(live.AllocationMarker.count, prevCount + 100); + equal(live.AllocationMarker.bytes, prevBytes + 100 * markerSize); + + prevCount = live.AllocationMarker.count; + prevBytes = live.AllocationMarker.bytes; + } + + // Second, test that the reported allocation stacks and counts and sizes at + // those allocation stacks match up. + + const { live, offline } = doLiveAndOfflineCensus(g, dbg, { + breakdown: { by: "objectClass", + then: { by: "allocationStack"} } + }); + + equal(live.AllocationMarker.size, offline.AllocationMarker.size); + // One stack with the loop further above, and another stack featuring the call + // right above. + equal(live.AllocationMarker.size, 2); + + // Note that because SavedFrame stacks reconstructed from an offline heap + // snapshot don't have the same principals as SavedFrame stacks captured from + // a live stack, the live and offline allocation stacks won't be identity + // equal, but should be structurally the same. + + const liveEntries = []; + live.AllocationMarker.forEach((v, k) => { + dumpn("Allocation stack:"); + k.toString().split(/\n/g).forEach(s => dumpn(s)); + + equal(k.functionDisplayName, "unsafeAtAnySpeed"); + equal(k.line, 4); + + liveEntries.push([k.toString(), v]); + }); + + const offlineEntries = []; + offline.AllocationMarker.forEach((v, k) => { + dumpn("Allocation stack:"); + k.toString().split(/\n/g).forEach(s => dumpn(s)); + + equal(k.functionDisplayName, "unsafeAtAnySpeed"); + equal(k.line, 4); + + offlineEntries.push([k.toString(), v]); + }); + + const sortEntries = (a, b) => { + if (a[0] < b[0]) { + return -1; + } else if (a[0] > b[0]) { + return 1; + } else { + return 0; + } + }; + liveEntries.sort(sortEntries); + offlineEntries.sort(sortEntries); + + equal(liveEntries.length, live.AllocationMarker.size); + equal(liveEntries.length, offlineEntries.length); + + for (let i = 0; i < liveEntries.length; i++) { + equal(liveEntries[i][0], offlineEntries[i][0]); + equal(liveEntries[i][1].count, offlineEntries[i][1].count); + equal(liveEntries[i][1].bytes, offlineEntries[i][1].bytes); + } + + do_test_finished(); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_12.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_12.js new file mode 100644 index 000000000..f10dd5b03 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_takeCensus_12.js @@ -0,0 +1,50 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that when we take a census and get a bucket list of ids that matched the +// given category, that the returned ids are all in the snapshot and their +// reported category. + +function run_test() { + const g = newGlobal(); + const dbg = new Debugger(g); + + const path = saveNewHeapSnapshot({ debugger: dbg }); + const snapshot = readHeapSnapshot(path); + + const bucket = { by: "bucket" }; + const count = { by: "count", count: true, bytes: false }; + const objectClassCount = { by: "objectClass", then: count, other: count }; + + const byClassName = snapshot.takeCensus({ + breakdown: { + by: "objectClass", + then: bucket, + other: bucket, + } + }); + + const byClassNameCount = snapshot.takeCensus({ + breakdown: objectClassCount + }); + + const keys = new Set(Object.keys(byClassName)); + equal(keys.size, Object.keys(byClassNameCount).length, + "Should have the same number of keys."); + for (let k of Object.keys(byClassNameCount)) { + ok(keys.has(k), "Should not have any unexpected class names"); + } + + for (let key of Object.keys(byClassName)) { + equal(byClassNameCount[key].count, byClassName[key].length, + "Length of the bucket and count should be equal"); + + for (let id of byClassName[key]) { + const desc = snapshot.describeNode(objectClassCount, id); + equal(desc[key].count, 1, + "Describing the bucketed node confirms that it belongs to the category"); + } + } + + do_test_finished(); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_ReadHeapSnapshot.js b/devtools/shared/heapsnapshot/tests/unit/test_ReadHeapSnapshot.js new file mode 100644 index 000000000..dde139ffd --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_ReadHeapSnapshot.js @@ -0,0 +1,20 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that we can read core dumps into HeapSnapshot instances. + +if (typeof Debugger != "function") { + const { addDebuggerToGlobal } = Cu.import("resource://gre/modules/jsdebugger.jsm", {}); + addDebuggerToGlobal(this); +} + +function run_test() { + const filePath = ChromeUtils.saveHeapSnapshot({ globals: [this] }); + ok(true, "Should be able to save a snapshot."); + + const snapshot = ChromeUtils.readHeapSnapshot(filePath); + ok(snapshot, "Should be able to read a heap snapshot"); + ok(snapshot instanceof HeapSnapshot, "Should be an instanceof HeapSnapshot"); + + do_test_finished(); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_ReadHeapSnapshot_with_allocations.js b/devtools/shared/heapsnapshot/tests/unit/test_ReadHeapSnapshot_with_allocations.js new file mode 100644 index 000000000..d91f36f56 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_ReadHeapSnapshot_with_allocations.js @@ -0,0 +1,36 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that we can save a core dump with allocation stacks and read it back +// into a HeapSnapshot. + +if (typeof Debugger != "function") { + const { addDebuggerToGlobal } = Cu.import("resource://gre/modules/jsdebugger.jsm", {}); + addDebuggerToGlobal(this); +} + +function run_test() { + // Create a Debugger observing a debuggee's allocations. + const debuggee = new Cu.Sandbox(null); + const dbg = new Debugger(debuggee); + dbg.memory.trackingAllocationSites = true; + + // Allocate some objects in the debuggee that will have their allocation + // stacks recorded by the Debugger. + debuggee.eval("this.objects = []"); + for (let i = 0; i < 100; i++) { + debuggee.eval("this.objects.push({})"); + } + + // Now save a snapshot that will include the allocation stacks and read it + // back again. + + const filePath = ChromeUtils.saveHeapSnapshot({ runtime: true }); + ok(true, "Should be able to save a snapshot."); + + const snapshot = ChromeUtils.readHeapSnapshot(filePath); + ok(snapshot, "Should be able to read a heap snapshot"); + ok(snapshot instanceof HeapSnapshot, "Should be an instanceof HeapSnapshot"); + + do_test_finished(); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_ReadHeapSnapshot_worker.js b/devtools/shared/heapsnapshot/tests/unit/test_ReadHeapSnapshot_worker.js new file mode 100644 index 000000000..76461b694 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_ReadHeapSnapshot_worker.js @@ -0,0 +1,40 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that we can read core dumps into HeapSnapshot instances in a worker. + +add_task(function* () { + const worker = new ChromeWorker("resource://test/heap-snapshot-worker.js"); + worker.postMessage({}); + + let assertionCount = 0; + worker.onmessage = e => { + if (e.data.type !== "assertion") { + return; + } + + ok(e.data.passed, e.data.msg + "\n" + e.data.stack); + assertionCount++; + }; + + yield waitForDone(worker); + + ok(assertionCount > 0); + worker.terminate(); +}); + +function waitForDone(w) { + return new Promise((resolve, reject) => { + w.onerror = e => { + reject(); + ok(false, "Error in worker: " + e); + }; + + w.addEventListener("message", function listener(e) { + if (e.data.type === "done") { + w.removeEventListener("message", listener, false); + resolve(); + } + }, false); + }); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_SaveHeapSnapshot.js b/devtools/shared/heapsnapshot/tests/unit/test_SaveHeapSnapshot.js new file mode 100644 index 000000000..affd8d1e4 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_SaveHeapSnapshot.js @@ -0,0 +1,82 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test the ChromeUtils interface. + +if (typeof Debugger != "function") { + const { addDebuggerToGlobal } = Cu.import("resource://gre/modules/jsdebugger.jsm", {}); + addDebuggerToGlobal(this); +} + +function run_test() { + ok(ChromeUtils, "Should be able to get the ChromeUtils interface"); + + testBadParameters(); + testGoodParameters(); + + do_test_finished(); +} + +function testBadParameters() { + throws(() => ChromeUtils.saveHeapSnapshot(), + "Should throw if arguments aren't passed in."); + + throws(() => ChromeUtils.saveHeapSnapshot(null), + "Should throw if boundaries isn't an object."); + + throws(() => ChromeUtils.saveHeapSnapshot({}), + "Should throw if the boundaries object doesn't have any properties."); + + throws(() => ChromeUtils.saveHeapSnapshot({ runtime: true, + globals: [this] }), + "Should throw if the boundaries object has more than one property."); + + throws(() => ChromeUtils.saveHeapSnapshot({ debugger: {} }), + "Should throw if the debuggees object is not a Debugger object"); + + throws(() => ChromeUtils.saveHeapSnapshot({ globals: [{}] }), + "Should throw if the globals array contains non-global objects."); + + throws(() => ChromeUtils.saveHeapSnapshot({ runtime: false }), + "Should throw if runtime is supplied and is not true."); + + throws(() => ChromeUtils.saveHeapSnapshot({ globals: null }), + "Should throw if globals is not an object."); + + throws(() => ChromeUtils.saveHeapSnapshot({ globals: {} }), + "Should throw if globals is not an array."); + + throws(() => ChromeUtils.saveHeapSnapshot({ debugger: Debugger.prototype }), + "Should throw if debugger is the Debugger.prototype object."); + + throws(() => ChromeUtils.saveHeapSnapshot({ get globals() { return [this]; } }), + "Should throw if boundaries property is a getter."); +} + +const makeNewSandbox = () => + Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")()); + +function testGoodParameters() { + let sandbox = makeNewSandbox(); + let dbg = new Debugger(sandbox); + + ChromeUtils.saveHeapSnapshot({ debugger: dbg }); + ok(true, "Should be able to save a snapshot for a debuggee global."); + + dbg = new Debugger; + let sandboxes = Array(10).fill(null).map(makeNewSandbox); + sandboxes.forEach(sb => dbg.addDebuggee(sb)); + + ChromeUtils.saveHeapSnapshot({ debugger: dbg }); + ok(true, "Should be able to save a snapshot for many debuggee globals."); + + dbg = new Debugger; + ChromeUtils.saveHeapSnapshot({ debugger: dbg }); + ok(true, "Should be able to save a snapshot with no debuggee globals."); + + ChromeUtils.saveHeapSnapshot({ globals: [this] }); + ok(true, "Should be able to save a snapshot for a specific global."); + + ChromeUtils.saveHeapSnapshot({ runtime: true }); + ok(true, "Should be able to save a snapshot of the full runtime."); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-01.js b/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-01.js new file mode 100644 index 000000000..16038c5c4 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-01.js @@ -0,0 +1,76 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * Tests CensusTreeNode with `internalType` breakdown. + */ + +const BREAKDOWN = { + by: "internalType", + then: { by: "count", count: true, bytes: true } +}; + +const REPORT = { + "JSObject": { + "bytes": 100, + "count": 10, + }, + "js::Shape": { + "bytes": 500, + "count": 50, + }, + "JSString": { + "bytes": 10, + "count": 1, + }, +}; + +const EXPECTED = { + name: null, + bytes: 0, + totalBytes: 610, + count: 0, + totalCount: 61, + children: [ + { + name: "js::Shape", + bytes: 500, + totalBytes: 500, + count: 50, + totalCount: 50, + children: undefined, + id: 3, + parent: 1, + reportLeafIndex: 2, + }, + { + name: "JSObject", + bytes: 100, + totalBytes: 100, + count: 10, + totalCount: 10, + children: undefined, + id: 2, + parent: 1, + reportLeafIndex: 1, + }, + { + name: "JSString", + bytes: 10, + totalBytes: 10, + count: 1, + totalCount: 1, + children: undefined, + id: 4, + parent: 1, + reportLeafIndex: 3, + }, + ], + id: 1, + parent: undefined, + reportLeafIndex: undefined, +}; + +function run_test() { + compareCensusViewData(BREAKDOWN, REPORT, EXPECTED); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-02.js b/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-02.js new file mode 100644 index 000000000..37d039954 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-02.js @@ -0,0 +1,136 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * Tests CensusTreeNode with `coarseType` breakdown. + */ + +const countBreakdown = { by: "count", count: true, bytes: true }; + +const BREAKDOWN = { + by: "coarseType", + objects: { by: "objectClass", then: countBreakdown }, + strings: countBreakdown, + scripts: countBreakdown, + other: { by: "internalType", then: countBreakdown }, +}; + +const REPORT = { + "objects": { + "Function": { bytes: 10, count: 1 }, + "Array": { bytes: 20, count: 2 }, + }, + "strings": { bytes: 10, count: 1 }, + "scripts": { bytes: 1, count: 1 }, + "other": { + "js::Shape": { bytes: 30, count: 3 }, + "js::Shape2": { bytes: 40, count: 4 } + }, +}; + +const EXPECTED = { + name: null, + bytes: 0, + totalBytes: 111, + count: 0, + totalCount: 12, + children: [ + { + name: "other", + count: 0, + totalCount: 7, + bytes: 0, + totalBytes: 70, + children: [ + { + name: "js::Shape2", + bytes: 40, + totalBytes: 40, + count: 4, + totalCount: 4, + children: undefined, + id: 9, + parent: 7, + reportLeafIndex: 8, + }, + { + name: "js::Shape", + bytes: 30, + totalBytes: 30, + count: 3, + totalCount: 3, + children: undefined, + id: 8, + parent: 7, + reportLeafIndex: 7, + }, + ], + id: 7, + parent: 1, + reportLeafIndex: undefined, + }, + { + name: "objects", + count: 0, + totalCount: 3, + bytes: 0, + totalBytes: 30, + children: [ + { + name: "Array", + bytes: 20, + totalBytes: 20, + count: 2, + totalCount: 2, + children: undefined, + id: 4, + parent: 2, + reportLeafIndex: 3, + }, + { + name: "Function", + bytes: 10, + totalBytes: 10, + count: 1, + totalCount: 1, + children: undefined, + id: 3, + parent: 2, + reportLeafIndex: 2, + }, + ], + id: 2, + parent: 1, + reportLeafIndex: undefined, + }, + { + name: "strings", + count: 1, + totalCount: 1, + bytes: 10, + totalBytes: 10, + children: undefined, + id: 6, + parent: 1, + reportLeafIndex: 5, + }, + { + name: "scripts", + count: 1, + totalCount: 1, + bytes: 1, + totalBytes: 1, + children: undefined, + id: 5, + parent: 1, + reportLeafIndex: 4, + }, + ], + id: 1, + parent: undefined, + reportLeafIndex: undefined, +}; + +function run_test() { + compareCensusViewData(BREAKDOWN, REPORT, EXPECTED); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-03.js b/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-03.js new file mode 100644 index 000000000..bdf932099 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-03.js @@ -0,0 +1,96 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * Tests CensusTreeNode with `objectClass` breakdown. + */ + +const countBreakdown = { by: "count", count: true, bytes: true }; + +const BREAKDOWN = { + by: "objectClass", + then: countBreakdown, + other: { by: "internalType", then: countBreakdown } +}; + +const REPORT = { + "Function": { bytes: 10, count: 10 }, + "Array": { bytes: 100, count: 1 }, + "other": { + "JIT::CODE::NOW!!!": { bytes: 20, count: 2 }, + "JIT::CODE::LATER!!!": { bytes: 40, count: 4 } + } +}; + +const EXPECTED = { + name: null, + count: 0, + totalCount: 17, + bytes: 0, + totalBytes: 170, + children: [ + { + name: "Array", + bytes: 100, + totalBytes: 100, + count: 1, + totalCount: 1, + children: undefined, + id: 3, + parent: 1, + reportLeafIndex: 2, + }, + { + name: "other", + count: 0, + totalCount: 6, + bytes: 0, + totalBytes: 60, + children: [ + { + name: "JIT::CODE::LATER!!!", + bytes: 40, + totalBytes: 40, + count: 4, + totalCount: 4, + children: undefined, + id: 6, + parent: 4, + reportLeafIndex: 5, + }, + { + name: "JIT::CODE::NOW!!!", + bytes: 20, + totalBytes: 20, + count: 2, + totalCount: 2, + children: undefined, + id: 5, + parent: 4, + reportLeafIndex: 4, + }, + ], + id: 4, + parent: 1, + reportLeafIndex: undefined, + }, + { + name: "Function", + bytes: 10, + totalBytes: 10, + count: 10, + totalCount: 10, + children: undefined, + id: 2, + parent: 1, + reportLeafIndex: 1, + }, + ], + id: 1, + parent: undefined, + reportLeafIndex: undefined, +}; + +function run_test() { + compareCensusViewData(BREAKDOWN, REPORT, EXPECTED); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-04.js b/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-04.js new file mode 100644 index 000000000..cc0c3bac0 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-04.js @@ -0,0 +1,159 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * Tests CensusTreeNode with `allocationStack` breakdown. + */ + +function run_test() { + const countBreakdown = { by: "count", count: true, bytes: true }; + + const BREAKDOWN = { + by: "allocationStack", + then: countBreakdown, + noStack: countBreakdown, + }; + + let stack1, stack2, stack3, stack4, stack5; + + (function a() { + (function b() { + (function c() { + stack1 = saveStack(3); + }()); + (function d() { + stack2 = saveStack(3); + stack3 = saveStack(3); + }()); + stack4 = saveStack(2); + }()); + }()); + + stack5 = saveStack(1); + + const REPORT = new Map([ + [stack1, { bytes: 10, count: 1 }], + [stack2, { bytes: 20, count: 2 }], + [stack3, { bytes: 30, count: 3 }], + [stack4, { bytes: 40, count: 4 }], + [stack5, { bytes: 50, count: 5 }], + ["noStack", { bytes: 60, count: 6 }], + ]); + + const EXPECTED = { + name: null, + bytes: 0, + totalBytes: 210, + count: 0, + totalCount: 21, + children: [ + { + name: stack4.parent, + bytes: 0, + totalBytes: 100, + count: 0, + totalCount: 10, + children: [ + { + name: stack3.parent, + bytes: 0, + totalBytes: 50, + count: 0, + totalCount: 5, + children: [ + { + name: stack3, + bytes: 30, + totalBytes: 30, + count: 3, + totalCount: 3, + children: undefined, + id: 7, + parent: 5, + reportLeafIndex: 3, + }, + { + name: stack2, + bytes: 20, + totalBytes: 20, + count: 2, + totalCount: 2, + children: undefined, + id: 6, + parent: 5, + reportLeafIndex: 2, + } + ], + id: 5, + parent: 2, + reportLeafIndex: undefined, + }, + { + name: stack4, + bytes: 40, + totalBytes: 40, + count: 4, + totalCount: 4, + children: undefined, + id: 8, + parent: 2, + reportLeafIndex: 4, + }, + { + name: stack1.parent, + bytes: 0, + totalBytes: 10, + count: 0, + totalCount: 1, + children: [ + { + name: stack1, + bytes: 10, + totalBytes: 10, + count: 1, + totalCount: 1, + children: undefined, + id: 4, + parent: 3, + reportLeafIndex: 1, + }, + ], + id: 3, + parent: 2, + reportLeafIndex: undefined, + }, + ], + id: 2, + parent: 1, + reportLeafIndex: undefined, + }, + { + name: "noStack", + bytes: 60, + totalBytes: 60, + count: 6, + totalCount: 6, + children: undefined, + id: 10, + parent: 1, + reportLeafIndex: 6, + }, + { + name: stack5, + bytes: 50, + totalBytes: 50, + count: 5, + totalCount: 5, + children: undefined, + id: 9, + parent: 1, + reportLeafIndex: 5 + }, + ], + id: 1, + parent: undefined, + reportLeafIndex: undefined, + }; + + compareCensusViewData(BREAKDOWN, REPORT, EXPECTED); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-05.js b/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-05.js new file mode 100644 index 000000000..20fb76bd2 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-05.js @@ -0,0 +1,145 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * Tests CensusTreeNode with `allocationStack` => `objectClass` breakdown. + */ + +function run_test() { + const countBreakdown = { by: "count", count: true, bytes: true }; + + const BREAKDOWN = { + by: "allocationStack", + then: { + by: "objectClass", + then: countBreakdown, + other: countBreakdown + }, + noStack: countBreakdown, + }; + + let stack; + + (function a() { + (function b() { + (function c() { + stack = saveStack(3); + }()); + }()); + }()); + + const REPORT = new Map([ + [stack, { Foo: { bytes: 10, count: 1 }, + Bar: { bytes: 20, count: 2 }, + Baz: { bytes: 30, count: 3 }, + other: { bytes: 40, count: 4 } + }], + ["noStack", { bytes: 50, count: 5 }], + ]); + + const EXPECTED = { + name: null, + bytes: 0, + totalBytes: 150, + count: 0, + totalCount: 15, + children: [ + { + name: stack.parent.parent, + bytes: 0, + totalBytes: 100, + count: 0, + totalCount: 10, + children: [ + { + name: stack.parent, + bytes: 0, + totalBytes: 100, + count: 0, + totalCount: 10, + children: [ + { + name: stack, + bytes: 0, + totalBytes: 100, + count: 0, + totalCount: 10, + children: [ + { + name: "other", + bytes: 40, + totalBytes: 40, + count: 4, + totalCount: 4, + children: undefined, + id: 8, + parent: 4, + reportLeafIndex: 5, + }, + { + name: "Baz", + bytes: 30, + totalBytes: 30, + count: 3, + totalCount: 3, + children: undefined, + id: 7, + parent: 4, + reportLeafIndex: 4, + }, + { + name: "Bar", + bytes: 20, + totalBytes: 20, + count: 2, + totalCount: 2, + children: undefined, + id: 6, + parent: 4, + reportLeafIndex: 3, + }, + { + name: "Foo", + bytes: 10, + totalBytes: 10, + count: 1, + totalCount: 1, + children: undefined, + id: 5, + parent: 4, + reportLeafIndex: 2, + }, + ], + id: 4, + parent: 3, + reportLeafIndex: undefined, + } + ], + id: 3, + parent: 2, + reportLeafIndex: undefined, + } + ], + id: 2, + parent: 1, + reportLeafIndex: undefined, + }, + { + name: "noStack", + bytes: 50, + totalBytes: 50, + count: 5, + totalCount: 5, + children: undefined, + id: 9, + parent: 1, + reportLeafIndex: 6, + }, + ], + id: 1, + parent: undefined, + reportLeafIndex: undefined, + }; + + compareCensusViewData(BREAKDOWN, REPORT, EXPECTED); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-06.js b/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-06.js new file mode 100644 index 000000000..eb1801207 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-06.js @@ -0,0 +1,200 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * Test inverting CensusTreeNode with a by alloaction stack breakdown. + */ + +function run_test() { + const BREAKDOWN = { + by: "allocationStack", + then: { by: "count", count: true, bytes: true }, + noStack: { by: "count", count: true, bytes: true }, + }; + + let stack1, stack2, stack3, stack4; + + function a(n) { + return b(n); + } + function b(n) { + return c(n); + } + function c(n) { + return saveStack(n); + } + function d(n) { + return b(n); + } + function e(n) { + return c(n); + } + + const abc_Stack = a(3); + const bc_Stack = b(2); + const c_Stack = c(1); + const dbc_Stack = d(3); + const ec_Stack = e(2); + + const REPORT = new Map([ + [abc_Stack, { bytes: 10, count: 1 }], + [ bc_Stack, { bytes: 10, count: 1 }], + [ c_Stack, { bytes: 10, count: 1 }], + [dbc_Stack, { bytes: 10, count: 1 }], + [ ec_Stack, { bytes: 10, count: 1 }], + ["noStack", { bytes: 50, count: 5 }], + ]); + + const EXPECTED = { + name: null, + bytes: 0, + totalBytes: 100, + count: 0, + totalCount: 10, + children: [ + { + name: "noStack", + bytes: 50, + totalBytes: 50, + count: 5, + totalCount: 5, + children: [ + { + name: null, + bytes: 0, + totalBytes: 100, + count: 0, + totalCount: 10, + children: undefined, + id: 16, + parent: 15, + reportLeafIndex: undefined, + } + ], + id: 15, + parent: 14, + reportLeafIndex: 6, + }, + { + name: abc_Stack, + bytes: 50, + totalBytes: 10, + count: 5, + totalCount: 1, + children: [ + { + name: null, + bytes: 0, + totalBytes: 100, + count: 0, + totalCount: 10, + children: undefined, + id: 18, + parent: 17, + reportLeafIndex: undefined, + }, + { + name: abc_Stack.parent, + bytes: 0, + totalBytes: 10, + count: 0, + totalCount: 1, + children: [ + { + name: null, + bytes: 0, + totalBytes: 100, + count: 0, + totalCount: 10, + children: undefined, + id: 22, + parent: 19, + reportLeafIndex: undefined, + }, + { + name: abc_Stack.parent.parent, + bytes: 0, + totalBytes: 10, + count: 0, + totalCount: 1, + children: [ + { + name: null, + bytes: 0, + totalBytes: 100, + count: 0, + totalCount: 10, + children: undefined, + id: 21, + parent: 20, + reportLeafIndex: undefined, + } + ], + id: 20, + parent: 19, + reportLeafIndex: undefined, + }, + { + name: dbc_Stack.parent.parent, + bytes: 0, + totalBytes: 10, + count: 0, + totalCount: 1, + children: [ + { + name: null, + bytes: 0, + totalBytes: 100, + count: 0, + totalCount: 10, + children: undefined, + id: 24, + parent: 23, + reportLeafIndex: undefined, + } + ], + id: 23, + parent: 19, + reportLeafIndex: undefined, + } + ], + id: 19, + parent: 17, + reportLeafIndex: undefined, + }, + { + name: ec_Stack.parent, + bytes: 0, + totalBytes: 10, + count: 0, + totalCount: 1, + children: [ + { + name: null, + bytes: 0, + totalBytes: 100, + count: 0, + totalCount: 10, + children: undefined, + id: 26, + parent: 25, + reportLeafIndex: undefined, + }, + ], + id: 25, + parent: 17, + reportLeafIndex: undefined, + }, + ], + id: 17, + parent: 14, + reportLeafIndex: new Set([1, 2, 3, 4, 5]), + } + ], + id: 14, + parent: undefined, + reportLeafIndex: undefined, + }; + + compareCensusViewData(BREAKDOWN, REPORT, EXPECTED, { invert: true }); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-07.js b/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-07.js new file mode 100644 index 000000000..6bc085257 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-07.js @@ -0,0 +1,200 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * Test inverting CensusTreeNode with a non-allocation stack breakdown. + */ + +function run_test() { + const BREAKDOWN = { + by: "coarseType", + objects: { + by: "objectClass", + then: { by: "count", count: true, bytes: true }, + other: { by: "count", count: true, bytes: true }, + }, + scripts: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + strings: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + other:{ + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + }; + + const REPORT = { + objects: { + Array: { bytes: 50, count: 5 }, + other: { bytes: 0, count: 0 }, + }, + scripts: { + "js::jit::JitScript": { bytes: 30, count: 3 }, + }, + strings: { + JSAtom: { bytes: 60, count: 6 }, + }, + other: { + "js::Shape": { bytes: 80, count: 8 }, + } + }; + + const EXPECTED = { + name: null, + bytes: 0, + totalBytes: 220, + count: 0, + totalCount: 22, + children: [ + { + name: "js::Shape", + bytes: 80, + totalBytes: 80, + count: 8, + totalCount: 8, + children: [ + { + name: "other", + bytes: 0, + totalBytes: 80, + count: 0, + totalCount: 8, + children: [ + { + name: null, + bytes: 0, + totalBytes: 220, + count: 0, + totalCount: 22, + children: undefined, + id: 14, + parent: 13, + reportLeafIndex: undefined, + } + ], + id: 13, + parent: 12, + reportLeafIndex: undefined, + } + ], + id: 12, + parent: 11, + reportLeafIndex: 9, + }, + { + name: "JSAtom", + bytes: 60, + totalBytes: 60, + count: 6, + totalCount: 6, + children: [ + { + name: "strings", + bytes: 0, + totalBytes: 60, + count: 0, + totalCount: 6, + children: [ + { + name: null, + bytes: 0, + totalBytes: 220, + count: 0, + totalCount: 22, + children: undefined, + id: 17, + parent: 16, + reportLeafIndex: undefined, + } + ], + id: 16, + parent: 15, + reportLeafIndex: undefined, + } + ], + id: 15, + parent: 11, + reportLeafIndex: 7, + }, + { + name: "Array", + bytes: 50, + totalBytes: 50, + count: 5, + totalCount: 5, + children: [ + { + name: "objects", + bytes: 0, + totalBytes: 50, + count: 0, + totalCount: 5, + children: [ + { + name: null, + bytes: 0, + totalBytes: 220, + count: 0, + totalCount: 22, + children: undefined, + id: 20, + parent: 19, + reportLeafIndex: undefined, + } + ], + id: 19, + parent: 18, + reportLeafIndex: undefined, + } + ], + id: 18, + parent: 11, + reportLeafIndex: 2, + }, + { + name: "js::jit::JitScript", + bytes: 30, + totalBytes: 30, + count: 3, + totalCount: 3, + children: [ + { + name: "scripts", + bytes: 0, + totalBytes: 30, + count: 0, + totalCount: 3, + children: [ + { + name: null, + bytes: 0, + totalBytes: 220, + count: 0, + totalCount: 22, + children: undefined, + id: 23, + parent: 22, + reportLeafIndex: undefined, + } + ], + id: 22, + parent: 21, + reportLeafIndex: undefined, + } + ], + id: 21, + parent: 11, + reportLeafIndex: 5, + }, + ], + id: 11, + parent: undefined, + reportLeafIndex: undefined, + }; + + compareCensusViewData(BREAKDOWN, REPORT, EXPECTED, { invert: true }); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-08.js b/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-08.js new file mode 100644 index 000000000..1c686c810 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-08.js @@ -0,0 +1,142 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * Test inverting CensusTreeNode with a non-allocation stack breakdown. + */ + +function run_test() { + const BREAKDOWN = { + by: "filename", + then: { + by: "internalType", + then: { by: "count", count: true, bytes: true } + }, + noFilename: { + by: "internalType", + then: { by: "count", count: true, bytes: true } + }, + }; + + const REPORT = { + "http://example.com/app.js": { + JSScript: { count: 10, bytes: 100 } + }, + "http://example.com/ads.js": { + "js::LazyScript": { count: 20, bytes: 200 } + }, + "http://example.com/trackers.js": { + JSScript: { count: 30, bytes: 300 } + }, + noFilename: { + "js::jit::JitCode": { count: 40, bytes: 400 } + } + }; + + const EXPECTED = { + name: null, + bytes: 0, + totalBytes: 1000, + count: 0, + totalCount: 100, + children: [ + { + name: "noFilename", + bytes: 0, + totalBytes: 400, + count: 0, + totalCount: 40, + children: [ + { + name: "js::jit::JitCode", + bytes: 400, + totalBytes: 400, + count: 40, + totalCount: 40, + children: undefined, + id: 9, + parent: 8, + reportLeafIndex: 8, + } + ], + id: 8, + parent: 1, + reportLeafIndex: undefined, + }, + { + name: "http://example.com/trackers.js", + bytes: 0, + totalBytes: 300, + count: 0, + totalCount: 30, + children: [ + { + name: "JSScript", + bytes: 300, + totalBytes: 300, + count: 30, + totalCount: 30, + children: undefined, + id: 7, + parent: 6, + reportLeafIndex: 6, + } + ], + id: 6, + parent: 1, + reportLeafIndex: undefined, + }, + { + name: "http://example.com/ads.js", + bytes: 0, + totalBytes: 200, + count: 0, + totalCount: 20, + children: [ + { + name: "js::LazyScript", + bytes: 200, + totalBytes: 200, + count: 20, + totalCount: 20, + children: undefined, + id: 5, + parent: 4, + reportLeafIndex: 4, + } + ], + id: 4, + parent: 1, + reportLeafIndex: undefined, + }, + { + name: "http://example.com/app.js", + bytes: 0, + totalBytes: 100, + count: 0, + totalCount: 10, + children: [ + { + name: "JSScript", + bytes: 100, + totalBytes: 100, + count: 10, + totalCount: 10, + children: undefined, + id: 3, + parent: 2, + reportLeafIndex: 2, + } + ], + id: 2, + parent: 1, + reportLeafIndex: undefined, + } + ], + id: 1, + parent: undefined, + reportLeafIndex: undefined, + }; + + compareCensusViewData(BREAKDOWN, REPORT, EXPECTED); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-09.js b/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-09.js new file mode 100644 index 000000000..3efed04b0 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-09.js @@ -0,0 +1,44 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +/** + * Test that repeatedly converting the same census report to a CensusTreeNode + * tree results in the same CensusTreeNode tree. + */ + +function run_test() { + const BREAKDOWN = { + by: "filename", + then: { + by: "internalType", + then: { by: "count", count: true, bytes: true } + }, + noFilename: { + by: "internalType", + then: { by: "count", count: true, bytes: true } + }, + }; + + const REPORT = { + "http://example.com/app.js": { + JSScript: { count: 10, bytes: 100 } + }, + "http://example.com/ads.js": { + "js::LazyScript": { count: 20, bytes: 200 } + }, + "http://example.com/trackers.js": { + JSScript: { count: 30, bytes: 300 } + }, + noFilename: { + "js::jit::JitCode": { count: 40, bytes: 400 } + } + }; + + const first = censusReportToCensusTreeNode(BREAKDOWN, REPORT); + const second = censusReportToCensusTreeNode(BREAKDOWN, REPORT); + const third = censusReportToCensusTreeNode(BREAKDOWN, REPORT); + + assertStructurallyEquivalent(first, second); + assertStructurallyEquivalent(second, third); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-10.js b/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-10.js new file mode 100644 index 000000000..b7798f23f --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_census-tree-node-10.js @@ -0,0 +1,43 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +/** + * Test when multiple leaves in the census report map to the same node in an + * inverted CensusReportTree. + */ + +function run_test() { + const BREAKDOWN = { + by: "coarseType", + objects: { + by: "objectClass", + then: { by: "count", count: true, bytes: true }, + }, + other: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + strings: { by: "count", count: true, bytes: true }, + scripts: { by: "count", count: true, bytes: true }, + }; + + const REPORT = { + objects: { + Array: { count: 1, bytes: 10 }, + }, + other: { + Array: { count: 1, bytes: 10 }, + }, + strings: { count: 0, bytes: 0 }, + scripts: { count: 0, bytes: 0 }, + }; + + const node = censusReportToCensusTreeNode(BREAKDOWN, REPORT, { invert: true }); + + equal(node.children[0].name, "Array"); + equal(node.children[0].reportLeafIndex.size, 2); + dumpn(`node.children[0].reportLeafIndex = ${[...node.children[0].reportLeafIndex]}`); + ok(node.children[0].reportLeafIndex.has(2)); + ok(node.children[0].reportLeafIndex.has(6)); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_census_diff_01.js b/devtools/shared/heapsnapshot/tests/unit/test_census_diff_01.js new file mode 100644 index 000000000..75977bccb --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_census_diff_01.js @@ -0,0 +1,74 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test diffing census reports of breakdown by "internalType". + +const BREAKDOWN = { + by: "internalType", + then: { by: "count", count: true, bytes: true } +}; + +const REPORT1 = { + "JSObject": { + "count": 10, + "bytes": 100, + }, + "js::Shape": { + "count": 50, + "bytes": 500, + }, + "JSString": { + "count": 0, + "bytes": 0, + }, + "js::LazyScript": { + "count": 1, + "bytes": 10, + }, +}; + +const REPORT2 = { + "JSObject": { + "count": 11, + "bytes": 110, + }, + "js::Shape": { + "count": 51, + "bytes": 510, + }, + "JSString": { + "count": 1, + "bytes": 1, + }, + "js::BaseShape": { + "count": 1, + "bytes": 42, + }, +}; + +const EXPECTED = { + "JSObject": { + "count": 1, + "bytes": 10, + }, + "js::Shape": { + "count": 1, + "bytes": 10, + }, + "JSString": { + "count": 1, + "bytes": 1, + }, + "js::LazyScript": { + "count": -1, + "bytes": -10, + }, + "js::BaseShape": { + "count": 1, + "bytes": 42, + }, +}; + +function run_test() { + assertDiff(BREAKDOWN, REPORT1, REPORT2, EXPECTED); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_census_diff_02.js b/devtools/shared/heapsnapshot/tests/unit/test_census_diff_02.js new file mode 100644 index 000000000..169e3f036 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_census_diff_02.js @@ -0,0 +1,25 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test diffing census reports of breakdown by "count". + +const BREAKDOWN = { by: "count", count: true, bytes: true }; + +const REPORT1 = { + "count": 10, + "bytes": 100, +}; + +const REPORT2 = { + "count": 11, + "bytes": 110, +}; + +const EXPECTED = { + "count": 1, + "bytes": 10, +}; + +function run_test() { + assertDiff(BREAKDOWN, REPORT1, REPORT2, EXPECTED); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_census_diff_03.js b/devtools/shared/heapsnapshot/tests/unit/test_census_diff_03.js new file mode 100644 index 000000000..6dbca3e40 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_census_diff_03.js @@ -0,0 +1,73 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test diffing census reports of breakdown by "coarseType". + +const BREAKDOWN = { + by: "coarseType", + objects: { by: "count", count: true, bytes: true }, + scripts: { by: "count", count: true, bytes: true }, + strings: { by: "count", count: true, bytes: true }, + other: { by: "count", count: true, bytes: true }, +}; + +const REPORT1 = { + objects: { + count: 1, + bytes: 10, + }, + scripts: { + count: 1, + bytes: 10, + }, + strings: { + count: 1, + bytes: 10, + }, + other: { + count: 3, + bytes: 30, + }, +}; + +const REPORT2 = { + objects: { + count: 1, + bytes: 10, + }, + scripts: { + count: 0, + bytes: 0, + }, + strings: { + count: 2, + bytes: 20, + }, + other: { + count: 4, + bytes: 40, + }, +}; + +const EXPECTED = { + objects: { + count: 0, + bytes: 0, + }, + scripts: { + count: -1, + bytes: -10, + }, + strings: { + count: 1, + bytes: 10, + }, + other: { + count: 1, + bytes: 10, + }, +}; + +function run_test() { + assertDiff(BREAKDOWN, REPORT1, REPORT2, EXPECTED); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_census_diff_04.js b/devtools/shared/heapsnapshot/tests/unit/test_census_diff_04.js new file mode 100644 index 000000000..a10097945 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_census_diff_04.js @@ -0,0 +1,63 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test diffing census reports of breakdown by "objectClass". + +const BREAKDOWN = { + by: "objectClass", + then: { by: "count", count: true, bytes: true }, + other: { by: "count", count: true, bytes: true }, +}; + +const REPORT1 = { + "Array": { + count: 1, + bytes: 100, + }, + "Function": { + count: 10, + bytes: 10, + }, + "other": { + count: 10, + bytes: 100, + } +}; + +const REPORT2 = { + "Object": { + count: 1, + bytes: 100, + }, + "Function": { + count: 20, + bytes: 20, + }, + "other": { + count: 10, + bytes: 100, + } +}; + +const EXPECTED = { + "Array": { + count: -1, + bytes: -100, + }, + "Function": { + count: 10, + bytes: 10, + }, + "other": { + count: 0, + bytes: 0, + }, + "Object": { + count: 1, + bytes: 100, + }, +}; + +function run_test() { + assertDiff(BREAKDOWN, REPORT1, REPORT2, EXPECTED); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_census_diff_05.js b/devtools/shared/heapsnapshot/tests/unit/test_census_diff_05.js new file mode 100644 index 000000000..b6d99f823 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_census_diff_05.js @@ -0,0 +1,34 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test diffing census reports of breakdown by "allocationStack". + +const BREAKDOWN = { + by: "allocationStack", + then: { by: "count", count: true, bytes: true }, + noStack: { by: "count", count: true, bytes: true }, +}; + +const stack1 = saveStack(); +const stack2 = saveStack(); +const stack3 = saveStack(); + +const REPORT1 = new Map([ + [stack1, { "count": 10, "bytes": 100 }], + [stack2, { "count": 1, "bytes": 10 }], +]); + +const REPORT2 = new Map([ + [stack2, { "count": 10, "bytes": 100 }], + [stack3, { "count": 1, "bytes": 10 }], +]); + +const EXPECTED = new Map([ + [stack1, { "count": -10, "bytes": -100 }], + [stack2, { "count": 9, "bytes": 90 }], + [stack3, { "count": 1, "bytes": 10 }], +]); + +function run_test() { + assertDiff(BREAKDOWN, REPORT1, REPORT2, EXPECTED); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_census_diff_06.js b/devtools/shared/heapsnapshot/tests/unit/test_census_diff_06.js new file mode 100644 index 000000000..430ff8c9c --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_census_diff_06.js @@ -0,0 +1,137 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test diffing census reports of a "complex" and "realistic" breakdown. + +const BREAKDOWN = { + by: "coarseType", + objects: { + by: "allocationStack", + then: { + by: "objectClass", + then: { by: "count", count: false, bytes: true }, + other: { by: "count", count: false, bytes: true } + }, + noStack: { + by: "objectClass", + then: { by: "count", count: false, bytes: true }, + other: { by: "count", count: false, bytes: true } + } + }, + strings: { + by: "internalType", + then: { by: "count", count: false, bytes: true } + }, + scripts: { + by: "internalType", + then: { by: "count", count: false, bytes: true } + }, + other: { + by: "internalType", + then: { by: "count", count: false, bytes: true } + }, +}; + +const stack1 = saveStack(); +const stack2 = saveStack(); +const stack3 = saveStack(); + +const REPORT1 = { + objects: new Map([ + [stack1, { Function: { bytes: 1 }, + Object: { bytes: 2 }, + other: { bytes: 0 }, + }], + [stack2, { Array: { bytes: 3 }, + Date: { bytes: 4 }, + other: { bytes: 0 }, + }], + ["noStack", { Object: { bytes: 3 }}], + ]), + strings: { + JSAtom: { bytes: 10 }, + JSLinearString: { bytes: 5 }, + }, + scripts: { + JSScript: { bytes: 1 }, + "js::jit::JitCode": { bytes: 2 }, + }, + other: { + "mozilla::dom::Thing": { bytes: 1 }, + } +}; + +const REPORT2 = { + objects: new Map([ + [stack2, { Array: { bytes: 1 }, + Date: { bytes: 2 }, + other: { bytes: 3 }, + }], + [stack3, { Function: { bytes: 1 }, + Object: { bytes: 2 }, + other: { bytes: 0 }, + }], + ["noStack", { Object: { bytes: 3 }}], + ]), + strings: { + JSAtom: { bytes: 5 }, + JSLinearString: { bytes: 10 }, + }, + scripts: { + JSScript: { bytes: 2 }, + "js::LazyScript": { bytes: 42 }, + "js::jit::JitCode": { bytes: 1 }, + }, + other: { + "mozilla::dom::OtherThing": { bytes: 1 }, + } +}; + +const EXPECTED = { + "objects": new Map([ + [stack1, { Function: { bytes: -1 }, + Object: { bytes: -2 }, + other: { bytes: 0 }, + }], + [stack2, { Array: { bytes: -2 }, + Date: { bytes: -2 }, + other: { bytes: 3 }, + }], + [stack3, { Function: { bytes: 1 }, + Object: { bytes: 2 }, + other: { bytes: 0 }, + }], + ["noStack", { Object: { bytes: 0 }}], + ]), + "scripts": { + "JSScript": { + "bytes": 1 + }, + "js::jit::JitCode": { + "bytes": -1 + }, + "js::LazyScript": { + "bytes": 42 + } + }, + "strings": { + "JSAtom": { + "bytes": -5 + }, + "JSLinearString": { + "bytes": 5 + } + }, + "other": { + "mozilla::dom::Thing": { + "bytes": -1 + }, + "mozilla::dom::OtherThing": { + "bytes": 1 + } + } +}; + +function run_test() { + assertDiff(BREAKDOWN, REPORT1, REPORT2, EXPECTED); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_census_filtering_01.js b/devtools/shared/heapsnapshot/tests/unit/test_census_filtering_01.js new file mode 100644 index 000000000..57724d7c1 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_census_filtering_01.js @@ -0,0 +1,105 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test filtering basic CensusTreeNode trees. + +function run_test() { + const BREAKDOWN = { + by: "coarseType", + objects: { + by: "objectClass", + then: { by: "count", count: true, bytes: true }, + other: { by: "count", count: true, bytes: true }, + }, + scripts: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + strings: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + other:{ + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + }; + + const REPORT = { + objects: { + Array: { bytes: 50, count: 5 }, + UInt8Array: { bytes: 80, count: 8 }, + Int32Array: { bytes: 320, count: 32 }, + other: { bytes: 0, count: 0 }, + }, + scripts: { + "js::jit::JitScript": { bytes: 30, count: 3 }, + }, + strings: { + JSAtom: { bytes: 60, count: 6 }, + }, + other: { + "js::Shape": { bytes: 80, count: 8 }, + } + }; + + const EXPECTED = { + name: null, + bytes: 0, + totalBytes: 620, + count: 0, + totalCount: 62, + children: [ + { + name: "objects", + bytes: 0, + totalBytes: 450, + count: 0, + totalCount: 45, + children: [ + { + name: "Int32Array", + bytes: 320, + totalBytes: 320, + count: 32, + totalCount: 32, + children: undefined, + id: 15, + parent: 14, + reportLeafIndex: 4, + }, + { + name: "UInt8Array", + bytes: 80, + totalBytes: 80, + count: 8, + totalCount: 8, + children: undefined, + id: 16, + parent: 14, + reportLeafIndex: 3, + }, + { + name: "Array", + bytes: 50, + totalBytes: 50, + count: 5, + totalCount: 5, + children: undefined, + id: 17, + parent: 14, + reportLeafIndex: 2, + } + ], + id: 14, + parent: 13, + reportLeafIndex: undefined, + } + ], + id: 13, + parent: undefined, + reportLeafIndex: undefined, + }; + + compareCensusViewData(BREAKDOWN, REPORT, EXPECTED, { filter: "Array" }); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_census_filtering_02.js b/devtools/shared/heapsnapshot/tests/unit/test_census_filtering_02.js new file mode 100644 index 000000000..0a57ce66d --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_census_filtering_02.js @@ -0,0 +1,124 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test filtering CensusTreeNode trees with an `allocationStack` breakdown. + +function run_test() { + const countBreakdown = { by: "count", count: true, bytes: true }; + + const BREAKDOWN = { + by: "allocationStack", + then: countBreakdown, + noStack: countBreakdown, + }; + + let stack1, stack2, stack3, stack4, stack5; + + (function foo() { + (function bar() { + (function baz() { + stack1 = saveStack(3); + }()); + (function quux() { + stack2 = saveStack(3); + stack3 = saveStack(3); + }()); + }()); + stack4 = saveStack(2); + }()); + + stack5 = saveStack(1); + + const REPORT = new Map([ + [stack1, { bytes: 10, count: 1 }], + [stack2, { bytes: 20, count: 2 }], + [stack3, { bytes: 30, count: 3 }], + [stack4, { bytes: 40, count: 4 }], + [stack5, { bytes: 50, count: 5 }], + ["noStack", { bytes: 60, count: 6 }], + ]); + + const EXPECTED = { + name: null, + bytes: 0, + totalBytes: 210, + count: 0, + totalCount: 21, + children: [ + { + name: stack1.parent.parent, + bytes: 0, + totalBytes: 60, + count: 0, + totalCount: 6, + children: [ + { + name: stack2.parent, + bytes: 0, + totalBytes: 50, + count: 0, + totalCount: 5, + children: [ + { + name: stack3, + bytes: 30, + totalBytes: 30, + count: 3, + totalCount: 3, + children: undefined, + id: 15, + parent: 14, + reportLeafIndex: 3, + }, + { + name: stack2, + bytes: 20, + totalBytes: 20, + count: 2, + totalCount: 2, + children: undefined, + id: 16, + parent: 14, + reportLeafIndex: 2, + } + ], + id: 14, + parent: 13, + reportLeafIndex: undefined, + }, + { + name: stack1.parent, + bytes: 0, + totalBytes: 10, + count: 0, + totalCount: 1, + children: [ + { + name: stack1, + bytes: 10, + totalBytes: 10, + count: 1, + totalCount: 1, + children: undefined, + id: 18, + parent: 17, + reportLeafIndex: 1, + } + ], + id: 17, + parent: 13, + reportLeafIndex: undefined, + } + ], + id: 13, + parent: 12, + reportLeafIndex: undefined, + } + ], + id: 12, + parent: undefined, + reportLeafIndex: undefined, + }; + + compareCensusViewData(BREAKDOWN, REPORT, EXPECTED, { filter: "bar" }); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_census_filtering_03.js b/devtools/shared/heapsnapshot/tests/unit/test_census_filtering_03.js new file mode 100644 index 000000000..2c69a14b8 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_census_filtering_03.js @@ -0,0 +1,59 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test filtering with no matches. + +function run_test() { + const BREAKDOWN = { + by: "coarseType", + objects: { + by: "objectClass", + then: { by: "count", count: true, bytes: true }, + other: { by: "count", count: true, bytes: true }, + }, + scripts: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + strings: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + other:{ + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + }; + + const REPORT = { + objects: { + Array: { bytes: 50, count: 5 }, + UInt8Array: { bytes: 80, count: 8 }, + Int32Array: { bytes: 320, count: 32 }, + other: { bytes: 0, count: 0 }, + }, + scripts: { + "js::jit::JitScript": { bytes: 30, count: 3 }, + }, + strings: { + JSAtom: { bytes: 60, count: 6 }, + }, + other: { + "js::Shape": { bytes: 80, count: 8 }, + } + }; + + const EXPECTED = { + name: null, + bytes: 0, + totalBytes: 620, + count: 0, + totalCount: 62, + children: undefined, + id: 13, + parent: undefined, + reportLeafIndex: undefined, + }; + + compareCensusViewData(BREAKDOWN, REPORT, EXPECTED, { filter: "zzzzzzzzzzzzzzzzzzzz" }); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_census_filtering_04.js b/devtools/shared/heapsnapshot/tests/unit/test_census_filtering_04.js new file mode 100644 index 000000000..c9871436b --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_census_filtering_04.js @@ -0,0 +1,102 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test the filtered nodes' counts and bytes are the same as they were when +// unfiltered. + +function run_test() { + const COUNT = { by: "count", count: true, bytes: true }; + const INTERNAL_TYPE = { by: "internalType", then: COUNT }; + + const BREAKDOWN = { + by: "coarseType", + objects: { by: "objectClass", then: COUNT, other: COUNT }, + strings: COUNT, + scripts: { + by: "filename", + then: INTERNAL_TYPE, + noFilename: INTERNAL_TYPE + }, + other: INTERNAL_TYPE, + }; + + const REPORT = { + objects: { + Function: { + count: 7, + bytes: 70 + }, + Array: { + count: 6, + bytes: 60 + } + }, + scripts: { + "http://mozilla.github.io/pdf.js/build/pdf.js": { + "js::LazyScript": { + count: 4, + bytes: 40 + }, + } + }, + strings: { + count: 2, + bytes: 20 + }, + other: { + "js::Shape": { + count: 1, + bytes: 10 + } + } + }; + + const EXPECTED = { + name: null, + bytes: 0, + totalBytes: 200, + count: 0, + totalCount: 20, + parent: undefined, + children: [ + { + name: "objects", + bytes: 0, + totalBytes: 130, + count: 0, + totalCount: 13, + children: [ + { + name: "Function", + bytes: 70, + totalBytes: 70, + count: 7, + totalCount: 7, + id: 13, + parent: 12, + children: undefined, + reportLeafIndex: 2, + }, + { + name: "Array", + bytes: 60, + totalBytes: 60, + count: 6, + totalCount: 6, + id: 14, + parent: 12, + children: undefined, + reportLeafIndex: 3, + }, + ], + id: 12, + parent: 11, + reportLeafIndex: undefined, + } + ], + id: 11, + reportLeafIndex: undefined, + }; + + compareCensusViewData(BREAKDOWN, REPORT, EXPECTED, { filter: "objects" }); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_census_filtering_05.js b/devtools/shared/heapsnapshot/tests/unit/test_census_filtering_05.js new file mode 100644 index 000000000..1d1f4fa55 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_census_filtering_05.js @@ -0,0 +1,71 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that filtered and inverted allocation stack census trees are sorted +// properly. + +function run_test() { + const countBreakdown = { by: "count", count: true, bytes: true }; + + const BREAKDOWN = { + by: "allocationStack", + then: countBreakdown, + noStack: countBreakdown, + }; + + const stacks = []; + + function foo(depth = 1) { + stacks.push(saveStack(depth)); + bar(depth + 1); + baz(depth + 1); + stacks.push(saveStack(depth)); + } + + function bar(depth = 1) { + stacks.push(saveStack(depth)); + stacks.push(saveStack(depth)); + } + + function baz(depth = 1) { + stacks.push(saveStack(depth)); + bang(depth + 1); + stacks.push(saveStack(depth)); + } + + function bang(depth = 1) { + stacks.push(saveStack(depth)); + stacks.push(saveStack(depth)); + stacks.push(saveStack(depth)); + } + + foo(); + bar(); + baz(); + bang(); + + const REPORT = new Map(stacks.map((s, i) => { + return [s, { + count: i + 1, + bytes: (i + 1) * 10 + }]; + })); + + const tree = censusReportToCensusTreeNode(BREAKDOWN, REPORT, { + filter: "baz", + invert: true + }); + + dumpn("tree = " + JSON.stringify(tree, savedFrameReplacer, 4)); + + (function assertSortedBySelf(node) { + if (node.children) { + let lastSelfBytes = Infinity; + for (let child of node.children) { + ok(child.bytes <= lastSelfBytes, `${child.bytes} <= ${lastSelfBytes}`); + lastSelfBytes = child.bytes; + assertSortedBySelf(child); + } + } + }(tree)); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_countToBucketBreakdown_01.js b/devtools/shared/heapsnapshot/tests/unit/test_countToBucketBreakdown_01.js new file mode 100644 index 000000000..e89048c33 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_countToBucketBreakdown_01.js @@ -0,0 +1,37 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +// Test that we can turn a breakdown with { by: "count" } leaves into a +// breakdown with { by: "bucket" } leaves. + +const COUNT = { by: "count", count: true, bytes: true }; +const BUCKET = { by: "bucket" }; + +const BREAKDOWN = { + by: "coarseType", + objects: { by: "objectClass", then: COUNT, other: COUNT }, + strings: COUNT, + scripts: { + by: "filename", + then: { by: "internalType", then: COUNT }, + noFilename: { by: "internalType", then: COUNT }, + }, + other: { by: "internalType", then: COUNT }, +}; + +const EXPECTED = { + by: "coarseType", + objects: { by: "objectClass", then: BUCKET, other: BUCKET }, + strings: BUCKET, + scripts: { + by: "filename", + then: { by: "internalType", then: BUCKET }, + noFilename: { by: "internalType", then: BUCKET }, + }, + other: { by: "internalType", then: BUCKET }, +}; + +function run_test() { + assertCountToBucketBreakdown(BREAKDOWN, EXPECTED); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_deduplicatePaths_01.js b/devtools/shared/heapsnapshot/tests/unit/test_deduplicatePaths_01.js new file mode 100644 index 000000000..418b49db3 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_deduplicatePaths_01.js @@ -0,0 +1,113 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +// Test the behavior of the deduplicatePaths utility function. + +function edge(from, to, name) { + return { from, to, name }; +} + +function run_test() { + const a = 1; + const b = 2; + const c = 3; + const d = 4; + const e = 5; + const f = 6; + const g = 7; + + dumpn("Single long path"); + assertDeduplicatedPaths({ + target: g, + paths: [ + [ + pathEntry(a, "e1"), + pathEntry(b, "e2"), + pathEntry(c, "e3"), + pathEntry(d, "e4"), + pathEntry(e, "e5"), + pathEntry(f, "e6"), + ] + ], + expectedNodes: [a, b, c, d, e, f, g], + expectedEdges: [ + edge(a, b, "e1"), + edge(b, c, "e2"), + edge(c, d, "e3"), + edge(d, e, "e4"), + edge(e, f, "e5"), + edge(f, g, "e6"), + ] + }); + + dumpn("Multiple edges from and to the same nodes"); + assertDeduplicatedPaths({ + target: a, + paths: [ + [pathEntry(b, "x")], + [pathEntry(b, "y")], + [pathEntry(b, "z")], + ], + expectedNodes: [a, b], + expectedEdges: [ + edge(b, a, "x"), + edge(b, a, "y"), + edge(b, a, "z"), + ] + }); + + dumpn("Multiple paths sharing some nodes and edges"); + assertDeduplicatedPaths({ + target: g, + paths: [ + [ + pathEntry(a, "a->b"), + pathEntry(b, "b->c"), + pathEntry(c, "foo"), + ], + [ + pathEntry(a, "a->b"), + pathEntry(b, "b->d"), + pathEntry(d, "bar"), + ], + [ + pathEntry(a, "a->b"), + pathEntry(b, "b->e"), + pathEntry(e, "baz"), + ], + ], + expectedNodes: [a, b, c, d, e, g], + expectedEdges: [ + edge(a, b, "a->b"), + edge(b, c, "b->c"), + edge(b, d, "b->d"), + edge(b, e, "b->e"), + edge(c, g, "foo"), + edge(d, g, "bar"), + edge(e, g, "baz"), + ] + }); + + dumpn("Second shortest path contains target itself"); + assertDeduplicatedPaths({ + target: g, + paths: [ + [ + pathEntry(a, "a->b"), + pathEntry(b, "b->g"), + ], + [ + pathEntry(a, "a->b"), + pathEntry(b, "b->g"), + pathEntry(g, "g->f"), + pathEntry(f, "f->g"), + ], + ], + expectedNodes: [a, b, g], + expectedEdges: [ + edge(a, b, "a->b"), + edge(b, g, "b->g"), + ] + }); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_getCensusIndividuals_01.js b/devtools/shared/heapsnapshot/tests/unit/test_getCensusIndividuals_01.js new file mode 100644 index 000000000..9c4f60991 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_getCensusIndividuals_01.js @@ -0,0 +1,60 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +// Test basic functionality of `CensusUtils.getCensusIndividuals`. + +function run_test() { + const stack1 = saveStack(1); + const stack2 = saveStack(1); + const stack3 = saveStack(1); + + const COUNT = { by: "count", count: true, bytes: true }; + const INTERNAL_TYPE = { by: "internalType", then: COUNT }; + + const BREAKDOWN = { + by: "allocationStack", + then: INTERNAL_TYPE, + noStack: INTERNAL_TYPE, + }; + + const MOCK_SNAPSHOT = { + takeCensus: ({ breakdown }) => { + assertStructurallyEquivalent( + breakdown, + CensusUtils.countToBucketBreakdown(BREAKDOWN)); + + // DFS Index + return new Map([ // 0 + [stack1, { // 1 + JSObject: [101, 102, 103], // 2 + JSString: [111, 112, 113], // 3 + }], + [stack2, { // 4 + JSObject: [201, 202, 203], // 5 + JSString: [211, 212, 213], // 6 + }], + [stack3, { // 7 + JSObject: [301, 302, 303], // 8 + JSString: [311, 312, 313], // 9 + }], + ["noStack", { // 10 + JSObject: [401, 402, 403], // 11 + JSString: [411, 412, 413], // 12 + }], + ]); + } + }; + + const INDICES = new Set([3, 5, 9]); + + const EXPECTED = new Set([111, 112, 113, + 201, 202, 203, + 311, 312, 313]); + + const actual = new Set(CensusUtils.getCensusIndividuals(INDICES, + BREAKDOWN, + MOCK_SNAPSHOT)); + + assertStructurallyEquivalent(EXPECTED, actual); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_getReportLeaves_01.js b/devtools/shared/heapsnapshot/tests/unit/test_getReportLeaves_01.js new file mode 100644 index 000000000..4c4298b6a --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_getReportLeaves_01.js @@ -0,0 +1,114 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +// Test basic functionality of `CensusUtils.getReportLeaves`. + +function run_test() { + const BREAKDOWN = { + by: "coarseType", + objects: { + by: "objectClass", + then: { by: "count", count: true, bytes: true }, + other: { by: "count", count: true, bytes: true }, + }, + strings: { by: "count", count: true, bytes: true }, + scripts: { + by: "filename", + then: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + noFilename: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + }, + other: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + }; + + const REPORT = { + objects: { + Array: { count: 6, bytes: 60 }, + Function: { count: 1, bytes: 10 }, + Object: { count: 1, bytes: 10 }, + RegExp: { count: 1, bytes: 10 }, + other: { count: 0, bytes: 0 }, + }, + strings: { count: 1, bytes: 10 }, + scripts: { + "foo.js": { + JSScript: { count: 1, bytes: 10 }, + "js::jit::IonScript": { count: 1, bytes: 10 }, + }, + noFilename: { + JSScript: { count: 1, bytes: 10 }, + "js::jit::IonScript": { count: 1, bytes: 10 }, + }, + }, + other: { + "js::Shape": { count: 7, bytes: 70 }, + "js::BaseShape": { count: 1, bytes: 10 }, + }, + }; + + const root = censusReportToCensusTreeNode(BREAKDOWN, REPORT); + dumpn("CensusTreeNode tree = " + JSON.stringify(root, null, 4)); + + (function assertEveryNodeCanFindItsLeaf(node) { + if (node.reportLeafIndex) { + const [ leaf ] = CensusUtils.getReportLeaves(new Set([node.reportLeafIndex]), + BREAKDOWN, + REPORT); + ok(leaf, "Should be able to find leaf for a node with a reportLeafIndex = " + node.reportLeafIndex); + } + + if (node.children) { + for (let child of node.children) { + assertEveryNodeCanFindItsLeaf(child); + } + } + }(root)); + + // Test finding multiple leaves at a time. + + function find(name, node) { + if (node.name === name) { + return node; + } + + if (node.children) { + for (let child of node.children) { + const found = find(name, child); + if (found) { + return found; + } + } + } + } + + const arrayNode = find("Array", root); + ok(arrayNode); + equal(typeof arrayNode.reportLeafIndex, "number"); + + const shapeNode = find("js::Shape", root); + ok(shapeNode); + equal(typeof shapeNode.reportLeafIndex, "number"); + + const indices = new Set([arrayNode.reportLeafIndex, shapeNode.reportLeafIndex]); + const leaves = CensusUtils.getReportLeaves(indices, BREAKDOWN, REPORT); + equal(leaves.length, 2); + + // `getReportLeaves` does not guarantee order of the results, so handle both + // cases. + ok(leaves.some(l => l === REPORT.objects.Array)); + ok(leaves.some(l => l === REPORT.other["js::Shape"])); + + // Test that bad indices do not yield results. + + const none = CensusUtils.getReportLeaves(new Set([999999999999]), BREAKDOWN, REPORT); + equal(none.length, 0); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/test_saveHeapSnapshot_e10s_01.js b/devtools/shared/heapsnapshot/tests/unit/test_saveHeapSnapshot_e10s_01.js new file mode 100644 index 000000000..067b9effb --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_saveHeapSnapshot_e10s_01.js @@ -0,0 +1,8 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test saving a heap snapshot in the sandboxed e10s child process. + +function run_test() { + run_test_in_child("../unit/test_SaveHeapSnapshot.js"); +} diff --git a/devtools/shared/heapsnapshot/tests/unit/xpcshell.ini b/devtools/shared/heapsnapshot/tests/unit/xpcshell.ini new file mode 100644 index 000000000..f84b282d1 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/xpcshell.ini @@ -0,0 +1,98 @@ +[DEFAULT] +tags = devtools heapsnapshot devtools-memory +head = head_heapsnapshot.js +tail = +firefox-appdir = browser +skip-if = toolkit == 'android' + +support-files = + Census.jsm + dominator-tree-worker.js + heap-snapshot-worker.js + Match.jsm + +[test_census_diff_01.js] +[test_census_diff_02.js] +[test_census_diff_03.js] +[test_census_diff_04.js] +[test_census_diff_05.js] +[test_census_diff_06.js] +[test_census_filtering_01.js] +[test_census_filtering_02.js] +[test_census_filtering_03.js] +[test_census_filtering_04.js] +[test_census_filtering_05.js] +[test_census-tree-node-01.js] +[test_census-tree-node-02.js] +[test_census-tree-node-03.js] +[test_census-tree-node-04.js] +[test_census-tree-node-05.js] +[test_census-tree-node-06.js] +[test_census-tree-node-07.js] +[test_census-tree-node-08.js] +[test_census-tree-node-09.js] +[test_census-tree-node-10.js] +[test_countToBucketBreakdown_01.js] +[test_deduplicatePaths_01.js] +[test_DominatorTree_01.js] +[test_DominatorTree_02.js] +[test_DominatorTree_03.js] +[test_DominatorTree_04.js] +[test_DominatorTree_05.js] +[test_DominatorTree_06.js] +[test_DominatorTreeNode_attachShortestPaths_01.js] +[test_DominatorTreeNode_getNodeByIdAlongPath_01.js] +[test_DominatorTreeNode_insert_01.js] +[test_DominatorTreeNode_insert_02.js] +[test_DominatorTreeNode_insert_03.js] +[test_DominatorTreeNode_LabelAndShallowSize_01.js] +[test_DominatorTreeNode_LabelAndShallowSize_02.js] +[test_DominatorTreeNode_LabelAndShallowSize_03.js] +[test_DominatorTreeNode_LabelAndShallowSize_04.js] +[test_DominatorTreeNode_partialTraversal_01.js] +[test_getCensusIndividuals_01.js] +[test_getReportLeaves_01.js] +[test_HeapAnalyses_computeDominatorTree_01.js] +[test_HeapAnalyses_computeDominatorTree_02.js] +[test_HeapAnalyses_deleteHeapSnapshot_01.js] +[test_HeapAnalyses_deleteHeapSnapshot_02.js] +[test_HeapAnalyses_deleteHeapSnapshot_03.js] +[test_HeapAnalyses_getCensusIndividuals_01.js] +[test_HeapAnalyses_getCreationTime_01.js] +[test_HeapAnalyses_getDominatorTree_01.js] +[test_HeapAnalyses_getDominatorTree_02.js] +[test_HeapAnalyses_getImmediatelyDominated_01.js] +[test_HeapAnalyses_readHeapSnapshot_01.js] +[test_HeapAnalyses_takeCensusDiff_01.js] +[test_HeapAnalyses_takeCensusDiff_02.js] +[test_HeapAnalyses_takeCensus_01.js] +[test_HeapAnalyses_takeCensus_02.js] +[test_HeapAnalyses_takeCensus_03.js] +[test_HeapAnalyses_takeCensus_04.js] +[test_HeapAnalyses_takeCensus_05.js] +[test_HeapAnalyses_takeCensus_06.js] +[test_HeapAnalyses_takeCensus_07.js] +[test_HeapSnapshot_creationTime_01.js] +[test_HeapSnapshot_deepStack_01.js] +[test_HeapSnapshot_describeNode_01.js] +[test_HeapSnapshot_computeShortestPaths_01.js] +[test_HeapSnapshot_computeShortestPaths_02.js] +[test_HeapSnapshot_takeCensus_01.js] +[test_HeapSnapshot_takeCensus_02.js] +[test_HeapSnapshot_takeCensus_03.js] +[test_HeapSnapshot_takeCensus_04.js] +[test_HeapSnapshot_takeCensus_05.js] +[test_HeapSnapshot_takeCensus_06.js] +[test_HeapSnapshot_takeCensus_07.js] +[test_HeapSnapshot_takeCensus_08.js] +[test_HeapSnapshot_takeCensus_09.js] +[test_HeapSnapshot_takeCensus_10.js] +[test_HeapSnapshot_takeCensus_11.js] +[test_HeapSnapshot_takeCensus_12.js] +[test_ReadHeapSnapshot.js] +[test_ReadHeapSnapshot_with_allocations.js] +skip-if = os == 'linux' # Bug 1176173 +[test_ReadHeapSnapshot_worker.js] +skip-if = os == 'linux' # Bug 1176173 +[test_SaveHeapSnapshot.js] +[test_saveHeapSnapshot_e10s_01.js] diff --git a/devtools/shared/indentation.js b/devtools/shared/indentation.js new file mode 100644 index 000000000..9d3cabcb7 --- /dev/null +++ b/devtools/shared/indentation.js @@ -0,0 +1,160 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2; fill-column: 80 -*- */ +/* vim:set ts=2 sw=2 sts=2 et tw=80: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const Services = require("Services"); + +const EXPAND_TAB = "devtools.editor.expandtab"; +const TAB_SIZE = "devtools.editor.tabsize"; +const DETECT_INDENT = "devtools.editor.detectindentation"; +const DETECT_INDENT_MAX_LINES = 500; + +/** + * Get the indentation to use in an editor, or return false if the user has + * asked for the indentation to be guessed from some text. + * + * @return {false | Object} + * Returns false if the "detect indentation" pref is set. + * an object of the form {indentUnit, indentWithTabs}. + * |indentUnit| is the number of indentation units to use + * to indent a "block". + * |indentWithTabs| is a boolean which is true if indentation + * should be done using tabs. + */ +function getIndentationFromPrefs() { + let shouldDetect = Services.prefs.getBoolPref(DETECT_INDENT); + if (shouldDetect) { + return false; + } + + let indentWithTabs = !Services.prefs.getBoolPref(EXPAND_TAB); + let indentUnit = Services.prefs.getIntPref(TAB_SIZE); + return {indentUnit, indentWithTabs}; +} + +/** + * Given a function that can iterate over some text, compute the indentation to + * use. This consults various prefs to arrive at a decision. + * + * @param {Function} iterFunc A function of three arguments: + * (start, end, callback); where |start| and |end| describe + * the range of text lines to examine, and |callback| is a function + * to be called with the text of each line. + * + * @return {Object} an object of the form {indentUnit, indentWithTabs}. + * |indentUnit| is the number of indentation units to use + * to indent a "block". + * |indentWithTabs| is a boolean which is true if indentation + * should be done using tabs. + */ +function getIndentationFromIteration(iterFunc) { + let indentWithTabs = !Services.prefs.getBoolPref(EXPAND_TAB); + let indentUnit = Services.prefs.getIntPref(TAB_SIZE); + let shouldDetect = Services.prefs.getBoolPref(DETECT_INDENT); + + if (shouldDetect) { + let indent = detectIndentation(iterFunc); + if (indent != null) { + indentWithTabs = indent.tabs; + indentUnit = indent.spaces ? indent.spaces : indentUnit; + } + } + + return {indentUnit, indentWithTabs}; +} + +/** + * A wrapper for @see getIndentationFromIteration which computes the + * indentation of a given string. + * + * @param {String} string the input text + * @return {Object} an object of the same form as returned by + * getIndentationFromIteration + */ +function getIndentationFromString(string) { + let iteratorFn = function (start, end, callback) { + let split = string.split(/\r\n|\r|\n|\f/); + split.slice(start, end).forEach(callback); + }; + return getIndentationFromIteration(iteratorFn); +} + +/** + * Detect the indentation used in an editor. Returns an object + * with 'tabs' - whether this is tab-indented and 'spaces' - the + * width of one indent in spaces. Or `null` if it's inconclusive. + */ +function detectIndentation(textIteratorFn) { + // # spaces indent -> # lines with that indent + let spaces = {}; + // indentation width of the last line we saw + let last = 0; + // # of lines that start with a tab + let tabs = 0; + // # of indented lines (non-zero indent) + let total = 0; + + textIteratorFn(0, DETECT_INDENT_MAX_LINES, (text) => { + if (text.startsWith("\t")) { + tabs++; + total++; + return; + } + let width = 0; + while (text[width] === " ") { + width++; + } + // don't count lines that are all spaces + if (width == text.length) { + last = 0; + return; + } + if (width > 1) { + total++; + } + + // see how much this line is offset from the line above it + let indent = Math.abs(width - last); + if (indent > 1 && indent <= 8) { + spaces[indent] = (spaces[indent] || 0) + 1; + } + last = width; + }); + + // this file is not indented at all + if (total == 0) { + return null; + } + + // mark as tabs if they start more than half the lines + if (tabs >= total / 2) { + return { tabs: true }; + } + + // find most frequent non-zero width difference between adjacent lines + let freqIndent = null, max = 1; + for (let width in spaces) { + width = parseInt(width, 10); + let tally = spaces[width]; + if (tally > max) { + max = tally; + freqIndent = width; + } + } + if (!freqIndent) { + return null; + } + + return { tabs: false, spaces: freqIndent }; +} + +exports.EXPAND_TAB = EXPAND_TAB; +exports.TAB_SIZE = TAB_SIZE; +exports.DETECT_INDENT = DETECT_INDENT; +exports.getIndentationFromPrefs = getIndentationFromPrefs; +exports.getIndentationFromIteration = getIndentationFromIteration; +exports.getIndentationFromString = getIndentationFromString; diff --git a/devtools/shared/inspector/css-logic.js b/devtools/shared/inspector/css-logic.js new file mode 100644 index 000000000..c8cdd2fdb --- /dev/null +++ b/devtools/shared/inspector/css-logic.js @@ -0,0 +1,325 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set ts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * About the objects defined in this file: + * - CssLogic contains style information about a view context. It provides + * access to 2 sets of objects: Css[Sheet|Rule|Selector] provide access to + * information that does not change when the selected element changes while + * Css[Property|Selector]Info provide information that is dependent on the + * selected element. + * Its key methods are highlight(), getPropertyInfo() and forEachSheet(), etc + * It also contains a number of static methods for l10n, naming, etc + * + * - CssSheet provides a more useful API to a DOM CSSSheet for our purposes, + * including shortSource and href. + * - CssRule a more useful API to a nsIDOMCSSRule including access to the group + * of CssSelectors that the rule provides properties for + * - CssSelector A single selector - i.e. not a selector group. In other words + * a CssSelector does not contain ','. This terminology is different from the + * standard DOM API, but more inline with the definition in the spec. + * + * - CssPropertyInfo contains style information for a single property for the + * highlighted element. + * - CssSelectorInfo is a wrapper around CssSelector, which adds sorting with + * reference to the selected element. + */ + +"use strict"; + +/** + * Provide access to the style information in a page. + * CssLogic uses the standard DOM API, and the Gecko inIDOMUtils API to access + * styling information in the page, and present this to the user in a way that + * helps them understand: + * - why their expectations may not have been fulfilled + * - how browsers process CSS + * @constructor + */ + +const Services = require("Services"); +const CSSLexer = require("devtools/shared/css/lexer"); +const {LocalizationHelper} = require("devtools/shared/l10n"); +const styleInspectorL10N = + new LocalizationHelper("devtools/shared/locales/styleinspector.properties"); + +/** + * Special values for filter, in addition to an href these values can be used + */ +exports.FILTER = { + // show properties for all user style sheets. + USER: "user", + // USER, plus user-agent (i.e. browser) style sheets + UA: "ua", +}; + +/** + * Each rule has a status, the bigger the number, the better placed it is to + * provide styling information. + * + * These statuses are localized inside the styleinspector.properties + * string bundle. + * @see csshtmltree.js RuleView._cacheStatusNames() + */ +exports.STATUS = { + BEST: 3, + MATCHED: 2, + PARENT_MATCH: 1, + UNMATCHED: 0, + UNKNOWN: -1, +}; + +/** + * Lookup a l10n string in the shared styleinspector string bundle. + * + * @param {String} name + * The key to lookup. + * @returns {String} A localized version of the given key. + */ +exports.l10n = name => styleInspectorL10N.getStr(name); + +/** + * Is the given property sheet a content stylesheet? + * + * @param {CSSStyleSheet} sheet a stylesheet + * @return {boolean} true if the given stylesheet is a content stylesheet, + * false otherwise. + */ +exports.isContentStylesheet = function (sheet) { + return sheet.parsingMode !== "agent"; +}; + +/** + * Return a shortened version of a style sheet's source. + * + * @param {CSSStyleSheet} sheet the DOM object for the style sheet. + */ +exports.shortSource = function (sheet) { + // Use a string like "inline" if there is no source href + if (!sheet || !sheet.href) { + return exports.l10n("rule.sourceInline"); + } + + // We try, in turn, the filename, filePath, query string, whole thing + let url = {}; + try { + url = new URL(sheet.href); + } catch (ex) { + // Some UA-provided stylesheets are not valid URLs. + } + + if (url.pathname) { + let index = url.pathname.lastIndexOf("/"); + if (index !== -1 && index < url.pathname.length) { + return url.pathname.slice(index + 1); + } + return url.pathname; + } + + if (url.query) { + return url.query; + } + + let dataUrl = sheet.href.match(/^(data:[^,]*),/); + return dataUrl ? dataUrl[1] : sheet.href; +}; + +const TAB_CHARS = "\t"; + +/** + * Prettify minified CSS text. + * This prettifies CSS code where there is no indentation in usual places while + * keeping original indentation as-is elsewhere. + * @param string text The CSS source to prettify. + * @return string Prettified CSS source + */ +function prettifyCSS(text, ruleCount) { + if (prettifyCSS.LINE_SEPARATOR == null) { + let os = Services.appinfo.OS; + prettifyCSS.LINE_SEPARATOR = (os === "WINNT" ? "\r\n" : "\n"); + } + + // remove initial and terminating HTML comments and surrounding whitespace + text = text.replace(/(?:^\s*\s*$)/g, ""); + let originalText = text; + text = text.trim(); + + // don't attempt to prettify if there's more than one line per rule. + let lineCount = text.split("\n").length - 1; + if (ruleCount !== null && lineCount >= ruleCount) { + return originalText; + } + + // We reformat the text using a simple state machine. The + // reformatting preserves most of the input text, changing only + // whitespace. The rules are: + // + // * After a "{" or ";" symbol, ensure there is a newline and + // indentation before the next non-comment, non-whitespace token. + // * Additionally after a "{" symbol, increase the indentation. + // * A "}" symbol ensures there is a preceding newline, and + // decreases the indentation level. + // * Ensure there is whitespace before a "{". + // + // This approach can be confused sometimes, but should do ok on a + // minified file. + let indent = ""; + let indentLevel = 0; + let tokens = CSSLexer.getCSSLexer(text); + let result = ""; + let pushbackToken = undefined; + + // A helper function that reads tokens, looking for the next + // non-comment, non-whitespace token. Comment and whitespace tokens + // are appended to |result|. If this encounters EOF, it returns + // null. Otherwise it returns the last whitespace token that was + // seen. This function also updates |pushbackToken|. + let readUntilSignificantToken = () => { + while (true) { + let token = tokens.nextToken(); + if (!token || token.tokenType !== "whitespace") { + pushbackToken = token; + return token; + } + // Saw whitespace. Before committing to it, check the next + // token. + let nextToken = tokens.nextToken(); + if (!nextToken || nextToken.tokenType !== "comment") { + pushbackToken = nextToken; + return token; + } + // Saw whitespace + comment. Update the result and continue. + result = result + text.substring(token.startOffset, nextToken.endOffset); + } + }; + + // State variables for readUntilNewlineNeeded. + // + // Starting index of the accumulated tokens. + let startIndex; + // Ending index of the accumulated tokens. + let endIndex; + // True if any non-whitespace token was seen. + let anyNonWS; + // True if the terminating token is "}". + let isCloseBrace; + // True if the token just before the terminating token was + // whitespace. + let lastWasWS; + + // A helper function that reads tokens until there is a reason to + // insert a newline. This updates the state variables as needed. + // If this encounters EOF, it returns null. Otherwise it returns + // the final token read. Note that if the returned token is "{", + // then it will not be included in the computed start/end token + // range. This is used to handle whitespace insertion before a "{". + let readUntilNewlineNeeded = () => { + let token; + while (true) { + if (pushbackToken) { + token = pushbackToken; + pushbackToken = undefined; + } else { + token = tokens.nextToken(); + } + if (!token) { + endIndex = text.length; + break; + } + + // A "}" symbol must be inserted later, to deal with indentation + // and newline. + if (token.tokenType === "symbol" && token.text === "}") { + isCloseBrace = true; + break; + } else if (token.tokenType === "symbol" && token.text === "{") { + break; + } + + if (token.tokenType !== "whitespace") { + anyNonWS = true; + } + + if (startIndex === undefined) { + startIndex = token.startOffset; + } + endIndex = token.endOffset; + + if (token.tokenType === "symbol" && token.text === ";") { + break; + } + + lastWasWS = token.tokenType === "whitespace"; + } + return token; + }; + + while (true) { + // Set the initial state. + startIndex = undefined; + endIndex = undefined; + anyNonWS = false; + isCloseBrace = false; + lastWasWS = false; + + // Read tokens until we see a reason to insert a newline. + let token = readUntilNewlineNeeded(); + + // Append any saved up text to the result, applying indentation. + if (startIndex !== undefined) { + if (isCloseBrace && !anyNonWS) { + // If we saw only whitespace followed by a "}", then we don't + // need anything here. + } else { + result = result + indent + text.substring(startIndex, endIndex); + if (isCloseBrace) { + result += prettifyCSS.LINE_SEPARATOR; + } + } + } + + if (isCloseBrace) { + indent = TAB_CHARS.repeat(--indentLevel); + result = result + indent + "}"; + } + + if (!token) { + break; + } + + if (token.tokenType === "symbol" && token.text === "{") { + if (!lastWasWS) { + result += " "; + } + result += "{"; + indent = TAB_CHARS.repeat(++indentLevel); + } + + // Now it is time to insert a newline. However first we want to + // deal with any trailing comments. + token = readUntilSignificantToken(); + + // "Early" bail-out if the text does not appear to be minified. + // Here we ignore the case where whitespace appears at the end of + // the text. + if (pushbackToken && token && token.tokenType === "whitespace" && + /\n/g.test(text.substring(token.startOffset, token.endOffset))) { + return originalText; + } + + // Finally time for that newline. + result = result + prettifyCSS.LINE_SEPARATOR; + + // Maybe we hit EOF. + if (!pushbackToken) { + break; + } + } + + return result; +} + +exports.prettifyCSS = prettifyCSS; diff --git a/devtools/shared/inspector/moz.build b/devtools/shared/inspector/moz.build new file mode 100644 index 000000000..e2c143fc3 --- /dev/null +++ b/devtools/shared/inspector/moz.build @@ -0,0 +1,9 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +DevToolsModules( + 'css-logic.js' +) diff --git a/devtools/shared/jar.mn b/devtools/shared/jar.mn new file mode 100644 index 000000000..4d0823550 --- /dev/null +++ b/devtools/shared/jar.mn @@ -0,0 +1,10 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +devtools.jar: +% resource devtools %modules/devtools/ +# The typical approach would be to list all the resource files in this manifest +# for installation. Instead of doing this, use the DevToolsModules syntax via +# moz.build files to do the installation so that we can enforce correct paths +# based on source tree location. diff --git a/devtools/shared/jsbeautify/UPGRADING.md b/devtools/shared/jsbeautify/UPGRADING.md new file mode 100644 index 000000000..dc6e0fe43 --- /dev/null +++ b/devtools/shared/jsbeautify/UPGRADING.md @@ -0,0 +1,37 @@ +# UPGRADING + +1. `git clone https://github.com/beautify-web/js-beautify.git` + +2. Copy `js/lib/beautify.js` to `devtools/shared/jsbeautify/src/beautify-js.js` + +3. Remove the acorn section from the file and add the following to the top: + + ``` + const acorn = require("acorn/acorn"); + ``` + +4. Just above `function Beautifier(js_source_text, options) {` add: + + ``` + exports.jsBeautify = js_beautify; + ``` + +5. Copy `beautify-html.js` to `devtools/shared/jsbeautify/src/beautify-html.js` + +6. Replace the require blocks at the bottom of the file with: + + ``` + var beautify = require('devtools/shared/jsbeautify/beautify'); + + exports.htmlBeautify = function(html_source, options) { + return style_html(html_source, options, beautify.js, beautify.css); + }; + ``` + +7. Copy `beautify-css.js` to `devtools/shared/jsbeautify/src/beautify-css.js` + +8. Replace the global define block at the bottom of the file with: + ``` + exports.cssBeautify = css_beautify; + ``` +9. Copy `js/test/beautify-tests.js` to `devtools/shared/jsbeautify/src/beautify-tests.js` diff --git a/devtools/shared/jsbeautify/beautify.js b/devtools/shared/jsbeautify/beautify.js new file mode 100644 index 000000000..df2e31eff --- /dev/null +++ b/devtools/shared/jsbeautify/beautify.js @@ -0,0 +1,7 @@ +var { cssBeautify } = require("devtools/shared/jsbeautify/src/beautify-css"); +var { htmlBeautify } = require("devtools/shared/jsbeautify/src/beautify-html"); +var { jsBeautify } = require("devtools/shared/jsbeautify/src/beautify-js"); + +exports.css = cssBeautify; +exports.html = htmlBeautify; +exports.js = jsBeautify; diff --git a/devtools/shared/jsbeautify/lib/moz.build b/devtools/shared/jsbeautify/lib/moz.build new file mode 100644 index 000000000..8fc89a102 --- /dev/null +++ b/devtools/shared/jsbeautify/lib/moz.build @@ -0,0 +1,10 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +DevToolsModules( + 'sanitytest.js', + 'urlencode_unpacker.js', +) diff --git a/devtools/shared/jsbeautify/lib/sanitytest.js b/devtools/shared/jsbeautify/lib/sanitytest.js new file mode 100644 index 000000000..f072a74b1 --- /dev/null +++ b/devtools/shared/jsbeautify/lib/sanitytest.js @@ -0,0 +1,137 @@ +// +// simple testing interface +// written by Einar Lielmanis, einar@jsbeautifier.org +// +// usage: +// +// var t = new SanityTest(function (x) { return x; }, 'my function'); +// t.expect('input', 'output'); +// t.expect('a', 'a'); +// output_somewhere(t.results()); // good for
, html safe-ish
+// alert(t.results_raw());        // html unescaped
+
+
+function SanityTest (func, name_of_test) {
+
+    var test_func = func || function (x) {
+        return x;
+    };
+
+    var test_name = name_of_test || '';
+
+    var n_failed = 0;
+    var n_succeeded = 0;
+
+    this.failures = [];
+    this.successes = [];
+
+    this.test_function = function(func, name) {
+        test_func = func;
+        test_name = name || '';
+    };
+
+    this.get_exitcode = function() {
+        return n_succeeded === 0 || n_failed !== 0 ? 1 : 0;
+    };
+
+    this.expect = function(parameters, expected_value) {
+        // multi-parameter calls not supported (I don't need them now).
+        var result = test_func(parameters);
+        // proper array checking is a pain. i'll maybe do it later, compare strings representations instead
+        if ((result === expected_value) || (expected_value instanceof Array && result.join(', ') == expected_value.join(', '))) {
+            n_succeeded += 1;
+            this.successes.push([test_name, parameters, expected_value, result]);
+        } else {
+            n_failed += 1;
+            this.failures.push([test_name, parameters, expected_value, result]);
+        }
+    };
+
+
+    this.results_raw = function() {
+        var results = '';
+        if (n_failed === 0) {
+            if (n_succeeded === 0) {
+                results = 'No tests run.';
+            } else {
+                results = 'All ' + n_succeeded + ' tests passed.';
+            }
+        } else {
+            for (var i = 0 ; i < this.failures.length; i++) {
+                var f = this.failures[i];
+                if (f[0]) {
+                    f[0] = f[0] + ' ';
+                }
+                results += '---- ' + f[0] + 'input -------\n' + this.prettyprint(f[1]) + '\n';
+                results += '---- ' + f[0] + 'expected ----\n' + this.prettyprint(f[2]) + '\n';
+                results += '---- ' + f[0] + 'output ------\n' + this.prettyprint(f[3]) + '\n\n';
+
+            }
+            results += n_failed + ' tests failed.\n';
+        }
+        return results;
+    };
+
+
+    this.results = function() {
+        return this.lazy_escape(this.results_raw());
+    };
+
+
+    this.prettyprint = function(something, quote_strings) {
+        var type = typeof something;
+        switch(type.toLowerCase()) {
+        case 'string':
+            if (quote_strings) {
+                return "'" + something.replace("'", "\\'") + "'";
+            } else {
+                return something;
+            }
+        case 'number':
+            return '' + something;
+        case 'boolean':
+            return something ? 'true' : 'false';
+        case 'undefined':
+            return 'undefined';
+        case 'object':
+            if (something instanceof Array) {
+                var x = [];
+                var expected_index = 0;
+                for (var k in something) {
+                    if (k == expected_index) {
+                        x.push(this.prettyprint(something[k], true));
+                        expected_index += 1;
+                    } else {
+                        x.push('\n' + k + ': ' + this.prettyprint(something[k], true));
+                    }
+                }
+                return '[' + x.join(', ') + ']';
+            } else {
+                return 'object: ' + something;
+            }
+        default:
+            return type + ': ' + something;
+        }
+    };
+
+
+    this.lazy_escape = function (str) {
+        return str.replace(//g, '>').replace(/\n/g, '
'); + }; + + + this.log = function () { + if (window.console) { + if (console.firebug) { + console.log.apply(console, Array.prototype.slice.call(arguments)); + } else { + console.log.call(console, Array.prototype.slice.call(arguments)); + } + } + }; + +} + +if (typeof module !== 'undefined' && module.exports) { + module.exports = SanityTest; +} diff --git a/devtools/shared/jsbeautify/lib/urlencode_unpacker.js b/devtools/shared/jsbeautify/lib/urlencode_unpacker.js new file mode 100644 index 000000000..b45cd15c0 --- /dev/null +++ b/devtools/shared/jsbeautify/lib/urlencode_unpacker.js @@ -0,0 +1,73 @@ +/*global unescape */ +/*jshint curly: false, scripturl: true */ +// +// trivial bookmarklet/escaped script detector for the javascript beautifier +// written by Einar Lielmanis +// +// usage: +// +// if (Urlencoded.detect(some_string)) { +// var unpacked = Urlencoded.unpack(some_string); +// } +// +// + +var isNode = (typeof module !== 'undefined' && module.exports); +if (isNode) { + var SanityTest = require("devtools/shared/jsbeautify/lib/sanitytest"); +} + +var Urlencoded = { + detect: function (str) { + // the fact that script doesn't contain any space, but has %20 instead + // should be sufficient check for now. + if (str.indexOf(' ') == -1) { + if (str.indexOf('%2') != -1) return true; + if (str.replace(/[^%]+/g, '').length > 3) return true; + } + return false; + }, + + unpack: function (str) { + if (Urlencoded.detect(str)) { + if (str.indexOf('%2B') != -1 || str.indexOf('%2b') != -1) { + // "+" escaped as "%2B" + return unescape(str.replace(/\+/g, '%20')); + } else { + return unescape(str); + } + } + return str; + }, + + + + run_tests: function (sanity_test) { + var t = sanity_test || new SanityTest(); + t.test_function(Urlencoded.detect, "Urlencoded.detect"); + t.expect('', false); + t.expect('var a = b', false); + t.expect('var%20a+=+b', true); + t.expect('var%20a=b', true); + t.expect('var%20%21%22', true); + t.expect('javascript:(function(){var%20whatever={init:function(){alert(%22a%22+%22b%22)}};whatever.init()})();', true); + t.test_function(Urlencoded.unpack, 'Urlencoded.unpack'); + + t.expect('javascript:(function(){var%20whatever={init:function(){alert(%22a%22+%22b%22)}};whatever.init()})();', + 'javascript:(function(){var whatever={init:function(){alert("a"+"b")}};whatever.init()})();' + ); + t.expect('', ''); + t.expect('abcd', 'abcd'); + t.expect('var a = b', 'var a = b'); + t.expect('var%20a=b', 'var a=b'); + t.expect('var%20a=b+1', 'var a=b+1'); + t.expect('var%20a=b%2b1', 'var a=b+1'); + return t; + } + + +}; + +if (isNode) { + module.exports = Urlencoded; +} diff --git a/devtools/shared/jsbeautify/moz.build b/devtools/shared/jsbeautify/moz.build new file mode 100644 index 000000000..939ca8943 --- /dev/null +++ b/devtools/shared/jsbeautify/moz.build @@ -0,0 +1,16 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +DIRS += [ + 'lib', + 'src', +] + +XPCSHELL_TESTS_MANIFESTS += ['tests/unit/xpcshell.ini'] + +DevToolsModules( + 'beautify.js', +) diff --git a/devtools/shared/jsbeautify/src/beautify-css.js b/devtools/shared/jsbeautify/src/beautify-css.js new file mode 100644 index 000000000..faf9ac0f2 --- /dev/null +++ b/devtools/shared/jsbeautify/src/beautify-css.js @@ -0,0 +1,367 @@ +/*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */ +/* + + The MIT License (MIT) + + Copyright (c) 2007-2013 Einar Lielmanis and contributors. + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation files + (the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, + publish, distribute, sublicense, and/or sell copies of the Software, + and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + + + CSS Beautifier +--------------- + + Written by Harutyun Amirjanyan, (amirjanyan@gmail.com) + + Based on code initially developed by: Einar Lielmanis, + http://jsbeautifier.org/ + + Usage: + css_beautify(source_text); + css_beautify(source_text, options); + + The options are (default in brackets): + indent_size (4) — indentation size, + indent_char (space) — character to indent with, + selector_separator_newline (true) - separate selectors with newline or + not (e.g. "a,\nbr" or "a, br") + end_with_newline (false) - end with a newline + + e.g + + css_beautify(css_source_text, { + 'indent_size': 1, + 'indent_char': '\t', + 'selector_separator': ' ', + 'end_with_newline': false, + }); +*/ + +// http://www.w3.org/TR/CSS21/syndata.html#tokenization +// http://www.w3.org/TR/css3-syntax/ + +(function () { + function css_beautify(source_text, options) { + options = options || {}; + var indentSize = options.indent_size || 4; + var indentCharacter = options.indent_char || ' '; + var selectorSeparatorNewline = (options.selector_separator_newline === undefined) ? true : options.selector_separator_newline; + var endWithNewline = (options.end_with_newline === undefined) ? false : options.end_with_newline; + + // compatibility + if (typeof indentSize === "string") { + indentSize = parseInt(indentSize, 10); + } + + + // tokenizer + var whiteRe = /^\s+$/; + var wordRe = /[\w$\-_]/; + + var pos = -1, + ch; + + function next() { + ch = source_text.charAt(++pos); + return ch; + } + + function peek() { + return source_text.charAt(pos + 1); + } + + function eatString(endChar) { + var start = pos; + while (next()) { + if (ch === "\\") { + next(); + next(); + } else if (ch === endChar) { + break; + } else if (ch === "\n") { + break; + } + } + return source_text.substring(start, pos + 1); + } + + function eatWhitespace() { + var start = pos; + while (whiteRe.test(peek())) { + pos++; + } + return pos !== start; + } + + function skipWhitespace() { + var start = pos; + do {} while (whiteRe.test(next())); + return pos !== start + 1; + } + + function eatComment(singleLine) { + var start = pos; + next(); + while (next()) { + if (ch === "*" && peek() === "/") { + pos++; + break; + } else if (singleLine && ch === "\n") { + break; + } + } + + return source_text.substring(start, pos + 1); + } + + + function lookBack(str) { + return source_text.substring(pos - str.length, pos).toLowerCase() === + str; + } + + function isCommentOnLine() { + var endOfLine = source_text.indexOf('\n', pos); + if (endOfLine === -1) { + return false; + } + var restOfLine = source_text.substring(pos, endOfLine); + return restOfLine.indexOf('//') !== -1; + } + + // printer + var indentString = source_text.match(/^[\r\n]*[\t ]*/)[0]; + var singleIndent = new Array(indentSize + 1).join(indentCharacter); + var indentLevel = 0; + var nestedLevel = 0; + + function indent() { + indentLevel++; + indentString += singleIndent; + } + + function outdent() { + indentLevel--; + indentString = indentString.slice(0, -indentSize); + } + + var print = {}; + print["{"] = function (ch) { + print.singleSpace(); + output.push(ch); + print.newLine(); + }; + print["}"] = function (ch) { + print.newLine(); + output.push(ch); + print.newLine(); + }; + + print._lastCharWhitespace = function () { + return whiteRe.test(output[output.length - 1]); + }; + + print.newLine = function (keepWhitespace) { + if (!keepWhitespace) { + while (print._lastCharWhitespace()) { + output.pop(); + } + } + + if (output.length) { + output.push('\n'); + } + if (indentString) { + output.push(indentString); + } + }; + print.singleSpace = function () { + if (output.length && !print._lastCharWhitespace()) { + output.push(' '); + } + }; + var output = []; + if (indentString) { + output.push(indentString); + } + /*_____________________--------------------_____________________*/ + + var insideRule = false; + var enteringConditionalGroup = false; + + while (true) { + var isAfterSpace = skipWhitespace(); + + if (!ch) { + break; + } else if (ch === '/' && peek() === '*') { /* css comment */ + print.newLine(); + output.push(eatComment(), "\n", indentString); + var header = lookBack(""); + if (header) { + print.newLine(); + } + } else if (ch === '/' && peek() === '/') { // single line comment + output.push(eatComment(true), indentString); + } else if (ch === '@') { + // strip trailing space, if present, for hash property checks + var atRule = eatString(" ").replace(/ $/, ''); + + // pass along the space we found as a separate item + output.push(atRule, ch); + + // might be a nesting at-rule + if (atRule in css_beautify.NESTED_AT_RULE) { + nestedLevel += 1; + if (atRule in css_beautify.CONDITIONAL_GROUP_RULE) { + enteringConditionalGroup = true; + } + } + } else if (ch === '{') { + eatWhitespace(); + if (peek() === '}') { + next(); + output.push(" {}"); + } else { + indent(); + print["{"](ch); + // when entering conditional groups, only rulesets are allowed + if (enteringConditionalGroup) { + enteringConditionalGroup = false; + insideRule = (indentLevel > nestedLevel); + } else { + // otherwise, declarations are also allowed + insideRule = (indentLevel >= nestedLevel); + } + } + } else if (ch === '}') { + outdent(); + print["}"](ch); + insideRule = false; + if (nestedLevel) { + nestedLevel--; + } + } else if (ch === ":") { + eatWhitespace(); + if (insideRule || enteringConditionalGroup) { + // 'property: value' delimiter + // which could be in a conditional group query + output.push(ch, " "); + } else { + if (peek() === ":") { + // pseudo-element + next(); + output.push("::"); + } else { + // pseudo-class + output.push(ch); + } + } + } else if (ch === '"' || ch === '\'') { + output.push(eatString(ch)); + } else if (ch === ';') { + if (isCommentOnLine()) { + var beforeComment = eatString('/'); + var comment = eatComment(true); + output.push(beforeComment, comment.substring(1, comment.length - 1), '\n', indentString); + } else { + output.push(ch, '\n', indentString); + } + } else if (ch === '(') { // may be a url + if (lookBack("url")) { + output.push(ch); + eatWhitespace(); + if (next()) { + if (ch !== ')' && ch !== '"' && ch !== '\'') { + output.push(eatString(')')); + } else { + pos--; + } + } + } else { + if (isAfterSpace) { + print.singleSpace(); + } + output.push(ch); + eatWhitespace(); + } + } else if (ch === ')') { + output.push(ch); + } else if (ch === ',') { + eatWhitespace(); + output.push(ch); + if (!insideRule && selectorSeparatorNewline) { + print.newLine(); + } else { + print.singleSpace(); + } + } else if (ch === ']') { + output.push(ch); + } else if (ch === '[') { + if (isAfterSpace) { + print.singleSpace(); + } + output.push(ch); + } else if (ch === '=') { // no whitespace before or after + eatWhitespace(); + output.push(ch); + } else { + if (isAfterSpace) { + print.singleSpace(); + } + + output.push(ch); + } + } + + + var sweetCode = output.join('').replace(/[\n ]+$/, ''); + + // establish end_with_newline + var should = endWithNewline; + var actually = /\n$/.test(sweetCode); + if (should && !actually) { + sweetCode += "\n"; + } else if (!should && actually) { + sweetCode = sweetCode.slice(0, -1); + } + + return sweetCode; + } + + // https://developer.mozilla.org/en-US/docs/Web/CSS/At-rule + css_beautify.NESTED_AT_RULE = { + "@page": true, + "@font-face": true, + "@keyframes": true, + // also in CONDITIONAL_GROUP_RULE below + "@media": true, + "@supports": true, + "@document": true + }; + css_beautify.CONDITIONAL_GROUP_RULE = { + "@media": true, + "@supports": true, + "@document": true + }; + + exports.cssBeautify = css_beautify; +}()); diff --git a/devtools/shared/jsbeautify/src/beautify-html.js b/devtools/shared/jsbeautify/src/beautify-html.js new file mode 100644 index 000000000..4967c3e3d --- /dev/null +++ b/devtools/shared/jsbeautify/src/beautify-html.js @@ -0,0 +1,822 @@ +/*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */ +/* + + The MIT License (MIT) + + Copyright (c) 2007-2013 Einar Lielmanis and contributors. + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation files + (the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, + publish, distribute, sublicense, and/or sell copies of the Software, + and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + + + Style HTML +--------------- + + Written by Nochum Sossonko, (nsossonko@hotmail.com) + + Based on code initially developed by: Einar Lielmanis, + http://jsbeautifier.org/ + + Usage: + style_html(html_source); + + style_html(html_source, options); + + The options are: + indent_inner_html (default false) — indent and sections, + indent_size (default 4) — indentation size, + indent_char (default space) — character to indent with, + wrap_line_length (default 250) - maximum amount of characters per line (0 = disable) + brace_style (default "collapse") - "collapse" | "expand" | "end-expand" + put braces on the same line as control statements (default), or put braces on own line (Allman / ANSI style), or just put end braces on own line. + unformatted (defaults to inline tags) - list of tags, that shouldn't be reformatted + indent_scripts (default normal) - "keep"|"separate"|"normal" + preserve_newlines (default true) - whether existing line breaks before elements should be preserved + Only works before elements, not inside tags or for text. + max_preserve_newlines (default unlimited) - maximum number of line breaks to be preserved in one chunk + indent_handlebars (default false) - format and indent {{#foo}} and {{/foo}} + + e.g. + + style_html(html_source, { + 'indent_inner_html': false, + 'indent_size': 2, + 'indent_char': ' ', + 'wrap_line_length': 78, + 'brace_style': 'expand', + 'unformatted': ['a', 'sub', 'sup', 'b', 'i', 'u'], + 'preserve_newlines': true, + 'max_preserve_newlines': 5, + 'indent_handlebars': false + }); +*/ + +(function() { + + function trim(s) { + return s.replace(/^\s+|\s+$/g, ''); + } + + function ltrim(s) { + return s.replace(/^\s+/g, ''); + } + + function style_html(html_source, options, js_beautify, css_beautify) { + //Wrapper function to invoke all the necessary constructors and deal with the output. + + var multi_parser, + indent_inner_html, + indent_size, + indent_character, + wrap_line_length, + brace_style, + unformatted, + preserve_newlines, + max_preserve_newlines, + indent_handlebars; + + options = options || {}; + + // backwards compatibility to 1.3.4 + if ((options.wrap_line_length === undefined || parseInt(options.wrap_line_length, 10) === 0) && + (options.max_char !== undefined && parseInt(options.max_char, 10) !== 0)) { + options.wrap_line_length = options.max_char; + } + + indent_inner_html = (options.indent_inner_html === undefined) ? false : options.indent_inner_html; + indent_size = (options.indent_size === undefined) ? 4 : parseInt(options.indent_size, 10); + indent_character = (options.indent_char === undefined) ? ' ' : options.indent_char; + brace_style = (options.brace_style === undefined) ? 'collapse' : options.brace_style; + wrap_line_length = parseInt(options.wrap_line_length, 10) === 0 ? 32786 : parseInt(options.wrap_line_length || 250, 10); + unformatted = options.unformatted || ['a', 'span', 'bdo', 'em', 'strong', 'dfn', 'code', 'samp', 'kbd', 'var', 'cite', 'abbr', 'acronym', 'q', 'sub', 'sup', 'tt', 'i', 'b', 'big', 'small', 'u', 's', 'strike', 'font', 'ins', 'del', 'pre', 'address', 'dt', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6']; + preserve_newlines = (options.preserve_newlines === undefined) ? true : options.preserve_newlines; + max_preserve_newlines = preserve_newlines ? + (isNaN(parseInt(options.max_preserve_newlines, 10)) ? 32786 : parseInt(options.max_preserve_newlines, 10)) + : 0; + indent_handlebars = (options.indent_handlebars === undefined) ? false : options.indent_handlebars; + + function Parser() { + + this.pos = 0; //Parser position + this.token = ''; + this.current_mode = 'CONTENT'; //reflects the current Parser mode: TAG/CONTENT + this.tags = { //An object to hold tags, their position, and their parent-tags, initiated with default values + parent: 'parent1', + parentcount: 1, + parent1: '' + }; + this.tag_type = ''; + this.token_text = this.last_token = this.last_text = this.token_type = ''; + this.newlines = 0; + this.indent_content = indent_inner_html; + + this.Utils = { //Uilities made available to the various functions + whitespace: "\n\r\t ".split(''), + single_token: 'br,input,link,meta,!doctype,basefont,base,area,hr,wbr,param,img,isindex,?xml,embed,?php,?,?='.split(','), //all the single tags for HTML + extra_liners: 'head,body,/html'.split(','), //for tags that need a line of whitespace before them + in_array: function(what, arr) { + for (var i = 0; i < arr.length; i++) { + if (what === arr[i]) { + return true; + } + } + return false; + } + }; + + this.traverse_whitespace = function() { + var input_char = ''; + + input_char = this.input.charAt(this.pos); + if (this.Utils.in_array(input_char, this.Utils.whitespace)) { + this.newlines = 0; + while (this.Utils.in_array(input_char, this.Utils.whitespace)) { + if (preserve_newlines && input_char === '\n' && this.newlines <= max_preserve_newlines) { + this.newlines += 1; + } + + this.pos++; + input_char = this.input.charAt(this.pos); + } + return true; + } + return false; + }; + + this.get_content = function() { //function to capture regular content between tags + + var input_char = '', + content = [], + space = false; //if a space is needed + + while (this.input.charAt(this.pos) !== '<') { + if (this.pos >= this.input.length) { + return content.length ? content.join('') : ['', 'TK_EOF']; + } + + if (this.traverse_whitespace()) { + if (content.length) { + space = true; + } + continue; //don't want to insert unnecessary space + } + + if (indent_handlebars) { + // Handlebars parsing is complicated. + // {{#foo}} and {{/foo}} are formatted tags. + // {{something}} should get treated as content, except: + // {{else}} specifically behaves like {{#if}} and {{/if}} + var peek3 = this.input.substr(this.pos, 3); + if (peek3 === '{{#' || peek3 === '{{/') { + // These are tags and not content. + break; + } else if (this.input.substr(this.pos, 2) === '{{') { + if (this.get_tag(true) === '{{else}}') { + break; + } + } + } + + input_char = this.input.charAt(this.pos); + this.pos++; + + if (space) { + if (this.line_char_count >= this.wrap_line_length) { //insert a line when the wrap_line_length is reached + this.print_newline(false, content); + this.print_indentation(content); + } else { + this.line_char_count++; + content.push(' '); + } + space = false; + } + this.line_char_count++; + content.push(input_char); //letter at-a-time (or string) inserted to an array + } + return content.length ? content.join('') : ''; + }; + + this.get_contents_to = function(name) { //get the full content of a script or style to pass to js_beautify + if (this.pos === this.input.length) { + return ['', 'TK_EOF']; + } + var input_char = ''; + var content = ''; + var reg_match = new RegExp('', 'igm'); + reg_match.lastIndex = this.pos; + var reg_array = reg_match.exec(this.input); + var end_script = reg_array ? reg_array.index : this.input.length; //absolute end of script + if (this.pos < end_script) { //get everything in between the script tags + content = this.input.substring(this.pos, end_script); + this.pos = end_script; + } + return content; + }; + + this.record_tag = function(tag) { //function to record a tag and its parent in this.tags Object + if (this.tags[tag + 'count']) { //check for the existence of this tag type + this.tags[tag + 'count']++; + this.tags[tag + this.tags[tag + 'count']] = this.indent_level; //and record the present indent level + } else { //otherwise initialize this tag type + this.tags[tag + 'count'] = 1; + this.tags[tag + this.tags[tag + 'count']] = this.indent_level; //and record the present indent level + } + this.tags[tag + this.tags[tag + 'count'] + 'parent'] = this.tags.parent; //set the parent (i.e. in the case of a div this.tags.div1parent) + this.tags.parent = tag + this.tags[tag + 'count']; //and make this the current parent (i.e. in the case of a div 'div1') + }; + + this.retrieve_tag = function(tag) { //function to retrieve the opening tag to the corresponding closer + if (this.tags[tag + 'count']) { //if the openener is not in the Object we ignore it + var temp_parent = this.tags.parent; //check to see if it's a closable tag. + while (temp_parent) { //till we reach '' (the initial value); + if (tag + this.tags[tag + 'count'] === temp_parent) { //if this is it use it + break; + } + temp_parent = this.tags[temp_parent + 'parent']; //otherwise keep on climbing up the DOM Tree + } + if (temp_parent) { //if we caught something + this.indent_level = this.tags[tag + this.tags[tag + 'count']]; //set the indent_level accordingly + this.tags.parent = this.tags[temp_parent + 'parent']; //and set the current parent + } + delete this.tags[tag + this.tags[tag + 'count'] + 'parent']; //delete the closed tags parent reference... + delete this.tags[tag + this.tags[tag + 'count']]; //...and the tag itself + if (this.tags[tag + 'count'] === 1) { + delete this.tags[tag + 'count']; + } else { + this.tags[tag + 'count']--; + } + } + }; + + this.indent_to_tag = function(tag) { + // Match the indentation level to the last use of this tag, but don't remove it. + if (!this.tags[tag + 'count']) { + return; + } + var temp_parent = this.tags.parent; + while (temp_parent) { + if (tag + this.tags[tag + 'count'] === temp_parent) { + break; + } + temp_parent = this.tags[temp_parent + 'parent']; + } + if (temp_parent) { + this.indent_level = this.tags[tag + this.tags[tag + 'count']]; + } + }; + + this.get_tag = function(peek) { //function to get a full tag and parse its type + var input_char = '', + content = [], + comment = '', + space = false, + tag_start, tag_end, + tag_start_char, + orig_pos = this.pos, + orig_line_char_count = this.line_char_count; + + peek = peek !== undefined ? peek : false; + + do { + if (this.pos >= this.input.length) { + if (peek) { + this.pos = orig_pos; + this.line_char_count = orig_line_char_count; + } + return content.length ? content.join('') : ['', 'TK_EOF']; + } + + input_char = this.input.charAt(this.pos); + this.pos++; + + if (this.Utils.in_array(input_char, this.Utils.whitespace)) { //don't want to insert unnecessary space + space = true; + continue; + } + + if (input_char === "'" || input_char === '"') { + input_char += this.get_unformatted(input_char); + space = true; + + } + + if (input_char === '=') { //no space before = + space = false; + } + + if (content.length && content[content.length - 1] !== '=' && input_char !== '>' && space) { + //no space after = or before > + if (this.line_char_count >= this.wrap_line_length) { + this.print_newline(false, content); + this.print_indentation(content); + } else { + content.push(' '); + this.line_char_count++; + } + space = false; + } + + if (indent_handlebars && tag_start_char === '<') { + // When inside an angle-bracket tag, put spaces around + // handlebars not inside of strings. + if ((input_char + this.input.charAt(this.pos)) === '{{') { + input_char += this.get_unformatted('}}'); + if (content.length && content[content.length - 1] !== ' ' && content[content.length - 1] !== '<') { + input_char = ' ' + input_char; + } + space = true; + } + } + + if (input_char === '<' && !tag_start_char) { + tag_start = this.pos - 1; + tag_start_char = '<'; + } + + if (indent_handlebars && !tag_start_char) { + if (content.length >= 2 && content[content.length - 1] === '{' && content[content.length - 2] == '{') { + if (input_char === '#' || input_char === '/') { + tag_start = this.pos - 3; + } else { + tag_start = this.pos - 2; + } + tag_start_char = '{'; + } + } + + this.line_char_count++; + content.push(input_char); //inserts character at-a-time (or string) + + if (content[1] && content[1] === '!') { //if we're in a comment, do something special + // We treat all comments as literals, even more than preformatted tags + // we just look for the appropriate close tag + content = [this.get_comment(tag_start)]; + break; + } + + if (indent_handlebars && tag_start_char === '{' && content.length > 2 && content[content.length - 2] === '}' && content[content.length - 1] === '}') { + break; + } + } while (input_char !== '>'); + + var tag_complete = content.join(''); + var tag_index; + var tag_offset; + + if (tag_complete.indexOf(' ') !== -1) { //if there's whitespace, thats where the tag name ends + tag_index = tag_complete.indexOf(' '); + } else if (tag_complete[0] === '{') { + tag_index = tag_complete.indexOf('}'); + } else { //otherwise go with the tag ending + tag_index = tag_complete.indexOf('>'); + } + if (tag_complete[0] === '<' || !indent_handlebars) { + tag_offset = 1; + } else { + tag_offset = tag_complete[2] === '#' ? 3 : 2; + } + var tag_check = tag_complete.substring(tag_offset, tag_index).toLowerCase(); + if (tag_complete.charAt(tag_complete.length - 2) === '/' || + this.Utils.in_array(tag_check, this.Utils.single_token)) { //if this tag name is a single tag type (either in the list or has a closing /) + if (!peek) { + this.tag_type = 'SINGLE'; + } + } else if (indent_handlebars && tag_complete[0] === '{' && tag_check === 'else') { + if (!peek) { + this.indent_to_tag('if'); + this.tag_type = 'HANDLEBARS_ELSE'; + this.indent_content = true; + this.traverse_whitespace(); + } + } else if (tag_check === 'script' && + (tag_complete.search('type') === -1 || + (tag_complete.search('type') > -1 && + tag_complete.search(/\b(text|application)\/(x-)?(javascript|ecmascript|jscript|livescript)/) > -1))) { + if (!peek) { + this.record_tag(tag_check); + this.tag_type = 'SCRIPT'; + } + } else if (tag_check === 'style' && + (tag_complete.search('type') === -1 || + (tag_complete.search('type') > -1 && tag_complete.search('text/css') > -1))) { + if (!peek) { + this.record_tag(tag_check); + this.tag_type = 'STYLE'; + } + } else if (this.is_unformatted(tag_check, unformatted)) { // do not reformat the "unformatted" tags + comment = this.get_unformatted('', tag_complete); //...delegate to get_unformatted function + content.push(comment); + // Preserve collapsed whitespace either before or after this tag. + if (tag_start > 0 && this.Utils.in_array(this.input.charAt(tag_start - 1), this.Utils.whitespace)) { + content.splice(0, 0, this.input.charAt(tag_start - 1)); + } + tag_end = this.pos - 1; + if (this.Utils.in_array(this.input.charAt(tag_end + 1), this.Utils.whitespace)) { + content.push(this.input.charAt(tag_end + 1)); + } + this.tag_type = 'SINGLE'; + } else if (tag_check.charAt(0) === '!') { //peek for ', + matched = false; + + this.pos = start_pos; + input_char = this.input.charAt(this.pos); + this.pos++; + + while (this.pos <= this.input.length) { + comment += input_char; + + // only need to check for the delimiter if the last chars match + if (comment[comment.length - 1] === delimiter[delimiter.length - 1] && + comment.indexOf(delimiter) !== -1) { + break; + } + + // only need to search for custom delimiter for the first few characters + if (!matched && comment.length < 10) { + if (comment.indexOf(''; + matched = true; + } else if (comment.indexOf(''; + matched = true; + } else if (comment.indexOf(''; + matched = true; + } else if (comment.indexOf(''; + matched = true; + } + } + + input_char = this.input.charAt(this.pos); + this.pos++; + } + + return comment; + }; + + this.get_unformatted = function(delimiter, orig_tag) { //function to return unformatted content in its entirety + + if (orig_tag && orig_tag.toLowerCase().indexOf(delimiter) !== -1) { + return ''; + } + var input_char = ''; + var content = ''; + var min_index = 0; + var space = true; + do { + + if (this.pos >= this.input.length) { + return content; + } + + input_char = this.input.charAt(this.pos); + this.pos++; + + if (this.Utils.in_array(input_char, this.Utils.whitespace)) { + if (!space) { + this.line_char_count--; + continue; + } + if (input_char === '\n' || input_char === '\r') { + content += '\n'; + /* Don't change tab indention for unformatted blocks. If using code for html editing, this will greatly affect
 tags if they are specified in the 'unformatted array'
+                for (var i=0; i]*>\s*$/);
+
+                // if next_tag comes back but is not an isolated tag, then
+                // let's treat the 'a' tag as having content
+                // and respect the unformatted option
+                if (!tag || this.Utils.in_array(tag, unformatted)) {
+                    return true;
+                } else {
+                    return false;
+                }
+            };
+
+            this.printer = function(js_source, indent_character, indent_size, wrap_line_length, brace_style) { //handles input/output and some other printing functions
+
+                this.input = js_source || ''; //gets the input for the Parser
+                this.output = [];
+                this.indent_character = indent_character;
+                this.indent_string = '';
+                this.indent_size = indent_size;
+                this.brace_style = brace_style;
+                this.indent_level = 0;
+                this.wrap_line_length = wrap_line_length;
+                this.line_char_count = 0; //count to see if wrap_line_length was exceeded
+
+                for (var i = 0; i < this.indent_size; i++) {
+                    this.indent_string += this.indent_character;
+                }
+
+                this.print_newline = function(force, arr) {
+                    this.line_char_count = 0;
+                    if (!arr || !arr.length) {
+                        return;
+                    }
+                    if (force || (arr[arr.length - 1] !== '\n')) { //we might want the extra line
+                        arr.push('\n');
+                    }
+                };
+
+                this.print_indentation = function(arr) {
+                    for (var i = 0; i < this.indent_level; i++) {
+                        arr.push(this.indent_string);
+                        this.line_char_count += this.indent_string.length;
+                    }
+                };
+
+                this.print_token = function(text) {
+                    if (text || text !== '') {
+                        if (this.output.length && this.output[this.output.length - 1] === '\n') {
+                            this.print_indentation(this.output);
+                            text = ltrim(text);
+                        }
+                    }
+                    this.print_token_raw(text);
+                };
+
+                this.print_token_raw = function(text) {
+                    if (text && text !== '') {
+                        if (text.length > 1 && text[text.length - 1] === '\n') {
+                            // unformatted tags can grab newlines as their last character
+                            this.output.push(text.slice(0, -1));
+                            this.print_newline(false, this.output);
+                        } else {
+                            this.output.push(text);
+                        }
+                    }
+
+                    for (var n = 0; n < this.newlines; n++) {
+                        this.print_newline(n > 0, this.output);
+                    }
+                    this.newlines = 0;
+                };
+
+                this.indent = function() {
+                    this.indent_level++;
+                };
+
+                this.unindent = function() {
+                    if (this.indent_level > 0) {
+                        this.indent_level--;
+                    }
+                };
+            };
+            return this;
+        }
+
+        /*_____________________--------------------_____________________*/
+
+        multi_parser = new Parser(); //wrapping functions Parser
+        multi_parser.printer(html_source, indent_character, indent_size, wrap_line_length, brace_style); //initialize starting values
+
+        while (true) {
+            var t = multi_parser.get_token();
+            multi_parser.token_text = t[0];
+            multi_parser.token_type = t[1];
+
+            if (multi_parser.token_type === 'TK_EOF') {
+                break;
+            }
+
+            switch (multi_parser.token_type) {
+                case 'TK_TAG_START':
+                    multi_parser.print_newline(false, multi_parser.output);
+                    multi_parser.print_token(multi_parser.token_text);
+                    if (multi_parser.indent_content) {
+                        multi_parser.indent();
+                        multi_parser.indent_content = false;
+                    }
+                    multi_parser.current_mode = 'CONTENT';
+                    break;
+                case 'TK_TAG_STYLE':
+                case 'TK_TAG_SCRIPT':
+                    multi_parser.print_newline(false, multi_parser.output);
+                    multi_parser.print_token(multi_parser.token_text);
+                    multi_parser.current_mode = 'CONTENT';
+                    break;
+                case 'TK_TAG_END':
+                    //Print new line only if the tag has no content and has child
+                    if (multi_parser.last_token === 'TK_CONTENT' && multi_parser.last_text === '') {
+                        var tag_name = multi_parser.token_text.match(/\w+/)[0];
+                        var tag_extracted_from_last_output = null;
+                        if (multi_parser.output.length) {
+                            tag_extracted_from_last_output = multi_parser.output[multi_parser.output.length - 1].match(/(?:<|{{#)\s*(\w+)/);
+                        }
+                        if (tag_extracted_from_last_output === null ||
+                            tag_extracted_from_last_output[1] !== tag_name) {
+                            multi_parser.print_newline(false, multi_parser.output);
+                        }
+                    }
+                    multi_parser.print_token(multi_parser.token_text);
+                    multi_parser.current_mode = 'CONTENT';
+                    break;
+                case 'TK_TAG_SINGLE':
+                    // Don't add a newline before elements that should remain unformatted.
+                    var tag_check = multi_parser.token_text.match(/^\s*<([a-z]+)/i);
+                    if (!tag_check || !multi_parser.Utils.in_array(tag_check[1], unformatted)) {
+                        multi_parser.print_newline(false, multi_parser.output);
+                    }
+                    multi_parser.print_token(multi_parser.token_text);
+                    multi_parser.current_mode = 'CONTENT';
+                    break;
+                case 'TK_TAG_HANDLEBARS_ELSE':
+                    multi_parser.print_token(multi_parser.token_text);
+                    if (multi_parser.indent_content) {
+                        multi_parser.indent();
+                        multi_parser.indent_content = false;
+                    }
+                    multi_parser.current_mode = 'CONTENT';
+                    break;
+                case 'TK_CONTENT':
+                    multi_parser.print_token(multi_parser.token_text);
+                    multi_parser.current_mode = 'TAG';
+                    break;
+                case 'TK_STYLE':
+                case 'TK_SCRIPT':
+                    if (multi_parser.token_text !== '') {
+                        multi_parser.print_newline(false, multi_parser.output);
+                        var text = multi_parser.token_text,
+                            _beautifier,
+                            script_indent_level = 1;
+                        if (multi_parser.token_type === 'TK_SCRIPT') {
+                            _beautifier = typeof js_beautify === 'function' && js_beautify;
+                        } else if (multi_parser.token_type === 'TK_STYLE') {
+                            _beautifier = typeof css_beautify === 'function' && css_beautify;
+                        }
+
+                        if (options.indent_scripts === "keep") {
+                            script_indent_level = 0;
+                        } else if (options.indent_scripts === "separate") {
+                            script_indent_level = -multi_parser.indent_level;
+                        }
+
+                        var indentation = multi_parser.get_full_indent(script_indent_level);
+                        if (_beautifier) {
+                            // call the Beautifier if avaliable
+                            text = _beautifier(text.replace(/^\s*/, indentation), options);
+                        } else {
+                            // simply indent the string otherwise
+                            var white = text.match(/^\s*/)[0];
+                            var _level = white.match(/[^\n\r]*$/)[0].split(multi_parser.indent_string).length - 1;
+                            var reindent = multi_parser.get_full_indent(script_indent_level - _level);
+                            text = text.replace(/^\s*/, indentation)
+                                .replace(/\r\n|\r|\n/g, '\n' + reindent)
+                                .replace(/\s+$/, '');
+                        }
+                        if (text) {
+                            multi_parser.print_token_raw(indentation + trim(text));
+                            multi_parser.print_newline(false, multi_parser.output);
+                        }
+                    }
+                    multi_parser.current_mode = 'TAG';
+                    break;
+            }
+            multi_parser.last_token = multi_parser.token_type;
+            multi_parser.last_text = multi_parser.token_text;
+        }
+        return multi_parser.output.join('');
+    }
+
+    var beautify = require('devtools/shared/jsbeautify/beautify');
+
+    exports.htmlBeautify = function(html_source, options) {
+        return style_html(html_source, options, beautify.js, beautify.css);
+    };
+}());
diff --git a/devtools/shared/jsbeautify/src/beautify-js.js b/devtools/shared/jsbeautify/src/beautify-js.js
new file mode 100644
index 000000000..053d973e0
--- /dev/null
+++ b/devtools/shared/jsbeautify/src/beautify-js.js
@@ -0,0 +1,1662 @@
+/*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */
+
+"use strict";
+
+const acorn = require("acorn/acorn");
+
+/*
+
+  The MIT License (MIT)
+
+  Copyright (c) 2007-2013 Einar Lielmanis and contributors.
+
+  Permission is hereby granted, free of charge, to any person
+  obtaining a copy of this software and associated documentation files
+  (the "Software"), to deal in the Software without restriction,
+  including without limitation the rights to use, copy, modify, merge,
+  publish, distribute, sublicense, and/or sell copies of the Software,
+  and to permit persons to whom the Software is furnished to do so,
+  subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be
+  included in all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+
+ JS Beautifier
+---------------
+
+
+  Written by Einar Lielmanis, 
+      http://jsbeautifier.org/
+
+  Originally converted to javascript by Vital, 
+  "End braces on own line" added by Chris J. Shull, 
+  Parsing improvements for brace-less statements by Liam Newman 
+
+
+  Usage:
+    js_beautify(js_source_text);
+    js_beautify(js_source_text, options);
+
+  The options are:
+    indent_size (default 4)          - indentation size,
+    indent_char (default space)      - character to indent with,
+    preserve_newlines (default true) - whether existing line breaks should be preserved,
+    max_preserve_newlines (default unlimited) - maximum number of line breaks to be preserved in one chunk,
+
+    jslint_happy (default false) - if true, then jslint-stricter mode is enforced.
+
+            jslint_happy       !jslint_happy
+            ---------------------------------
+            function ()        function()
+
+    brace_style (default "collapse") - "collapse" | "expand" | "end-expand"
+            put braces on the same line as control statements (default), or put braces on own line (Allman / ANSI style), or just put end braces on own line.
+
+    space_before_conditional (default true) - should the space before conditional statement be added, "if(true)" vs "if (true)",
+
+    unescape_strings (default false) - should printable characters in strings encoded in \xNN notation be unescaped, "example" vs "\x65\x78\x61\x6d\x70\x6c\x65"
+
+    wrap_line_length (default unlimited) - lines should wrap at next opportunity after this number of characters.
+          NOTE: This is not a hard limit. Lines will continue until a point where a newline would
+                be preserved if it were present.
+
+    e.g
+
+    js_beautify(js_source_text, {
+      'indent_size': 1,
+      'indent_char': '\t'
+    });
+
+*/
+
+var js_beautify = function js_beautify(js_source_text, options) {
+    var beautifier = new Beautifier(js_source_text, options);
+    return beautifier.beautify();
+};
+
+exports.jsBeautify = js_beautify;
+
+function Beautifier(js_source_text, options) {
+    var input, output_lines;
+    var token_text, token_type, last_type, last_last_text, indent_string;
+    var flags, previous_flags, flag_store;
+    var whitespace, wordchar, punct, parser_pos, line_starters, reserved_words, digits;
+    var prefix;
+    var input_wanted_newline;
+    var output_space_before_token;
+    var input_length, n_newlines, whitespace_before_token;
+    var handlers, MODE, opt;
+    var preindent_string = '';
+
+
+
+    whitespace = "\n\r\t ".split('');
+    wordchar = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$'.split('');
+    digits = '0123456789'.split('');
+
+    punct = '+ - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> << >>> >>>= >>= <<= && &= | || ! ~ , : ? ^ ^= |= :: =>';
+    punct += ' <%= <% %> '; // try to be a good boy and try not to break the markup language identifiers
+    punct = punct.split(' ');
+
+    // words which should always start on new line.
+    line_starters = 'continue,try,throw,return,var,let,const,if,switch,case,default,for,while,break,function,yield'.split(',');
+    reserved_words = line_starters.concat(['do', 'in', 'else', 'get', 'set', 'new', 'catch', 'finally', 'typeof']);
+
+
+    MODE = {
+        BlockStatement: 'BlockStatement', // 'BLOCK'
+        Statement: 'Statement', // 'STATEMENT'
+        ObjectLiteral: 'ObjectLiteral', // 'OBJECT',
+        ArrayLiteral: 'ArrayLiteral', //'[EXPRESSION]',
+        ForInitializer: 'ForInitializer', //'(FOR-EXPRESSION)',
+        Conditional: 'Conditional', //'(COND-EXPRESSION)',
+        Expression: 'Expression' //'(EXPRESSION)'
+    };
+
+    handlers = {
+        'TK_START_EXPR': handle_start_expr,
+        'TK_END_EXPR': handle_end_expr,
+        'TK_START_BLOCK': handle_start_block,
+        'TK_END_BLOCK': handle_end_block,
+        'TK_WORD': handle_word,
+        'TK_RESERVED': handle_word,
+        'TK_SEMICOLON': handle_semicolon,
+        'TK_STRING': handle_string,
+        'TK_EQUALS': handle_equals,
+        'TK_OPERATOR': handle_operator,
+        'TK_COMMA': handle_comma,
+        'TK_BLOCK_COMMENT': handle_block_comment,
+        'TK_INLINE_COMMENT': handle_inline_comment,
+        'TK_COMMENT': handle_comment,
+        'TK_DOT': handle_dot,
+        'TK_UNKNOWN': handle_unknown
+    };
+
+    function create_flags(flags_base, mode) {
+        var next_indent_level = 0;
+        if (flags_base) {
+            next_indent_level = flags_base.indentation_level;
+            if (!just_added_newline() &&
+                flags_base.line_indent_level > next_indent_level) {
+                next_indent_level = flags_base.line_indent_level;
+            }
+        }
+
+        var next_flags = {
+            mode: mode,
+            parent: flags_base,
+            last_text: flags_base ? flags_base.last_text : '', // last token text
+            last_word: flags_base ? flags_base.last_word : '', // last 'TK_WORD' passed
+            declaration_statement: false,
+            declaration_assignment: false,
+            in_html_comment: false,
+            multiline_frame: false,
+            if_block: false,
+            else_block: false,
+            do_block: false,
+            do_while: false,
+            in_case_statement: false, // switch(..){ INSIDE HERE }
+            in_case: false, // we're on the exact line with "case 0:"
+            case_body: false, // the indented case-action block
+            indentation_level: next_indent_level,
+            line_indent_level: flags_base ? flags_base.line_indent_level : next_indent_level,
+            start_line_index: output_lines.length,
+            had_comment: false,
+            ternary_depth: 0
+        };
+        return next_flags;
+    }
+
+    // Using object instead of string to allow for later expansion of info about each line
+
+    function create_output_line() {
+        return {
+            text: []
+        };
+    }
+
+    // Some interpreters have unexpected results with foo = baz || bar;
+    options = options ? options : {};
+    opt = {};
+
+    // compatibility
+    if (options.space_after_anon_function !== undefined && options.jslint_happy === undefined) {
+        options.jslint_happy = options.space_after_anon_function;
+    }
+    if (options.braces_on_own_line !== undefined) { //graceful handling of deprecated option
+        opt.brace_style = options.braces_on_own_line ? "expand" : "collapse";
+    }
+    opt.brace_style = options.brace_style ? options.brace_style : (opt.brace_style ? opt.brace_style : "collapse");
+
+    // graceful handling of deprecated option
+    if (opt.brace_style === "expand-strict") {
+        opt.brace_style = "expand";
+    }
+
+
+    opt.indent_size = options.indent_size ? parseInt(options.indent_size, 10) : 4;
+    opt.indent_char = options.indent_char ? options.indent_char : ' ';
+    opt.preserve_newlines = (options.preserve_newlines === undefined) ? true : options.preserve_newlines;
+    opt.break_chained_methods = (options.break_chained_methods === undefined) ? false : options.break_chained_methods;
+    opt.max_preserve_newlines = (options.max_preserve_newlines === undefined) ? 0 : parseInt(options.max_preserve_newlines, 10);
+    opt.space_in_paren = (options.space_in_paren === undefined) ? false : options.space_in_paren;
+    opt.space_in_empty_paren = (options.space_in_empty_paren === undefined) ? false : options.space_in_empty_paren;
+    opt.jslint_happy = (options.jslint_happy === undefined) ? false : options.jslint_happy;
+    opt.keep_array_indentation = (options.keep_array_indentation === undefined) ? false : options.keep_array_indentation;
+    opt.space_before_conditional = (options.space_before_conditional === undefined) ? true : options.space_before_conditional;
+    opt.unescape_strings = (options.unescape_strings === undefined) ? false : options.unescape_strings;
+    opt.wrap_line_length = (options.wrap_line_length === undefined) ? 0 : parseInt(options.wrap_line_length, 10);
+    opt.e4x = (options.e4x === undefined) ? false : options.e4x;
+
+    if(options.indent_with_tabs){
+        opt.indent_char = '\t';
+        opt.indent_size = 1;
+    }
+
+    //----------------------------------
+    indent_string = '';
+    while (opt.indent_size > 0) {
+        indent_string += opt.indent_char;
+        opt.indent_size -= 1;
+    }
+
+    while (js_source_text && (js_source_text.charAt(0) === ' ' || js_source_text.charAt(0) === '\t')) {
+        preindent_string += js_source_text.charAt(0);
+        js_source_text = js_source_text.substring(1);
+    }
+    input = js_source_text;
+    // cache the source's length.
+    input_length = js_source_text.length;
+
+    last_type = 'TK_START_BLOCK'; // last token type
+    last_last_text = ''; // pre-last token text
+    output_lines = [create_output_line()];
+    output_space_before_token = false;
+    whitespace_before_token = [];
+
+    // Stack of parsing/formatting states, including MODE.
+    // We tokenize, parse, and output in an almost purely a forward-only stream of token input
+    // and formatted output.  This makes the beautifier less accurate than full parsers
+    // but also far more tolerant of syntax errors.
+    //
+    // For example, the default mode is MODE.BlockStatement. If we see a '{' we push a new frame of type
+    // MODE.BlockStatement on the the stack, even though it could be object literal.  If we later
+    // encounter a ":", we'll switch to to MODE.ObjectLiteral.  If we then see a ";",
+    // most full parsers would die, but the beautifier gracefully falls back to
+    // MODE.BlockStatement and continues on.
+    flag_store = [];
+    set_mode(MODE.BlockStatement);
+
+    parser_pos = 0;
+
+    this.beautify = function() {
+        /*jshint onevar:true */
+        var t, i, keep_whitespace, sweet_code;
+
+        while (true) {
+            t = get_next_token();
+            token_text = t[0];
+            token_type = t[1];
+
+            if (token_type === 'TK_EOF') {
+                // Unwind any open statements
+                while (flags.mode === MODE.Statement) {
+                    restore_mode();
+                }
+                break;
+            }
+
+            keep_whitespace = opt.keep_array_indentation && is_array(flags.mode);
+            input_wanted_newline = n_newlines > 0;
+
+            if (keep_whitespace) {
+                for (i = 0; i < n_newlines; i += 1) {
+                    print_newline(i > 0);
+                }
+            } else {
+                if (opt.max_preserve_newlines && n_newlines > opt.max_preserve_newlines) {
+                    n_newlines = opt.max_preserve_newlines;
+                }
+
+                if (opt.preserve_newlines) {
+                    if (n_newlines > 1) {
+                        print_newline();
+                        for (i = 1; i < n_newlines; i += 1) {
+                            print_newline(true);
+                        }
+                    }
+                }
+            }
+
+            handlers[token_type]();
+
+            // The cleanest handling of inline comments is to treat them as though they aren't there.
+            // Just continue formatting and the behavior should be logical.
+            // Also ignore unknown tokens.  Again, this should result in better behavior.
+            if (token_type !== 'TK_INLINE_COMMENT' && token_type !== 'TK_COMMENT' &&
+                token_type !== 'TK_BLOCK_COMMENT' && token_type !== 'TK_UNKNOWN') {
+                last_last_text = flags.last_text;
+                last_type = token_type;
+                flags.last_text = token_text;
+            }
+            flags.had_comment = (token_type === 'TK_INLINE_COMMENT' || token_type === 'TK_COMMENT'
+                || token_type === 'TK_BLOCK_COMMENT');
+        }
+
+
+        sweet_code = output_lines[0].text.join('');
+        for (var line_index = 1; line_index < output_lines.length; line_index++) {
+            sweet_code += '\n' + output_lines[line_index].text.join('');
+        }
+        sweet_code = sweet_code.replace(/[\r\n ]+$/, '');
+        return sweet_code;
+    };
+
+    function trim_output(eat_newlines) {
+        eat_newlines = (eat_newlines === undefined) ? false : eat_newlines;
+
+        if (output_lines.length) {
+            trim_output_line(output_lines[output_lines.length - 1], eat_newlines);
+
+            while (eat_newlines && output_lines.length > 1 &&
+                output_lines[output_lines.length - 1].text.length === 0) {
+                output_lines.pop();
+                trim_output_line(output_lines[output_lines.length - 1], eat_newlines);
+            }
+        }
+    }
+
+    function trim_output_line(line) {
+        while (line.text.length &&
+            (line.text[line.text.length - 1] === ' ' ||
+                line.text[line.text.length - 1] === indent_string ||
+                line.text[line.text.length - 1] === preindent_string)) {
+            line.text.pop();
+        }
+    }
+
+    function trim(s) {
+        return s.replace(/^\s+|\s+$/g, '');
+    }
+
+    // we could use just string.split, but
+    // IE doesn't like returning empty strings
+
+    function split_newlines(s) {
+        //return s.split(/\x0d\x0a|\x0a/);
+
+        s = s.replace(/\x0d/g, '');
+        var out = [],
+            idx = s.indexOf("\n");
+        while (idx !== -1) {
+            out.push(s.substring(0, idx));
+            s = s.substring(idx + 1);
+            idx = s.indexOf("\n");
+        }
+        if (s.length) {
+            out.push(s);
+        }
+        return out;
+    }
+
+    function just_added_newline() {
+        var line = output_lines[output_lines.length - 1];
+        return line.text.length === 0;
+    }
+
+    function just_added_blankline() {
+        if (just_added_newline()) {
+            if (output_lines.length === 1) {
+                return true; // start of the file and newline = blank
+            }
+
+            var line = output_lines[output_lines.length - 2];
+            return line.text.length === 0;
+        }
+        return false;
+    }
+
+    function allow_wrap_or_preserved_newline(force_linewrap) {
+        force_linewrap = (force_linewrap === undefined) ? false : force_linewrap;
+        if (opt.wrap_line_length && !force_linewrap) {
+            var line = output_lines[output_lines.length - 1];
+            var proposed_line_length = 0;
+            // never wrap the first token of a line.
+            if (line.text.length > 0) {
+                proposed_line_length = line.text.join('').length + token_text.length +
+                    (output_space_before_token ? 1 : 0);
+                if (proposed_line_length >= opt.wrap_line_length) {
+                    force_linewrap = true;
+                }
+            }
+        }
+        if (((opt.preserve_newlines && input_wanted_newline) || force_linewrap) && !just_added_newline()) {
+            print_newline(false, true);
+
+        }
+    }
+
+    function print_newline(force_newline, preserve_statement_flags) {
+        output_space_before_token = false;
+
+        if (!preserve_statement_flags) {
+            if (flags.last_text !== ';' && flags.last_text !== ',' && flags.last_text !== '=' && last_type !== 'TK_OPERATOR') {
+                while (flags.mode === MODE.Statement && !flags.if_block && !flags.do_block) {
+                    restore_mode();
+                }
+            }
+        }
+
+        if (output_lines.length === 1 && just_added_newline()) {
+            return; // no newline on start of file
+        }
+
+        if (force_newline || !just_added_newline()) {
+            flags.multiline_frame = true;
+            output_lines.push(create_output_line());
+        }
+    }
+
+    function print_token_line_indentation() {
+        if (just_added_newline()) {
+            var line = output_lines[output_lines.length - 1];
+            if (opt.keep_array_indentation && is_array(flags.mode) && input_wanted_newline) {
+                // prevent removing of this whitespace as redundant
+                line.text.push('');
+                for (var i = 0; i < whitespace_before_token.length; i += 1) {
+                    line.text.push(whitespace_before_token[i]);
+                }
+            } else {
+                if (preindent_string) {
+                    line.text.push(preindent_string);
+                }
+
+                print_indent_string(flags.indentation_level);
+            }
+        }
+    }
+
+    function print_indent_string(level) {
+        // Never indent your first output indent at the start of the file
+        if (output_lines.length > 1) {
+            var line = output_lines[output_lines.length - 1];
+
+            flags.line_indent_level = level;
+            for (var i = 0; i < level; i += 1) {
+                line.text.push(indent_string);
+            }
+        }
+    }
+
+    function print_token_space_before() {
+        var line = output_lines[output_lines.length - 1];
+        if (output_space_before_token && line.text.length) {
+            var last_output = line.text[line.text.length - 1];
+            if (last_output !== ' ' && last_output !== indent_string) { // prevent occassional duplicate space
+                line.text.push(' ');
+            }
+        }
+    }
+
+    function print_token(printable_token) {
+        printable_token = printable_token || token_text;
+        print_token_line_indentation();
+        print_token_space_before();
+        output_space_before_token = false;
+        output_lines[output_lines.length - 1].text.push(printable_token);
+    }
+
+    function indent() {
+        flags.indentation_level += 1;
+    }
+
+    function deindent() {
+        if (flags.indentation_level > 0 &&
+            ((!flags.parent) || flags.indentation_level > flags.parent.indentation_level))
+            flags.indentation_level -= 1;
+    }
+
+    function remove_redundant_indentation(frame) {
+        // This implementation is effective but has some issues:
+        //     - less than great performance due to array splicing
+        //     - can cause line wrap to happen too soon due to indent removal
+        //           after wrap points are calculated
+        // These issues are minor compared to ugly indentation.
+
+        if (frame.multiline_frame) return;
+
+        // remove one indent from each line inside this section
+        var index = frame.start_line_index;
+        var splice_index = 0;
+        var line;
+
+        while (index < output_lines.length) {
+            line = output_lines[index];
+            index++;
+
+            // skip empty lines
+            if (line.text.length === 0) {
+                continue;
+            }
+
+            // skip the preindent string if present
+            if (preindent_string && line.text[0] === preindent_string) {
+                splice_index = 1;
+            } else {
+                splice_index = 0;
+            }
+
+            // remove one indent, if present
+            if (line.text[splice_index] === indent_string) {
+                line.text.splice(splice_index, 1);
+            }
+        }
+    }
+
+    function set_mode(mode) {
+        if (flags) {
+            flag_store.push(flags);
+            previous_flags = flags;
+        } else {
+            previous_flags = create_flags(null, mode);
+        }
+
+        flags = create_flags(previous_flags, mode);
+    }
+
+    function is_array(mode) {
+        return mode === MODE.ArrayLiteral;
+    }
+
+    function is_expression(mode) {
+        return in_array(mode, [MODE.Expression, MODE.ForInitializer, MODE.Conditional]);
+    }
+
+    function restore_mode() {
+        if (flag_store.length > 0) {
+            previous_flags = flags;
+            flags = flag_store.pop();
+            if (previous_flags.mode === MODE.Statement) {
+                remove_redundant_indentation(previous_flags);
+            }
+        }
+    }
+
+    function start_of_object_property() {
+        return flags.parent.mode === MODE.ObjectLiteral && flags.mode === MODE.Statement && flags.last_text === ':' &&
+            flags.ternary_depth === 0;
+    }
+
+    function start_of_statement() {
+        if (
+                (last_type === 'TK_RESERVED' && in_array(flags.last_text, ['var', 'let', 'const']) && token_type === 'TK_WORD') ||
+                (last_type === 'TK_RESERVED' && flags.last_text === 'do') ||
+                (last_type === 'TK_RESERVED' && flags.last_text === 'return' && !input_wanted_newline) ||
+                (last_type === 'TK_RESERVED' && flags.last_text === 'else' && !(token_type === 'TK_RESERVED' && token_text === 'if')) ||
+                (last_type === 'TK_END_EXPR' && (previous_flags.mode === MODE.ForInitializer || previous_flags.mode === MODE.Conditional)) ||
+                (last_type === 'TK_WORD' && flags.mode === MODE.BlockStatement
+                    && !flags.in_case
+                    && !(token_text === '--' || token_text === '++')
+                    && token_type !== 'TK_WORD' && token_type !== 'TK_RESERVED') ||
+                (flags.mode === MODE.ObjectLiteral && flags.last_text === ':' && flags.ternary_depth === 0)
+
+            ) {
+
+            set_mode(MODE.Statement);
+            indent();
+
+            if (last_type === 'TK_RESERVED' && in_array(flags.last_text, ['var', 'let', 'const']) && token_type === 'TK_WORD') {
+                flags.declaration_statement = true;
+            }
+
+            // Issue #276:
+            // If starting a new statement with [if, for, while, do], push to a new line.
+            // if (a) if (b) if(c) d(); else e(); else f();
+            if (!start_of_object_property()) {
+                allow_wrap_or_preserved_newline(
+                    token_type === 'TK_RESERVED' && in_array(token_text, ['do', 'for', 'if', 'while']));
+            }
+
+            return true;
+        }
+        return false;
+    }
+
+    function all_lines_start_with(lines, c) {
+        for (var i = 0; i < lines.length; i++) {
+            var line = trim(lines[i]);
+            if (line.charAt(0) !== c) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    function each_line_matches_indent(lines, indent) {
+        var i = 0,
+            len = lines.length,
+            line;
+        for (; i < len; i++) {
+            line = lines[i];
+            // allow empty lines to pass through
+            if (line && line.indexOf(indent) !== 0) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    function is_special_word(word) {
+        return in_array(word, ['case', 'return', 'do', 'if', 'throw', 'else']);
+    }
+
+    function in_array(what, arr) {
+        for (var i = 0; i < arr.length; i += 1) {
+            if (arr[i] === what) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    function unescape_string(s) {
+        var esc = false,
+            out = '',
+            pos = 0,
+            s_hex = '',
+            escaped = 0,
+            c;
+
+        while (esc || pos < s.length) {
+
+            c = s.charAt(pos);
+            pos++;
+
+            if (esc) {
+                esc = false;
+                if (c === 'x') {
+                    // simple hex-escape \x24
+                    s_hex = s.substr(pos, 2);
+                    pos += 2;
+                } else if (c === 'u') {
+                    // unicode-escape, \u2134
+                    s_hex = s.substr(pos, 4);
+                    pos += 4;
+                } else {
+                    // some common escape, e.g \n
+                    out += '\\' + c;
+                    continue;
+                }
+                if (!s_hex.match(/^[0123456789abcdefABCDEF]+$/)) {
+                    // some weird escaping, bail out,
+                    // leaving whole string intact
+                    return s;
+                }
+
+                escaped = parseInt(s_hex, 16);
+
+                if (escaped >= 0x00 && escaped < 0x20) {
+                    // leave 0x00...0x1f escaped
+                    if (c === 'x') {
+                        out += '\\x' + s_hex;
+                    } else {
+                        out += '\\u' + s_hex;
+                    }
+                    continue;
+                } else if (escaped === 0x22 || escaped === 0x27 || escaped === 0x5c) {
+                    // single-quote, apostrophe, backslash - escape these
+                    out += '\\' + String.fromCharCode(escaped);
+                } else if (c === 'x' && escaped > 0x7e && escaped <= 0xff) {
+                    // we bail out on \x7f..\xff,
+                    // leaving whole string escaped,
+                    // as it's probably completely binary
+                    return s;
+                } else {
+                    out += String.fromCharCode(escaped);
+                }
+            } else if (c === '\\') {
+                esc = true;
+            } else {
+                out += c;
+            }
+        }
+        return out;
+    }
+
+    function is_next(find) {
+        var local_pos = parser_pos;
+        var c = input.charAt(local_pos);
+        while (in_array(c, whitespace) && c !== find) {
+            local_pos++;
+            if (local_pos >= input_length) {
+                return false;
+            }
+            c = input.charAt(local_pos);
+        }
+        return c === find;
+    }
+
+    function get_next_token() {
+        var i, resulting_string;
+
+        n_newlines = 0;
+
+        if (parser_pos >= input_length) {
+            return ['', 'TK_EOF'];
+        }
+
+        input_wanted_newline = false;
+        whitespace_before_token = [];
+
+        var c = input.charAt(parser_pos);
+        parser_pos += 1;
+
+        while (in_array(c, whitespace)) {
+
+            if (c === '\n') {
+                n_newlines += 1;
+                whitespace_before_token = [];
+            } else if (n_newlines) {
+                if (c === indent_string) {
+                    whitespace_before_token.push(indent_string);
+                } else if (c !== '\r') {
+                    whitespace_before_token.push(' ');
+                }
+            }
+
+            if (parser_pos >= input_length) {
+                return ['', 'TK_EOF'];
+            }
+
+            c = input.charAt(parser_pos);
+            parser_pos += 1;
+        }
+
+        // NOTE: because beautifier doesn't fully parse, it doesn't use acorn.isIdentifierStart.
+        // It just treats all identifiers and numbers and such the same.
+        if (acorn.isIdentifierChar(input.charCodeAt(parser_pos-1))) {
+            if (parser_pos < input_length) {
+                while (acorn.isIdentifierChar(input.charCodeAt(parser_pos))) {
+                    c += input.charAt(parser_pos);
+                    parser_pos += 1;
+                    if (parser_pos === input_length) {
+                        break;
+                    }
+                }
+            }
+
+            // small and surprisingly unugly hack for 1E-10 representation
+            if (parser_pos !== input_length && c.match(/^[0-9]+[Ee]$/) && (input.charAt(parser_pos) === '-' || input.charAt(parser_pos) === '+')) {
+
+                var sign = input.charAt(parser_pos);
+                parser_pos += 1;
+
+                var t = get_next_token();
+                c += sign + t[0];
+                return [c, 'TK_WORD'];
+            }
+
+            if (!(last_type === 'TK_DOT' ||
+                    (last_type === 'TK_RESERVED' && in_array(flags.last_text, ['set', 'get'])))
+                && in_array(c, reserved_words)) {
+                if (c === 'in') { // hack for 'in' operator
+                    return [c, 'TK_OPERATOR'];
+                }
+                return [c, 'TK_RESERVED'];
+            }
+            return [c, 'TK_WORD'];
+        }
+
+        if (c === '(' || c === '[') {
+            return [c, 'TK_START_EXPR'];
+        }
+
+        if (c === ')' || c === ']') {
+            return [c, 'TK_END_EXPR'];
+        }
+
+        if (c === '{') {
+            return [c, 'TK_START_BLOCK'];
+        }
+
+        if (c === '}') {
+            return [c, 'TK_END_BLOCK'];
+        }
+
+        if (c === ';') {
+            return [c, 'TK_SEMICOLON'];
+        }
+
+        if (c === '/') {
+            var comment = '';
+            // peek for comment /* ... */
+            var inline_comment = true;
+            if (input.charAt(parser_pos) === '*') {
+                parser_pos += 1;
+                if (parser_pos < input_length) {
+                    while (parser_pos < input_length && !(input.charAt(parser_pos) === '*' && input.charAt(parser_pos + 1) && input.charAt(parser_pos + 1) === '/')) {
+                        c = input.charAt(parser_pos);
+                        comment += c;
+                        if (c === "\n" || c === "\r") {
+                            inline_comment = false;
+                        }
+                        parser_pos += 1;
+                        if (parser_pos >= input_length) {
+                            break;
+                        }
+                    }
+                }
+                parser_pos += 2;
+                if (inline_comment && n_newlines === 0) {
+                    return ['/*' + comment + '*/', 'TK_INLINE_COMMENT'];
+                } else {
+                    return ['/*' + comment + '*/', 'TK_BLOCK_COMMENT'];
+                }
+            }
+            // peek for comment // ...
+            if (input.charAt(parser_pos) === '/') {
+                comment = c;
+                while (input.charAt(parser_pos) !== '\r' && input.charAt(parser_pos) !== '\n') {
+                    comment += input.charAt(parser_pos);
+                    parser_pos += 1;
+                    if (parser_pos >= input_length) {
+                        break;
+                    }
+                }
+                return [comment, 'TK_COMMENT'];
+            }
+
+        }
+
+
+        if (c === '`' || c === "'" || c === '"' || // string
+            (
+                (c === '/') || // regexp
+                (opt.e4x && c === "<" && input.slice(parser_pos - 1).match(/^<([-a-zA-Z:0-9_.]+|{[^{}]*}|!\[CDATA\[[\s\S]*?\]\])\s*([-a-zA-Z:0-9_.]+=('[^']*'|"[^"]*"|{[^{}]*})\s*)*\/?\s*>/)) // xml
+            ) && ( // regex and xml can only appear in specific locations during parsing
+                (last_type === 'TK_RESERVED' && is_special_word(flags.last_text)) ||
+                (last_type === 'TK_END_EXPR' && in_array(previous_flags.mode, [MODE.Conditional, MODE.ForInitializer])) ||
+                (in_array(last_type, ['TK_COMMENT', 'TK_START_EXPR', 'TK_START_BLOCK',
+                    'TK_END_BLOCK', 'TK_OPERATOR', 'TK_EQUALS', 'TK_EOF', 'TK_SEMICOLON', 'TK_COMMA'
+                ]))
+            )) {
+
+            var sep = c,
+                esc = false,
+                has_char_escapes = false;
+
+            resulting_string = c;
+
+            if (parser_pos < input_length) {
+                if (sep === '/') {
+                    //
+                    // handle regexp
+                    //
+                    var in_char_class = false;
+                    while (esc || in_char_class || input.charAt(parser_pos) !== sep) {
+                        resulting_string += input.charAt(parser_pos);
+                        if (!esc) {
+                            esc = input.charAt(parser_pos) === '\\';
+                            if (input.charAt(parser_pos) === '[') {
+                                in_char_class = true;
+                            } else if (input.charAt(parser_pos) === ']') {
+                                in_char_class = false;
+                            }
+                        } else {
+                            esc = false;
+                        }
+                        parser_pos += 1;
+                        if (parser_pos >= input_length) {
+                            // incomplete string/rexp when end-of-file reached.
+                            // bail out with what had been received so far.
+                            return [resulting_string, 'TK_STRING'];
+                        }
+                    }
+                } else if (opt.e4x && sep === '<') {
+                    //
+                    // handle e4x xml literals
+                    //
+                    var xmlRegExp = /<(\/?)([-a-zA-Z:0-9_.]+|{[^{}]*}|!\[CDATA\[[\s\S]*?\]\])\s*([-a-zA-Z:0-9_.]+=('[^']*'|"[^"]*"|{[^{}]*})\s*)*(\/?)\s*>/g;
+                    var xmlStr = input.slice(parser_pos - 1);
+                    var match = xmlRegExp.exec(xmlStr);
+                    if (match && match.index === 0) {
+                        var rootTag = match[2];
+                        var depth = 0;
+                        while (match) {
+                            var isEndTag = !! match[1];
+                            var tagName = match[2];
+                            var isSingletonTag = ( !! match[match.length - 1]) || (tagName.slice(0, 8) === "![CDATA[");
+                            if (tagName === rootTag && !isSingletonTag) {
+                                if (isEndTag) {
+                                    --depth;
+                                } else {
+                                    ++depth;
+                                }
+                            }
+                            if (depth <= 0) {
+                                break;
+                            }
+                            match = xmlRegExp.exec(xmlStr);
+                        }
+                        var xmlLength = match ? match.index + match[0].length : xmlStr.length;
+                        parser_pos += xmlLength - 1;
+                        return [xmlStr.slice(0, xmlLength), "TK_STRING"];
+                    }
+                } else {
+                    //
+                    // handle string
+                    //
+                    while (esc || input.charAt(parser_pos) !== sep) {
+                        resulting_string += input.charAt(parser_pos);
+                        if (esc) {
+                            if (input.charAt(parser_pos) === 'x' || input.charAt(parser_pos) === 'u') {
+                                has_char_escapes = true;
+                            }
+                            esc = false;
+                        } else {
+                            esc = input.charAt(parser_pos) === '\\';
+                        }
+                        parser_pos += 1;
+                        if (parser_pos >= input_length) {
+                            // incomplete string/rexp when end-of-file reached.
+                            // bail out with what had been received so far.
+                            return [resulting_string, 'TK_STRING'];
+                        }
+                    }
+
+                }
+            }
+
+            parser_pos += 1;
+            resulting_string += sep;
+
+            if (has_char_escapes && opt.unescape_strings) {
+                resulting_string = unescape_string(resulting_string);
+            }
+
+            if (sep === '/') {
+                // regexps may have modifiers /regexp/MOD , so fetch those, too
+                while (parser_pos < input_length && in_array(input.charAt(parser_pos), wordchar)) {
+                    resulting_string += input.charAt(parser_pos);
+                    parser_pos += 1;
+                }
+            }
+            return [resulting_string, 'TK_STRING'];
+        }
+
+        if (c === '#') {
+
+
+            if (output_lines.length === 1 && output_lines[0].text.length === 0 &&
+                input.charAt(parser_pos) === '!') {
+                // shebang
+                resulting_string = c;
+                while (parser_pos < input_length && c !== '\n') {
+                    c = input.charAt(parser_pos);
+                    resulting_string += c;
+                    parser_pos += 1;
+                }
+                return [trim(resulting_string) + '\n', 'TK_UNKNOWN'];
+            }
+
+
+
+            // Spidermonkey-specific sharp variables for circular references
+            // https://developer.mozilla.org/En/Sharp_variables_in_JavaScript
+            // http://dxr.mozilla.org/mozilla-central/source/js/src/jsscan.cpp around line 1935
+            var sharp = '#';
+            if (parser_pos < input_length && in_array(input.charAt(parser_pos), digits)) {
+                do {
+                    c = input.charAt(parser_pos);
+                    sharp += c;
+                    parser_pos += 1;
+                } while (parser_pos < input_length && c !== '#' && c !== '=');
+                if (c === '#') {
+                    //
+                } else if (input.charAt(parser_pos) === '[' && input.charAt(parser_pos + 1) === ']') {
+                    sharp += '[]';
+                    parser_pos += 2;
+                } else if (input.charAt(parser_pos) === '{' && input.charAt(parser_pos + 1) === '}') {
+                    sharp += '{}';
+                    parser_pos += 2;
+                }
+                return [sharp, 'TK_WORD'];
+            }
+        }
+
+        if (c === '<' && input.substring(parser_pos - 1, parser_pos + 3) === '') {
+            flags.in_html_comment = false;
+            parser_pos += 2;
+            return ['-->', 'TK_COMMENT'];
+        }
+
+        if (c === '.') {
+            return [c, 'TK_DOT'];
+        }
+
+        if (in_array(c, punct)) {
+            while (parser_pos < input_length && in_array(c + input.charAt(parser_pos), punct)) {
+                c += input.charAt(parser_pos);
+                parser_pos += 1;
+                if (parser_pos >= input_length) {
+                    break;
+                }
+            }
+
+            if (c === ',') {
+                return [c, 'TK_COMMA'];
+            } else if (c === '=') {
+                return [c, 'TK_EQUALS'];
+            } else {
+                return [c, 'TK_OPERATOR'];
+            }
+        }
+
+        return [c, 'TK_UNKNOWN'];
+    }
+
+    function handle_start_expr() {
+        if (start_of_statement()) {
+            // The conditional starts the statement if appropriate.
+        }
+
+        var next_mode = MODE.Expression;
+        if (token_text === '[') {
+
+            if (last_type === 'TK_WORD' || flags.last_text === ')') {
+                // this is array index specifier, break immediately
+                // a[x], fn()[x]
+                if (last_type === 'TK_RESERVED' && in_array(flags.last_text, line_starters)) {
+                    output_space_before_token = true;
+                }
+                set_mode(next_mode);
+                print_token();
+                indent();
+                if (opt.space_in_paren) {
+                    output_space_before_token = true;
+                }
+                return;
+            }
+
+            next_mode = MODE.ArrayLiteral;
+            if (is_array(flags.mode)) {
+                if (flags.last_text === '[' ||
+                    (flags.last_text === ',' && (last_last_text === ']' || last_last_text === '}'))) {
+                    // ], [ goes to new line
+                    // }, [ goes to new line
+                    if (!opt.keep_array_indentation) {
+                        print_newline();
+                    }
+                }
+            }
+
+        } else {
+            if (last_type === 'TK_RESERVED' && flags.last_text === 'for') {
+                next_mode = MODE.ForInitializer;
+            } else if (last_type === 'TK_RESERVED' && in_array(flags.last_text, ['if', 'while'])) {
+                next_mode = MODE.Conditional;
+            } else {
+                // next_mode = MODE.Expression;
+            }
+        }
+
+        if (flags.last_text === ';' || last_type === 'TK_START_BLOCK') {
+            print_newline();
+        } else if (last_type === 'TK_END_EXPR' || last_type === 'TK_START_EXPR' || last_type === 'TK_END_BLOCK' || flags.last_text === '.') {
+            // TODO: Consider whether forcing this is required.  Review failing tests when removed.
+            allow_wrap_or_preserved_newline(input_wanted_newline);
+            // do nothing on (( and )( and ][ and ]( and .(
+        } else if (!(last_type === 'TK_RESERVED' && token_text === '(') && last_type !== 'TK_WORD' && last_type !== 'TK_OPERATOR') {
+            output_space_before_token = true;
+        } else if ((last_type === 'TK_RESERVED' && (flags.last_word === 'function' || flags.last_word === 'typeof')) ||
+            (flags.last_text === '*' && last_last_text === 'function')) {
+            // function() vs function ()
+            if (opt.jslint_happy) {
+                output_space_before_token = true;
+            }
+        } else if (last_type === 'TK_RESERVED' && (in_array(flags.last_text, line_starters) || flags.last_text === 'catch')) {
+            if (opt.space_before_conditional) {
+                output_space_before_token = true;
+            }
+        }
+
+        // Support of this kind of newline preservation.
+        // a = (b &&
+        //     (c || d));
+        if (token_text === '(') {
+            if (last_type === 'TK_EQUALS' || last_type === 'TK_OPERATOR') {
+                if (!start_of_object_property()) {
+                    allow_wrap_or_preserved_newline();
+                }
+            }
+        }
+
+        set_mode(next_mode);
+        print_token();
+        if (opt.space_in_paren) {
+            output_space_before_token = true;
+        }
+
+        // In all cases, if we newline while inside an expression it should be indented.
+        indent();
+    }
+
+    function handle_end_expr() {
+        // statements inside expressions are not valid syntax, but...
+        // statements must all be closed when their container closes
+        while (flags.mode === MODE.Statement) {
+            restore_mode();
+        }
+
+        if (flags.multiline_frame) {
+            allow_wrap_or_preserved_newline(token_text === ']' && is_array(flags.mode) && !opt.keep_array_indentation);
+        }
+
+        if (opt.space_in_paren) {
+            if (last_type === 'TK_START_EXPR' && ! opt.space_in_empty_paren) {
+                // () [] no inner space in empty parens like these, ever, ref #320
+                trim_output();
+                output_space_before_token = false;
+            } else {
+                output_space_before_token = true;
+            }
+        }
+        if (token_text === ']' && opt.keep_array_indentation) {
+            print_token();
+            restore_mode();
+        } else {
+            restore_mode();
+            print_token();
+        }
+        remove_redundant_indentation(previous_flags);
+
+        // do {} while () // no statement required after
+        if (flags.do_while && previous_flags.mode === MODE.Conditional) {
+            previous_flags.mode = MODE.Expression;
+            flags.do_block = false;
+            flags.do_while = false;
+
+        }
+    }
+
+    function handle_start_block() {
+        set_mode(MODE.BlockStatement);
+
+        var empty_braces = is_next('}');
+        var empty_anonymous_function = empty_braces && flags.last_word === 'function' &&
+            last_type === 'TK_END_EXPR';
+
+        if (opt.brace_style === "expand") {
+            if (last_type !== 'TK_OPERATOR' &&
+                (empty_anonymous_function ||
+                    last_type === 'TK_EQUALS' ||
+                    (last_type === 'TK_RESERVED' && is_special_word(flags.last_text) && flags.last_text !== 'else'))) {
+                output_space_before_token = true;
+            } else {
+                print_newline(false, true);
+            }
+        } else { // collapse
+            if (last_type !== 'TK_OPERATOR' && last_type !== 'TK_START_EXPR') {
+                if (last_type === 'TK_START_BLOCK') {
+                    print_newline();
+                } else {
+                    output_space_before_token = true;
+                }
+            } else {
+                // if TK_OPERATOR or TK_START_EXPR
+                if (is_array(previous_flags.mode) && flags.last_text === ',') {
+                    if (last_last_text === '}') {
+                        // }, { in array context
+                        output_space_before_token = true;
+                    } else {
+                        print_newline(); // [a, b, c, {
+                    }
+                }
+            }
+        }
+        print_token();
+        indent();
+    }
+
+    function handle_end_block() {
+        // statements must all be closed when their container closes
+        while (flags.mode === MODE.Statement) {
+            restore_mode();
+        }
+        var empty_braces = last_type === 'TK_START_BLOCK';
+
+        if (opt.brace_style === "expand") {
+            if (!empty_braces) {
+                print_newline();
+            }
+        } else {
+            // skip {}
+            if (!empty_braces) {
+                if (is_array(flags.mode) && opt.keep_array_indentation) {
+                    // we REALLY need a newline here, but newliner would skip that
+                    opt.keep_array_indentation = false;
+                    print_newline();
+                    opt.keep_array_indentation = true;
+
+                } else {
+                    print_newline();
+                }
+            }
+        }
+        restore_mode();
+        print_token();
+    }
+
+    function handle_word() {
+        if (start_of_statement()) {
+            // The conditional starts the statement if appropriate.
+        } else if (input_wanted_newline && !is_expression(flags.mode) &&
+            (last_type !== 'TK_OPERATOR' || (flags.last_text === '--' || flags.last_text === '++')) &&
+            last_type !== 'TK_EQUALS' &&
+            (opt.preserve_newlines || !(last_type === 'TK_RESERVED' && in_array(flags.last_text, ['var', 'let', 'const', 'set', 'get'])))) {
+
+            print_newline();
+        }
+
+        if (flags.do_block && !flags.do_while) {
+            if (token_type === 'TK_RESERVED' && token_text === 'while') {
+                // do {} ## while ()
+                output_space_before_token = true;
+                print_token();
+                output_space_before_token = true;
+                flags.do_while = true;
+                return;
+            } else {
+                // do {} should always have while as the next word.
+                // if we don't see the expected while, recover
+                print_newline();
+                flags.do_block = false;
+            }
+        }
+
+        // if may be followed by else, or not
+        // Bare/inline ifs are tricky
+        // Need to unwind the modes correctly: if (a) if (b) c(); else d(); else e();
+        if (flags.if_block) {
+            if (!flags.else_block && (token_type === 'TK_RESERVED' && token_text === 'else')) {
+                flags.else_block = true;
+            } else {
+                while (flags.mode === MODE.Statement) {
+                    restore_mode();
+                }
+                flags.if_block = false;
+                flags.else_block = false;
+            }
+        }
+
+        if (token_type === 'TK_RESERVED' && (token_text === 'case' || (token_text === 'default' && flags.in_case_statement))) {
+            print_newline();
+            if (flags.case_body || opt.jslint_happy) {
+                // switch cases following one another
+                deindent();
+                flags.case_body = false;
+            }
+            print_token();
+            flags.in_case = true;
+            flags.in_case_statement = true;
+            return;
+        }
+
+        if (token_type === 'TK_RESERVED' && token_text === 'function') {
+            if (in_array(flags.last_text, ['}', ';']) || (just_added_newline() && ! in_array(flags.last_text, ['{', ':', '=', ',']))) {
+                // make sure there is a nice clean space of at least one blank line
+                // before a new function definition
+                if ( ! just_added_blankline() && ! flags.had_comment) {
+                    print_newline();
+                    print_newline(true);
+                }
+            }
+            if (last_type === 'TK_RESERVED' || last_type === 'TK_WORD') {
+                if (last_type === 'TK_RESERVED' && in_array(flags.last_text, ['get', 'set', 'new', 'return'])) {
+                    output_space_before_token = true;
+                } else {
+                    print_newline();
+                }
+            } else if (last_type === 'TK_OPERATOR' || flags.last_text === '=') {
+                // foo = function
+                output_space_before_token = true;
+            } else if (is_expression(flags.mode)) {
+                // (function
+            } else {
+                print_newline();
+            }
+        }
+
+        if (last_type === 'TK_COMMA' || last_type === 'TK_START_EXPR' || last_type === 'TK_EQUALS' || last_type === 'TK_OPERATOR') {
+            if (!start_of_object_property()) {
+                allow_wrap_or_preserved_newline();
+            }
+        }
+
+        if (token_type === 'TK_RESERVED' && token_text === 'function') {
+            print_token();
+            flags.last_word = token_text;
+            return;
+        }
+
+        prefix = 'NONE';
+
+        if (last_type === 'TK_END_BLOCK') {
+            if (!(token_type === 'TK_RESERVED' && in_array(token_text, ['else', 'catch', 'finally']))) {
+                prefix = 'NEWLINE';
+            } else {
+                if (opt.brace_style === "expand" || opt.brace_style === "end-expand") {
+                    prefix = 'NEWLINE';
+                } else {
+                    prefix = 'SPACE';
+                    output_space_before_token = true;
+                }
+            }
+        } else if (last_type === 'TK_SEMICOLON' && flags.mode === MODE.BlockStatement) {
+            // TODO: Should this be for STATEMENT as well?
+            prefix = 'NEWLINE';
+        } else if (last_type === 'TK_SEMICOLON' && is_expression(flags.mode)) {
+            prefix = 'SPACE';
+        } else if (last_type === 'TK_STRING') {
+            prefix = 'NEWLINE';
+        } else if (last_type === 'TK_RESERVED' || last_type === 'TK_WORD' ||
+            (flags.last_text === '*' && last_last_text === 'function')) {
+            prefix = 'SPACE';
+        } else if (last_type === 'TK_START_BLOCK') {
+            prefix = 'NEWLINE';
+        } else if (last_type === 'TK_END_EXPR') {
+            output_space_before_token = true;
+            prefix = 'NEWLINE';
+        }
+
+        if (token_type === 'TK_RESERVED' && in_array(token_text, line_starters) && flags.last_text !== ')') {
+            if (flags.last_text === 'else') {
+                prefix = 'SPACE';
+            } else {
+                prefix = 'NEWLINE';
+            }
+
+        }
+
+        if (token_type === 'TK_RESERVED' && in_array(token_text, ['else', 'catch', 'finally'])) {
+            if (last_type !== 'TK_END_BLOCK' || opt.brace_style === "expand" || opt.brace_style === "end-expand") {
+                print_newline();
+            } else {
+                trim_output(true);
+                var line = output_lines[output_lines.length - 1];
+                // If we trimmed and there's something other than a close block before us
+                // put a newline back in.  Handles '} // comment' scenario.
+                if (line.text[line.text.length - 1] !== '}') {
+                    print_newline();
+                }
+                output_space_before_token = true;
+            }
+        } else if (prefix === 'NEWLINE') {
+            if (last_type === 'TK_RESERVED' && is_special_word(flags.last_text)) {
+                // no newline between 'return nnn'
+                output_space_before_token = true;
+            } else if (last_type !== 'TK_END_EXPR') {
+                if ((last_type !== 'TK_START_EXPR' || !(token_type === 'TK_RESERVED' && in_array(token_text, ['var', 'let', 'const']))) && flags.last_text !== ':') {
+                    // no need to force newline on 'var': for (var x = 0...)
+                    if (token_type === 'TK_RESERVED' && token_text === 'if' && flags.last_word === 'else' && flags.last_text !== '{') {
+                        // no newline for } else if {
+                        output_space_before_token = true;
+                    } else {
+                        print_newline();
+                    }
+                }
+            } else if (token_type === 'TK_RESERVED' && in_array(token_text, line_starters) && flags.last_text !== ')') {
+                print_newline();
+            }
+        } else if (is_array(flags.mode) && flags.last_text === ',' && last_last_text === '}') {
+            print_newline(); // }, in lists get a newline treatment
+        } else if (prefix === 'SPACE') {
+            output_space_before_token = true;
+        }
+        print_token();
+        flags.last_word = token_text;
+
+        if (token_type === 'TK_RESERVED' && token_text === 'do') {
+            flags.do_block = true;
+        }
+
+        if (token_type === 'TK_RESERVED' && token_text === 'if') {
+            flags.if_block = true;
+        }
+    }
+
+    function handle_semicolon() {
+        if (start_of_statement()) {
+            // The conditional starts the statement if appropriate.
+            // Semicolon can be the start (and end) of a statement
+            output_space_before_token = false;
+        }
+        while (flags.mode === MODE.Statement && !flags.if_block && !flags.do_block) {
+            restore_mode();
+        }
+        print_token();
+        if (flags.mode === MODE.ObjectLiteral) {
+            // if we're in OBJECT mode and see a semicolon, its invalid syntax
+            // recover back to treating this as a BLOCK
+            flags.mode = MODE.BlockStatement;
+        }
+    }
+
+    function handle_string() {
+        if (start_of_statement()) {
+            // The conditional starts the statement if appropriate.
+            // One difference - strings want at least a space before
+            output_space_before_token = true;
+        } else if (last_type === 'TK_RESERVED' || last_type === 'TK_WORD') {
+            output_space_before_token = true;
+        } else if (last_type === 'TK_COMMA' || last_type === 'TK_START_EXPR' || last_type === 'TK_EQUALS' || last_type === 'TK_OPERATOR') {
+            if (!start_of_object_property()) {
+                allow_wrap_or_preserved_newline();
+            }
+        } else {
+            print_newline();
+        }
+        print_token();
+    }
+
+    function handle_equals() {
+        if (start_of_statement()) {
+            // The conditional starts the statement if appropriate.
+        }
+
+        if (flags.declaration_statement) {
+            // just got an '=' in a var-line, different formatting/line-breaking, etc will now be done
+            flags.declaration_assignment = true;
+        }
+        output_space_before_token = true;
+        print_token();
+        output_space_before_token = true;
+    }
+
+    function handle_comma() {
+        if (flags.declaration_statement) {
+            if (is_expression(flags.parent.mode)) {
+                // do not break on comma, for(var a = 1, b = 2)
+                flags.declaration_assignment = false;
+            }
+
+            print_token();
+
+            if (flags.declaration_assignment) {
+                flags.declaration_assignment = false;
+                print_newline(false, true);
+            } else {
+                output_space_before_token = true;
+            }
+            return;
+        }
+
+        print_token();
+        if (flags.mode === MODE.ObjectLiteral ||
+            (flags.mode === MODE.Statement && flags.parent.mode === MODE.ObjectLiteral)) {
+            if (flags.mode === MODE.Statement) {
+                restore_mode();
+            }
+            print_newline();
+        } else {
+            // EXPR or DO_BLOCK
+            output_space_before_token = true;
+        }
+
+    }
+
+    function handle_operator() {
+        // Check if this is a BlockStatement that should be treated as a ObjectLiteral
+        if (token_text === ':' && flags.mode === MODE.BlockStatement &&
+                last_last_text === '{' &&
+                (last_type === 'TK_WORD' || last_type === 'TK_RESERVED')){
+            flags.mode = MODE.ObjectLiteral;
+        }
+
+        if (start_of_statement()) {
+            // The conditional starts the statement if appropriate.
+        }
+
+        var space_before = true;
+        var space_after = true;
+        if (last_type === 'TK_RESERVED' && is_special_word(flags.last_text)) {
+            // "return" had a special handling in TK_WORD. Now we need to return the favor
+            output_space_before_token = true;
+            print_token();
+            return;
+        }
+
+        // hack for actionscript's import .*;
+        if (token_text === '*' && last_type === 'TK_DOT' && !last_last_text.match(/^\d+$/)) {
+            print_token();
+            return;
+        }
+
+        if (token_text === ':' && flags.in_case) {
+            flags.case_body = true;
+            indent();
+            print_token();
+            print_newline();
+            flags.in_case = false;
+            return;
+        }
+
+        if (token_text === '::') {
+            // no spaces around exotic namespacing syntax operator
+            print_token();
+            return;
+        }
+
+        // http://www.ecma-international.org/ecma-262/5.1/#sec-7.9.1
+        // if there is a newline between -- or ++ and anything else we should preserve it.
+        if (input_wanted_newline && (token_text === '--' || token_text === '++')) {
+            print_newline();
+        }
+
+        // Allow line wrapping between operators
+        if (last_type === 'TK_OPERATOR') {
+            allow_wrap_or_preserved_newline();
+        }
+
+        if (in_array(token_text, ['--', '++', '!', '~']) || (in_array(token_text, ['-', '+']) && (in_array(last_type, ['TK_START_BLOCK', 'TK_START_EXPR', 'TK_EQUALS', 'TK_OPERATOR']) || in_array(flags.last_text, line_starters) || flags.last_text === ','))) {
+            // unary operators (and binary +/- pretending to be unary) special cases
+
+            space_before = false;
+            space_after = false;
+
+            if (flags.last_text === ';' && is_expression(flags.mode)) {
+                // for (;; ++i)
+                //        ^^^
+                space_before = true;
+            }
+
+            if (last_type === 'TK_RESERVED') {
+                space_before = true;
+            }
+
+            if ((flags.mode === MODE.BlockStatement || flags.mode === MODE.Statement) && (flags.last_text === '{' || flags.last_text === ';')) {
+                // { foo; --i }
+                // foo(); --bar;
+                print_newline();
+            }
+        } else if (token_text === ':') {
+            if (flags.ternary_depth === 0) {
+                if (flags.mode === MODE.BlockStatement) {
+                    flags.mode = MODE.ObjectLiteral;
+                }
+                space_before = false;
+            } else {
+                flags.ternary_depth -= 1;
+            }
+        } else if (token_text === '?') {
+            flags.ternary_depth += 1;
+        } else if (token_text === '*' && last_type === 'TK_RESERVED' && flags.last_text === 'function') {
+            space_before = false;
+            space_after = false;
+        }
+        output_space_before_token = output_space_before_token || space_before;
+        print_token();
+        output_space_before_token = space_after;
+    }
+
+    function handle_block_comment() {
+        var lines = split_newlines(token_text);
+        var j; // iterator for this case
+        var javadoc = false;
+        var starless = false;
+        var lastIndent = whitespace_before_token.join('');
+        var lastIndentLength = lastIndent.length;
+
+        // block comment starts with a new line
+        print_newline(false, true);
+        if (lines.length > 1) {
+            if (all_lines_start_with(lines.slice(1), '*')) {
+                javadoc = true;
+            }
+            else if (each_line_matches_indent(lines.slice(1), lastIndent)) {
+                starless = true;
+            }
+        }
+
+        // first line always indented
+        print_token(lines[0]);
+        for (j = 1; j < lines.length; j++) {
+            print_newline(false, true);
+            if (javadoc) {
+                // javadoc: reformat and re-indent
+                print_token(' ' + trim(lines[j]));
+            } else if (starless && lines[j].length > lastIndentLength) {
+                // starless: re-indent non-empty content, avoiding trim
+                print_token(lines[j].substring(lastIndentLength));
+            } else {
+                // normal comments output raw
+                output_lines[output_lines.length - 1].text.push(lines[j]);
+            }
+        }
+
+        // for comments of more than one line, make sure there's a new line after
+        print_newline(false, true);
+    }
+
+    function handle_inline_comment() {
+        output_space_before_token = true;
+        print_token();
+        output_space_before_token = true;
+    }
+
+    function handle_comment() {
+        if (input_wanted_newline) {
+            print_newline(false, true);
+        } else {
+            trim_output(true);
+        }
+
+        output_space_before_token = true;
+        print_token();
+        print_newline(false, true);
+    }
+
+    function handle_dot() {
+        if (start_of_statement()) {
+            // The conditional starts the statement if appropriate.
+        }
+
+        if (last_type === 'TK_RESERVED' && is_special_word(flags.last_text)) {
+            output_space_before_token = true;
+        } else {
+            // allow preserved newlines before dots in general
+            // force newlines on dots after close paren when break_chained - for bar().baz()
+            allow_wrap_or_preserved_newline(flags.last_text === ')' && opt.break_chained_methods);
+        }
+
+        print_token();
+    }
+
+    function handle_unknown() {
+        print_token();
+
+        if (token_text[token_text.length - 1] === '\n') {
+            print_newline();
+        }
+    }
+}
diff --git a/devtools/shared/jsbeautify/src/beautify-tests.js b/devtools/shared/jsbeautify/src/beautify-tests.js
new file mode 100644
index 000000000..254a9ca94
--- /dev/null
+++ b/devtools/shared/jsbeautify/src/beautify-tests.js
@@ -0,0 +1,2096 @@
+/*global js_beautify: true */
+
+function run_beautifier_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_beautify)
+{
+
+    var opts = {
+        indent_size: 4,
+        indent_char: ' ',
+        preserve_newlines: true,
+        jslint_happy: false,
+        keep_array_indentation: false,
+        brace_style: 'collapse',
+        space_before_conditional: true,
+        break_chained_methods: false,
+        selector_separator: '\n',
+        end_with_newline: true
+    };
+
+    function test_js_beautifier(input)
+    {
+        return js_beautify(input, opts);
+    }
+
+    function test_html_beautifier(input)
+    {
+        return html_beautify(input, opts);
+    }
+
+    function test_css_beautifier(input)
+    {
+        return css_beautify(input, opts);
+    }
+
+    var sanitytest;
+
+    // test the input on beautifier with the current flag settings
+    // does not check the indentation / surroundings as bt() does
+    function test_fragment(input, expected)
+    {
+        expected = expected || input;
+        sanitytest.expect(input, expected);
+        // if the expected is different from input, run it again
+        // expected output should be unchanged when run twice.
+        if (expected != input) {
+            sanitytest.expect(expected, expected);
+        }
+    }
+
+
+
+    // test the input on beautifier with the current flag settings
+    // test both the input as well as { input } wrapping
+    function bt(input, expectation)
+    {
+        var wrapped_input, wrapped_expectation;
+
+        expectation = expectation || input;
+        sanitytest.test_function(test_js_beautifier, 'js_beautify');
+        test_fragment(input, expectation);
+
+        // test also the returned indentation
+        // e.g if input = "asdf();"
+        // then test that this remains properly formatted as well:
+        // {
+        //     asdf();
+        //     indent;
+        // }
+
+        if (opts.indent_size === 4 && input) {
+            wrapped_input = '{\n' + input.replace(/^(.+)$/mg, '    $1') + '\n    foo = bar;\n}';
+            wrapped_expectation = '{\n' + expectation.replace(/^(.+)$/mg, '    $1') + '\n    foo = bar;\n}';
+            test_fragment(wrapped_input, wrapped_expectation);
+        }
+
+    }
+
+    // test html
+    function bth(input, expectation)
+    {
+        var wrapped_input, wrapped_expectation, field_input, field_expectation;
+
+        expectation = expectation || input;
+        sanitytest.test_function(test_html_beautifier, 'html_beautify');
+        test_fragment(input, expectation);
+
+        if (opts.indent_size === 4 && input) {
+            wrapped_input = '
\n' + input.replace(/^(.+)$/mg, ' $1') + '\n inline\n
'; + wrapped_expectation = '
\n' + expectation.replace(/^(.+)$/mg, ' $1') + '\n inline\n
'; + test_fragment(wrapped_input, wrapped_expectation); + } + + // Test that handlebars non-block {{}} tags act as content and do not + // get any spacing or line breaks. + if (input.indexOf('content') != -1) { + // Just {{field}} + field_input = input.replace(/content/g, '{{field}}'); + field_expectation = expectation.replace(/content/g, '{{field}}'); + test_fragment(field_input, field_expectation); + + // handlebars comment + field_input = input.replace(/content/g, '{{! comment}}'); + field_expectation = expectation.replace(/content/g, '{{! comment}}'); + test_fragment(field_input, field_expectation); + + // mixed {{field}} and content + field_input = input.replace(/content/g, 'pre{{field1}} {{field2}} {{field3}}post'); + field_expectation = expectation.replace(/content/g, 'pre{{field1}} {{field2}} {{field3}}post'); + test_fragment(field_input, field_expectation); + } + } + + // test css + function btc(input, expectation) + { + var wrapped_input, wrapped_expectation; + + expectation = expectation || input; + sanitytest.test_function(test_css_beautifier, 'css_beautify'); + test_fragment(input, expectation); + } + + // test the input on beautifier with the current flag settings, + // but dont't + function bt_braces(input, expectation) + { + var braces_ex = opts.brace_style; + opts.brace_style = 'expand'; + bt(input, expectation); + opts.brace_style = braces_ex; + } + + function beautifier_tests() + { + sanitytest = test_obj; + + opts.indent_size = 4; + opts.indent_char = ' '; + opts.preserve_newlines = true; + opts.jslint_happy = false; + opts.keep_array_indentation = false; + opts.brace_style = "collapse"; + + + // unicode support + bt('var ' + String.fromCharCode(3232) + '_' + String.fromCharCode(3232) + ' = "hi";'); + bt('var ' + String.fromCharCode(228) + 'x = {\n ' + String.fromCharCode(228) + 'rgerlich: true\n};'); + + bt(''); + bt('return .5'); + test_fragment(' return .5'); + test_fragment(' return .5;\n a();'); + bt('a = 1', 'a = 1'); + bt('a=1', 'a = 1'); + bt("a();\n\nb();", "a();\n\nb();"); + bt('var a = 1 var b = 2', "var a = 1\nvar b = 2"); + bt('var a=1, b=c[d], e=6;', 'var a = 1,\n b = c[d],\n e = 6;'); + bt('var a,\n b,\n c;'); + bt('let a = 1 let b = 2', "let a = 1\nlet b = 2"); + bt('let a=1, b=c[d], e=6;', 'let a = 1,\n b = c[d],\n e = 6;'); + bt('let a,\n b,\n c;'); + bt('const a = 1 const b = 2', "const a = 1\nconst b = 2"); + bt('const a=1, b=c[d], e=6;', 'const a = 1,\n b = c[d],\n e = 6;'); + bt('const a,\n b,\n c;'); + bt('a = " 12345 "'); + bt("a = ' 12345 '"); + bt('if (a == 1) b = 2;', "if (a == 1) b = 2;"); + bt('if(1){2}else{3}', "if (1) {\n 2\n} else {\n 3\n}"); + bt('if(1||2);', 'if (1 || 2);'); + bt('(a==1)||(b==2)', '(a == 1) || (b == 2)'); + bt('var a = 1 if (2) 3;', "var a = 1\nif (2) 3;"); + bt('a = a + 1'); + bt('a = a == 1'); + bt('/12345[^678]*9+/.match(a)'); + bt('a /= 5'); + bt('a = 0.5 * 3'); + bt('a *= 10.55'); + bt('a < .5'); + bt('a <= .5'); + bt('a<.5', 'a < .5'); + bt('a<=.5', 'a <= .5'); + bt('a = 0xff;'); + bt('a=0xff+4', 'a = 0xff + 4'); + bt('a = [1, 2, 3, 4]'); + bt('F*(g/=f)*g+b', 'F * (g /= f) * g + b'); + bt('a.b({c:d})', 'a.b({\n c: d\n})'); + bt('a.b\n(\n{\nc:\nd\n}\n)', 'a.b({\n c: d\n})'); + bt('a.b({c:"d"})', 'a.b({\n c: "d"\n})'); + bt('a.b\n(\n{\nc:\n"d"\n}\n)', 'a.b({\n c: "d"\n})'); + bt('a=!b', 'a = !b'); + bt('a=!!b', 'a = !!b'); + bt('a?b:c', 'a ? b : c'); + bt('a?1:2', 'a ? 1 : 2'); + bt('a?(b):c', 'a ? (b) : c'); + bt('x={a:1,b:w=="foo"?x:y,c:z}', 'x = {\n a: 1,\n b: w == "foo" ? x : y,\n c: z\n}'); + bt('x=a?b?c?d:e:f:g;', 'x = a ? b ? c ? d : e : f : g;'); + bt('x=a?b?c?d:{e1:1,e2:2}:f:g;', 'x = a ? b ? c ? d : {\n e1: 1,\n e2: 2\n} : f : g;'); + bt('function void(void) {}'); + bt('if(!a)foo();', 'if (!a) foo();'); + bt('a=~a', 'a = ~a'); + bt('a;/*comment*/b;', "a; /*comment*/\nb;"); + bt('a;/* comment */b;', "a; /* comment */\nb;"); + test_fragment('a;/*\ncomment\n*/b;', "a;\n/*\ncomment\n*/\nb;"); // simple comments don't get touched at all + bt('a;/**\n* javadoc\n*/b;', "a;\n/**\n * javadoc\n */\nb;"); + test_fragment('a;/**\n\nno javadoc\n*/b;', "a;\n/**\n\nno javadoc\n*/\nb;"); + bt('a;/*\n* javadoc\n*/b;', "a;\n/*\n * javadoc\n */\nb;"); // comment blocks detected and reindented even w/o javadoc starter + bt('if(a)break;', "if (a) break;"); + bt('if(a){break}', "if (a) {\n break\n}"); + bt('if((a))foo();', 'if ((a)) foo();'); + bt('for(var i=0;;) a', 'for (var i = 0;;) a'); + bt('for(var i=0;;)\na', 'for (var i = 0;;)\n a'); + bt('a++;', 'a++;'); + bt('for(;;i++)a()', 'for (;; i++) a()'); + bt('for(;;i++)\na()', 'for (;; i++)\n a()'); + bt('for(;;++i)a', 'for (;; ++i) a'); + bt('return(1)', 'return (1)'); + bt('try{a();}catch(b){c();}finally{d();}', "try {\n a();\n} catch (b) {\n c();\n} finally {\n d();\n}"); + bt('(xx)()'); // magic function call + bt('a[1]()'); // another magic function call + bt('if(a){b();}else if(c) foo();', "if (a) {\n b();\n} else if (c) foo();"); + bt('switch(x) {case 0: case 1: a(); break; default: break}', "switch (x) {\n case 0:\n case 1:\n a();\n break;\n default:\n break\n}"); + bt('switch(x){case -1:break;case !y:break;}', 'switch (x) {\n case -1:\n break;\n case !y:\n break;\n}'); + bt('a !== b'); + bt('if (a) b(); else c();', "if (a) b();\nelse c();"); + bt("// comment\n(function something() {})"); // typical greasemonkey start + bt("{\n\n x();\n\n}"); // was: duplicating newlines + bt('if (a in b) foo();'); + bt('var a, b;'); + // bt('var a, b'); + bt('{a:1, b:2}', "{\n a: 1,\n b: 2\n}"); + bt('a={1:[-1],2:[+1]}', 'a = {\n 1: [-1],\n 2: [+1]\n}'); + bt('var l = {\'a\':\'1\', \'b\':\'2\'}', "var l = {\n 'a': '1',\n 'b': '2'\n}"); + bt('if (template.user[n] in bk) foo();'); + bt('{{}/z/}', "{\n {}\n /z/\n}"); + bt('return 45', "return 45"); + bt('return this.prevObject ||\n\n this.constructor(null);'); + bt('If[1]', "If[1]"); + bt('Then[1]', "Then[1]"); + bt('a = 1e10', "a = 1e10"); + bt('a = 1.3e10', "a = 1.3e10"); + bt('a = 1.3e-10', "a = 1.3e-10"); + bt('a = -1.3e-10', "a = -1.3e-10"); + bt('a = 1e-10', "a = 1e-10"); + bt('a = e - 10', "a = e - 10"); + bt('a = 11-10', "a = 11 - 10"); + bt("a = 1;// comment", "a = 1; // comment"); + bt("a = 1; // comment", "a = 1; // comment"); + bt("a = 1;\n // comment", "a = 1;\n// comment"); + bt('a = [-1, -1, -1]'); + + // The exact formatting these should have is open for discussion, but they are at least reasonable + bt('a = [ // comment\n -1, -1, -1\n]'); + bt('var a = [ // comment\n -1, -1, -1\n]'); + bt('a = [ // comment\n -1, // comment\n -1, -1\n]'); + bt('var a = [ // comment\n -1, // comment\n -1, -1\n]'); + + bt('o = [{a:b},{c:d}]', 'o = [{\n a: b\n}, {\n c: d\n}]'); + + bt("if (a) {\n do();\n}"); // was: extra space appended + + bt("if (a) {\n// comment\n}else{\n// comment\n}", "if (a) {\n // comment\n} else {\n // comment\n}"); // if/else statement with empty body + bt("if (a) {\n// comment\n// comment\n}", "if (a) {\n // comment\n // comment\n}"); // multiple comments indentation + bt("if (a) b() else c();", "if (a) b()\nelse c();"); + bt("if (a) b() else if c() d();", "if (a) b()\nelse if c() d();"); + + bt("{}"); + bt("{\n\n}"); + bt("do { a(); } while ( 1 );", "do {\n a();\n} while (1);"); + bt("do {} while (1);"); + bt("do {\n} while (1);", "do {} while (1);"); + bt("do {\n\n} while (1);"); + bt("var a = x(a, b, c)"); + bt("delete x if (a) b();", "delete x\nif (a) b();"); + bt("delete x[x] if (a) b();", "delete x[x]\nif (a) b();"); + bt("for(var a=1,b=2)d", "for (var a = 1, b = 2) d"); + bt("for(var a=1,b=2,c=3) d", "for (var a = 1, b = 2, c = 3) d"); + bt("for(var a=1,b=2,c=3;d<3;d++)\ne", "for (var a = 1, b = 2, c = 3; d < 3; d++)\n e"); + bt("function x(){(a||b).c()}", "function x() {\n (a || b).c()\n}"); + bt("function x(){return - 1}", "function x() {\n return -1\n}"); + bt("function x(){return ! a}", "function x() {\n return !a\n}"); + bt("x => x", "x => x"); + bt("(x) => x", "(x) => x"); + bt("x => { x }", "x => {\n x\n}"); + bt("(x) => { x }", "(x) => {\n x\n}"); + + // a common snippet in jQuery plugins + bt("settings = $.extend({},defaults,settings);", "settings = $.extend({}, defaults, settings);"); + + // reserved words used as property names + bt("$http().then().finally().default()", "$http().then().finally().default()"); + bt("$http()\n.then()\n.finally()\n.default()", "$http()\n .then()\n .finally()\n .default()"); + bt("$http().when.in.new.catch().throw()", "$http().when.in.new.catch().throw()"); + bt("$http()\n.when\n.in\n.new\n.catch()\n.throw()", "$http()\n .when\n .in\n .new\n .catch()\n .throw()"); + + bt('{xxx;}()', '{\n xxx;\n}()'); + + bt("a = 'a'\nb = 'b'"); + bt("a = /reg/exp"); + bt("a = /reg/"); + bt('/abc/.test()'); + bt('/abc/i.test()'); + bt("{/abc/i.test()}", "{\n /abc/i.test()\n}"); + bt('var x=(a)/a;', 'var x = (a) / a;'); + + bt('x != -1', 'x != -1'); + + bt('for (; s-->0;)t', 'for (; s-- > 0;) t'); + bt('for (; s++>0;)u', 'for (; s++ > 0;) u'); + bt('a = s++>s--;', 'a = s++ > s--;'); + bt('a = s++>--s;', 'a = s++ > --s;'); + + bt('{x=#1=[]}', '{\n x = #1=[]\n}'); + bt('{a:#1={}}', '{\n a: #1={}\n}'); + bt('{a:#1#}', '{\n a: #1#\n}'); + + test_fragment('"incomplete-string'); + test_fragment("'incomplete-string"); + test_fragment('/incomplete-regex'); + test_fragment('`incomplete-template-string'); + + test_fragment('{a:1},{a:2}', '{\n a: 1\n}, {\n a: 2\n}'); + test_fragment('var ary=[{a:1}, {a:2}];', 'var ary = [{\n a: 1\n}, {\n a: 2\n}];'); + + test_fragment('{a:#1', '{\n a: #1'); // incomplete + test_fragment('{a:#', '{\n a: #'); // incomplete + + test_fragment('}}}', '}\n}\n}'); // incomplete + + test_fragment('', ''); + + test_fragment('a=/regexp', 'a = /regexp'); // incomplete regexp + + bt('{a:#1=[],b:#1#,c:#999999#}', '{\n a: #1=[],\n b: #1#,\n c: #999999#\n}'); + + bt("a = 1e+2"); + bt("a = 1e-2"); + bt("do{x()}while(a>1)", "do {\n x()\n} while (a > 1)"); + + bt("x(); /reg/exp.match(something)", "x();\n/reg/exp.match(something)"); + + test_fragment("something();(", "something();\n("); + test_fragment("#!she/bangs, she bangs\nf=1", "#!she/bangs, she bangs\n\nf = 1"); + test_fragment("#!she/bangs, she bangs\n\nf=1", "#!she/bangs, she bangs\n\nf = 1"); + test_fragment("#!she/bangs, she bangs\n\n/* comment */", "#!she/bangs, she bangs\n\n/* comment */"); + test_fragment("#!she/bangs, she bangs\n\n\n/* comment */", "#!she/bangs, she bangs\n\n\n/* comment */"); + test_fragment("#", "#"); + test_fragment("#!", "#!"); + + bt("function namespace::something()"); + + test_fragment("", ""); + test_fragment("", ""); + + bt('{foo();--bar;}', '{\n foo();\n --bar;\n}'); + bt('{foo();++bar;}', '{\n foo();\n ++bar;\n}'); + bt('{--bar;}', '{\n --bar;\n}'); + bt('{++bar;}', '{\n ++bar;\n}'); + + // Handling of newlines around unary ++ and -- operators + bt('{foo\n++bar;}', '{\n foo\n ++bar;\n}'); + bt('{foo++\nbar;}', '{\n foo++\n bar;\n}'); + + // This is invalid, but harder to guard against. Issue #203. + bt('{foo\n++\nbar;}', '{\n foo\n ++\n bar;\n}'); + + + // regexps + bt('a(/abc\\/\\/def/);b()', "a(/abc\\/\\/def/);\nb()"); + bt('a(/a[b\\[\\]c]d/);b()', "a(/a[b\\[\\]c]d/);\nb()"); + test_fragment('a(/a[b\\[', "a(/a[b\\["); // incomplete char class + // allow unescaped / in char classes + bt('a(/[a/b]/);b()', "a(/[a/b]/);\nb()"); + + bt('function foo() {\n return [\n "one",\n "two"\n ];\n}'); + bt('a=[[1,2],[4,5],[7,8]]', "a = [\n [1, 2],\n [4, 5],\n [7, 8]\n]"); + bt('a=[[1,2],[4,5],function(){},[7,8]]', + "a = [\n [1, 2],\n [4, 5],\n function() {},\n [7, 8]\n]"); + bt('a=[[1,2],[4,5],function(){},function(){},[7,8]]', + "a = [\n [1, 2],\n [4, 5],\n function() {},\n function() {},\n [7, 8]\n]"); + bt('a=[[1,2],[4,5],function(){},[7,8]]', + "a = [\n [1, 2],\n [4, 5],\n function() {},\n [7, 8]\n]"); + bt('a=[b,c,function(){},function(){},d]', + "a = [b, c,\n function() {},\n function() {},\n d\n]"); + bt('a=[a[1],b[4],c[d[7]]]', "a = [a[1], b[4], c[d[7]]]"); + bt('[1,2,[3,4,[5,6],7],8]', "[1, 2, [3, 4, [5, 6], 7], 8]"); + + bt('[[["1","2"],["3","4"]],[["5","6","7"],["8","9","0"]],[["1","2","3"],["4","5","6","7"],["8","9","0"]]]', + '[\n [\n ["1", "2"],\n ["3", "4"]\n ],\n [\n ["5", "6", "7"],\n ["8", "9", "0"]\n ],\n [\n ["1", "2", "3"],\n ["4", "5", "6", "7"],\n ["8", "9", "0"]\n ]\n]'); + + bt('{[x()[0]];indent;}', '{\n [x()[0]];\n indent;\n}'); + + bt('return ++i', 'return ++i'); + bt('return !!x', 'return !!x'); + bt('return !x', 'return !x'); + bt('return [1,2]', 'return [1, 2]'); + bt('return;', 'return;'); + bt('return\nfunc', 'return\nfunc'); + bt('catch(e)', 'catch (e)'); + bt('yield [1, 2]'); + + bt('var a=1,b={foo:2,bar:3},{baz:4,wham:5},c=4;', + 'var a = 1,\n b = {\n foo: 2,\n bar: 3\n },\n {\n baz: 4,\n wham: 5\n }, c = 4;'); + bt('var a=1,b={foo:2,bar:3},{baz:4,wham:5},\nc=4;', + 'var a = 1,\n b = {\n foo: 2,\n bar: 3\n },\n {\n baz: 4,\n wham: 5\n },\n c = 4;'); + + + // inline comment + bt('function x(/*int*/ start, /*string*/ foo)', 'function x( /*int*/ start, /*string*/ foo)'); + + // javadoc comment + bt('/**\n* foo\n*/', '/**\n * foo\n */'); + bt('{\n/**\n* foo\n*/\n}', '{\n /**\n * foo\n */\n}'); + + // starless block comment + bt('/**\nfoo\n*/'); + bt('/**\nfoo\n**/'); + bt('/**\nfoo\nbar\n**/'); + bt('/**\nfoo\n\nbar\n**/'); + bt('/**\nfoo\n bar\n**/'); + bt('{\n/**\nfoo\n*/\n}', '{\n /**\n foo\n */\n}'); + bt('{\n/**\nfoo\n**/\n}', '{\n /**\n foo\n **/\n}'); + bt('{\n/**\nfoo\nbar\n**/\n}', '{\n /**\n foo\n bar\n **/\n}'); + bt('{\n/**\nfoo\n\nbar\n**/\n}', '{\n /**\n foo\n\n bar\n **/\n}'); + bt('{\n/**\nfoo\n bar\n**/\n}', '{\n /**\n foo\n bar\n **/\n}'); + bt('{\n /**\n foo\nbar\n **/\n}'); + + bt('var a,b,c=1,d,e,f=2;', 'var a, b, c = 1,\n d, e, f = 2;'); + bt('var a,b,c=[],d,e,f=2;', 'var a, b, c = [],\n d, e, f = 2;'); + bt('function() {\n var a, b, c, d, e = [],\n f;\n}'); + + bt('do/regexp/;\nwhile(1);', 'do /regexp/;\nwhile (1);'); // hmmm + + bt('var a = a,\na;\nb = {\nb\n}', 'var a = a,\n a;\nb = {\n b\n}'); + + bt('var a = a,\n /* c */\n b;'); + bt('var a = a,\n // c\n b;'); + + bt('foo.("bar");'); // weird element referencing + + + bt('if (a) a()\nelse b()\nnewline()'); + bt('if (a) a()\nnewline()'); + bt('a=typeof(x)', 'a = typeof(x)'); + + bt('var a = function() {\n return null;\n },\n b = false;'); + + bt('var a = function() {\n func1()\n}'); + bt('var a = function() {\n func1()\n}\nvar b = function() {\n func2()\n}'); + + // code with and without semicolons + bt( 'var whatever = require("whatever");\nfunction() {\n a = 6;\n}', + 'var whatever = require("whatever");\n\nfunction() {\n a = 6;\n}'); + bt( 'var whatever = require("whatever")\nfunction() {\n a = 6\n}', + 'var whatever = require("whatever")\n\nfunction() {\n a = 6\n}'); + + + opts.jslint_happy = true; + + bt('a=typeof(x)', 'a = typeof (x)'); + bt('x();\n\nfunction(){}', 'x();\n\nfunction () {}'); + bt('function () {\n var a, b, c, d, e = [],\n f;\n}'); + bt('switch(x) {case 0: case 1: a(); break; default: break}', + "switch (x) {\ncase 0:\ncase 1:\n a();\n break;\ndefault:\n break\n}"); + bt('switch(x){case -1:break;case !y:break;}', + 'switch (x) {\ncase -1:\n break;\ncase !y:\n break;\n}'); + test_fragment("// comment 1\n(function()", "// comment 1\n(function ()"); // typical greasemonkey start + bt('var o1=$.extend(a);function(){alert(x);}', 'var o1 = $.extend(a);\n\nfunction () {\n alert(x);\n}'); + bt('function* () {\n yield 1;\n}'); + + opts.jslint_happy = false; + + bt('switch(x) {case 0: case 1: a(); break; default: break}', + "switch (x) {\n case 0:\n case 1:\n a();\n break;\n default:\n break\n}"); + bt('switch(x){case -1:break;case !y:break;}', + 'switch (x) {\n case -1:\n break;\n case !y:\n break;\n}'); + test_fragment("// comment 2\n(function()", "// comment 2\n(function()"); // typical greasemonkey start + bt("var a2, b2, c2, d2 = 0, c = function() {}, d = '';", "var a2, b2, c2, d2 = 0,\n c = function() {},\n d = '';"); + bt("var a2, b2, c2, d2 = 0, c = function() {},\nd = '';", "var a2, b2, c2, d2 = 0,\n c = function() {},\n d = '';"); + bt('var o2=$.extend(a);function(){alert(x);}', 'var o2 = $.extend(a);\n\nfunction() {\n alert(x);\n}'); + bt('function*() {\n yield 1;\n}'); + + bt('function* x() {\n yield 1;\n}'); + + bt('{"x":[{"a":1,"b":3},7,8,8,8,8,{"b":99},{"a":11}]}', '{\n "x": [{\n "a": 1,\n "b": 3\n },\n 7, 8, 8, 8, 8, {\n "b": 99\n }, {\n "a": 11\n }\n ]\n}'); + + bt('{"1":{"1a":"1b"},"2"}', '{\n "1": {\n "1a": "1b"\n },\n "2"\n}'); + bt('{a:{a:b},c}', '{\n a: {\n a: b\n },\n c\n}'); + + bt('{[y[a]];keep_indent;}', '{\n [y[a]];\n keep_indent;\n}'); + + bt('if (x) {y} else { if (x) {y}}', 'if (x) {\n y\n} else {\n if (x) {\n y\n }\n}'); + + bt('if (foo) one()\ntwo()\nthree()'); + bt('if (1 + foo() && bar(baz()) / 2) one()\ntwo()\nthree()'); + bt('if (1 + foo() && bar(baz()) / 2) one();\ntwo();\nthree();'); + + opts.indent_size = 1; + opts.indent_char = ' '; + bt('{ one_char() }', "{\n one_char()\n}"); + + bt('var a,b=1,c=2', 'var a, b = 1,\n c = 2'); + + opts.indent_size = 4; + opts.indent_char = ' '; + bt('{ one_char() }', "{\n one_char()\n}"); + + opts.indent_size = 1; + opts.indent_char = "\t"; + bt('{ one_char() }', "{\n\tone_char()\n}"); + bt('x = a ? b : c; x;', 'x = a ? b : c;\nx;'); + + //set to something else than it should change to, but with tabs on, should override + opts.indent_size = 5; + opts.indent_char = ' '; + opts.indent_with_tabs = true; + + bt('{ one_char() }', "{\n\tone_char()\n}"); + bt('x = a ? b : c; x;', 'x = a ? b : c;\nx;'); + + opts.indent_size = 4; + opts.indent_char = ' '; + opts.indent_with_tabs = false; + + opts.preserve_newlines = false; + + bt('var\na=dont_preserve_newlines;', 'var a = dont_preserve_newlines;'); + + // make sure the blank line between function definitions stays + // even when preserve_newlines = false + bt('function foo() {\n return 1;\n}\n\nfunction foo() {\n return 1;\n}'); + bt('function foo() {\n return 1;\n}\nfunction foo() {\n return 1;\n}', + 'function foo() {\n return 1;\n}\n\nfunction foo() {\n return 1;\n}' + ); + bt('function foo() {\n return 1;\n}\n\n\nfunction foo() {\n return 1;\n}', + 'function foo() {\n return 1;\n}\n\nfunction foo() {\n return 1;\n}' + ); + + opts.preserve_newlines = true; + bt('var\na=do_preserve_newlines;', 'var\n a = do_preserve_newlines;'); + bt('// a\n// b\n\n// c\n// d'); + bt('if (foo) // comment\n{\n bar();\n}'); + + + opts.keep_array_indentation = false; + bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f']", + "a = ['a', 'b', 'c',\n 'd', 'e', 'f'\n]"); + bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']", + "a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i'\n]"); + bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']", + "a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i'\n]"); + bt('var x = [{}\n]', 'var x = [{}]'); + bt('var x = [{foo:bar}\n]', 'var x = [{\n foo: bar\n}]'); + bt("a = ['something',\n 'completely',\n 'different'];\nif (x);", + "a = ['something',\n 'completely',\n 'different'\n];\nif (x);"); + bt("a = ['a','b','c']", "a = ['a', 'b', 'c']"); + + bt("a = ['a', 'b','c']", "a = ['a', 'b', 'c']"); + bt("x = [{'a':0}]", + "x = [{\n 'a': 0\n}]"); + bt('{a([[a1]], {b;});}', + '{\n a([\n [a1]\n ], {\n b;\n });\n}'); + bt("a();\n [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();", + "a();\n[\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n].toString();"); + bt("a();\na = [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();", + "a();\na = [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n].toString();"); + bt("function() {\n Foo([\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ]);\n}", + "function() {\n Foo([\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ]);\n}"); + bt('function foo() {\n return [\n "one",\n "two"\n ];\n}'); + // 4 spaces per indent input, processed with 4-spaces per indent + bt( "function foo() {\n" + + " return [\n" + + " {\n" + + " one: 'x',\n" + + " two: [\n" + + " {\n" + + " id: 'a',\n" + + " name: 'apple'\n" + + " }, {\n" + + " id: 'b',\n" + + " name: 'banana'\n" + + " }\n" + + " ]\n" + + " }\n" + + " ];\n" + + "}", + "function foo() {\n" + + " return [{\n" + + " one: 'x',\n" + + " two: [{\n" + + " id: 'a',\n" + + " name: 'apple'\n" + + " }, {\n" + + " id: 'b',\n" + + " name: 'banana'\n" + + " }]\n" + + " }];\n" + + "}"); + // 3 spaces per indent input, processed with 4-spaces per indent + bt( "function foo() {\n" + + " return [\n" + + " {\n" + + " one: 'x',\n" + + " two: [\n" + + " {\n" + + " id: 'a',\n" + + " name: 'apple'\n" + + " }, {\n" + + " id: 'b',\n" + + " name: 'banana'\n" + + " }\n" + + " ]\n" + + " }\n" + + " ];\n" + + "}", + "function foo() {\n" + + " return [{\n" + + " one: 'x',\n" + + " two: [{\n" + + " id: 'a',\n" + + " name: 'apple'\n" + + " }, {\n" + + " id: 'b',\n" + + " name: 'banana'\n" + + " }]\n" + + " }];\n" + + "}"); + + opts.keep_array_indentation = true; + bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f']"); + bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']"); + bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']"); + bt('var x = [{}\n]', 'var x = [{}\n]'); + bt('var x = [{foo:bar}\n]', 'var x = [{\n foo: bar\n }\n]'); + bt("a = ['something',\n 'completely',\n 'different'];\nif (x);"); + bt("a = ['a','b','c']", "a = ['a', 'b', 'c']"); + bt("a = ['a', 'b','c']", "a = ['a', 'b', 'c']"); + bt("x = [{'a':0}]", + "x = [{\n 'a': 0\n}]"); + bt('{a([[a1]], {b;});}', + '{\n a([[a1]], {\n b;\n });\n}'); + bt("a();\n [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();", + "a();\n [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();"); + bt("a();\na = [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();", + "a();\na = [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();"); + bt("function() {\n Foo([\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ]);\n}", + "function() {\n Foo([\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ]);\n}"); + bt('function foo() {\n return [\n "one",\n "two"\n ];\n}'); + // 4 spaces per indent input, processed with 4-spaces per indent + bt( "function foo() {\n" + + " return [\n" + + " {\n" + + " one: 'x',\n" + + " two: [\n" + + " {\n" + + " id: 'a',\n" + + " name: 'apple'\n" + + " }, {\n" + + " id: 'b',\n" + + " name: 'banana'\n" + + " }\n" + + " ]\n" + + " }\n" + + " ];\n" + + "}"); + // 3 spaces per indent input, processed with 4-spaces per indent + // Should be unchanged, but is not - #445 +// bt( "function foo() {\n" + +// " return [\n" + +// " {\n" + +// " one: 'x',\n" + +// " two: [\n" + +// " {\n" + +// " id: 'a',\n" + +// " name: 'apple'\n" + +// " }, {\n" + +// " id: 'b',\n" + +// " name: 'banana'\n" + +// " }\n" + +// " ]\n" + +// " }\n" + +// " ];\n" + +// "}"); + + + opts.keep_array_indentation = false; + + + bt('a = //comment\n /regex/;'); + + test_fragment('/*\n * X\n */'); + test_fragment('/*\r\n * X\r\n */', '/*\n * X\n */'); + + bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}', 'if (a) {\n b;\n} else {\n c;\n}'); + + + opts.brace_style = 'expand'; + + bt('//case 1\nif (a == 1)\n{}\n//case 2\nelse if (a == 2)\n{}'); + bt('if(1){2}else{3}', "if (1)\n{\n 2\n}\nelse\n{\n 3\n}"); + bt('try{a();}catch(b){c();}catch(d){}finally{e();}', + "try\n{\n a();\n}\ncatch (b)\n{\n c();\n}\ncatch (d)\n{}\nfinally\n{\n e();\n}"); + bt('if(a){b();}else if(c) foo();', + "if (a)\n{\n b();\n}\nelse if (c) foo();"); + bt('if(X)if(Y)a();else b();else c();', + "if (X)\n if (Y) a();\n else b();\nelse c();"); + bt("if (a) {\n// comment\n}else{\n// comment\n}", + "if (a)\n{\n // comment\n}\nelse\n{\n // comment\n}"); // if/else statement with empty body + bt('if (x) {y} else { if (x) {y}}', + 'if (x)\n{\n y\n}\nelse\n{\n if (x)\n {\n y\n }\n}'); + bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}', + 'if (a)\n{\n b;\n}\nelse\n{\n c;\n}'); + test_fragment(' /*\n* xx\n*/\n// xx\nif (foo) {\n bar();\n}', + ' /*\n * xx\n */\n // xx\n if (foo)\n {\n bar();\n }'); + bt('if (foo)\n{}\nelse /regex/.test();'); + bt('if (foo) /regex/.test();'); + bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}', 'if (a)\n{\n b;\n}\nelse\n{\n c;\n}'); + test_fragment('if (foo) {', 'if (foo)\n{'); + test_fragment('foo {', 'foo\n{'); + test_fragment('return {', 'return {'); // return needs the brace. + test_fragment('return /* inline */ {', 'return /* inline */ {'); + // test_fragment('return\n{', 'return\n{'); // can't support this?, but that's an improbable and extreme case anyway. + test_fragment('return;\n{', 'return;\n{'); + bt("throw {}"); + bt("throw {\n foo;\n}"); + bt('var foo = {}'); + bt('if (foo) bar();\nelse break'); + bt('function x() {\n foo();\n}zzz', 'function x()\n{\n foo();\n}\nzzz'); + bt('a: do {} while (); xxx', 'a: do {} while ();\nxxx'); + bt('var a = new function();'); + bt('var a = new function() {};'); + bt('var a = new function()\n{};', 'var a = new function() {};'); + bt('var a = new function a()\n{};'); + bt('var a = new function a()\n {},\n b = new function b()\n {};'); + test_fragment('new function'); + bt("foo({\n 'a': 1\n},\n10);", + "foo(\n {\n 'a': 1\n },\n 10);"); + bt('(["foo","bar"]).each(function(i) {return i;});', + '(["foo", "bar"]).each(function(i)\n{\n return i;\n});'); + bt('(function(i) {return i;})();', + '(function(i)\n{\n return i;\n})();'); + bt( "test( /*Argument 1*/ {\n" + + " 'Value1': '1'\n" + + "}, /*Argument 2\n" + + " */ {\n" + + " 'Value2': '2'\n" + + "});", + // expected + "test( /*Argument 1*/\n" + + " {\n" + + " 'Value1': '1'\n" + + " },\n" + + " /*Argument 2\n" + + " */\n" + + " {\n" + + " 'Value2': '2'\n" + + " });"); + bt( "test(\n" + + "/*Argument 1*/ {\n" + + " 'Value1': '1'\n" + + "},\n" + + "/*Argument 2\n" + + " */ {\n" + + " 'Value2': '2'\n" + + "});", + // expected + "test(\n" + + " /*Argument 1*/\n" + + " {\n" + + " 'Value1': '1'\n" + + " },\n" + + " /*Argument 2\n" + + " */\n" + + " {\n" + + " 'Value2': '2'\n" + + " });"); + bt( "test( /*Argument 1*/\n" + + "{\n" + + " 'Value1': '1'\n" + + "}, /*Argument 2\n" + + " */\n" + + "{\n" + + " 'Value2': '2'\n" + + "});", + // expected + "test( /*Argument 1*/\n" + + " {\n" + + " 'Value1': '1'\n" + + " },\n" + + " /*Argument 2\n" + + " */\n" + + " {\n" + + " 'Value2': '2'\n" + + " });"); + + opts.brace_style = 'collapse'; + + bt('//case 1\nif (a == 1) {}\n//case 2\nelse if (a == 2) {}'); + bt('if(1){2}else{3}', "if (1) {\n 2\n} else {\n 3\n}"); + bt('try{a();}catch(b){c();}catch(d){}finally{e();}', + "try {\n a();\n} catch (b) {\n c();\n} catch (d) {} finally {\n e();\n}"); + bt('if(a){b();}else if(c) foo();', + "if (a) {\n b();\n} else if (c) foo();"); + bt("if (a) {\n// comment\n}else{\n// comment\n}", + "if (a) {\n // comment\n} else {\n // comment\n}"); // if/else statement with empty body + bt('if (x) {y} else { if (x) {y}}', + 'if (x) {\n y\n} else {\n if (x) {\n y\n }\n}'); + bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}', + 'if (a) {\n b;\n} else {\n c;\n}'); + test_fragment(' /*\n* xx\n*/\n// xx\nif (foo) {\n bar();\n}', + ' /*\n * xx\n */\n // xx\n if (foo) {\n bar();\n }'); + bt('if (foo) {} else /regex/.test();'); + bt('if (foo) /regex/.test();'); + bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}', 'if (a) {\n b;\n} else {\n c;\n}'); + test_fragment('if (foo) {', 'if (foo) {'); + test_fragment('foo {', 'foo {'); + test_fragment('return {', 'return {'); // return needs the brace. + test_fragment('return /* inline */ {', 'return /* inline */ {'); + // test_fragment('return\n{', 'return\n{'); // can't support this?, but that's an improbable and extreme case anyway. + test_fragment('return;\n{', 'return; {'); + bt("throw {}"); + bt("throw {\n foo;\n}"); + bt('var foo = {}'); + bt('if (foo) bar();\nelse break'); + bt('function x() {\n foo();\n}zzz', 'function x() {\n foo();\n}\nzzz'); + bt('a: do {} while (); xxx', 'a: do {} while ();\nxxx'); + bt('var a = new function();'); + bt('var a = new function() {};'); + bt('var a = new function a() {};'); + test_fragment('new function'); + bt("foo({\n 'a': 1\n},\n10);", + "foo({\n 'a': 1\n },\n 10);"); + bt('(["foo","bar"]).each(function(i) {return i;});', + '(["foo", "bar"]).each(function(i) {\n return i;\n});'); + bt('(function(i) {return i;})();', + '(function(i) {\n return i;\n})();'); + bt( "test( /*Argument 1*/ {\n" + + " 'Value1': '1'\n" + + "}, /*Argument 2\n" + + " */ {\n" + + " 'Value2': '2'\n" + + "});", + // expected + "test( /*Argument 1*/ {\n" + + " 'Value1': '1'\n" + + " },\n" + + " /*Argument 2\n" + + " */\n" + + " {\n" + + " 'Value2': '2'\n" + + " });"); + bt( "test(\n" + + "/*Argument 1*/ {\n" + + " 'Value1': '1'\n" + + "},\n" + + "/*Argument 2\n" + + " */ {\n" + + " 'Value2': '2'\n" + + "});", + // expected + "test(\n" + + " /*Argument 1*/\n" + + " {\n" + + " 'Value1': '1'\n" + + " },\n" + + " /*Argument 2\n" + + " */\n" + + " {\n" + + " 'Value2': '2'\n" + + " });"); + bt( "test( /*Argument 1*/\n" + + "{\n" + + " 'Value1': '1'\n" + + "}, /*Argument 2\n" + + " */\n" + + "{\n" + + " 'Value2': '2'\n" + + "});", + // expected + "test( /*Argument 1*/ {\n" + + " 'Value1': '1'\n" + + " },\n" + + " /*Argument 2\n" + + " */\n" + + " {\n" + + " 'Value2': '2'\n" + + " });"); + + opts.brace_style = "end-expand"; + + bt('//case 1\nif (a == 1) {}\n//case 2\nelse if (a == 2) {}'); + bt('if(1){2}else{3}', "if (1) {\n 2\n}\nelse {\n 3\n}"); + bt('try{a();}catch(b){c();}catch(d){}finally{e();}', + "try {\n a();\n}\ncatch (b) {\n c();\n}\ncatch (d) {}\nfinally {\n e();\n}"); + bt('if(a){b();}else if(c) foo();', + "if (a) {\n b();\n}\nelse if (c) foo();"); + bt("if (a) {\n// comment\n}else{\n// comment\n}", + "if (a) {\n // comment\n}\nelse {\n // comment\n}"); // if/else statement with empty body + bt('if (x) {y} else { if (x) {y}}', + 'if (x) {\n y\n}\nelse {\n if (x) {\n y\n }\n}'); + bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}', + 'if (a) {\n b;\n}\nelse {\n c;\n}'); + test_fragment(' /*\n* xx\n*/\n// xx\nif (foo) {\n bar();\n}', + ' /*\n * xx\n */\n // xx\n if (foo) {\n bar();\n }'); + bt('if (foo) {}\nelse /regex/.test();'); + bt('if (foo) /regex/.test();'); + bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}', 'if (a) {\n b;\n}\nelse {\n c;\n}'); + test_fragment('if (foo) {', 'if (foo) {'); + test_fragment('foo {', 'foo {'); + test_fragment('return {', 'return {'); // return needs the brace. + test_fragment('return /* inline */ {', 'return /* inline */ {'); + // test_fragment('return\n{', 'return\n{'); // can't support this?, but that's an improbable and extreme case anyway. + test_fragment('return;\n{', 'return; {'); + bt("throw {}"); + bt("throw {\n foo;\n}"); + bt('var foo = {}'); + bt('if (foo) bar();\nelse break'); + bt('function x() {\n foo();\n}zzz', 'function x() {\n foo();\n}\nzzz'); + bt('a: do {} while (); xxx', 'a: do {} while ();\nxxx'); + bt('var a = new function();'); + bt('var a = new function() {};'); + bt('var a = new function a() {};'); + test_fragment('new function'); + bt("foo({\n 'a': 1\n},\n10);", + "foo({\n 'a': 1\n },\n 10);"); + bt('(["foo","bar"]).each(function(i) {return i;});', + '(["foo", "bar"]).each(function(i) {\n return i;\n});'); + bt('(function(i) {return i;})();', + '(function(i) {\n return i;\n})();'); + bt( "test( /*Argument 1*/ {\n" + + " 'Value1': '1'\n" + + "}, /*Argument 2\n" + + " */ {\n" + + " 'Value2': '2'\n" + + "});", + // expected + "test( /*Argument 1*/ {\n" + + " 'Value1': '1'\n" + + " },\n" + + " /*Argument 2\n" + + " */\n" + + " {\n" + + " 'Value2': '2'\n" + + " });"); + bt( "test(\n" + + "/*Argument 1*/ {\n" + + " 'Value1': '1'\n" + + "},\n" + + "/*Argument 2\n" + + " */ {\n" + + " 'Value2': '2'\n" + + "});", + // expected + "test(\n" + + " /*Argument 1*/\n" + + " {\n" + + " 'Value1': '1'\n" + + " },\n" + + " /*Argument 2\n" + + " */\n" + + " {\n" + + " 'Value2': '2'\n" + + " });"); + bt( "test( /*Argument 1*/\n" + + "{\n" + + " 'Value1': '1'\n" + + "}, /*Argument 2\n" + + " */\n" + + "{\n" + + " 'Value2': '2'\n" + + "});", + // expected + "test( /*Argument 1*/ {\n" + + " 'Value1': '1'\n" + + " },\n" + + " /*Argument 2\n" + + " */\n" + + " {\n" + + " 'Value2': '2'\n" + + " });"); + + opts.brace_style = 'collapse'; + + + bt('a = ;'); // not the most perfect thing in the world, but you're the weirdo beaufifying php mix-ins with javascript beautifier + bt('a = <%= external() %> ;'); + + bt('// func-comment\n\nfunction foo() {}\n\n// end-func-comment'); + + test_fragment('roo = {\n /*\n ****\n FOO\n ****\n */\n BAR: 0\n};'); + + bt('"foo""bar""baz"', '"foo"\n"bar"\n"baz"'); + bt("'foo''bar''baz'", "'foo'\n'bar'\n'baz'"); + + + test_fragment("if (zz) {\n // ....\n}\n(function"); + + bt("{\n get foo() {}\n}"); + bt("{\n var a = get\n foo();\n}"); + bt("{\n set foo() {}\n}"); + bt("{\n var a = set\n foo();\n}"); + bt("var x = {\n get function()\n}"); + bt("var x = {\n set function()\n}"); + bt("var x = set\n\na() {}", "var x = set\n\n a() {}"); + bt("var x = set\n\nfunction() {}", "var x = set\n\n function() {}"); + + bt(''); + bt(' + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/devtools/shared/locales/en-US/csscoverage.properties b/devtools/shared/locales/en-US/csscoverage.properties new file mode 100644 index 000000000..646e75981 --- /dev/null +++ b/devtools/shared/locales/en-US/csscoverage.properties @@ -0,0 +1,32 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +# LOCALIZATION NOTE These strings are used in the 'csscoverage' command and in +# the user interface that this command creates. + +# LOCALIZATION NOTE (csscoverageDesc, csscoverageStartDesc2, +# csscoverageStopDesc2, csscoverageOneShotDesc2, csscoverageToggleDesc2, +# csscoverageReportDesc2): Short descriptions of the csscoverage commands +csscoverageDesc=Control CSS coverage analysis +csscoverageStartDesc2=Begin collecting CSS coverage data +csscoverageStopDesc2=Stop collecting CSS coverage data +csscoverageOneShotDesc2=Collect instantaneous CSS coverage data +csscoverageToggleDesc2=Toggle collecting CSS coverage data +csscoverageReportDesc2=Show CSS coverage report +csscoverageStartNoReloadDesc=Don’t start with a page reload +csscoverageStartNoReloadManual=It’s best if we start by reloading the current page because that starts the test at a known point, but there could be reasons why we don’t want to do that (e.g. the page contains state that will be lost across a reload) + +# LOCALIZATION NOTE (csscoverageRunningReply, csscoverageDoneReply): Text that +# describes the current state of the css coverage system +csscoverageRunningReply=Running CSS coverage analysis +csscoverageDoneReply=CSS Coverage analysis completed + +# LOCALIZATION NOTE (csscoverageRunningError, csscoverageNotRunningError, +# csscoverageNotRunError): Error message that describe things that can go wrong +# with the css coverage system +csscoverageRunningError=CSS coverage analysis already running +csscoverageNotRunningError=CSS coverage analysis not running +csscoverageNotRunError=CSS coverage analysis has not been run +csscoverageNoRemoteError=Target does not support CSS Coverage +csscoverageOneShotReportError=CSS coverage report is not available for ‘oneshot’ data. Please use start/stop. diff --git a/devtools/shared/locales/en-US/debugger.properties b/devtools/shared/locales/en-US/debugger.properties new file mode 100644 index 000000000..50e42a725 --- /dev/null +++ b/devtools/shared/locales/en-US/debugger.properties @@ -0,0 +1,59 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +# LOCALIZATION NOTE These strings are used inside the Debugger +# which is available from the Web Developer sub-menu -> 'Debugger'. +# The correct localization of this file might be to keep it in +# English, or another language commonly spoken among web developers. +# You want to make that choice consistent across the developer tools. +# A good criteria is the language in which you'd find the best +# documentation on web development on the web. + +# LOCALIZATION NOTE (remoteIncomingPromptTitle): The title displayed on the +# dialog that prompts the user to allow the incoming connection. +remoteIncomingPromptTitle=Incoming Connection + +# LOCALIZATION NOTE (remoteIncomingPromptHeader): Header displayed on the +# dialog that prompts the user to allow the incoming connection. +remoteIncomingPromptHeader=An incoming request to permit remote debugging connection was detected. A remote client can take complete control over your browser! +# LOCALIZATION NOTE (remoteIncomingPromptClientEndpoint): Part of the prompt +# dialog for the user to choose whether an incoming connection should be +# allowed. +# %1$S: The host and port of the client such as "127.0.0.1:6000" +remoteIncomingPromptClientEndpoint=Client Endpoint: %1$S +# LOCALIZATION NOTE (remoteIncomingPromptServerEndpoint): Part of the prompt +# dialog for the user to choose whether an incoming connection should be +# allowed. +# %1$S: The host and port of the server such as "127.0.0.1:6000" +remoteIncomingPromptServerEndpoint=Server Endpoint: %1$S +# LOCALIZATION NOTE (remoteIncomingPromptFooter): Footer displayed on the +# dialog that prompts the user to allow the incoming connection. +remoteIncomingPromptFooter=Allow connection? + +# LOCALIZATION NOTE (remoteIncomingPromptDisable): The label displayed on the +# third button in the incoming connection dialog that lets the user disable the +# remote debugger server. +remoteIncomingPromptDisable=Disable + +# LOCALIZATION NOTE (clientSendOOBTitle): The title displayed on the dialog that +# instructs the user to transfer an authentication token to the server. +clientSendOOBTitle=Client Identification +# LOCALIZATION NOTE (clientSendOOBHeader): Header displayed on the dialog that +# instructs the user to transfer an authentication token to the server. +clientSendOOBHeader=The endpoint you are connecting to needs more information to authenticate this connection. Please provide the token below in the prompt that appears on the other end. +# LOCALIZATION NOTE (clientSendOOBHash): Part of the dialog that instructs the +# user to transfer an authentication token to the server. +# %1$S: The client's cert fingerprint +clientSendOOBHash=My Cert: %1$S +# LOCALIZATION NOTE (clientSendOOBToken): Part of the dialog that instructs the +# user to transfer an authentication token to the server. +# %1$S: The authentication token that the user will transfer. +clientSendOOBToken=Token: %1$S + +# LOCALIZATION NOTE (serverReceiveOOBTitle): The title displayed on the dialog +# that instructs the user to provide an authentication token from the client. +serverReceiveOOBTitle=Provide Client Token +# LOCALIZATION NOTE (serverReceiveOOBBody): Main text displayed on the dialog +# that instructs the user to provide an authentication token from the client. +serverReceiveOOBBody=The client should be displaying a token value. Enter that token value here to complete authentication with this client. diff --git a/devtools/shared/locales/en-US/gcli.properties b/devtools/shared/locales/en-US/gcli.properties new file mode 100644 index 000000000..e5231e44a --- /dev/null +++ b/devtools/shared/locales/en-US/gcli.properties @@ -0,0 +1,318 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +# LOCALIZATION NOTE These strings are used inside the Web Console +# command line which is available from the Web Developer sub-menu +# -> 'Web Console'. +# The correct localization of this file might be to keep it in +# English, or another language commonly spoken among web developers. +# You want to make that choice consistent across the developer tools. +# A good criteria is the language in which you'd find the best +# documentation on web development on the web. + +# For each command there are in general two strings. As an example consider +# the 'pref' command. +# commandDesc (e.g. prefDesc for the command 'pref'): this string contains a +# very short description of the command. It's designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +# commandManual (e.g. prefManual for the command 'pref'): this string will +# contain a fuller description of the command. It's diplayed when the user +# asks for help about a specific command (e.g. 'help pref'). + +# LOCALIZATION NOTE: This message is used to describe any command or command +# parameter when no description has been provided. +canonDescNone=(No description) + +# LOCALIZATION NOTE: The default name for a group of parameters. +canonDefaultGroupName=Options + +# LOCALIZATION NOTE (canonProxyDesc, canonProxyManual): These commands are +# used to execute commands on a remote system (using a proxy). Parameters: %S +# is the name of the remote system. +canonProxyDesc=Execute a command on %S +canonProxyManual=A set of commands that are executed on a remote system. The remote system is reached via %S + +# LOCALIZATION NOTE: This error message is displayed when we try to add a new +# command (using a proxy) where one already exists with the same name. +canonProxyExists=There is already a command called ‘%S’ + +# LOCALIZATION NOTE: This message describes the '{' command, which allows +# entry of JavaScript like traditional developer tool command lines. +cliEvalJavascript=Enter JavaScript directly + +# LOCALIZATION NOTE: This message is displayed when the command line has more +# arguments than the current command can understand. +cliUnusedArg=Too many arguments + +# LOCALIZATION NOTE: The title of the dialog which displays the options that +# are available to the current command. +cliOptions=Available Options + +# LOCALIZATION NOTE: The error message when the user types a command that +# isn't registered +cliUnknownCommand2=Invalid Command: ‘%1$S’. + +# LOCALIZATION NOTE: A parameter should have a value, but doesn't +cliIncompleteParam=Value required for ‘%1$S’. + +# LOCALIZATION NOTE: Error message given when a file argument points to a file +# that does not exist, but should (e.g. for use with File->Open) %1$S is a +# filename +fileErrNotExists=‘%1$S’ doesn’t exist + +# LOCALIZATION NOTE: Error message given when a file argument points to a file +# that exists, but should not (e.g. for use with File->Save As) %1$S is a +# filename +fileErrExists=‘%1$S’ already exists + +# LOCALIZATION NOTE: Error message given when a file argument points to a +# non-file, when a file is needed. %1$S is a filename +fileErrIsNotFile=‘%1$S’ is not a file + +# LOCALIZATION NOTE: Error message given when a file argument points to a +# non-directory, when a directory is needed (e.g. for use with 'cd') %1$S is a +# filename +fileErrIsNotDirectory=‘%1$S’ is not a directory + +# LOCALIZATION NOTE: Error message given when a file argument does not match +# the specified regular expression %1$S is a filename %2$S is a regular +# expression +fileErrDoesntMatch=‘%1$S’ does not match ‘%2$S’ + +# LOCALIZATION NOTE: When the menu has displayed all the matches that it +# should (i.e. about 10 items) then we display this to alert the user that +# more matches are available. +fieldMenuMore=More matches, keep typing + +# LOCALIZATION NOTE: The command line provides completion for JavaScript +# commands, however there are times when the scope of what we're completing +# against can't be used. This error message is displayed when this happens. +jstypeParseScope=Scope lost + +# LOCALIZATION NOTE (jstypeParseMissing, jstypeBeginSyntax, +# jstypeBeginUnterm): These error messages are displayed when the command line +# is doing JavaScript completion and encounters errors. +jstypeParseMissing=Can’t find property ‘%S’ +jstypeBeginSyntax=Syntax error +jstypeBeginUnterm=Unterminated string literal + +# LOCALIZATION NOTE: This message is displayed if the system for providing +# JavaScript completions encounters and error it displays this. +jstypeParseError=Error + +# LOCALIZATION NOTE (typesNumberNan, typesNumberNotInt2, typesDateNan): These +# error messages are displayed when the command line is passed a variable +# which has the wrong format and can't be converted. Parameters: %S is the +# passed variable. +typesNumberNan=Can’t convert “%S” to a number. +typesNumberNotInt2=Can’t convert “%S” to an integer. +typesDateNan=Can’t convert “%S” to a date. + +# LOCALIZATION NOTE (typesNumberMax, typesNumberMin, typesDateMax, +# typesDateMin): These error messages are displayed when the command line is +# passed a variable which has a value out of range (number or date). +# Parameters: %1$S is the passed variable, %2$S is the limit value. +typesNumberMax=%1$S is greater than maximum allowed: %2$S. +typesNumberMin=%1$S is smaller than minimum allowed: %2$S. +typesDateMax=%1$S is later than maximum allowed: %2$S. +typesDateMin=%1$S is earlier than minimum allowed: %2$S. + +# LOCALIZATION NOTE: This error message is displayed when the command line is +# passed an option with a limited number of correct values, but the passed +# value is not one of them. +typesSelectionNomatch=Can’t use ‘%S’. + +# LOCALIZATION NOTE: This error message is displayed when the command line is +# expecting a CSS query string, however the passed string is not valid. +nodeParseSyntax=Syntax error in CSS query + +# LOCALIZATION NOTE (nodeParseMultiple, nodeParseNone): These error messages +# are displayed when the command line is expecting a CSS string that matches a +# single node, but more nodes (or none) match. +nodeParseMultiple=Too many matches (%S) +nodeParseNone=No matches + +# LOCALIZATION NOTE (helpDesc, helpManual, helpSearchDesc, helpSearchManual3): +# These strings describe the "help" command, used to display a description of +# a command (e.g. "help pref"), and its parameter 'search'. +helpDesc=Get help on the available commands +helpManual=Provide help either on a specific command (if a search string is provided and an exact match is found) or on the available commands (if a search string is not provided, or if no exact match is found). +helpSearchDesc=Search string +helpSearchManual3=search string to use in narrowing down the displayed commands. Regular expressions not supported. + +# LOCALIZATION NOTE: These strings are displayed in the help page for a +# command in the console. +helpManSynopsis=Synopsis + +# LOCALIZATION NOTE: This message is displayed in the help page if the command +# has no parameters. +helpManNone=None + +# LOCALIZATION NOTE: This message is displayed in response to the 'help' +# command when used without a filter, just above the list of known commands. +helpListAll=Available Commands: + +# LOCALIZATION NOTE (helpListPrefix, helpListNone): These messages are +# displayed in response to the 'help ' command (i.e. with a search +# string), just above the list of matching commands. Parameters: %S is the +# search string. +helpListPrefix=Commands starting with ‘%S’: +helpListNone=No commands starting with ‘%S’ + +# LOCALIZATION NOTE (helpManRequired, helpManOptional, helpManDefault): When +# the 'help x' command wants to show the manual for the 'x' command, it needs +# to be able to describe the parameters as either required or optional, or if +# they have a default value. +helpManRequired=required +helpManOptional=optional +helpManDefault=optional, default=%S + +# LOCALIZATION NOTE: This forms part of the output from the 'help' command. +# 'GCLI' is a project name and should be left untranslated. +helpIntro=GCLI is an experiment to create a highly usable command line for web developers. + +# LOCALIZATION NOTE: Text shown as part of the output of the 'help' command +# when the command in question has sub-commands, before a list of the matching +# sub-commands. +subCommands=Sub-Commands + +# LOCALIZATION NOTE: This error message is displayed when the command line is +# cannot find a match for the parse types. +commandParseError=Command line parsing error + +# LOCALIZATION NOTE (contextDesc, contextManual, contextPrefixDesc): These +# strings are used to describe the 'context' command and its 'prefix' +# parameter. See localization comment for 'connect' for an explanation about +# 'prefix'. +contextDesc=Concentrate on a group of commands +contextManual=Setup a default prefix to future commands. For example ‘context git’ would allow you to type ‘commit’ rather than ‘git commit’. +contextPrefixDesc=The command prefix + +# LOCALIZATION NOTE: This message message displayed during the processing of +# the 'context' command, when the found command is not a parent command. +contextNotParentError=Can’t use ‘%S’ as a prefix because it is not a parent command. + +# LOCALIZATION NOTE (contextReply, contextEmptyReply): These messages are +# displayed during the processing of the 'context' command, to indicate +# success or that there is no command prefix. +contextReply=Using %S as a command prefix +contextEmptyReply=Command prefix is unset + +# LOCALIZATION NOTE (connectDesc, connectManual, connectPrefixDesc, +# connectMethodDesc, connectUrlDesc, connectDupReply): These strings describe +# the 'connect' command and all its available parameters. A 'prefix' is an +# alias for the remote server (think of it as a "connection name"), and it +# allows to identify a specific server when connected to multiple remote +# servers. +connectDesc=Proxy commands to server +connectManual=Connect to the server, creating local versions of the commands on the server. Remote commands initially have a prefix to distinguish them from local commands (but see the context command to get past this) +connectPrefixDesc=Parent prefix for imported commands +connectMethodDesc=The method of connecting +connectUrlDesc=The URL to connect to +connectDupReply=Connection called %S already exists. + +# LOCALIZATION NOTE: The output of the 'connect' command, telling the user +# what it has done. Parameters: %S is the prefix command. See localization +# comment for 'connect' for an explanation about 'prefix'. +connectReply=Added %S commands. + +# LOCALIZATION NOTE (disconnectDesc2, disconnectManual2, +# disconnectPrefixDesc): These strings describe the 'disconnect' command and +# all its available parameters. See localization comment for 'connect' for an +# explanation about 'prefix'. +disconnectDesc2=Disconnect from server +disconnectManual2=Disconnect from a server currently connected for remote commands execution +disconnectPrefixDesc=Parent prefix for imported commands + +# LOCALIZATION NOTE: This is the output of the 'disconnect' command, +# explaining the user what has been done. Parameters: %S is the number of +# commands removed. +disconnectReply=Removed %S commands. + +# LOCALIZATION NOTE (globalDesc, globalWindowDesc, globalOutput): These +# strings describe the 'global' command and its parameters +globalDesc=Change the JS global +globalWindowDesc=The new window/global +globalOutput=JS global is now %S + +# LOCALIZATION NOTE: These strings describe the 'clear' command +clearDesc=Clear the output area + +# LOCALIZATION NOTE (langDesc, langOutput): These strings describe the 'lang' +# command and its parameters +langDesc=Enter commands in different languages +langOutput=You are now using %S + +# LOCALIZATION NOTE (prefDesc, prefManual, prefListDesc, prefListManual, +# prefListSearchDesc, prefListSearchManual, prefShowDesc, prefShowManual, +# prefShowSettingDesc, prefShowSettingManual): These strings describe the +# 'pref' command and all its available sub-commands and parameters. +prefDesc=Commands to control settings +prefManual=Commands to display and alter preferences both for GCLI and the surrounding environment +prefListDesc=Display available settings +prefListManual=Display a list of preferences, optionally filtered when using the ‘search’ parameter +prefListSearchDesc=Filter the list of settings displayed +prefListSearchManual=Search for the given string in the list of available preferences +prefShowDesc=Display setting value +prefShowManual=Display the value of a given preference +prefShowSettingDesc=Setting to display +prefShowSettingManual=The name of the setting to display + +# LOCALIZATION NOTE: This message is used to show the preference name and the +# associated preference value. Parameters: %1$S is the preference name, %2$S +# is the preference value. +prefShowSettingValue=%1$S: %2$S + +# LOCALIZATION NOTE (prefSetDesc, prefSetManual, prefSetSettingDesc, +# prefSetSettingManual, prefSetValueDesc, prefSetValueManual): These strings +# describe the 'pref set' command and all its parameters. +prefSetDesc=Alter a setting +prefSetManual=Alter preferences defined by the environment +prefSetSettingDesc=Setting to alter +prefSetSettingManual=The name of the setting to alter. +prefSetValueDesc=New value for setting +prefSetValueManual=The new value for the specified setting + +# LOCALIZATION NOTE (prefResetDesc, prefResetManual, prefResetSettingDesc, +# prefResetSettingManual): These strings describe the 'pref reset' command and +# all its parameters. +prefResetDesc=Reset a setting +prefResetManual=Reset the value of a setting to the system defaults +prefResetSettingDesc=Setting to reset +prefResetSettingManual=The name of the setting to reset to the system default value + +# LOCALIZATION NOTE: This string is displayed in the output from the 'pref +# list' command as a label to an input element that allows the user to filter +# the results. +prefOutputFilter=Filter + +# LOCALIZATION NOTE (prefOutputName, prefOutputValue): These strings are +# displayed in the output from the 'pref list' command as table headings. +prefOutputName=Name +prefOutputValue=Value + +# LOCALIZATION NOTE (introDesc, introManual): These strings describe the +# 'intro' command. The localization of 'Got it!' should be the same used in +# introTextGo. +introDesc=Show the opening message +introManual=Redisplay the message that is shown to new users until they click the ‘Got it!’ button + +# LOCALIZATION NOTE (introTextOpening3, introTextCommands, introTextKeys2, +# introTextF1Escape, introTextGo): These strings are displayed when the user +# first opens the developer toolbar to explain the command line, and is shown +# each time it is opened until the user clicks the 'Got it!' button. +introTextOpening3=GCLI is an experiment to create a highly usable command line for web developers. +introTextCommands=For a list of commands type +introTextKeys2=, or to show/hide command hints press +introTextF1Escape=F1/Escape +introTextGo=Got it! + +# LOCALIZATION NOTE: This is a short description of the 'hideIntro' setting. +hideIntroDesc=Show the initial welcome message + +# LOCALIZATION NOTE: This is a description of the 'eagerHelper' setting. It's +# displayed when the user asks for help on the settings. eagerHelper allows +# users to select between showing no tooltips, permanent tooltips, and only +# important tooltips. +eagerHelperDesc=How eager are the tooltips diff --git a/devtools/shared/locales/en-US/gclicommands.properties b/devtools/shared/locales/en-US/gclicommands.properties new file mode 100644 index 000000000..06a34e42b --- /dev/null +++ b/devtools/shared/locales/en-US/gclicommands.properties @@ -0,0 +1,1530 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +# LOCALIZATION NOTE These strings are used inside Web Console commands. +# The Web Console command line is available from the Web Developer sub-menu +# -> 'Web Console'. +# +# The correct localization of this file might be to keep it in +# English, or another language commonly spoken among web developers. +# You want to make that choice consistent across the developer tools. +# A good criteria is the language in which you'd find the best +# documentation on web development on the web. + +# LOCALIZATION NOTE (helpDesc) A very short string used to describe the +# function of the help command. +helpDesc=Get help on the available commands + +# LOCALIZATION NOTE (helpAvailable) Used in the output of the help command to +# explain the contents of the command help table. +helpAvailable=Available Commands + +# LOCALIZATION NOTE (notAvailableInE10S) Used in the output of any command that +# is not compatible with multiprocess mode (E10S). +notAvailableInE10S=The command ‘%1$S’ is not available in multiprocess mode (E10S) + +# LOCALIZATION NOTE (consoleDesc) A very short string used to describe the +# function of the console command. +consoleDesc=Commands to control the console + +# LOCALIZATION NOTE (consoleManual) A longer description describing the +# set of commands that control the console. +consoleManual=Filter, clear and close the web console + +# LOCALIZATION NOTE (consoleclearDesc) A very short string used to describe the +# function of the 'console clear' command. +consoleclearDesc=Clear the console + +# LOCALIZATION NOTE (screenshotDesc) A very short description of the +# 'screenshot' command. See screenshotManual for a fuller description of what +# it does. This string is designed to be shown in a menu alongside the +# command name, which is why it should be as short as possible. +screenshotDesc=Save an image of the page + +# LOCALIZATION NOTE (screenshotManual) A fuller description of the 'screenshot' +# command, displayed when the user asks for help on what it does. +screenshotManual=Save a PNG image of the entire visible window (optionally after a delay) + +# LOCALIZATION NOTE (screenshotFilenameDesc) A very short string to describe +# the 'filename' parameter to the 'screenshot' command, which is displayed in +# a dialog when the user is using this command. +screenshotFilenameDesc=Destination filename + +# LOCALIZATION NOTE (screenshotFilenameManual) A fuller description of the +# 'filename' parameter to the 'screenshot' command, displayed when the user +# asks for help on what it does. +screenshotFilenameManual=The name of the file (should have a ‘.png’ extension) to which we write the screenshot. + +# LOCALIZATION NOTE (screenshotClipboardDesc) A very short string to describe +# the 'clipboard' parameter to the 'screenshot' command, which is displayed in +# a dialog when the user is using this command. +screenshotClipboardDesc=Copy screenshot to clipboard? (true/false) + +# LOCALIZATION NOTE (screenshotClipboardManual) A fuller description of the +# 'clipboard' parameter to the 'screenshot' command, displayed when the user +# asks for help on what it does. +screenshotClipboardManual=True if you want to copy the screenshot instead of saving it to a file. + +# LOCALIZATION NOTE (screenshotGroupOptions) A label for the optional options of +# the screenshot command. +screenshotGroupOptions=Options + +# LOCALIZATION NOTE (screenshotDelayDesc) A very short string to describe +# the 'delay' parameter to the 'screenshot' command, which is displayed in +# a dialog when the user is using this command. +screenshotDelayDesc=Delay (seconds) + +# LOCALIZATION NOTE (screenshotDelayManual) A fuller description of the +# 'delay' parameter to the 'screenshot' command, displayed when the user +# asks for help on what it does. +screenshotDelayManual=The time to wait (in seconds) before the screenshot is taken + +# LOCALIZATION NOTE (screenshotDPRDesc) A very short string to describe +# the 'dpr' parameter to the 'screenshot' command, which is displayed in +# a dialog when the user is using this command. +screenshotDPRDesc=Device pixel ratio + +# LOCALIZATION NOTE (screenshotDPRManual) A fuller description of the +# 'dpr' parameter to the 'screenshot' command, displayed when the user +# asks for help on what it does. +screenshotDPRManual=The device pixel ratio to use when taking the screenshot + +# LOCALIZATION NOTE (screenshotFullscreenDesc) A very short string to describe +# the 'fullscreen' parameter to the 'screenshot' command, which is displayed in +# a dialog when the user is using this command. +screenshotFullPageDesc=Entire webpage? (true/false) + +# LOCALIZATION NOTE (screenshotFullscreenManual) A fuller description of the +# 'fullscreen' parameter to the 'screenshot' command, displayed when the user +# asks for help on what it does. +screenshotFullPageManual=True if the screenshot should also include parts of the webpage which are outside the current scrolled bounds. + +# LOCALIZATION NOTE (screenshotGeneratedFilename) The auto generated filename +# when no file name is provided. The first argument (%1$S) is the date string +# in yyyy-mm-dd format and the second argument (%2$S) is the time string +# in HH.MM.SS format. Please don't add the extension here. +screenshotGeneratedFilename=Screen Shot %1$S at %2$S + +# LOCALIZATION NOTE (screenshotErrorSavingToFile) Text displayed to user upon +# encountering error while saving the screenshot to the file specified. +screenshotErrorSavingToFile=Error saving to + +# LOCALIZATION NOTE (screenshotSavedToFile) Text displayed to user when the +# screenshot is successfully saved to the file specified. +screenshotSavedToFile=Saved to + +# LOCALIZATION NOTE (screenshotErrorCopying) Text displayed to user upon +# encountering error while copying the screenshot to clipboard. +screenshotErrorCopying=Error occurred while copying to clipboard. + +# LOCALIZATION NOTE (screenshotCopied) Text displayed to user when the +# screenshot is successfully copied to the clipboard. +screenshotCopied=Copied to clipboard. + +# LOCALIZATION NOTE (screenshotTooltipPage) Text displayed as tooltip for screenshot button in devtools ToolBox. +screenshotTooltipPage=Take a screenshot of the entire page + +# LOCALIZATION NOTE (screenshotImgurDesc) A very short string to describe +# the 'imgur' parameter to the 'screenshot' command, which is displayed in +# a dialog when the user is using this command. +screenshotImgurDesc=Upload to imgur.com + +# LOCALIZATION NOTE (screenshotImgurManual) A fuller description of the +# 'imgur' parameter to the 'screenshot' command, displayed when the user +# asks for help on what it does. +screenshotImgurManual=Use if you want to upload to imgur.com instead of saving to disk + +# LOCALIZATION NOTE (screenshotImgurError) Text displayed to user upon +# encountering error while uploading the screenshot to imgur.com. +screenshotImgurError=Could not reach imgur API + +# LOCALIZATION NOTE (screenshotImgurUploading) Text displayed to user when the +# screenshot is successfully sent to Imgur but the program is waiting on a response. +# The argument (%1$S) is a new image URL at Imgur. +screenshotImgurUploaded=Uploaded to %1$S + +# LOCALIZATION NOTE (highlightDesc) A very short description of the +# 'highlight' command. See highlightManual for a fuller description of what +# it does. This string is designed to be shown in a menu alongside the +# command name, which is why it should be as short as possible. +highlightDesc=Highlight nodes + +# LOCALIZATION NOTE (highlightManual) A fuller description of the 'highlight' +# command, displayed when the user asks for help on what it does. +highlightManual=Highlight nodes that match a selector on the page + +# LOCALIZATION NOTE (highlightSelectorDesc) A very short string to describe +# the 'selector' parameter to the 'highlight' command, which is displayed in +# a dialog when the user is using this command. +highlightSelectorDesc=CSS selector + +# LOCALIZATION NOTE (highlightSelectorManual) A fuller description of the +# 'selector' parameter to the 'highlight' command, displayed when the user +# asks for help on what it does. +highlightSelectorManual=The CSS selector used to match nodes in the page + +# LOCALIZATION NOTE (highlightOptionsDesc) The title of a set of options to +# the 'highlight' command, displayed as a heading to the list of option. +highlightOptionsDesc=Options + +# LOCALIZATION NOTE (highlightHideGuidesDesc) A very short string to describe +# the 'hideguides' option parameter to the 'highlight' command, which is +# displayed in a dialog when the user is using this command. +highlightHideGuidesDesc=Hide guides + +# LOCALIZATION NOTE (highlightHideGuidesManual) A fuller description of the +# 'hideguides' option parameter to the 'highlight' command, displayed when the +# user asks for help on what it does. +highlightHideGuidesManual=Hide the guides around the highlighted node + +# LOCALIZATION NOTE (highlightShowInfoBarDesc) A very short string to describe +# the 'showinfobar' option parameter to the 'highlight' command, which is +# displayed in a dialog when the user is using this command. +highlightShowInfoBarDesc=Show the node infobar + +# LOCALIZATION NOTE (highlightShowInfoBarManual) A fuller description of the +# 'showinfobar' option parameter to the 'highlight' command, displayed when the +# user asks for help on what it does. +highlightShowInfoBarManual=Show the infobar above the highlighted node (the infobar displays the tagname, attributes and dimension) + +# LOCALIZATION NOTE (highlightShowAllDesc) A very short string to describe +# the 'showall' option parameter to the 'highlight' command, which is +# displayed in a dialog when the user is using this command. +highlightShowAllDesc=Show all matches + +# LOCALIZATION NOTE (highlightShowAllManual) A fuller description of the +# 'showall' option parameter to the 'highlight' command, displayed when the +# user asks for help on what it does. +highlightShowAllManual=If too many nodes match the selector, only the first 100 will be shown to avoid slowing down the page too much. Use this option to show all matches instead + +# LOCALIZATION NOTE (highlightRegionDesc) A very short string to describe the +# 'region' option parameter to the 'highlight' command, which is displayed in a +# dialog when the user is using this command. +highlightRegionDesc=Box model region + +# LOCALIZATION NOTE (highlightRegionManual) A fuller description of the 'region' +# option parameter to the 'highlight' command, displayed when the user asks for +# help on what it does. +highlightRegionManual=Which box model region should be highlighted: ‘content’, ‘padding’, ‘border’ or ‘margin’ + +# LOCALIZATION NOTE (highlightFillDesc) A very short string to describe the +# 'fill' option parameter to the 'highlight' command, which is displayed in a +# dialog when the user is using this command. +highlightFillDesc=Fill style + +# LOCALIZATION NOTE (highlightFillManual) A fuller description of the 'fill' +# option parameter to the 'highlight' command, displayed when the user asks for +# help on what it does. +highlightFillManual=Override the default region fill style with a custom color + +# LOCALIZATION NOTE (highlightKeepDesc) A very short string to describe the +# 'keep' option parameter to the 'highlight' command, which is displayed in a +# dialog when the user is using this command. +highlightKeepDesc=Keep existing highlighters + +# LOCALIZATION NOTE (highlightKeepManual) A fuller description of the 'keep' +# option parameter to the 'highlight' command, displayed when the user asks for +# help on what it does. +highlightKeepManual=By default, existing highlighters are hidden when running the command, unless this option is set + +# LOCALIZATION NOTE (highlightOutputConfirm) A confirmation message for the +# 'highlight' command, displayed to the user once the command has been entered, +# informing the user how many nodes have been highlighted successfully and how +# to turn highlighting off +highlightOutputConfirm2=%1$S node highlighted;%1$S nodes highlighted + +# LOCALIZATION NOTE (highlightOutputMaxReached) A confirmation message for the +# 'highlight' command, displayed to the user once the command has been entered, +# informing the user how many nodes have been highlighted successfully and that +# some nodes could not be highlighted due to the maximum number of nodes being +# reached, and how to turn highlighting off +highlightOutputMaxReached=%1$S nodes matched, but only %2$S nodes highlighted. Use ‘--showall’ to show all + +# LOCALIZATION NOTE (unhighlightDesc) A very short description of the +# 'unhighlight' command. See unhighlightManual for a fuller description of what +# it does. This string is designed to be shown in a menu alongside the +# command name, which is why it should be as short as possible. +unhighlightDesc=Unhighlight all nodes + +# LOCALIZATION NOTE (unhighlightManual) A fuller description of the 'unhighlight' +# command, displayed when the user asks for help on what it does. +unhighlightManual=Unhighlight all nodes previously highlighted with the ‘highlight’ command + +# LOCALIZATION NOTE (restartBrowserDesc) A very short description of the +# 'restart' command. This string is designed to be shown in a menu alongside the +# command name, which is why it should be as short as possible. +# The argument (%1$S) is the browser name. +restartBrowserDesc=Restart %1$S + +# LOCALIZATION NOTE (restartBrowserNocacheDesc) A very short string to +# describe the 'nocache' parameter to the 'restart' command, which is +# displayed in a dialog when the user is using this command. +restartBrowserNocacheDesc=Disables loading content from cache upon restart + +# LOCALIZATION NOTE (restartBrowserRequestCancelled) A string displayed to the +# user when a scheduled restart has been aborted by the user. +restartBrowserRequestCancelled=Restart request cancelled by user. + +# LOCALIZATION NOTE (restartBrowserRestarting) A string displayed to the +# user when a restart has been initiated without a delay. +# The argument (%1$S) is the browser name. +restartBrowserRestarting=Restarting %1$S… + +# LOCALIZATION NOTE (restartBrowserGroupOptions) A label for the optional options of +# the restart command. +restartBrowserGroupOptions=Options + +# LOCALIZATION NOTE (restartBrowserSafemodeDesc) A very short string to +# describe the 'safemode' parameter to the 'restart' command, which is +# displayed in a dialog when the user is using this command. +restartBrowserSafemodeDesc=Enables Safe Mode upon restart + +# LOCALIZATION NOTE (inspectDesc) A very short description of the 'inspect' +# command. See inspectManual for a fuller description of what it does. This +# string is designed to be shown in a menu alongside the command name, which +# is why it should be as short as possible. +inspectDesc=Inspect a node + +# LOCALIZATION NOTE (inspectManual) A fuller description of the 'inspect' +# command, displayed when the user asks for help on what it does. +inspectManual=Investigate the dimensions and properties of an element using a CSS selector to open the DOM highlighter + +# LOCALIZATION NOTE (inspectNodeDesc) A very short string to describe the +# 'node' parameter to the 'inspect' command, which is displayed in a dialog +# when the user is using this command. +inspectNodeDesc=CSS selector + +# LOCALIZATION NOTE (inspectNodeManual) A fuller description of the 'node' +# parameter to the 'inspect' command, displayed when the user asks for help +# on what it does. +inspectNodeManual=A CSS selector for use with document.querySelector which identifies a single element + +# LOCALIZATION NOTE (eyedropperDesc) A very short description of the 'eyedropper' +# command. See eyedropperManual for a fuller description of what it does. This +# string is designed to be shown in a menu alongside the command name, which +# is why it should be as short as possible. +eyedropperDesc=Grab a color from the page + +# LOCALIZATION NOTE (eyedropperManual) A fuller description of the 'eyedropper' +# command, displayed when the user asks for help on what it does. +eyedropperManual=Open a panel that magnifies an area of page to inspect pixels and copy color values + +# LOCALIZATION NOTE (debuggerClosed) Used in the output of several commands +# to explain that the debugger must be opened first. +debuggerClosed=The debugger must be opened before using this command + +# LOCALIZATION NOTE (debuggerStopped) Used in the output of several commands +# to explain that the debugger must be opened first before setting breakpoints. +debuggerStopped=The debugger must be opened before setting breakpoints + +# LOCALIZATION NOTE (breakDesc) A very short string used to describe the +# function of the break command. +breakDesc=Manage breakpoints + +# LOCALIZATION NOTE (breakManual) A longer description describing the +# set of commands that control breakpoints. +breakManual=Commands to list, add and remove breakpoints + +# LOCALIZATION NOTE (breaklistDesc) A very short string used to describe the +# function of the 'break list' command. +breaklistDesc=Display known breakpoints + +# LOCALIZATION NOTE (breaklistNone) Used in the output of the 'break list' +# command to explain that the list is empty. +breaklistNone=No breakpoints set + +# LOCALIZATION NOTE (breaklistOutRemove) A title used in the output from the +# 'break list' command on a button which can be used to remove breakpoints +breaklistOutRemove=Remove + +# LOCALIZATION NOTE (breakaddAdded) Used in the output of the 'break add' +# command to explain that a breakpoint was added. +breakaddAdded=Added breakpoint + +# LOCALIZATION NOTE (breakaddFailed) Used in the output of the 'break add' +# command to explain that a breakpoint could not be added. +breakaddFailed=Could not set breakpoint: %S + +# LOCALIZATION NOTE (breakaddDesc) A very short string used to describe the +# function of the 'break add' command. +breakaddDesc=Add a breakpoint + +# LOCALIZATION NOTE (breakaddManual) A longer description describing the +# set of commands that are responsible for adding breakpoints. +breakaddManual=Breakpoint types supported: line + +# LOCALIZATION NOTE (breakaddlineDesc) A very short string used to describe the +# function of the 'break add line' command. +breakaddlineDesc=Add a line breakpoint + +# LOCALIZATION NOTE (breakaddlineFileDesc) A very short string used to describe +# the function of the file parameter in the 'break add line' command. +breakaddlineFileDesc=JS file URI + +# LOCALIZATION NOTE (breakaddlineLineDesc) A very short string used to describe +# the function of the line parameter in the 'break add line' command. +breakaddlineLineDesc=Line number + +# LOCALIZATION NOTE (breakdelDesc) A very short string used to describe the +# function of the 'break del' command. +breakdelDesc=Remove a breakpoint + +# LOCALIZATION NOTE (breakdelBreakidDesc) A very short string used to describe +# the function of the index parameter in the 'break del' command. +breakdelBreakidDesc=Index of breakpoint + +# LOCALIZATION NOTE (breakdelRemoved) Used in the output of the 'break del' +# command to explain that a breakpoint was removed. +breakdelRemoved=Breakpoint removed + +# LOCALIZATION NOTE (dbgDesc) A very short string used to describe the +# function of the dbg command. +dbgDesc=Manage debugger + +# LOCALIZATION NOTE (dbgManual) A longer description describing the +# set of commands that control the debugger. +dbgManual=Commands to interrupt or resume the main thread, step in, out and over lines of code + +# LOCALIZATION NOTE (dbgOpen) A very short string used to describe the function +# of the dbg open command. +dbgOpen=Open the debugger + +# LOCALIZATION NOTE (dbgClose) A very short string used to describe the function +# of the dbg close command. +dbgClose=Close the debugger + +# LOCALIZATION NOTE (dbgInterrupt) A very short string used to describe the +# function of the dbg interrupt command. +dbgInterrupt=Pauses the main thread + +# LOCALIZATION NOTE (dbgContinue) A very short string used to describe the +# function of the dbg continue command. +dbgContinue=Resumes the main thread, and continues execution following a breakpoint, until the next breakpoint or the termination of the script. + +# LOCALIZATION NOTE (dbgStepDesc) A very short string used to describe the +# function of the dbg step command. +dbgStepDesc=Manage stepping + +# LOCALIZATION NOTE (dbgStepManual) A longer description describing the +# set of commands that control stepping. +dbgStepManual=Commands to step in, out and over lines of code + +# LOCALIZATION NOTE (dbgStepOverDesc) A very short string used to describe the +# function of the dbg step over command. +dbgStepOverDesc=Executes the current statement and then stops at the next statement. If the current statement is a function call then the debugger executes the whole function, and it stops at the next statement after the function call + +# LOCALIZATION NOTE (dbgStepInDesc) A very short string used to describe the +# function of the dbg step in command. +dbgStepInDesc=Executes the current statement and then stops at the next statement. If the current statement is a function call, then the debugger steps into that function, otherwise it stops at the next statement + +# LOCALIZATION NOTE (dbgStepOutDesc) A very short string used to describe the +# function of the dbg step out command. +dbgStepOutDesc=Steps out of the current function and up one level if the function is nested. If in the main body, the script is executed to the end, or to the next breakpoint. The skipped statements are executed, but not stepped through + +# LOCALIZATION NOTE (dbgListSourcesDesc) A very short string used to describe the +# function of the dbg list command. +dbgListSourcesDesc=List the source URLs loaded in the debugger + +# LOCALIZATION NOTE (dbgBlackBoxDesc) A very short string used to describe the +# function of the 'dbg blackbox' command. +dbgBlackBoxDesc=Black box sources in the debugger + +# LOCALIZATION NOTE (dbgBlackBoxSourceDesc) A very short string used to describe the +# 'source' parameter to the 'dbg blackbox' command. +dbgBlackBoxSourceDesc=A specific source to black box + +# LOCALIZATION NOTE (dbgBlackBoxGlobDesc) A very short string used to describe the +# 'glob' parameter to the 'dbg blackbox' command. +dbgBlackBoxGlobDesc=Black box all sources that match this glob (for example: “*.min.js”) + +# LOCALIZATION NOTE (dbgBlackBoxInvertDesc) A very short string used to describe the +# 'invert' parameter to the 'dbg blackbox' command. +dbgBlackBoxInvertDesc=Invert matching, so that we black box every source that is not the source provided or does not match the provided glob pattern. + +# LOCALIZATION NOTE (dbgBlackBoxEmptyDesc) A very short string used to let the +# user know that no sources were black boxed. +dbgBlackBoxEmptyDesc=(No sources black boxed) + +# LOCALIZATION NOTE (dbgBlackBoxNonEmptyDesc) A very short string used to let the +# user know which sources were black boxed. +dbgBlackBoxNonEmptyDesc=The following sources were black boxed: + +# LOCALIZATION NOTE (dbgBlackBoxErrorDesc) A very short string used to let the +# user know there was an error black boxing a source (whose url follows this +# text). +dbgBlackBoxErrorDesc=Error black boxing: + +# LOCALIZATION NOTE (dbgUnBlackBoxDesc) A very short string used to describe the +# function of the 'dbg unblackbox' command. +dbgUnBlackBoxDesc=Stop black boxing sources in the debugger + +# LOCALIZATION NOTE (dbgUnBlackBoxSourceDesc) A very short string used to describe the +# 'source' parameter to the 'dbg unblackbox' command. +dbgUnBlackBoxSourceDesc=A specific source to stop black boxing + +# LOCALIZATION NOTE (dbgUnBlackBoxGlobDesc) A very short string used to describe the +# 'glob' parameter to the 'dbg blackbox' command. +dbgUnBlackBoxGlobDesc=Stop black boxing all sources that match this glob (for example: “*.min.js”) + +# LOCALIZATION NOTE (dbgUnBlackBoxEmptyDesc) A very short string used to let the +# user know that we did not stop black boxing any sources. +dbgUnBlackBoxEmptyDesc=(Did not stop black boxing any sources) + +# LOCALIZATION NOTE (dbgUnBlackBoxNonEmptyDesc) A very short string used to let the +# user know which sources we stopped black boxing. +dbgUnBlackBoxNonEmptyDesc=Stopped black boxing the following sources: + +# LOCALIZATION NOTE (dbgUnBlackBoxErrorDesc) A very short string used to let the +# user know there was an error black boxing a source (whose url follows this +# text). +dbgUnBlackBoxErrorDesc=Error stopping black boxing: + +# LOCALIZATION NOTE (dbgUnBlackBoxInvertDesc) A very short string used to describe the +# 'invert' parameter to the 'dbg unblackbox' command. +dbgUnBlackBoxInvertDesc=Invert matching, so that we stop black boxing every source that is not the source provided or does not match the provided glob pattern. + +# LOCALIZATION NOTE (consolecloseDesc) A very short description of the +# 'console close' command. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +consolecloseDesc=Close the console + +# LOCALIZATION NOTE (consoleopenDesc) A very short description of the +# 'console open' command. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +consoleopenDesc=Open the console + +# LOCALIZATION NOTE (editDesc) A very short description of the 'edit' +# command. See editManual2 for a fuller description of what it does. This +# string is designed to be shown in a menu alongside the command name, which +# is why it should be as short as possible. +editDesc=Tweak a page resource + +# LOCALIZATION NOTE (editManual2) A fuller description of the 'edit' command, +# displayed when the user asks for help on what it does. +editManual2=Edit one of the resources that is part of this page + +# LOCALIZATION NOTE (editResourceDesc) A very short string to describe the +# 'resource' parameter to the 'edit' command, which is displayed in a dialog +# when the user is using this command. +editResourceDesc=URL to edit + +# LOCALIZATION NOTE (editLineToJumpToDesc) A very short string to describe the +# 'line' parameter to the 'edit' command, which is displayed in a dialog +# when the user is using this command. +editLineToJumpToDesc=Line to jump to + +# LOCALIZATION NOTE (resizePageDesc) A very short string to describe the +# 'resizepage' command. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +resizePageDesc=Resize the page + +# LOCALIZATION NOTE (resizePageArgWidthDesc) A very short string to describe the +# 'width' parameter to the 'resizepage' command, which is displayed in a dialog +# when the user is using this command. +resizePageArgWidthDesc=Width in pixels + +# LOCALIZATION NOTE (resizePageArgWidthDesc) A very short string to describe the +# 'height' parameter to the 'resizepage' command, which is displayed in a dialog +# when the user is using this command. +resizePageArgHeightDesc=Height in pixels + +# LOCALIZATION NOTE (resizeModeOnDesc) A very short string to describe the +# 'resizeon ' command. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +resizeModeOnDesc=Enter Responsive Design Mode + +# LOCALIZATION NOTE (resizeModeOffDesc) A very short string to describe the +# 'resize off' command. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +resizeModeOffDesc=Exit Responsive Design Mode + +# LOCALIZATION NOTE (resizeModeToggleDesc) A very short string to describe the +# 'resize toggle' command. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +resizeModeToggleDesc=Toggle Responsive Design Mode + +# LOCALIZATION NOTE (resizeModeToggleTooltip) A string displayed as the +# tooltip of button in devtools toolbox which toggles Responsive Design Mode. +resizeModeToggleTooltip=Responsive Design Mode + +# LOCALIZATION NOTE (resizeModeToDesc) A very short string to describe the +# 'resize to' command. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +resizeModeToDesc=Alter page size + +# LOCALIZATION NOTE (resizeModeDesc) A very short string to describe the +# 'resize' command. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +resizeModeDesc=Control Responsive Design Mode + +# LOCALIZATION NOTE (resizeModeManual) A fuller description of the 'resize' +# command, displayed when the user asks for help on what it does. +# The argument (%1$S) is the browser name. +resizeModeManual2=Responsive websites respond to their environment, so they look good on a mobile display, a cinema display and everything in-between. Responsive Design Mode allows you to easily test a variety of page sizes in %1$S without needing to resize your whole browser. + +# LOCALIZATION NOTE (cmdDesc) A very short description of the 'cmd' +# command. This string is designed to be shown in a menu alongside the command +# name, which is why it should be as short as possible. +cmdDesc=Manipulate the commands + +# LOCALIZATION NOTE (cmdRefreshDesc) A very short description of the 'cmd refresh' +# command. This string is designed to be shown in a menu alongside the command +# name, which is why it should be as short as possible. +cmdRefreshDesc=Re-read mozcmd directory + +# LOCALIZATION NOTE (cmdStatus3) When the we load new commands from mozcmd +# directory, we report where we loaded from using %1$S. +cmdStatus3=Loaded commands from ‘%1$S’ + +# LOCALIZATION NOTE (cmdSetdirDesc) A very short description of the 'cmd setdir' +# command. This string is designed to be shown in a menu alongside the command +# name, which is why it should be as short as possible. +cmdSetdirDesc=Setup a mozcmd directory + +# LOCALIZATION NOTE (cmdSetdirManual3) A fuller description of the 'cmd setdir' +# command, displayed when the user asks for help on what it does. +cmdSetdirManual3=A ‘mozcmd’ directory is an easy way to create new custom commands. For more information see https://developer.mozilla.org/docs/Tools/GCLI/Customization + +# LOCALIZATION NOTE (cmdSetdirDirectoryDesc) The description of the directory +# parameter to the 'cmd setdir' command. +cmdSetdirDirectoryDesc=Directory containing .mozcmd files + +# LOCALIZATION NOTE (addonDesc) A very short description of the 'addon' +# command. This string is designed to be shown in a menu alongside the command +# name, which is why it should be as short as possible. +addonDesc=Manipulate add-ons + +# LOCALIZATION NOTE (addonListDesc) A very short description of the 'addon list' +# command. This string is designed to be shown in a menu alongside the command +# name, which is why it should be as short as possible. +addonListDesc=List installed add-ons + +# LOCALIZATION NOTE (addonListTypeDesc) A very short description of the +# 'addon list ' command. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +addonListTypeDesc=Select an add-on type + +# LOCALIZATION NOTE (addonListDictionaryHeading, addonListExtensionHeading, +# addonListLocaleHeading, addonListPluginHeading, addonListThemeHeading, +# addonListUnknownHeading) Used in the output of the 'addon list' command as the +# first line of output. +addonListDictionaryHeading=The following dictionaries are currently installed: +addonListExtensionHeading=The following extensions are currently installed: +addonListLocaleHeading=The following locales are currently installed: +addonListPluginHeading=The following plugins are currently installed: +addonListThemeHeading=The following themes are currently installed: +addonListAllHeading=The following add-ons are currently installed: +addonListUnknownHeading=The following add-ons of the selected type are currently installed: + +# LOCALIZATION NOTE (addonListOutEnable, addonListOutDisable) Used in the +# output of the 'addon list' command as the labels for the enable/disable +# action buttons in the listing. This string is designed to be shown in a +# small action button next to the addon name, which is why it should be as +# short as possible. +addonListOutEnable=Enable +addonListOutDisable=Disable + +# LOCALIZATION NOTE (addonPending, addonPendingEnable, addonPendingDisable, +# addonPendingUninstall, addonPendingInstall, addonPendingUpgrade) Used in +# the output of the 'addon list' command as the descriptions of pending +# addon operations. addonPending is used as a prefix for a list of pending +# actions (named by the other lookup variables). These strings are designed +# to be shown alongside addon names, which is why they should be as short +# as possible. +addonPending=pending +addonPendingEnable=enable +addonPendingDisable=disable +addonPendingUninstall=uninstall +addonPendingInstall=install +addonPendingUpgrade=upgrade + +# LOCALIZATION NOTE (addonNameDesc) A very short description of the +# name parameter of numerous add-on commands. This string is designed to be shown +# in a menu alongside the command name, which is why it should be as short as +# possible. +addonNameDesc=The name of the add-on + +# LOCALIZATION NOTE (addonNoneOfType) Used in the output of the 'addon list' +# command when a search for add-ons of a particular type were not found. +addonNoneOfType=There are no add-ons of that type installed. + +# LOCALIZATION NOTE (addonEnableDesc) A very short description of the +# 'addon enable ' command. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +addonEnableDesc=Enable the specified add-on + +# LOCALIZATION NOTE (addonAlreadyEnabled) Used in the output of the +# 'addon enable' command when an attempt is made to enable an add-on that is +# already enabled. +addonAlreadyEnabled=%S is already enabled. + +# LOCALIZATION NOTE (addonEnabled) Used in the output of the 'addon enable' +# command when an add-on is enabled. +addonEnabled=%S enabled. + +# LOCALIZATION NOTE (addonDisableDesc) A very short description of the +# 'addon disable ' command. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +addonDisableDesc=Disable the specified add-on + +# LOCALIZATION NOTE (addonAlreadyDisabled) Used in the output of the +# 'addon disable' command when an attempt is made to disable an add-on that is +# already disabled. +addonAlreadyDisabled=%S is already disabled. + +# LOCALIZATION NOTE (addonDisabled) Used in the output of the 'addon disable' +# command when an add-on is disabled. +addonDisabled=%S disabled. + +# LOCALIZATION NOTE (addonCtpDesc) A very short description of the +# 'addon ctp ' command. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +addonCtpDesc=Set the specified plugin to click-to-play. + +# LOCALIZATION NOTE (addonCtp) Used in the output of the 'addon ctp' +# command when a plugin is set to click-to-play. +addonCtp=%S set to click-to-play. + +# LOCALIZATION NOTE (addonAlreadyCtp) Used in the output of the +# 'addon ctp' command when an attempt is made to set a plugin to +# click-to-play that is already set to click-to-play. +addonAlreadyCtp=%S is already set to click-to-play. + +# LOCALIZATION NOTE (addonCantCtp) Used in the output of the 'addon +# ctp' command when an attempt is made to set an addon to click-to-play, +# but the addon is not a plugin. +addonCantCtp=%S cannot be set to click-to-play because it is not a plugin. + +# LOCALIZATION NOTE (addonNoCtp) Used in the output of the 'addon +# ctp' command when an attempt is made to set an addon to click-to-play, +# but the plugin cannot be set to click-to-play for some reason. +addonNoCtp=%S cannot be set to click-to-play. + +# LOCALIZATION NOTE (exportDesc) A very short description of the 'export' +# command. This string is designed to be shown in a menu alongside the command +# name, which is why it should be as short as possible. +exportDesc=Export resources + +# LOCALIZATION NOTE (exportHtmlDesc) A very short description of the 'export +# html' command. This string is designed to be shown in a menu alongside the +# command name, which is why it should be as short as possible. +exportHtmlDesc=Export HTML from page + +# LOCALIZATION NOTE (pagemodDesc) A very short description of the 'pagemod' +# command. This string is designed to be shown in a menu alongside the command +# name, which is why it should be as short as possible. +pagemodDesc=Make page changes + +# LOCALIZATION NOTE (pagemodReplaceDesc) A very short description of the +# 'pagemod replace' command. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +pagemodReplaceDesc=Search and replace in page elements + +# LOCALIZATION NOTE (pagemodReplaceSearchDesc) A very short string to describe +# the 'search' parameter to the 'pagemod replace' command, which is displayed in +# a dialog when the user is using this command. +pagemodReplaceSearchDesc=What to search for + +# LOCALIZATION NOTE (pagemodReplaceReplaceDesc) A very short string to describe +# the 'replace' parameter to the 'pagemod replace' command, which is displayed in +# a dialog when the user is using this command. +pagemodReplaceReplaceDesc=Replacement string + +# LOCALIZATION NOTE (pagemodReplaceIgnoreCaseDesc) A very short string to +# describe the 'ignoreCase' parameter to the 'pagemod replace' command, which is +# displayed in a dialog when the user is using this command. +pagemodReplaceIgnoreCaseDesc=Perform case-insensitive search + +# LOCALIZATION NOTE (pagemodReplaceRootDesc) A very short string to describe the +# 'root' parameter to the 'pagemod replace' command, which is displayed in +# a dialog when the user is using this command. +pagemodReplaceRootDesc=CSS selector to root of search + +# LOCALIZATION NOTE (pagemodReplaceSelectorDesc) A very short string to describe +# the 'selector' parameter to the 'pagemod replace' command, which is displayed +# in a dialog when the user is using this command. +pagemodReplaceSelectorDesc=CSS selector to match in search + +# LOCALIZATION NOTE (pagemodReplaceAttributesDesc) A very short string to +# describe the 'attributes' parameter to the 'pagemod replace' command, which is +# displayed in a dialog when the user is using this command. +pagemodReplaceAttributesDesc=Attribute match regexp + +# LOCALIZATION NOTE (pagemodReplaceAttrOnlyDesc) A very short string to describe +# the 'attrOnly' parameter to the 'pagemod replace' command, which is displayed +# in a dialog when the user is using this command. +pagemodReplaceAttrOnlyDesc=Restrict search to attributes + +# LOCALIZATION NOTE (pagemodReplaceContentOnlyDesc) A very short string to +# describe the 'contentOnly' parameter to the 'pagemod replace' command, which +# is displayed in a dialog when the user is using this command. +pagemodReplaceContentOnlyDesc=Restrict search to text nodes + +# LOCALIZATION NOTE (pagemodReplaceResultMatchedElements) A string displayed as +# the result of the 'pagemod replace' command. +pagemodReplaceResult=Elements matched by selector: %1$S. Replaces in text nodes: %2$S. Replaces in attributes: %3$S. + +# LOCALIZATION NOTE (pagemodRemoveDesc) A very short description of the +# 'pagemod remove' command. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +pagemodRemoveDesc=Remove elements and attributes from page + +# LOCALIZATION NOTE (pagemodRemoveElementDesc) A very short description of the +# 'pagemod remove element' command. This string is designed to be shown in +# a menu alongside the command name, which is why it should be as short as +# possible. +pagemodRemoveElementDesc=Remove elements from page + +# LOCALIZATION NOTE (pagemodRemoveElementSearchDesc) A very short string to +# describe the 'search' parameter to the 'pagemod remove element' command, which +# is displayed in a dialog when the user is using this command. +pagemodRemoveElementSearchDesc=CSS selector specifying elements to remove + +# LOCALIZATION NOTE (pagemodRemoveElementRootDesc) A very short string to +# describe the 'root' parameter to the 'pagemod remove element' command, which +# is displayed in a dialog when the user is using this command. +pagemodRemoveElementRootDesc=CSS selector specifying root of search + +# LOCALIZATION NOTE (pagemodRemoveElementStripOnlyDesc) A very short string to +# describe the 'stripOnly' parameter to the 'pagemod remove element' command, +# which is displayed in a dialog when the user is using this command. +pagemodRemoveElementStripOnlyDesc=Remove element, but leave content + +# LOCALIZATION NOTE (pagemodRemoveElementIfEmptyOnlyDesc) A very short string to +# describe the 'ifEmptyOnly' parameter to the 'pagemod remove element' command, +# which is displayed in a dialog when the user is using this command. +pagemodRemoveElementIfEmptyOnlyDesc=Remove only empty elements + +# LOCALIZATION NOTE (pagemodRemoveElementResultMatchedAndRemovedElements) +# A string displayed as the result of the 'pagemod remove element' command. +pagemodRemoveElementResultMatchedAndRemovedElements=Elements matched by selector: %1$S. Elements removed: %2$S. + +# LOCALIZATION NOTE (pagemodRemoveAttributeDesc) A very short description of the +# 'pagemod remove attribute' command. This string is designed to be shown in +# a menu alongside the command name, which is why it should be as short as +# possible. +pagemodRemoveAttributeDesc=Remove matching attributes + +# LOCALIZATION NOTE (pagemodRemoveAttributeSearchAttributesDesc) A very short +# string to describe the 'searchAttributes' parameter to the 'pagemod remove +# attribute' command, which is displayed in a dialog when the user is using this +# command. +pagemodRemoveAttributeSearchAttributesDesc=Regexp specifying attributes to remove + +# LOCALIZATION NOTE (pagemodRemoveAttributeSearchElementsDesc) A very short +# string to describe the 'searchElements' parameter to the 'pagemod remove +# attribute' command, which is displayed in a dialog when the user is using this +# command. +pagemodRemoveAttributeSearchElementsDesc=CSS selector of elements to include + +# LOCALIZATION NOTE (pagemodRemoveAttributeRootDesc) A very short string to +# describe the 'root' parameter to the 'pagemod remove attribute' command, which +# is displayed in a dialog when the user is using this command. +pagemodRemoveAttributeRootDesc=CSS selector of root of search + +# LOCALIZATION NOTE (pagemodRemoveAttributeIgnoreCaseDesc) A very short string +# to describe the 'ignoreCase' parameter to the 'pagemod remove attribute' +# command, which is displayed in a dialog when the user is using this command. +pagemodRemoveAttributeIgnoreCaseDesc=Perform case-insensitive search + +# LOCALIZATION NOTE (pagemodRemoveAttributeResult) A string displayed as the +# result of the 'pagemod remove attribute' command. +pagemodRemoveAttributeResult=Elements matched by selector: %1$S. Attributes removed: %2$S. + +# LOCALIZATION NOTE (toolsDesc2) A very short description of the 'tools' +# command, the parent command for tool-hacking commands. +# The argument (%1$S) is the browser name. +toolsDesc2=Hack the %1$S Developer Tools + +# LOCALIZATION NOTE (toolsManual2) A fuller description of the 'tools' +# command. The argument (%1$S) is the browser name. +toolsManual2=Various commands related to hacking directly on the %1$S Developer Tools. + +# LOCALIZATION NOTE (toolsSrcdirDesc) A very short description of the 'tools srcdir' +# command, for pointing your developer tools loader at a mozilla-central source tree. +toolsSrcdirDesc=Load tools from a mozilla-central checkout + +# LOCALIZATION NOTE (toolsSrcdirNotFound2) Shown when the 'tools srcdir' command was handed +# an invalid srcdir. +toolsSrcdirNotFound2=%1$S does not exist or is not a mozilla-central checkout. + +# LOCALIZATION NOTE (toolsSrcdirReloaded2) Displayed when tools have been reloaded by the +# 'tools srcdir' command. +toolsSrcdirReloaded2=Tools loaded from %1$S. + +# LOCALIZATION NOTE (toolsSrcdirManual2) A full description of the 'tools srcdir' +# command. The argument (%1$S) is the browser name. +toolsSrcdirManual2=Load the %1$S Developer Tools from a complete mozilla-central checkout. + +# LOCALIZATION NOTE (toolsSrcdirDir) The srcdir argument to the 'tools srcdir' command. +toolsSrcdirDir=A mozilla-central checkout + +# LOCALIZATION NOTE (toolsBuiltinDesc) A short description of the 'tools builtin' +# command, which overrides a previous 'tools srcdir' command. +toolsBuiltinDesc=Use the builtin tools + +# LOCALIZATION NOTE (toolsBuiltinDesc) A fuller description of the 'tools builtin' +# command. +toolsBuiltinManual=Use the builtin tools, overriding any previous srcdir command. + +# LOCALIZATION NOTE (toolsBuiltinReloaded) Displayed when tools are loaded with the +# 'tools builtin' command. +toolsBuiltinReloaded=Builtin tools loaded. + +# LOCALIZATION NOTE (toolsReloadDesc) A short description of the 'tools reload' command. +# which will reload the tools from the current srcdir. +toolsReloadDesc=Reload the developer tools + +# LOCALIZATION NOTE (toolsReloaded2) Displayed when tools are reloaded with the 'tools +# reload' command. +toolsReloaded2=Tools reloaded. + +# LOCALIZATION NOTE (cookieDesc) A very short description of the 'cookie' +# command. See cookieManual for a fuller description of what it does. This +# string is designed to be shown in a menu alongside the command name, which +# is why it should be as short as possible. +cookieDesc=Display and alter cookies + +# LOCALIZATION NOTE (cookieManual) A fuller description of the 'cookie' +# command, displayed when the user asks for help on what it does. +cookieManual=Commands to list, create, delete and alter cookies for the current domain. + +# LOCALIZATION NOTE (cookieListDesc) A very short description of the +# 'cookie list' command. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +cookieListDesc=Display cookies + +# LOCALIZATION NOTE (cookieListManual) A fuller description of the 'cookie list' +# command, displayed when the user asks for help on what it does. +cookieListManual=Display a list of the cookies relevant to the current page. + +# LOCALIZATION NOTE (cookieListOutHost,cookieListOutPath,cookieListOutExpires,cookieListOutAttributes): +# The 'cookie list' command has a number of headings for cookie properties. +# Particular care should be taken in translating these strings as they have +# references to names in the cookies spec. +cookieListOutHost=Host: +cookieListOutPath=Path: +cookieListOutExpires=Expires: +cookieListOutAttributes=Attributes: + +# LOCALIZATION NOTE (cookieListOutNone) The output of the 'cookie list' command +# uses this string when no cookie attributes (like httpOnly, secure, etc) apply +cookieListOutNone=None + +# LOCALIZATION NOTE (cookieListOutSession) The output of the 'cookie list' +# command uses this string to describe a cookie with an expiry value of '0' +# that is to say it is a session cookie +cookieListOutSession=At browser exit (session) + +# LOCALIZATION NOTE (cookieListOutNonePage) The output of the 'cookie list' +# command uses this string for pages like 'about:blank' which can't contain +# cookies +cookieListOutNonePage=No cookies found for this page + +# LOCALIZATION NOTE (cookieListOutNoneHost) The output of the 'cookie list' +# command uses this string when there are no cookies on a given web page +cookieListOutNoneHost=No cookies found for host %1$S + +# LOCALIZATION NOTE (cookieListOutEdit) A title used in the output from the +# 'cookie list' command on a button which can be used to edit cookie values +cookieListOutEdit=Edit + +# LOCALIZATION NOTE (cookieListOutRemove) A title used in the output from the +# 'cookie list' command on a button which can be used to remove cookies +cookieListOutRemove=Remove + +# LOCALIZATION NOTE (cookieRemoveDesc) A very short description of the +# 'cookie remove' command. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +cookieRemoveDesc=Remove a cookie + +# LOCALIZATION NOTE (cookieRemoveManual) A fuller description of the 'cookie remove' +# command, displayed when the user asks for help on what it does. +cookieRemoveManual=Remove a cookie, given its key + +# LOCALIZATION NOTE (cookieRemoveKeyDesc) A very short string to describe the +# 'key' parameter to the 'cookie remove' command, which is displayed in a dialog +# when the user is using this command. +cookieRemoveKeyDesc=The key of the cookie to remove + +# LOCALIZATION NOTE (cookieSetDesc) A very short description of the +# 'cookie set' command. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +cookieSetDesc=Set a cookie + +# LOCALIZATION NOTE (cookieSetManual) A fuller description of the 'cookie set' +# command, displayed when the user asks for help on what it does. +cookieSetManual=Set a cookie by specifying a key name, its value and optionally one or more of the following attributes: expires (max-age in seconds or the expires date in GMTString format), path, domain, secure + +# LOCALIZATION NOTE (cookieSetKeyDesc) A very short string to describe the +# 'key' parameter to the 'cookie set' command, which is displayed in a dialog +# when the user is using this command. +cookieSetKeyDesc=The key of the cookie to set + +# LOCALIZATION NOTE (cookieSetValueDesc) A very short string to describe the +# 'value' parameter to the 'cookie set' command, which is displayed in a dialog +# when the user is using this command. +cookieSetValueDesc=The value of the cookie to set + +# LOCALIZATION NOTE (cookieSetOptionsDesc) The title of a set of options to +# the 'cookie set' command, displayed as a heading to the list of option. +cookieSetOptionsDesc=Options + +# LOCALIZATION NOTE (cookieSetPathDesc) A very short string to describe the +# 'path' parameter to the 'cookie set' command, which is displayed in a dialog +# when the user is using this command. +cookieSetPathDesc=The path of the cookie to set + +# LOCALIZATION NOTE (cookieSetDomainDesc) A very short string to describe the +# 'domain' parameter to the 'cookie set' command, which is displayed in a dialog +# when the user is using this command. +cookieSetDomainDesc=The domain of the cookie to set + +# LOCALIZATION NOTE (cookieSetSecureDesc) A very short string to describe the +# 'secure' parameter to the 'cookie set' command, which is displayed in a dialog +# when the user is using this command. +cookieSetSecureDesc=Only transmitted over https + +# LOCALIZATION NOTE (cookieSetHttpOnlyDesc) A very short string to describe the +# 'httpOnly' parameter to the 'cookie set' command, which is displayed in a dialog +# when the user is using this command. +cookieSetHttpOnlyDesc=Not accessible from client side script + +# LOCALIZATION NOTE (cookieSetSessionDesc) A very short string to describe the +# 'session' parameter to the 'cookie set' command, which is displayed in a dialog +# when the user is using this command. +cookieSetSessionDesc=Only valid for the lifetime of the browser session + +# LOCALIZATION NOTE (cookieSetExpiresDesc) A very short string to describe the +# 'expires' parameter to the 'cookie set' command, which is displayed in a dialog +# when the user is using this command. +cookieSetExpiresDesc=The expiry date of the cookie (quoted RFC2822 or ISO 8601 date) + +# LOCALIZATION NOTE (jsbDesc) A very short description of the +# 'jsb' command. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +jsbDesc=JavaScript beautifier + +# LOCALIZATION NOTE (jsbUrlDesc) A very short description of the +# 'jsb ' parameter. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +jsbUrlDesc=The URL of the JS file to beautify + +# LOCALIZATION NOTE (jsbIndentSizeDesc) A very short description of the +# 'jsb ' parameter. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +jsbIndentSizeDesc=Indentation size in chars + +# LOCALIZATION NOTE (jsbIndentSizeManual) A fuller description of the +# 'jsb ' parameter, displayed when the user asks for help on what it +# does. +jsbIndentSizeManual=The number of chars with which to indent each line + +# LOCALIZATION NOTE (jsbIndentCharDesc) A very short description of the +# 'jsb ' parameter. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +jsbIndentCharDesc=The chars used to indent each line + +# LOCALIZATION NOTE (jsbIndentCharManual) A fuller description of the +# 'jsb ' parameter, displayed when the user asks for help on what it +# does. +jsbIndentCharManual=The chars used to indent each line. The possible choices are space or tab. + +# the 'jsb ' parameter. This string is designed to be +# shown in a menu alongside the command name, which is why it should be as short +# as possible. +jsbDoNotPreserveNewlinesDesc=Do not preserve line breaks + +# LOCALIZATION NOTE (jsbPreserveNewlinesManual) A fuller description of the +# 'jsb ' parameter, displayed when the user asks for help +# on what it does. +jsbPreserveNewlinesManual=Should existing line breaks be preserved + +# LOCALIZATION NOTE (jsbPreserveMaxNewlinesDesc) A very short description of the +# 'jsb ' parameter. This string is designed to be shown +# in a menu alongside the command name, which is why it should be as short as +# possible. +jsbPreserveMaxNewlinesDesc=Max consecutive line breaks + +# LOCALIZATION NOTE (jsbPreserveMaxNewlinesManual) A fuller description of the +# 'jsb ' parameter, displayed when the user asks for help +# on what it does. +jsbPreserveMaxNewlinesManual=The maximum number of consecutive line breaks to preserve + +# LOCALIZATION NOTE (jsbJslintHappyDesc) A very short description of the +# 'jsb ' parameter. This string is designed to be shown +# in a menu alongside the command name, which is why it should be as short as +# possible. +jsbJslintHappyDesc=Enforce jslint-stricter mode? + +# LOCALIZATION NOTE (jsbJslintHappyManual) A fuller description of the +# 'jsb ' parameter, displayed when the user asks for help +# on what it does. +jsbJslintHappyManual=When set to true, jslint-stricter mode is enforced + +# LOCALIZATION NOTE (jsbBraceStyleDesc2) A very short description of the +# 'jsb ' parameter. This string is designed to be shown +# in a menu alongside the command name, which is why it should be as short as +# possible. +jsbBraceStyleDesc2=Select the coding style of braces + +# LOCALIZATION NOTE (jsbBraceStyleManual2) A fuller description of the +# 'jsb ' parameter, displayed when the user asks for help +# on what it does. +# +# NOTES: The keywords collapse, expand, end-expand and expand-strict should not +# be translated. "even if it will break your code" means that the resulting code +# may no longer be functional. +jsbBraceStyleManual2=Select the coding style of braces: collapse - put braces on the same line as control statements; expand - put braces on own line (Allman / ANSI style); end-expand - put end braces on own line; expand-strict - put braces on own line even if it will break your code. + +# LOCALIZATION NOTE (jsbNoSpaceBeforeConditionalDesc) A very short description +# of the 'jsb ' parameter. This string is designed to +# be shown in a menu alongside the command name, which is why it should be as +# short as possible. +jsbNoSpaceBeforeConditionalDesc=No space before conditional statements + +# LOCALIZATION NOTE (jsbUnescapeStringsDesc) A very short description of the +# 'jsb ' parameter. This string is designed to be shown +# in a menu alongside the command name, which is why it should be as short as +# possible. +jsbUnescapeStringsDesc=Unescape \\xNN characters? + +# LOCALIZATION NOTE (jsbUnescapeStringsManual) A fuller description of the +# 'jsb ' parameter, displayed when the user asks for help +# on what it does. +jsbUnescapeStringsManual=Should printable characters in strings encoded in \\xNN notation be unescaped? + +# LOCALIZATION NOTE (jsbInvalidURL) Displayed when an invalid URL is passed to +# the jsb command. +jsbInvalidURL=Please enter a valid URL + +# LOCALIZATION NOTE (jsbOptionsDesc) The title of a set of options to +# the 'jsb' command, displayed as a heading to the list of options. +jsbOptionsDesc=Options + +# LOCALIZATION NOTE (calllogDesc) A very short description of the +# 'calllog' command. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +calllogDesc=Commands to manipulate function call logging + +# LOCALIZATION NOTE (calllogStartDesc) A very short description of the +# 'calllog start' command. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +calllogStartDesc=Start logging function calls to the console + +# LOCALIZATION NOTE (calllogStartReply) A string displayed as the result of +# the 'calllog start' command. +calllogStartReply=Call logging started. + +# LOCALIZATION NOTE (calllogStopDesc) A very short description of the +# 'calllog stop' command. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +calllogStopDesc=Stop function call logging + +# LOCALIZATION NOTE (calllogStopNoLogging) A string displayed as the result of +# the 'calllog stop' command when there is nothing to stop. +calllogStopNoLogging=No call logging is currently active + +# LOCALIZATION NOTE (calllogStopReply) A string displayed as the result of +# the 'calllog stop' command when there are logging actions to stop. +calllogStopReply=Stopped call logging. Active contexts: %1$S. + +# LOCALIZATION NOTE (calllogStartChromeDesc) A very short description of the +# 'calllog chromestart' command. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +calllogChromeStartDesc=Start logging function calls for chrome code to the console + +# LOCALIZATION NOTE (calllogChromeSourceTypeDesc) A very short description of the +# 'calllog chromestart ' parameter. This string is designed to be +# shown in a menu alongside the command name, which is why it should be as short as possible. +calllogChromeSourceTypeDesc=Global object, JSM URI, or JS to get a global object from + +# LOCALIZATION NOTE (calllogChromeSourceTypeDesc) A very short description of the +# 'calllog chromestart' command. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +calllogChromeSourceTypeManual=The global object, URI of a JSM, or JS to execute in the chrome window from which to obtain a global object + +# LOCALIZATION NOTE (calllogChromeStartReply) A string displayed as the result +# of the 'calllog chromestart' command. +calllogChromeStartReply=Call logging started. + +# LOCALIZATION NOTE (calllogChromeStopDesc) A very short description of the +# 'calllog chromestop' command. This string is designed to be shown in a menu +# alongside the command name, which is why it should be as short as possible. +calllogChromeStopDesc=Stop function call logging + +# LOCALIZATION NOTE (calllogChromeStopNoLogging) A string displayed as the +# result of the 'calllog chromestop' command when there is nothing to stop. +calllogChromeStopNoLogging=No call logging for chrome code is currently active + +# LOCALIZATION NOTE (calllogStopReply) A string displayed as the result of +# the 'calllog chromestop' command when there are logging actions to stop. +calllogChromeStopReply=Stopped call logging. Active contexts: %1$S. + +# LOCALIZATION NOTE (callLogChromeAnonFunction) A string displayed as the result +# of the 'calllog chromestart' command when an anonymouse function is to be +# logged. +callLogChromeAnonFunction= + +# LOCALIZATION NOTE (callLogChromeMethodCall) A string displayed as the result +# of the 'calllog chromestart' command to proceed a method name when it is to be +# logged. +callLogChromeMethodCall=Method call + +# LOCALIZATION NOTE (callLogChromeInvalidJSM) A string displayed as the result +# of the 'calllog chromestart' command with an invalid JSM or JSM path. +callLogChromeInvalidJSM=Invalid JSM! + +# LOCALIZATION NOTE (callLogChromeVarNotFoundContent) A string displayed as the +# result of the 'calllog chromestart' command with a source type of +# content-variable and an invalid variable name. +callLogChromeVarNotFoundContent=Variable not found in content window. + +# LOCALIZATION NOTE (callLogChromeVarNotFoundChrome) A string displayed as the +# result of the 'calllog chromestart' command with a source type of +# chrome-variable and an invalid variable name. +callLogChromeVarNotFoundChrome=Variable not found in chrome window. + +# LOCALIZATION NOTE (callLogChromeEvalException) A string displayed as the +# result of the 'calllog chromestart' command with a source type of JavaScript +# and invalid JavaScript code. +callLogChromeEvalException=Evaluated JavaScript threw the following exception + +# LOCALIZATION NOTE (callLogChromeEvalNeedsObject) A string displayed as the +# result of passing a non-JavaScript object creating source via the +# 'calllog chromestart javascript' command. +callLogChromeEvalNeedsObject=The JavaScript source must evaluate to an object whose method calls are to be logged e.g. “({a1: function() {this.a2()},a2: function() {}});” + +# LOCALIZATION NOTE (scratchpadOpenTooltip) A string displayed as the +# tooltip of button in devtools toolbox which opens Scratchpad. +scratchpadOpenTooltip=Scratchpad + +# LOCALIZATION NOTE (paintflashingDesc) A very short string used to describe the +# function of the "paintflashing" command +paintflashingDesc=Highlight painted area + +# LOCALIZATION NOTE (paintflashingOnDesc) A very short string used to describe the +# function of the "paintflashing on" command. +paintflashingOnDesc=Turn on paint flashing + +# LOCALIZATION NOTE (paintflashingOffDesc) A very short string used to describe the +# function of the "paintflashing off" command. +paintflashingOffDesc=Turn off paint flashing + +# LOCALIZATION NOTE (paintflashingChrome) A very short string used to describe the +# function of the "paintflashing on/off chrome" command. +paintflashingChromeDesc=chrome frames + +# LOCALIZATION NOTE (paintflashingManual) A longer description describing the +# set of commands that control paint flashing. +paintflashingManual=Draw repainted areas in different colors + +# LOCALIZATION NOTE (paintflashingTooltip) A string displayed as the +# tooltip of button in devtools toolbox which toggles paint flashing. +paintflashingTooltip=Highlight painted area + +# LOCALIZATION NOTE (paintflashingToggleDesc) A very short string used to describe the +# function of the "paintflashing toggle" command. +paintflashingToggleDesc=Toggle paint flashing + +# LOCALIZATION NOTE (splitconsoleTooltip) A string displayed as the +# tooltip of button in devtools toolbox which toggles the split webconsole. +splitconsoleTooltip=Toggle split console + +# LOCALIZATION NOTE (appCacheDesc) A very short string used to describe the +# function of the "appcache" command +appCacheDesc=Application cache utilities + +# LOCALIZATION NOTE (appCacheValidateDesc) A very short string used to describe +# the function of the "appcache validate" command. +appCacheValidateDesc=Validate cache manifest + +# LOCALIZATION NOTE (appCacheValidateManual) A fuller description of the +# 'validate' parameter to the 'appcache' command, displayed when the user asks +# for help on what it does. +appCacheValidateManual=Find issues relating to a cache manifest and the files that it references + +# LOCALIZATION NOTE (appCacheValidateUriDesc) A very short string used to describe +# the function of the "uri" parameter of the appcache validate" command. +appCacheValidateUriDesc=URI to check + +# LOCALIZATION NOTE (appCacheValidated) Displayed by the "appcache validate" +# command when it has been successfully validated. +appCacheValidatedSuccessfully=Appcache validated successfully. + +# LOCALIZATION NOTE (appCacheClearDesc) A very short string used to describe +# the function of the "appcache clear" command. +appCacheClearDesc=Clear entries from the application cache + +# LOCALIZATION NOTE (appCacheClearManual) A fuller description of the +# 'appcache clear' command, displayed when the user asks for help on what it does. +appCacheClearManual=Clear one or more entries from the application cache + +# LOCALIZATION NOTE (appCacheClearCleared) Displayed by the "appcache clear" +# command when entries are successfully cleared. +appCacheClearCleared=Entries cleared successfully. + +# LOCALIZATION NOTE (AppCacheListDesc) A very short string used to describe +# the function of the "appcache list" command. +appCacheListDesc=Display a list of application cache entries. + +# LOCALIZATION NOTE (AppCacheListManual) A fuller description of the +# 'appcache list' command, displayed when the user asks for help on what it does. +appCacheListManual=Display a list of all application cache entries. If the search parameter is used then the table displays the entries containing the search term. + +# LOCALIZATION NOTE (AppCacheListSearchDesc) A very short string used to describe +# the function of the "search" parameter of the appcache list" command. +appCacheListSearchDesc=Filter results using a search term. + +# LOCALIZATION NOTE (AppCacheList*) Row headers for the 'appcache list' command. +appCacheListKey=Key: +appCacheListDataSize=Data size: +appCacheListDeviceID=Device ID: +appCacheListExpirationTime=Expires: +appCacheListFetchCount=Fetch count: +appCacheListLastFetched=Last fetched: +appCacheListLastModified=Last modified: + +# LOCALIZATION NOTE (appCacheListViewEntry) The text for the view entry button +# of the 'appcache list' command. +appCacheListViewEntry=View Entry + +# LOCALIZATION NOTE (appCacheViewEntryDesc) A very short string used to describe +# the function of the "appcache viewentry" command. +appCacheViewEntryDesc=Open a new tab containing the specified cache entry information. + +# LOCALIZATION NOTE (appCacheViewEntryManual) A fuller description of the +# 'appcache viewentry' command, displayed when the user asks for help on what it +# does. +appCacheViewEntryManual=Open a new tab containing the specified cache entry information. + +# LOCALIZATION NOTE (appCacheViewEntryKey) A very short string used to describe +# the function of the "key" parameter of the 'appcache viewentry' command. +appCacheViewEntryKey=The key for the entry to display. + +# LOCALIZATION NOTE (profilerDesc) A very short string used to describe the +# function of the profiler command. +profilerDesc=Manage profiler + +# LOCALIZATION NOTE (profilerManual) A longer description describing the +# set of commands that control the profiler. +profilerManual=Commands to start or stop a JavaScript profiler + +# LOCALIZATION NOTE (profilerOpen) A very short string used to describe the function +# of the profiler open command. +profilerOpenDesc=Open the profiler + +# LOCALIZATION NOTE (profilerClose) A very short string used to describe the function +# of the profiler close command. +profilerCloseDesc=Close the profiler + +# LOCALIZATION NOTE (profilerStart) A very short string used to describe the function +# of the profiler start command. +profilerStartDesc=Start profiling + +# LOCALIZATION NOTE (profilerStartManual) A fuller description of the 'profile name' +# parameter. This parameter is used to name a newly created profile or to lookup +# an existing profile by its name. +profilerStartManual=Name of a profile you wish to start. + +# LOCALIZATION NOTE (profilerStop) A very short string used to describe the function +# of the profiler stop command. +profilerStopDesc=Stop profiling + +# LOCALIZATION NOTE (profilerStopManual) A fuller description of the 'profile name' +# parameter. This parameter is used to lookup an existing profile by its name. +profilerStopManual=Name of a profile you wish to stop. + +# LOCALIZATION NOTE (profilerList) A very short string used to describe the function +# of the profiler list command. +profilerListDesc=List all profiles + +# LOCALIZATION NOTE (profilerShow) A very short string used to describe the function +# of the profiler show command. +profilerShowDesc=Show individual profile + +# LOCALIZATION NOTE (profilerShowManual) A fuller description of the 'profile name' +# parameter. This parameter is used to name a newly created profile or to lookup +# an existing profile by its name. +profilerShowManual=Name of a profile. + +# LOCALIZATION NOTE (profilerAlreadyStarted) A message that is displayed whenever +# an operation cannot be completed because the profile in question has already +# been started. +profilerAlreadyStarted2=Profile has already been started + +# LOCALIZATION NOTE (profilerNotFound) A message that is displayed whenever +# an operation cannot be completed because the profile in question could not be +# found. +profilerNotFound=Profile not found + +# LOCALIZATION NOTE (profilerNotStarted) A message that is displayed whenever +# an operation cannot be completed because the profile in question has not been +# started yet. It also contains a hint to use the 'profile start' command to +# start the profiler. +profilerNotStarted3=Profiler has not been started yet. Use ‘profile start’ to start profiling + +# LOCALIZATION NOTE (profilerStarted2) A very short string that indicates that +# we have started recording. +profilerStarted2=Recording… + +# LOCALIZATION NOTE (profilerStopped) A very short string that indicates that +# we have stopped recording. +profilerStopped=Stopped… + +# LOCALIZATION NOTE (profilerNotReady) A message that is displayed whenever +# an operation cannot be completed because the profiler has not been opened yet. +profilerNotReady=For this command to work you need to open the profiler first + +# LOCALIZATION NOTE (listenDesc) A very short string used to describe the +# function of the 'listen' command. +listenDesc=Open a remote debug port + +# LOCALIZATION NOTE (listenManual2) A longer description of the 'listen' +# command. +listenManual2=%1$S can allow remote debugging over a TCP/IP connection. For security reasons this is turned off by default, but can be enabled using this command. + +# LOCALIZATION NOTE (listenPortDesc) A very short string used to describe the +# function of 'port' parameter to the 'listen' command. +listenPortDesc=The TCP port to listen on + +# LOCALIZATION NOTE (listenProtocolDesc) A very short string used to describe the +# function of 'protocol' parameter to the 'listen' command. +listenProtocolDesc=The protocol to be used + +# LOCALIZATION NOTE (listenDisabledOutput) Text of a message output during the +# execution of the 'listen' command. +listenDisabledOutput=Listen is disabled by the devtools.debugger.remote-enabled preference + +# LOCALIZATION NOTE (listenInitOutput) Text of a message output during the +# execution of the 'listen' command. %1$S is a port number +listenInitOutput=Listening on port %1$S + +# LOCALIZATION NOTE (listenNoInitOutput) Text of a message output during the +# execution of the 'listen' command. +listenNoInitOutput=DebuggerServer not initialized + +# LOCALIZATION NOTE (unlistenDesc) A very short string used to describe the +# function of the 'unlisten' command. +unlistenDesc=Close all remote debug ports + +# LOCALIZATION NOTE (unlistenManual) A longer description of the 'unlisten' +# command. +unlistenManual=Closes all the open ports for remote debugging. + +# LOCALIZATION NOTE (unlistenOutput) Text of a message output during the +# execution of the 'unlisten' command. +unlistenOutput=All TCP ports closed + +# LOCALIZATION NOTE (mediaDesc, mediaEmulateDesc, mediaEmulateManual, +# mediaEmulateType, mediaResetDesc, mediaResetManual) These strings describe +# the 'media' commands and all available parameters. +mediaDesc=CSS media type emulation +mediaEmulateDesc=Emulate a specified CSS media type +mediaEmulateManual=View the document as if rendered on a device supporting the given media type, with the relevant CSS rules applied. +mediaEmulateType=The media type to emulate +mediaResetDesc=Stop emulating a CSS media type + +# LOCALIZATION NOTE (qsaDesc, qsaQueryDesc) +# These strings describe the 'qsa' commands and all available parameters. +qsaDesc=Perform querySelectorAll on the current document and return number of matches +qsaQueryDesc=CSS selectors separated by comma + +# LOCALIZATION NOTE (injectDesc, injectManual, injectLibraryDesc, injectLoaded, +# injectFailed) These strings describe the 'inject' commands and all available +# parameters. +injectDesc=Inject common libraries into the page +injectManual2=Inject common libraries into the content of the page which can also be accessed from the console. +injectLibraryDesc=Select the library to inject or enter a valid script URI to inject +injectLoaded=%1$S loaded +injectFailed=Failed to load %1$S - Invalid URI + +# LOCALIZATION NOTE (folderDesc, folderOpenDesc, folderOpenDir, +# folderOpenProfileDesc) These strings describe the 'folder' commands and +# all available parameters. +folderDesc=Open folders +folderOpenDesc=Open folder path +folderOpenDir=Directory Path +folderOpenProfileDesc=Open profile directory + +# LOCALIZATION NOTE (folderInvalidPath) A string displayed as the result +# of the 'folder open' command with an invalid folder path. +folderInvalidPath=Please enter a valid path + +# LOCALIZATION NOTE (folderOpenDirResult) A very short string used to +# describe the result of the 'folder open' command. +# The argument (%1$S) is the folder path. +folderOpenDirResult=Opened %1$S + +# LOCALIZATION NOTE (mdnDesc) A very short string used to describe the +# use of 'mdn' command. +mdnDesc=Retrieve documentation from MDN +# LOCALIZATION NOTE (mdnCssDesc) A very short string used to describe the +# result of the 'mdn css' command. +mdnCssDesc=Retrieve documentation about a given CSS property name from MDN +# LOCALIZATION NOTE (mdnCssProp) String used to describe the 'property name' +# parameter used in the 'mdn css' command. +mdnCssProp=Property name +# LOCALIZATION NOTE (mdnCssPropertyNotFound) String used to display an error in +# the result of the 'mdn css' command. Errors occur when a given CSS property +# wasn't found on MDN. The %1$S parameter will be replaced with the name of the +# CSS property. +mdnCssPropertyNotFound=MDN documentation for the CSS property ‘%1$S’ was not found. +# LOCALIZATION NOTE (mdnCssVisitPage) String used as the label of a link to the +# MDN page for a given CSS property. +mdnCssVisitPage=Visit MDN page + +# LOCALIZATION NOTE (security) +securityPrivacyDesc=Display supported security and privacy features +securityManual=Commands to list and get suggestions about security features for the current domain. +securityListDesc=Display security features +securityListManual=Display a list of all relevant security features of the current page. +# CSP specific +securityCSPDesc=Display CSP specific security features +securityCSPManual=Display feedback about the CSP applied to the current page. +securityCSPRemWildCard=Can you remove the wildcard(*)? +securityCSPPotentialXSS=Potential XSS vulnerability! +# LOCALIZATION NOTE: do not translate 'Content-Security-Policy' +securityCSPNoCSPOnPage=Could not find Content-Security-Policy for +securityCSPHeaderOnPage=Content-Security-Policy for +securityCSPROHeaderOnPage=Content-Security-Policy-Report-Only for +# Referrer Policy specific +securityReferrerPolicyDesc=Display the current Referrer Policy +securityReferrerPolicyManual=Display the Referrer Policy for the current page with example referrers for different URIs. +securityReferrerNextURI=When Visiting +securityReferrerCalculatedReferrer=Referrer Will Be +# LOCALIZATION NOTE: %1$S is the current page URI +securityReferrerPolicyReportHeader=Referrer Policy for %1$S +securityReferrerPolicyOtherDomain=Other Origin +securityReferrerPolicyOtherDomainDowngrade=Other Origin HTTP +securityReferrerPolicySameDomain=Same Origin +securityReferrerPolicySameDomainDowngrade=Same Host HTTP + +# LOCALIZATION NOTE (rulersDesc) A very short description of the +# 'rulers' command. See rulersManual for a fuller description of what +# it does. This string is designed to be shown in a menu alongside the +# command name, which is why it should be as short as possible. +rulersDesc=Toggle rulers for the page + +# LOCALIZATION NOTE (rulersManual) A fuller description of the 'rulers' +# command, displayed when the user asks for help on what it does. +rulersManual=Toggle the horizontal and vertical rulers for the current page + +# LOCALIZATION NOTE (rulersTooltip) A string displayed as the +# tooltip of button in devtools toolbox which toggles the rulers. +rulersTooltip=Toggle rulers for the page + +# LOCALIZATION NOTE (measureDesc) A very short description of the +# 'measure' command. See measureManual for a fuller description of what +# it does. This string is designed to be shown in a menu alongside the +# command name, which is why it should be as short as possible. +measureDesc=Measure a portion of the page + +# LOCALIZATION NOTE (measureManual) A fuller description of the 'measure' +# command, displayed when the user asks for help on what it does. +measureManual=Activate the measuring tool to measure an arbitrary area of the page + +# LOCALIZATION NOTE (measureTooltip) A string displayed as the +# tooltip of button in devtools toolbox which toggles the measuring tool. +measureTooltip=Measure a portion of the page diff --git a/devtools/shared/locales/en-US/shared.properties b/devtools/shared/locales/en-US/shared.properties new file mode 100644 index 000000000..1fb1dc230 --- /dev/null +++ b/devtools/shared/locales/en-US/shared.properties @@ -0,0 +1,6 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +# LOCALIZATION NOTE (ellipsis): The ellipsis (three dots) character +ellipsis=… \ No newline at end of file diff --git a/devtools/shared/locales/en-US/styleinspector.properties b/devtools/shared/locales/en-US/styleinspector.properties new file mode 100644 index 000000000..b56650086 --- /dev/null +++ b/devtools/shared/locales/en-US/styleinspector.properties @@ -0,0 +1,188 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +# LOCALIZATION NOTE These strings are used inside the Style Inspector. +# +# The correct localization of this file might be to keep it in +# English, or another language commonly spoken among web developers. +# You want to make that choice consistent across the developer tools. +# A good criteria is the language in which you'd find the best +# documentation on web development on the web. + + +# LOCALIZATION NOTE (panelTitle): This is the panel title +panelTitle=Style Inspector + +# LOCALIZATION NOTE (rule.status): For each style property the panel shows +# the rules which hold that specific property. For every rule, the rule status +# is also displayed: a rule can be the best match, a match, a parent match, or a +# rule did not match the element the user has highlighted. +rule.status.BEST=Best Match +rule.status.MATCHED=Matched +rule.status.PARENT_MATCH=Parent Match + +# LOCALIZATION NOTE (rule.sourceElement, rule.sourceInline): For each +# style property the panel shows the rules which hold that specific property. +# For every rule, the rule source is also displayed: a rule can come from a +# file, from the same page (inline), or from the element itself (element). +rule.sourceInline=inline +rule.sourceElement=element + +# LOCALIZATION NOTE (rule.inheritedFrom): Shown for CSS rules +# that were inherited from a parent node. Will be passed a node +# identifier of the parent node. +# e.g "Inherited from body#bodyID" +rule.inheritedFrom=Inherited from %S + +# LOCALIZATION NOTE (rule.keyframe): Shown for CSS Rules keyframe header. +# Will be passed an identifier of the keyframe animation name. +rule.keyframe=Keyframes %S + +# LOCALIZATION NOTE (rule.userAgentStyles): Shown next to the style sheet +# link for CSS rules that were loaded from a user agent style sheet. +# These styles will not be editable, and will only be visible if the +# devtools.inspector.showUserAgentStyles pref is true. +rule.userAgentStyles=(user agent) + +# LOCALIZATION NOTE (rule.pseudoElement): Shown for CSS rules +# pseudo element header +rule.pseudoElement=Pseudo-elements + +# LOCALIZATION NOTE (rule.pseudoElement): Shown for CSS rules +# pseudo element header +rule.selectedElement=This Element + +# LOCALIZATION NOTE (rule.warning.title): When an invalid property value is +# entered into the rule view a warning icon is displayed. This text is used for +# the title attribute of the warning icon. +rule.warning.title=Invalid property value + +# LOCALIZATION NOTE (rule.filterProperty.title): Text displayed in the tooltip +# of the search button that is shown next to a property that has been overridden +# in the rule view. +rule.filterProperty.title=Filter rules containing this property + +# LOCALIZATION NOTE (ruleView.empty): Text displayed when the highlighter is +# first opened and there's no node selected in the rule view. +rule.empty=No element selected. + +# LOCALIZATION NOTE (ruleView.selectorHighlighter.tooltip): Text displayed in a +# tooltip when the mouse is over a selector highlighter icon in the rule view. +rule.selectorHighlighter.tooltip=Highlight all elements matching this selector + +# LOCALIZATION NOTE (rule.colorSwatch.tooltip): Text displayed in a tooltip +# when the mouse is over a color swatch in the rule view. +rule.colorSwatch.tooltip=Click to open the color picker, shift+click to change the color format + +# LOCALIZATION NOTE (rule.bezierSwatch.tooltip): Text displayed in a tooltip +# when the mouse is over a cubic-bezier swatch in the rule view. +rule.bezierSwatch.tooltip=Click to open the timing-function editor + +# LOCALIZATION NOTE (rule.filterSwatch.tooltip): Text displayed in a tooltip +# when the mouse is over a filter swatch in the rule view. +rule.filterSwatch.tooltip=Click to open the filter editor + +# LOCALIZATION NOTE (rule.angleSwatch.tooltip): Text displayed in a tooltip +# when the mouse is over a angle swatch in the rule view. +rule.angleSwatch.tooltip=Shift+click to change the angle format + +# LOCALIZATION NOTE (rule.gridToggle.tooltip): Text displayed in a tooltip +# when the mouse is over a CSS Grid toggle icon in the rule view. +rule.gridToggle.tooltip=Click to toggle the CSS Grid highlighter + +# LOCALIZATION NOTE (styleinspector.contextmenu.copyColor): Text displayed in the rule +# and computed view context menu when a color value was clicked. +styleinspector.contextmenu.copyColor=Copy Color + +# LOCALIZATION NOTE (styleinspector.contextmenu.copyColor.accessKey): Access key for +# the rule and computed view context menu "Copy Color" entry. +styleinspector.contextmenu.copyColor.accessKey=L + +# LOCALIZATION NOTE (styleinspector.contextmenu.copyUrl): In rule and computed view : +# text displayed in the context menu for an image URL. +# Clicking it copies the URL to the clipboard of the user. +styleinspector.contextmenu.copyUrl=Copy URL + +# LOCALIZATION NOTE (styleinspector.contextmenu.copyUrl.accessKey): Access key for +# the rule and computed view context menu "Copy URL" entry. +styleinspector.contextmenu.copyUrl.accessKey=U + +# LOCALIZATION NOTE (styleinspector.contextmenu.copyImageDataUrl): In rule and computed view : +# text displayed in the context menu for an image URL. +# Clicking it copies the image as Data-URL to the clipboard of the user. +styleinspector.contextmenu.copyImageDataUrl=Copy Image Data-URL + +# LOCALIZATION NOTE (styleinspector.contextmenu.copyDataUri.accessKey): Access key for +# the rule and computed view context menu "Copy Image Data-URL" entry. +styleinspector.contextmenu.copyImageDataUrl.accessKey=I + +# LOCALIZATION NOTE (styleinspector.copyDataUriError): Text set in the clipboard +# if an error occurs when using the copyImageDataUrl context menu action +# (invalid image link, timeout, etc...) +styleinspector.copyImageDataUrlError=Failed to copy image Data-URL + +# LOCALIZATION NOTE (styleinspector.contextmenu.toggleOrigSources): Text displayed in the rule view +# context menu. +styleinspector.contextmenu.toggleOrigSources=Show Original Sources + +# LOCALIZATION NOTE (styleinspector.contextmenu.toggleOrigSources.accessKey): Access key for +# the rule view context menu "Show original sources" entry. +styleinspector.contextmenu.toggleOrigSources.accessKey=O + +# LOCALIZATION NOTE (styleinspector.contextmenu.showMdnDocs): Text displayed in the rule view +# context menu to display docs from MDN for an item. +styleinspector.contextmenu.showMdnDocs=Show MDN Docs + +# LOCALIZATION NOTE (styleinspector.contextmenu.showMdnDocs.accessKey): Access key for +# the rule view context menu "Show MDN docs" entry. +styleinspector.contextmenu.showMdnDocs.accessKey=D + +# LOCALIZATION NOTE (styleinspector.contextmenu.addNewRule): Text displayed in the +# rule view context menu for adding a new rule to the element. +# This should match inspector.addRule.tooltip in inspector.properties +styleinspector.contextmenu.addNewRule=Add New Rule + +# LOCALIZATION NOTE (styleinspector.contextmenu.addRule.accessKey): Access key for +# the rule view context menu "Add rule" entry. +styleinspector.contextmenu.addNewRule.accessKey=R + +# LOCALIZATION NOTE (styleinspector.contextmenu.selectAll): Text displayed in the +# computed view context menu. +styleinspector.contextmenu.selectAll=Select All + +# LOCALIZATION NOTE (styleinspector.contextmenu.selectAll.accessKey): Access key for +# the computed view context menu "Select all" entry. +styleinspector.contextmenu.selectAll.accessKey=A + +# LOCALIZATION NOTE (styleinspector.contextmenu.copy): Text displayed in the +# computed view context menu. +styleinspector.contextmenu.copy=Copy + +# LOCALIZATION NOTE (styleinspector.contextmenu.copy.accessKey): Access key for +# the computed view context menu "Copy" entry. +styleinspector.contextmenu.copy.accessKey=C + +# LOCALIZATION NOTE (styleinspector.contextmenu.copyLocation): Text displayed in the +# rule view context menu for copying the source location. +styleinspector.contextmenu.copyLocation=Copy Location + +# LOCALIZATION NOTE (styleinspector.contextmenu.copyPropertyDeclaration): Text +# displayed in the rule view context menu for copying the property declaration. +styleinspector.contextmenu.copyPropertyDeclaration=Copy Property Declaration + +# LOCALIZATION NOTE (styleinspector.contextmenu.copyPropertyName): Text displayed in +# the rule view context menu for copying the property name. +styleinspector.contextmenu.copyPropertyName=Copy Property Name + +# LOCALIZATION NOTE (styleinspector.contextmenu.copyPropertyValue): Text displayed in +# the rule view context menu for copying the property value. +styleinspector.contextmenu.copyPropertyValue=Copy Property Value + +# LOCALIZATION NOTE (styleinspector.contextmenu.copyRule): Text displayed in the +# rule view context menu for copying the rule. +styleinspector.contextmenu.copyRule=Copy Rule + +# LOCALIZATION NOTE (styleinspector.contextmenu.copySelector): Text displayed in the +# rule view context menu for copying the selector. +styleinspector.contextmenu.copySelector=Copy Selector diff --git a/devtools/shared/locales/jar.mn b/devtools/shared/locales/jar.mn new file mode 100644 index 000000000..2d33b5425 --- /dev/null +++ b/devtools/shared/locales/jar.mn @@ -0,0 +1,8 @@ +#filter substitution +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +@AB_CD@.jar: +% locale devtools-shared @AB_CD@ %locale/@AB_CD@/devtools/shared/ + locale/@AB_CD@/devtools/shared/ (%*) diff --git a/devtools/shared/locales/moz.build b/devtools/shared/locales/moz.build new file mode 100644 index 000000000..aac3a838c --- /dev/null +++ b/devtools/shared/locales/moz.build @@ -0,0 +1,7 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +JAR_MANIFESTS += ['jar.mn'] diff --git a/devtools/shared/moz.build b/devtools/shared/moz.build new file mode 100644 index 000000000..e4de1d84a --- /dev/null +++ b/devtools/shared/moz.build @@ -0,0 +1,67 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +include('../templates.mozbuild') + +DIRS += [ + 'acorn', + 'apps', + 'client', + 'css', + 'discovery', + 'fronts', + 'gcli', + 'heapsnapshot', + 'inspector', + 'jsbeautify', + 'layout', + 'locales', + 'node-properties', + 'performance', + 'platform', + 'pretty-fast', + 'qrcode', + 'security', + 'sourcemap', + 'sprintfjs', + 'shims', + 'specs', + 'touch', + 'transport', + 'webconsole', + 'worker', +] + +BROWSER_CHROME_MANIFESTS += ['tests/browser/browser.ini'] +MOCHITEST_CHROME_MANIFESTS += ['tests/mochitest/chrome.ini'] +XPCSHELL_TESTS_MANIFESTS += ['tests/unit/xpcshell.ini'] + +JAR_MANIFESTS += ['jar.mn'] + +DevToolsModules( + 'async-storage.js', + 'async-utils.js', + 'builtin-modules.js', + 'content-observer.js', + 'defer.js', + 'deprecated-sync-thenables.js', + 'DevToolsUtils.js', + 'dom-node-constants.js', + 'dom-node-filter-constants.js', + 'event-emitter.js', + 'flags.js', + 'indentation.js', + 'l10n.js', + 'loader-plugin-raw.jsm', + 'Loader.jsm', + 'Parser.jsm', + 'path.js', + 'plural-form.js', + 'protocol.js', + 'system.js', + 'task.js', + 'ThreadSafeDevToolsUtils.js', +) diff --git a/devtools/shared/node-properties/UPGRADING.md b/devtools/shared/node-properties/UPGRADING.md new file mode 100644 index 000000000..086621f2b --- /dev/null +++ b/devtools/shared/node-properties/UPGRADING.md @@ -0,0 +1,12 @@ +NODE PROPERTIES UPGRADING + +Original library at https://github.com/gagle/node-properties +The original library is intended for node and not for the browser. Most files are not +needed here. + +To update +- copy https://github.com/gagle/node-properties/blob/master/lib/parse.js +- update the initial "module.exports" to "var parse" in parse.js +- copy https://github.com/gagle/node-properties/blob/master/lib/read.js +- remove the require statements at the beginning +- merge the two files, parse.js first, read.js second \ No newline at end of file diff --git a/devtools/shared/node-properties/moz.build b/devtools/shared/node-properties/moz.build new file mode 100644 index 000000000..e58b1fdb6 --- /dev/null +++ b/devtools/shared/node-properties/moz.build @@ -0,0 +1,9 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +DevToolsModules( + 'node-properties.js' +) diff --git a/devtools/shared/node-properties/node-properties.js b/devtools/shared/node-properties/node-properties.js new file mode 100644 index 000000000..05feba857 --- /dev/null +++ b/devtools/shared/node-properties/node-properties.js @@ -0,0 +1,776 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2014 Gabriel Llamas + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +"use strict"; + +var hex = function (c){ + switch (c){ + case "0": return 0; + case "1": return 1; + case "2": return 2; + case "3": return 3; + case "4": return 4; + case "5": return 5; + case "6": return 6; + case "7": return 7; + case "8": return 8; + case "9": return 9; + case "a": case "A": return 10; + case "b": case "B": return 11; + case "c": case "C": return 12; + case "d": case "D": return 13; + case "e": case "E": return 14; + case "f": case "F": return 15; + } +}; + +var parse = function (data, options, handlers, control){ + var c; + var code; + var escape; + var skipSpace = true; + var isCommentLine; + var isSectionLine; + var newLine = true; + var multiLine; + var isKey = true; + var key = ""; + var value = ""; + var section; + var unicode; + var unicodeRemaining; + var escapingUnicode; + var keySpace; + var sep; + var ignoreLine; + + var line = function (){ + if (key || value || sep){ + handlers.line (key, value); + key = ""; + value = ""; + sep = false; + } + }; + + var escapeString = function (key, c, code){ + if (escapingUnicode && unicodeRemaining){ + unicode = (unicode << 4) + hex (c); + if (--unicodeRemaining) return key; + escape = false; + escapingUnicode = false; + return key + String.fromCharCode (unicode); + } + + //code 117: u + if (code === 117){ + unicode = 0; + escapingUnicode = true; + unicodeRemaining = 4; + return key; + } + + escape = false; + + //code 116: t + //code 114: r + //code 110: n + //code 102: f + if (code === 116) return key + "\t"; + else if (code === 114) return key + "\r"; + else if (code === 110) return key + "\n"; + else if (code === 102) return key + "\f"; + + return key + c; + }; + + var isComment; + var isSeparator; + + if (options._strict){ + isComment = function (c, code, options){ + return options._comments[c]; + }; + + isSeparator = function (c, code, options){ + return options._separators[c]; + }; + }else{ + isComment = function (c, code, options){ + //code 35: # + //code 33: ! + return code === 35 || code === 33 || options._comments[c]; + }; + + isSeparator = function (c, code, options){ + //code 61: = + //code 58: : + return code === 61 || code === 58 || options._separators[c]; + }; + } + + for (var i=~~control.resume; i 1 || code < 33 || code > 126){ + throw new Error ("The comment token must be a single printable ASCII " + + "character"); + } + c[comment] = true; + }); + options._comments = c; + + var separators = options.separators || []; + if (!Array.isArray (separators)) separators = [separators]; + var s = {}; + separators.forEach (function (separator){ + code = separator.charCodeAt (0); + if (separator.length > 1 || code < 33 || code > 126){ + throw new Error ("The separator token must be a single printable ASCII " + + "character"); + } + s[separator] = true; + }); + options._separators = s; + + if (options.path){ + if (!cb) throw new Error ("A callback must be passed if the 'path' " + + "option is enabled"); + if (options.include){ + read (data, options, cb); + }else{ + fs.readFile (data, { encoding: "utf8" }, function (error, data){ + if (error) return cb (error); + build (data, options, ".", cb); + }); + } + }else{ + return build (data, options, ".", cb); + } +}; diff --git a/devtools/shared/path.js b/devtools/shared/path.js new file mode 100644 index 000000000..94083679a --- /dev/null +++ b/devtools/shared/path.js @@ -0,0 +1,28 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/* + * Join all the arguments together and normalize the resulting URI. + * The initial path must be an full URI with a protocol (i.e. http://). + */ +exports.joinURI = (initialPath, ...paths) => { + let url; + + try { + url = new URL(initialPath); + } + catch (e) { + return; + } + + for (let path of paths) { + if (path) { + url = new URL(path, url); + } + } + + return url.href; +}; diff --git a/devtools/shared/performance/moz.build b/devtools/shared/performance/moz.build new file mode 100644 index 000000000..202aac278 --- /dev/null +++ b/devtools/shared/performance/moz.build @@ -0,0 +1,12 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +XPCSHELL_TESTS_MANIFESTS += ['test/xpcshell.ini'] + +DevToolsModules( + 'recording-common.js', + 'recording-utils.js', +) diff --git a/devtools/shared/performance/recording-common.js b/devtools/shared/performance/recording-common.js new file mode 100644 index 000000000..d0826bd18 --- /dev/null +++ b/devtools/shared/performance/recording-common.js @@ -0,0 +1,97 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * A mixin to be used for PerformanceRecordingActor, PerformanceRecordingFront, + * and LegacyPerformanceRecording for helper methods to access data. + */ + +const PerformanceRecordingCommon = exports.PerformanceRecordingCommon = { + // Private fields, only needed when a recording is started or stopped. + _console: false, + _imported: false, + _recording: false, + _completed: false, + _configuration: {}, + _startingBufferStatus: null, + _localStartTime: 0, + + // Serializable fields, necessary and sufficient for import and export. + _label: "", + _duration: 0, + _markers: null, + _frames: null, + _memory: null, + _ticks: null, + _allocations: null, + _profile: null, + _systemHost: null, + _systemClient: null, + + /** + * Helper methods for returning the status of the recording. + * These methods should be consistent on both the front and actor. + */ + isRecording: function () { return this._recording; }, + isCompleted: function () { return this._completed || this.isImported(); }, + isFinalizing: function () { return !this.isRecording() && !this.isCompleted(); }, + isConsole: function () { return this._console; }, + isImported: function () { return this._imported; }, + + /** + * Helper methods for returning configuration for the recording. + * These methods should be consistent on both the front and actor. + */ + getConfiguration: function () { return this._configuration; }, + getLabel: function () { return this._label; }, + + /** + * Gets duration of this recording, in milliseconds. + * @return number + */ + getDuration: function () { + // Compute an approximate ending time for the current recording if it is + // still in progress. This is needed to ensure that the view updates even + // when new data is not being generated. If recording is completed, use + // the duration from the profiler; if between recording and being finalized, + // use the last estimated duration. + if (this.isRecording()) { + return this._estimatedDuration = Date.now() - this._localStartTime; + } else { + return this._duration || this._estimatedDuration || 0; + } + }, + + /** + * Helper methods for returning recording data. + * These methods should be consistent on both the front and actor. + */ + getMarkers: function () { return this._markers; }, + getFrames: function () { return this._frames; }, + getMemory: function () { return this._memory; }, + getTicks: function () { return this._ticks; }, + getAllocations: function () { return this._allocations; }, + getProfile: function () { return this._profile; }, + getHostSystemInfo: function () { return this._systemHost; }, + getClientSystemInfo: function () { return this._systemClient; }, + getStartingBufferStatus: function () { return this._startingBufferStatus; }, + + getAllData: function () { + let label = this.getLabel(); + let duration = this.getDuration(); + let markers = this.getMarkers(); + let frames = this.getFrames(); + let memory = this.getMemory(); + let ticks = this.getTicks(); + let allocations = this.getAllocations(); + let profile = this.getProfile(); + let configuration = this.getConfiguration(); + let systemHost = this.getHostSystemInfo(); + let systemClient = this.getClientSystemInfo(); + + return { label, duration, markers, frames, memory, ticks, allocations, profile, configuration, systemHost, systemClient }; + }, +}; diff --git a/devtools/shared/performance/recording-utils.js b/devtools/shared/performance/recording-utils.js new file mode 100644 index 000000000..64ed12c71 --- /dev/null +++ b/devtools/shared/performance/recording-utils.js @@ -0,0 +1,628 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const { Cc, Ci, Cu, Cr } = require("chrome"); +loader.lazyRequireGetter(this, "extend", + "sdk/util/object", true); + +/** + * Utility functions for managing recording models and their internal data, + * such as filtering profile samples or offsetting timestamps. + */ + +function mapRecordingOptions(type, options) { + if (type === "profiler") { + return { + entries: options.bufferSize, + interval: options.sampleFrequency ? (1000 / (options.sampleFrequency * 1000)) : void 0 + }; + } + + if (type === "memory") { + return { + probability: options.allocationsSampleProbability, + maxLogLength: options.allocationsMaxLogLength + }; + } + + if (type === "timeline") { + return { + withMarkers: true, + withTicks: options.withTicks, + withMemory: options.withMemory, + withFrames: true, + withGCEvents: true, + withDocLoadingEvents: false + }; + } + + return options; +} + +/** + * Takes an options object for `startRecording`, and normalizes + * it based off of server support. For example, if the user + * requests to record memory `withMemory = true`, but the server does + * not support that feature, then the `false` will overwrite user preference + * in order to define the recording with what is actually available, not + * what the user initially requested. + * + * @param {object} options + * @param {boolean} + */ +function normalizePerformanceFeatures(options, supportedFeatures) { + return Object.keys(options).reduce((modifiedOptions, feature) => { + if (supportedFeatures[feature] !== false) { + modifiedOptions[feature] = options[feature]; + } + return modifiedOptions; + }, Object.create(null)); +} + +/** + * Filters all the samples in the provided profiler data to be more recent + * than the specified start time. + * + * @param object profile + * The profiler data received from the backend. + * @param number profilerStartTime + * The earliest acceptable sample time (in milliseconds). + */ +function filterSamples(profile, profilerStartTime) { + let firstThread = profile.threads[0]; + const TIME_SLOT = firstThread.samples.schema.time; + firstThread.samples.data = firstThread.samples.data.filter(e => { + return e[TIME_SLOT] >= profilerStartTime; + }); +} + +/** + * Offsets all the samples in the provided profiler data by the specified time. + * + * @param object profile + * The profiler data received from the backend. + * @param number timeOffset + * The amount of time to offset by (in milliseconds). + */ +function offsetSampleTimes(profile, timeOffset) { + let firstThread = profile.threads[0]; + const TIME_SLOT = firstThread.samples.schema.time; + let samplesData = firstThread.samples.data; + for (let i = 0; i < samplesData.length; i++) { + samplesData[i][TIME_SLOT] -= timeOffset; + } +} + +/** + * Offsets all the markers in the provided timeline data by the specified time. + * + * @param array markers + * The markers array received from the backend. + * @param number timeOffset + * The amount of time to offset by (in milliseconds). + */ +function offsetMarkerTimes(markers, timeOffset) { + for (let marker of markers) { + marker.start -= timeOffset; + marker.end -= timeOffset; + } +} + +/** + * Offsets and scales all the timestamps in the provided array by the + * specified time and scale factor. + * + * @param array array + * A list of timestamps received from the backend. + * @param number timeOffset + * The amount of time to offset by (in milliseconds). + * @param number timeScale + * The factor to scale by, after offsetting. + */ +function offsetAndScaleTimestamps(timestamps, timeOffset, timeScale) { + for (let i = 0, len = timestamps.length; i < len; i++) { + timestamps[i] -= timeOffset; + if (timeScale) { + timestamps[i] /= timeScale; + } + } +} + +/** + * Push all elements of src array into dest array. Marker data will come in small chunks + * and add up over time, whereas allocation arrays can be > 500000 elements (and + * Function.prototype.apply throws if applying more than 500000 elements, which + * is what spawned this separate function), so iterate one element at a time. + * @see bug 1166823 + * @see http://jsperf.com/concat-large-arrays + * @see http://jsperf.com/concat-large-arrays/2 + * + * @param {Array} dest + * @param {Array} src + */ +function pushAll(dest, src) { + let length = src.length; + for (let i = 0; i < length; i++) { + dest.push(src[i]); + } +} + +/** + * Cache used in `RecordingUtils.getProfileThreadFromAllocations`. + */ +var gProfileThreadFromAllocationCache = new WeakMap(); + +/** + * Converts allocation data from the memory actor to something that follows + * the same structure as the samples data received from the profiler. + * + * @see MemoryActor.prototype.getAllocations for more information. + * + * @param object allocations + * A list of { sites, timestamps, frames, sizes } arrays. + * @return object + * The "profile" describing the allocations log. + */ +function getProfileThreadFromAllocations(allocations) { + let cached = gProfileThreadFromAllocationCache.get(allocations); + if (cached) { + return cached; + } + + let { sites, timestamps, frames, sizes } = allocations; + let uniqueStrings = new UniqueStrings(); + + // Convert allocation frames to the the stack and frame tables expected by + // the profiler format. + // + // Since the allocations log is already presented as a tree, we would be + // wasting time if we jumped through the same hoops as deflateProfile below + // and instead use the existing structure of the allocations log to build up + // the profile JSON. + // + // The allocations.frames array corresponds roughly to the profile stack + // table: a trie of all stacks. We could work harder to further deduplicate + // each individual frame as the profiler does, but it is not necessary for + // correctness. + let stackTable = new Array(frames.length); + let frameTable = new Array(frames.length); + + // Array used to concat the location. + let locationConcatArray = new Array(5); + + for (let i = 0; i < frames.length; i++) { + let frame = frames[i]; + if (!frame) { + stackTable[i] = frameTable[i] = null; + continue; + } + + let prefix = frame.parent; + + // Schema: + // [prefix, frame] + stackTable[i] = [frames[prefix] ? prefix : null, i]; + + // Schema: + // [location] + // + // The only field a frame will have in an allocations profile is location. + // + // If frame.functionDisplayName is present, the format is + // "functionDisplayName (source:line:column)" + // Otherwise, it is + // "source:line:column" + // + // A static array is used to join to save memory on intermediate strings. + locationConcatArray[0] = frame.source; + locationConcatArray[1] = ":"; + locationConcatArray[2] = String(frame.line); + locationConcatArray[3] = ":"; + locationConcatArray[4] = String(frame.column); + locationConcatArray[5] = ""; + + let location = locationConcatArray.join(""); + let funcName = frame.functionDisplayName; + + if (funcName) { + locationConcatArray[0] = funcName; + locationConcatArray[1] = " ("; + locationConcatArray[2] = location; + locationConcatArray[3] = ")"; + locationConcatArray[4] = ""; + locationConcatArray[5] = ""; + location = locationConcatArray.join(""); + } + + frameTable[i] = [uniqueStrings.getOrAddStringIndex(location)]; + } + + let samples = new Array(sites.length); + let writePos = 0; + for (let i = 0; i < sites.length; i++) { + // Schema: + // [stack, time, size] + // + // Originally, sites[i] indexes into the frames array. Note that in the + // loop above, stackTable[sites[i]] and frames[sites[i]] index the same + // information. + let stackIndex = sites[i]; + if (frames[stackIndex]) { + samples[writePos++] = [stackIndex, timestamps[i], sizes[i]]; + } + } + samples.length = writePos; + + let thread = { + name: "allocations", + samples: allocationsWithSchema(samples), + stackTable: stackTableWithSchema(stackTable), + frameTable: frameTableWithSchema(frameTable), + stringTable: uniqueStrings.stringTable + }; + + gProfileThreadFromAllocationCache.set(allocations, thread); + return thread; +} + +function allocationsWithSchema(data) { + let slot = 0; + return { + schema: { + stack: slot++, + time: slot++, + size: slot++, + }, + data: data + }; +} + +/** + * Deduplicates a profile by deduplicating stacks, frames, and strings. + * + * This is used to adapt version 2 profiles from the backend to version 3, for + * use with older Geckos (like B2G). + * + * Note that the schemas used by this must be kept in sync with schemas used + * by the C++ UniqueStacks class in tools/profiler/ProfileEntry.cpp. + * + * @param object profile + * A profile with version 2. + */ +function deflateProfile(profile) { + profile.threads = profile.threads.map((thread) => { + let uniqueStacks = new UniqueStacks(); + return deflateThread(thread, uniqueStacks); + }); + + profile.meta.version = 3; + return profile; +} + +/** + * Given an array of frame objects, deduplicates each frame as well as all + * prefixes in the stack. Returns the index of the deduplicated stack. + * + * @param object frames + * Array of frame objects. + * @param UniqueStacks uniqueStacks + * @return number index + */ +function deflateStack(frames, uniqueStacks) { + // Deduplicate every prefix in the stack by keeping track of the current + // prefix hash. + let prefixIndex = null; + for (let i = 0; i < frames.length; i++) { + let frameIndex = uniqueStacks.getOrAddFrameIndex(frames[i]); + prefixIndex = uniqueStacks.getOrAddStackIndex(prefixIndex, frameIndex); + } + return prefixIndex; +} + +/** + * Given an array of sample objects, deduplicate each sample's stack and + * convert the samples to a table with a schema. Returns the deflated samples. + * + * @param object samples + * Array of samples + * @param UniqueStacks uniqueStacks + * @return object + */ +function deflateSamples(samples, uniqueStacks) { + // Schema: + // [stack, time, responsiveness, rss, uss, frameNumber, power] + + let deflatedSamples = new Array(samples.length); + for (let i = 0; i < samples.length; i++) { + let sample = samples[i]; + deflatedSamples[i] = [ + deflateStack(sample.frames, uniqueStacks), + sample.time, + sample.responsiveness, + sample.rss, + sample.uss, + sample.frameNumber, + sample.power + ]; + } + + return samplesWithSchema(deflatedSamples); +} + +/** + * Given an array of marker objects, convert the markers to a table with a + * schema. Returns the deflated markers. + * + * If a marker contains a backtrace as its payload, the backtrace stack is + * deduplicated in the context of the profile it's in. + * + * @param object markers + * Array of markers + * @param UniqueStacks uniqueStacks + * @return object + */ +function deflateMarkers(markers, uniqueStacks) { + // Schema: + // [name, time, data] + + let deflatedMarkers = new Array(markers.length); + for (let i = 0; i < markers.length; i++) { + let marker = markers[i]; + if (marker.data && marker.data.type === "tracing" && marker.data.stack) { + marker.data.stack = deflateThread(marker.data.stack, uniqueStacks); + } + + deflatedMarkers[i] = [ + uniqueStacks.getOrAddStringIndex(marker.name), + marker.time, + marker.data + ]; + } + + let slot = 0; + return { + schema: { + name: slot++, + time: slot++, + data: slot++ + }, + data: deflatedMarkers + }; +} + +/** + * Deflate a thread. + * + * @param object thread + * The profile thread. + * @param UniqueStacks uniqueStacks + * @return object + */ +function deflateThread(thread, uniqueStacks) { + // Some extra threads in a profile come stringified as a full profile (so + // it has nested threads itself) so the top level "thread" does not have markers + // or samples. We don't use this anyway so just make this safe to deflate. + // can be a string rather than an object on import. Bug 1173695 + if (typeof thread === "string") { + thread = JSON.parse(thread); + } + if (!thread.samples) { + thread.samples = []; + } + if (!thread.markers) { + thread.markers = []; + } + + return { + name: thread.name, + tid: thread.tid, + samples: deflateSamples(thread.samples, uniqueStacks), + markers: deflateMarkers(thread.markers, uniqueStacks), + stackTable: uniqueStacks.getStackTableWithSchema(), + frameTable: uniqueStacks.getFrameTableWithSchema(), + stringTable: uniqueStacks.getStringTable() + }; +} + +function stackTableWithSchema(data) { + let slot = 0; + return { + schema: { + prefix: slot++, + frame: slot++ + }, + data: data + }; +} + +function frameTableWithSchema(data) { + let slot = 0; + return { + schema: { + location: slot++, + implementation: slot++, + optimizations: slot++, + line: slot++, + category: slot++ + }, + data: data + }; +} + +function samplesWithSchema(data) { + let slot = 0; + return { + schema: { + stack: slot++, + time: slot++, + responsiveness: slot++, + rss: slot++, + uss: slot++, + frameNumber: slot++, + power: slot++ + }, + data: data + }; +} + +/** + * A helper class to deduplicate strings. + */ +function UniqueStrings() { + this.stringTable = []; + this._stringHash = Object.create(null); +} + +UniqueStrings.prototype.getOrAddStringIndex = function (s) { + if (!s) { + return null; + } + + let stringHash = this._stringHash; + let stringTable = this.stringTable; + let index = stringHash[s]; + if (index !== undefined) { + return index; + } + + index = stringTable.length; + stringHash[s] = index; + stringTable.push(s); + return index; +}; + +/** + * A helper class to deduplicate old-version profiles. + * + * The main functionality provided is deduplicating frames and stacks. + * + * For example, given 2 stacks + * [A, B, C] + * and + * [A, B, D] + * + * There are 4 unique frames: A, B, C, and D. + * There are 4 unique prefixes: [A], [A, B], [A, B, C], [A, B, D] + * + * For the example, the output of using UniqueStacks is: + * + * Frame table: + * [A, B, C, D] + * + * That is, A has id 0, B has id 1, etc. + * + * Since stack prefixes are themselves deduplicated (shared), stacks are + * represented as a tree, or more concretely, a pair of ids, the prefix and + * the leaf. + * + * Stack table: + * [ + * [null, 0], + * [0, 1], + * [1, 2], + * [1, 3] + * ] + * + * That is, [A] has id 0 and value [null, 0]. This means it has no prefix, and + * has the leaf frame 0, which resolves to A in the frame table. + * + * [A, B] has id 1 and value [0, 1]. This means it has prefix 0, which is [A], + * and leaf 1, thus [A, B]. + * + * [A, B, C] has id 2 and value [1, 2]. This means it has prefix 1, which in + * turn is [A, B], and leaf 2, thus [A, B, C]. + * + * [A, B, D] has id 3 and value [1, 3]. Note how it shares the prefix 1 with + * [A, B, C]. + */ +function UniqueStacks() { + this._frameTable = []; + this._stackTable = []; + this._frameHash = Object.create(null); + this._stackHash = Object.create(null); + this._uniqueStrings = new UniqueStrings(); +} + +UniqueStacks.prototype.getStackTableWithSchema = function () { + return stackTableWithSchema(this._stackTable); +}; + +UniqueStacks.prototype.getFrameTableWithSchema = function () { + return frameTableWithSchema(this._frameTable); +}; + +UniqueStacks.prototype.getStringTable = function () { + return this._uniqueStrings.stringTable; +}; + +UniqueStacks.prototype.getOrAddFrameIndex = function (frame) { + // Schema: + // [location, implementation, optimizations, line, category] + + let frameHash = this._frameHash; + let frameTable = this._frameTable; + + let locationIndex = this.getOrAddStringIndex(frame.location); + let implementationIndex = this.getOrAddStringIndex(frame.implementation); + + // Super dumb. + let hash = `${locationIndex} ${implementationIndex || ""} ${frame.line || ""} ${frame.category || ""}`; + + let index = frameHash[hash]; + if (index !== undefined) { + return index; + } + + index = frameTable.length; + frameHash[hash] = index; + frameTable.push([ + this.getOrAddStringIndex(frame.location), + this.getOrAddStringIndex(frame.implementation), + // Don't bother with JIT optimization info for deflating old profile data + // format to the new format. + null, + frame.line, + frame.category + ]); + return index; +}; + +UniqueStacks.prototype.getOrAddStackIndex = function (prefixIndex, frameIndex) { + // Schema: + // [prefix, frame] + + let stackHash = this._stackHash; + let stackTable = this._stackTable; + + // Also super dumb. + let hash = prefixIndex + " " + frameIndex; + + let index = stackHash[hash]; + if (index !== undefined) { + return index; + } + + index = stackTable.length; + stackHash[hash] = index; + stackTable.push([prefixIndex, frameIndex]); + return index; +}; + +UniqueStacks.prototype.getOrAddStringIndex = function (s) { + return this._uniqueStrings.getOrAddStringIndex(s); +}; + +exports.pushAll = pushAll; +exports.mapRecordingOptions = mapRecordingOptions; +exports.normalizePerformanceFeatures = normalizePerformanceFeatures; +exports.filterSamples = filterSamples; +exports.offsetSampleTimes = offsetSampleTimes; +exports.offsetMarkerTimes = offsetMarkerTimes; +exports.offsetAndScaleTimestamps = offsetAndScaleTimestamps; +exports.getProfileThreadFromAllocations = getProfileThreadFromAllocations; +exports.deflateProfile = deflateProfile; +exports.deflateThread = deflateThread; +exports.UniqueStrings = UniqueStrings; +exports.UniqueStacks = UniqueStacks; diff --git a/devtools/shared/performance/test/head.js b/devtools/shared/performance/test/head.js new file mode 100644 index 000000000..9e7748055 --- /dev/null +++ b/devtools/shared/performance/test/head.js @@ -0,0 +1,7 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +var { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components; + +var { require } = Cu.import("resource://devtools/shared/Loader.jsm", {}); diff --git a/devtools/shared/performance/test/test_perf-utils-allocations-to-samples.js b/devtools/shared/performance/test/test_perf-utils-allocations-to-samples.js new file mode 100644 index 000000000..6429eff2d --- /dev/null +++ b/devtools/shared/performance/test/test_perf-utils-allocations-to-samples.js @@ -0,0 +1,93 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * Tests if allocations data received from the performance actor is properly + * converted to something that follows the same structure as the samples data + * received from the profiler. + */ + +function run_test() { + run_next_test(); +} + +add_task(function () { + const { getProfileThreadFromAllocations } = require("devtools/shared/performance/recording-utils"); + let output = getProfileThreadFromAllocations(TEST_DATA); + equal(output.toSource(), EXPECTED_OUTPUT.toSource(), "The output is correct."); +}); + +var TEST_DATA = { + sites: [0, 0, 1, 2, 3], + timestamps: [50, 100, 150, 200, 250], + sizes: [0, 0, 100, 200, 300], + frames: [ + null, { + source: "A", + line: 1, + column: 2, + functionDisplayName: "x", + parent: 0 + }, { + source: "B", + line: 3, + column: 4, + functionDisplayName: "y", + parent: 1 + }, { + source: "C", + line: 5, + column: 6, + functionDisplayName: null, + parent: 2 + } + ] +}; + +var EXPECTED_OUTPUT = { + name: "allocations", + samples: { + "schema": { + "stack": 0, + "time": 1, + "size": 2, + }, + data: [ + [ 1, 150, 100 ], + [ 2, 200, 200 ], + [ 3, 250, 300 ] + ] + }, + stackTable: { + "schema": { + "prefix": 0, + "frame": 1 + }, + "data": [ + null, + [ null, 1 ], // x (A:1:2) + [ 1, 2 ], // x (A:1:2) > y (B:3:4) + [ 2, 3 ] // x (A:1:2) > y (B:3:4) > C:5:6 + ] + }, + frameTable: { + "schema": { + "location": 0, + "implementation": 1, + "optimizations": 2, + "line": 3, + "category": 4 + }, + data: [ + null, + [ 0 ], + [ 1 ], + [ 2 ] + ] + }, + "stringTable": [ + "x (A:1:2)", + "y (B:3:4)", + "C:5:6" + ], +}; diff --git a/devtools/shared/performance/test/xpcshell.ini b/devtools/shared/performance/test/xpcshell.ini new file mode 100644 index 000000000..737f6d67b --- /dev/null +++ b/devtools/shared/performance/test/xpcshell.ini @@ -0,0 +1,8 @@ +[DEFAULT] +tags = devtools +head = head.js +tail = +firefox-appdir = browser +skip-if = toolkit == 'android' + +[test_perf-utils-allocations-to-samples.js] diff --git a/devtools/shared/platform/README.md b/devtools/shared/platform/README.md new file mode 100644 index 000000000..84accd495 --- /dev/null +++ b/devtools/shared/platform/README.md @@ -0,0 +1,13 @@ +This directory is treated specially by the loaders. + +In particular, when running in chrome, a resource like +"devtools/shared/platform/mumble" will be found in the chrome +subdirectory; and when running in content, it will be found in the +content subdirectory. + +Outside of tests, it's not ok to require a specific version of a file; +and there is an eslint test to check for that. That is, +require("devtools/shared/platform/client/mumble") is an error. + +When adding a new file, you must add two copies, one to chrome and one +to content. Otherwise, one case or the other will fail to work. diff --git a/devtools/shared/platform/chrome/clipboard.js b/devtools/shared/platform/chrome/clipboard.js new file mode 100644 index 000000000..fd98dfbc5 --- /dev/null +++ b/devtools/shared/platform/chrome/clipboard.js @@ -0,0 +1,28 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Helpers for clipboard handling. + +"use strict"; + +const {Cc, Ci} = require("chrome"); +const clipboardHelper = Cc["@mozilla.org/widget/clipboardhelper;1"] + .getService(Ci.nsIClipboardHelper); +var clipboard = require("sdk/clipboard"); + +function copyString(string) { + clipboardHelper.copyString(string); +} + +function getCurrentFlavors() { + return clipboard.currentFlavors; +} + +function getData() { + return clipboard.get(); +} + +exports.copyString = copyString; +exports.getCurrentFlavors = getCurrentFlavors; +exports.getData = getData; diff --git a/devtools/shared/platform/chrome/moz.build b/devtools/shared/platform/chrome/moz.build new file mode 100644 index 000000000..bb3bdacbb --- /dev/null +++ b/devtools/shared/platform/chrome/moz.build @@ -0,0 +1,10 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +DevToolsModules( + 'clipboard.js', + 'stack.js', +) diff --git a/devtools/shared/platform/chrome/stack.js b/devtools/shared/platform/chrome/stack.js new file mode 100644 index 000000000..abbe54120 --- /dev/null +++ b/devtools/shared/platform/chrome/stack.js @@ -0,0 +1,75 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// A few wrappers for stack-manipulation. This version of the module +// is used in chrome code. + +"use strict"; + +(function (factory) { + // This file might be require()d, but might also be loaded via + // Cu.import. Account for the differences here. + if (this.module && module.id.indexOf("stack") >= 0) { + // require. + const {components, Cu} = require("chrome"); + factory.call(this, components, Cu, exports); + } else { + // Cu.import. + this.isWorker = false; + factory.call(this, Components, Components.utils, this); + this.EXPORTED_SYMBOLS = ["callFunctionWithAsyncStack", "describeNthCaller", + "getStack"]; + } +}).call(this, function (components, Cu, exports) { + /** + * Return a description of the Nth caller, suitable for logging. + * + * @param {Number} n the caller to describe + * @return {String} a description of the nth caller. + */ + function describeNthCaller(n) { + if (isWorker) { + return ""; + } + + let caller = components.stack; + // Do one extra iteration to skip this function. + while (n >= 0) { + --n; + caller = caller.caller; + } + + let func = caller.name; + let file = caller.filename; + if (file.includes(" -> ")) { + file = caller.filename.split(/ -> /)[1]; + } + let path = file + ":" + caller.lineNumber; + + return func + "() -> " + path; + } + + /** + * Return a stack object that can be serialized and, when + * deserialized, passed to callFunctionWithAsyncStack. + */ + function getStack() { + return components.stack.caller; + } + + /** + * Like Cu.callFunctionWithAsyncStack but handles the isWorker case + * -- |Cu| isn't defined in workers. + */ + function callFunctionWithAsyncStack(callee, stack, id) { + if (isWorker) { + return callee(); + } + return Cu.callFunctionWithAsyncStack(callee, stack, id); + } + + exports.callFunctionWithAsyncStack = callFunctionWithAsyncStack; + exports.describeNthCaller = describeNthCaller; + exports.getStack = getStack; +}); diff --git a/devtools/shared/platform/content/.eslintrc.js b/devtools/shared/platform/content/.eslintrc.js new file mode 100644 index 000000000..515fe0261 --- /dev/null +++ b/devtools/shared/platform/content/.eslintrc.js @@ -0,0 +1,12 @@ +"use strict"; + +module.exports = { + // Extend from the devtools eslintrc. + "extends": "../../../.eslintrc.js", + + "rules": { + /* eslint-disable max-len */ + // All code in this directory must be content-clean. + "mozilla/reject-some-requires": ["error", "^(chrome|chrome:.*|resource:.*|devtools/server/.*|.*\\.jsm|devtools/shared/platform/(chome|content)/.*)$"], + }, +}; diff --git a/devtools/shared/platform/content/clipboard.js b/devtools/shared/platform/content/clipboard.js new file mode 100644 index 000000000..b43b996c2 --- /dev/null +++ b/devtools/shared/platform/content/clipboard.js @@ -0,0 +1,34 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Helpers for clipboard handling. + +/* globals document */ + +"use strict"; + +function copyString(string) { + let doCopy = function (e) { + e.clipboardData.setData("text/plain", string); + e.preventDefault(); + }; + + document.addEventListener("copy", doCopy); + document.execCommand("copy", false, null); + document.removeEventListener("copy", doCopy); +} + +function getCurrentFlavors() { + // See bug 1295692. + return []; +} + +function getData() { + // See bug 1295692. + return null; +} + +exports.copyString = copyString; +exports.getCurrentFlavors = getCurrentFlavors; +exports.getData = getData; diff --git a/devtools/shared/platform/content/moz.build b/devtools/shared/platform/content/moz.build new file mode 100644 index 000000000..b62205eb8 --- /dev/null +++ b/devtools/shared/platform/content/moz.build @@ -0,0 +1,16 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +DevToolsModules( + 'clipboard.js', + 'stack.js', +) + +XPCSHELL_TESTS_MANIFESTS += ['test/xpcshell.ini'] + +MOCHITEST_MANIFESTS += [ + 'test/mochitest.ini', +] diff --git a/devtools/shared/platform/content/stack.js b/devtools/shared/platform/content/stack.js new file mode 100644 index 000000000..87c7c4111 --- /dev/null +++ b/devtools/shared/platform/content/stack.js @@ -0,0 +1,49 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// A few wrappers for stack-manipulation. This version of the module +// is used in content code. Note that this particular copy of the +// file can only be loaded via require(), because Cu.import doesn't +// exist in the content case. So, we don't need the code to handle +// both require and import here. + +"use strict"; + +/** + * Looks like Cu.callFunctionWithAsyncStack, but just calls the callee. + */ +function callFunctionWithAsyncStack(callee, stack, id) { + return callee(); +} + +/** + * Return a description of the Nth caller, suitable for logging. + * + * @param {Number} n the caller to describe + * @return {String} a description of the nth caller. + */ +function describeNthCaller(n) { + if (isWorker) { + return ""; + } + + let stack = new Error().stack.split("\n"); + // Add one here to skip this function. + return stack[n + 1]; +} + +/** + * Return a stack object that can be serialized and, when + * deserialized, passed to callFunctionWithAsyncStack. + */ +function getStack() { + // There's no reason for this to do anything fancy, since it's only + // used to pass back into callFunctionWithAsyncStack, which we can't + // implement. + return null; +} + +exports.callFunctionWithAsyncStack = callFunctionWithAsyncStack; +exports.describeNthCaller = describeNthCaller; +exports.getStack = getStack; diff --git a/devtools/shared/platform/content/test/.eslintrc.js b/devtools/shared/platform/content/test/.eslintrc.js new file mode 100644 index 000000000..59adf410a --- /dev/null +++ b/devtools/shared/platform/content/test/.eslintrc.js @@ -0,0 +1,6 @@ +"use strict"; + +module.exports = { + // Extend from the common devtools xpcshell eslintrc config. + "extends": "../../../../.eslintrc.xpcshell.js" +}; diff --git a/devtools/shared/platform/content/test/mochitest.ini b/devtools/shared/platform/content/test/mochitest.ini new file mode 100644 index 000000000..f62cada6b --- /dev/null +++ b/devtools/shared/platform/content/test/mochitest.ini @@ -0,0 +1,5 @@ +[DEFAULT] +support-files = + +[test_clipboard.html] +subsuite = clipboard diff --git a/devtools/shared/platform/content/test/test_clipboard.html b/devtools/shared/platform/content/test/test_clipboard.html new file mode 100644 index 000000000..ccf5e6ccf --- /dev/null +++ b/devtools/shared/platform/content/test/test_clipboard.html @@ -0,0 +1,53 @@ + + + + + Test for Bug 1290230 - clipboard helpers + + + + + + + + + + + + +
Type Here
+ diff --git a/devtools/shared/platform/content/test/test_stack.js b/devtools/shared/platform/content/test/test_stack.js new file mode 100644 index 000000000..4dbb66541 --- /dev/null +++ b/devtools/shared/platform/content/test/test_stack.js @@ -0,0 +1,48 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// There isn't really very much about the content stack.js that we can +// test, but we'll do what we can. + +"use strict"; + +var Cu = Components.utils; +const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {}); + +// Make sure to explicitly require the content version of this module. +// We have to use the ".." trick due to the way the loader remaps +// devtools/shared/platform. +const { + callFunctionWithAsyncStack, + getStack, + describeNthCaller +} = require("devtools/shared/platform/../content/stack"); + +function f3() { + return describeNthCaller(2); +} + +function f2() { + return f3(); +} + +function f1() { + return f2(); +} + +function run_test() { + let value = 7; + + const changeValue = () => { + value = 9; + }; + + callFunctionWithAsyncStack(changeValue, getStack(), "test_stack"); + equal(value, 9, "callFunctionWithAsyncStack worked"); + + let stack = getStack(); + equal(JSON.parse(JSON.stringify(stack)), stack, "stack is serializable"); + + let desc = f1(); + ok(desc.includes("f1"), "stack description includes f1"); +} diff --git a/devtools/shared/platform/content/test/xpcshell.ini b/devtools/shared/platform/content/test/xpcshell.ini new file mode 100644 index 000000000..fa475165a --- /dev/null +++ b/devtools/shared/platform/content/test/xpcshell.ini @@ -0,0 +1,7 @@ +[DEFAULT] +tags = devtools +head = +tail = +firefox-appdir = browser + +[test_stack.js] diff --git a/devtools/shared/platform/moz.build b/devtools/shared/platform/moz.build new file mode 100644 index 000000000..84f56dce1 --- /dev/null +++ b/devtools/shared/platform/moz.build @@ -0,0 +1,10 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +DIRS += [ + 'chrome', + 'content', +] diff --git a/devtools/shared/plural-form.js b/devtools/shared/plural-form.js new file mode 100644 index 000000000..4e54ae963 --- /dev/null +++ b/devtools/shared/plural-form.js @@ -0,0 +1,196 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * The code below is mostly is a slight modification of intl/locale/PluralForm.jsm that + * removes dependencies on chrome privileged APIs. To make maintenance easier, this file + * is kept as close as possible to the original in terms of implementation. + * The modified methods here are + * - makeGetter (remove code adding the caller name to the log) + * - get ruleNum() (rely on LocalizationHelper instead of String.services) + * - log() (rely on console.log) + * + * Disable eslint warnings to preserve original code style. + */ + +/* eslint-disable */ + +/** + * This module provides the PluralForm object which contains a method to figure + * out which plural form of a word to use for a given number based on the + * current localization. There is also a makeGetter method that creates a get + * function for the desired plural rule. This is useful for extensions that + * specify their own plural rule instead of relying on the browser default. + * (I.e., the extension hasn't been localized to the browser's locale.) + * + * See: http://developer.mozilla.org/en/docs/Localization_and_Plurals + * + * List of methods: + * + * string pluralForm + * get(int aNum, string aWords) + * + * int numForms + * numForms() + * + * [string pluralForm get(int aNum, string aWords), int numForms numForms()] + * makeGetter(int aRuleNum) + * Note: Basically, makeGetter returns 2 functions that do "get" and "numForm" + */ + +const {LocalizationHelper} = require("devtools/shared/l10n"); +const L10N = new LocalizationHelper("toolkit/locales/intl.properties"); + +// These are the available plural functions that give the appropriate index +// based on the plural rule number specified. The first element is the number +// of plural forms and the second is the function to figure out the index. +var gFunctions = [ + // 0: Chinese + [1, (n) => 0], + // 1: English + [2, (n) => n!=1?1:0], + // 2: French + [2, (n) => n>1?1:0], + // 3: Latvian + [3, (n) => n%10==1&&n%100!=11?1:n!=0?2:0], + // 4: Scottish Gaelic + [4, (n) => n==1||n==11?0:n==2||n==12?1:n>0&&n<20?2:3], + // 5: Romanian + [3, (n) => n==1?0:n==0||n%100>0&&n%100<20?1:2], + // 6: Lithuanian + [3, (n) => n%10==1&&n%100!=11?0:n%10>=2&&(n%100<10||n%100>=20)?2:1], + // 7: Russian + [3, (n) => n%10==1&&n%100!=11?0:n%10>=2&&n%10<=4&&(n%100<10||n%100>=20)?1:2], + // 8: Slovak + [3, (n) => n==1?0:n>=2&&n<=4?1:2], + // 9: Polish + [3, (n) => n==1?0:n%10>=2&&n%10<=4&&(n%100<10||n%100>=20)?1:2], + // 10: Slovenian + [4, (n) => n%100==1?0:n%100==2?1:n%100==3||n%100==4?2:3], + // 11: Irish Gaeilge + [5, (n) => n==1?0:n==2?1:n>=3&&n<=6?2:n>=7&&n<=10?3:4], + // 12: Arabic + [6, (n) => n==0?5:n==1?0:n==2?1:n%100>=3&&n%100<=10?2:n%100>=11&&n%100<=99?3:4], + // 13: Maltese + [4, (n) => n==1?0:n==0||n%100>0&&n%100<=10?1:n%100>10&&n%100<20?2:3], + // 14: Macedonian + [3, (n) => n%10==1?0:n%10==2?1:2], + // 15: Icelandic + [2, (n) => n%10==1&&n%100!=11?0:1], + // 16: Breton + [5, (n) => n%10==1&&n%100!=11&&n%100!=71&&n%100!=91?0:n%10==2&&n%100!=12&&n%100!=72&&n%100!=92?1:(n%10==3||n%10==4||n%10==9)&&n%100!=13&&n%100!=14&&n%100!=19&&n%100!=73&&n%100!=74&&n%100!=79&&n%100!=93&&n%100!=94&&n%100!=99?2:n%1000000==0&&n!=0?3:4], +]; + +this.PluralForm = { + /** + * Get the correct plural form of a word based on the number + * + * @param aNum + * The number to decide which plural form to use + * @param aWords + * A semi-colon (;) separated string of words to pick the plural form + * @return The appropriate plural form of the word + */ + get get() + { + // This method will lazily load to avoid perf when it is first needed and + // creates getPluralForm function. The function it creates is based on the + // value of pluralRule specified in the intl stringbundle. + // See: http://developer.mozilla.org/en/docs/Localization_and_Plurals + + // Delete the getters to be overwritten + delete PluralForm.numForms; + delete PluralForm.get; + + // Make the plural form get function and set it as the default get + [PluralForm.get, PluralForm.numForms] = PluralForm.makeGetter(PluralForm.ruleNum); + return PluralForm.get; + }, + + /** + * Create a pair of plural form functions for the given plural rule number. + * + * @param aRuleNum + * The plural rule number to create functions + * @return A pair: [function that gets the right plural form, + * function that returns the number of plural forms] + */ + makeGetter: function(aRuleNum) + { + // Default to "all plural" if the value is out of bounds or invalid + if (aRuleNum < 0 || aRuleNum >= gFunctions.length || isNaN(aRuleNum)) { + log(["Invalid rule number: ", aRuleNum, " -- defaulting to 0"]); + aRuleNum = 0; + } + + // Get the desired pluralRule function + let [numForms, pluralFunc] = gFunctions[aRuleNum]; + + // Return functions that give 1) the number of forms and 2) gets the right + // plural form + return [function(aNum, aWords) { + // Figure out which index to use for the semi-colon separated words + let index = pluralFunc(aNum ? Number(aNum) : 0); + let words = aWords ? aWords.split(/;/) : [""]; + + // Explicitly check bounds to avoid strict warnings + let ret = index < words.length ? words[index] : undefined; + + // Check for array out of bounds or empty strings + if ((ret == undefined) || (ret == "")) { + // Display a message in the error console + log(["Index #", index, " of '", aWords, "' for value ", aNum, + " is invalid -- plural rule #", aRuleNum, ";"]); + + // Default to the first entry (which might be empty, but not undefined) + ret = words[0]; + } + + return ret; + }, () => numForms]; + }, + + /** + * Get the number of forms for the current plural rule + * + * @return The number of forms + */ + get numForms() + { + // We lazily load numForms, so trigger the init logic with get() + PluralForm.get(); + return PluralForm.numForms; + }, + + /** + * Get the plural rule number from the intl stringbundle + * + * @return The plural rule number + */ + get ruleNum() + { + try { + return parseInt(L10N.getStr("pluralRule"), 10); + } catch (e) { + // Fallback to English if the pluralRule property is not available. + return 1; + } + } +}; + +/** + * Private helper function to log errors to the error console and command line + * + * @param aMsg + * Error message to log or an array of strings to concat + */ +function log(aMsg) +{ + let msg = "plural-form.js: " + (aMsg.join ? aMsg.join("") : aMsg); + console.log(msg + "\n"); +} + +exports.PluralForm = this.PluralForm; + +/* eslint-ensable */ diff --git a/devtools/shared/pretty-fast/UPGRADING.md b/devtools/shared/pretty-fast/UPGRADING.md new file mode 100644 index 000000000..9758096eb --- /dev/null +++ b/devtools/shared/pretty-fast/UPGRADING.md @@ -0,0 +1,11 @@ +# UPGRADING + +1. `git clone https://github.com/mozilla/pretty-fast.git` + +2. Copy `pretty-fast/pretty-fast.js` to `devtools/shared/pretty-fast/pretty-fast.js` + +3. Copy `pretty-fast/test.js` to `devtools/shared/pretty-fast/tests/unit/test.js` + +4. If necessary, upgrade acorn (see devtools/shared/acorn/UPGRADING.md) + +5. Replace `acorn/dist/` with `acorn/` in pretty-fast.js. \ No newline at end of file diff --git a/devtools/shared/pretty-fast/moz.build b/devtools/shared/pretty-fast/moz.build new file mode 100644 index 000000000..3c72c8ff6 --- /dev/null +++ b/devtools/shared/pretty-fast/moz.build @@ -0,0 +1,11 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +XPCSHELL_TESTS_MANIFESTS += ['tests/unit/xpcshell.ini'] + +DevToolsModules( + 'pretty-fast.js', +) diff --git a/devtools/shared/pretty-fast/pretty-fast.js b/devtools/shared/pretty-fast/pretty-fast.js new file mode 100644 index 000000000..838a7b348 --- /dev/null +++ b/devtools/shared/pretty-fast/pretty-fast.js @@ -0,0 +1,873 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2; fill-column: 80 -*- */ +/* + * Copyright 2013 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE.md or: + * http://opensource.org/licenses/BSD-2-Clause + */ +(function (root, factory) { + "use strict"; + + if (typeof define === "function" && define.amd) { + define(factory); + } else if (typeof exports === "object") { + module.exports = factory(); + } else { + root.prettyFast = factory(); + } +}(this, function () { + "use strict"; + + var acorn = this.acorn || require("acorn/acorn"); + var sourceMap = this.sourceMap || require("source-map"); + var SourceNode = sourceMap.SourceNode; + + // If any of these tokens are seen before a "[" token, we know that "[" token + // is the start of an array literal, rather than a property access. + // + // The only exception is "}", which would need to be disambiguated by + // parsing. The majority of the time, an open bracket following a closing + // curly is going to be an array literal, so we brush the complication under + // the rug, and handle the ambiguity by always assuming that it will be an + // array literal. + var PRE_ARRAY_LITERAL_TOKENS = { + "typeof": true, + "void": true, + "delete": true, + "case": true, + "do": true, + "=": true, + "in": true, + "{": true, + "*": true, + "/": true, + "%": true, + "else": true, + ";": true, + "++": true, + "--": true, + "+": true, + "-": true, + "~": true, + "!": true, + ":": true, + "?": true, + ">>": true, + ">>>": true, + "<<": true, + "||": true, + "&&": true, + "<": true, + ">": true, + "<=": true, + ">=": true, + "instanceof": true, + "&": true, + "^": true, + "|": true, + "==": true, + "!=": true, + "===": true, + "!==": true, + ",": true, + + "}": true + }; + + /** + * Determines if we think that the given token starts an array literal. + * + * @param Object token + * The token we want to determine if it is an array literal. + * @param Object lastToken + * The last token we added to the pretty printed results. + * + * @returns Boolean + * True if we believe it is an array literal, false otherwise. + */ + function isArrayLiteral(token, lastToken) { + if (token.type.label != "[") { + return false; + } + if (!lastToken) { + return true; + } + if (lastToken.type.isAssign) { + return true; + } + return !!PRE_ARRAY_LITERAL_TOKENS[ + lastToken.type.keyword || lastToken.type.label + ]; + } + + // If any of these tokens are followed by a token on a new line, we know that + // ASI cannot happen. + var PREVENT_ASI_AFTER_TOKENS = { + // Binary operators + "*": true, + "/": true, + "%": true, + "+": true, + "-": true, + "<<": true, + ">>": true, + ">>>": true, + "<": true, + ">": true, + "<=": true, + ">=": true, + "instanceof": true, + "in": true, + "==": true, + "!=": true, + "===": true, + "!==": true, + "&": true, + "^": true, + "|": true, + "&&": true, + "||": true, + ",": true, + ".": true, + "=": true, + "*=": true, + "/=": true, + "%=": true, + "+=": true, + "-=": true, + "<<=": true, + ">>=": true, + ">>>=": true, + "&=": true, + "^=": true, + "|=": true, + // Unary operators + "delete": true, + "void": true, + "typeof": true, + "~": true, + "!": true, + "new": true, + // Function calls and grouped expressions + "(": true + }; + + // If any of these tokens are on a line after the token before it, we know + // that ASI cannot happen. + var PREVENT_ASI_BEFORE_TOKENS = { + // Binary operators + "*": true, + "/": true, + "%": true, + "<<": true, + ">>": true, + ">>>": true, + "<": true, + ">": true, + "<=": true, + ">=": true, + "instanceof": true, + "in": true, + "==": true, + "!=": true, + "===": true, + "!==": true, + "&": true, + "^": true, + "|": true, + "&&": true, + "||": true, + ",": true, + ".": true, + "=": true, + "*=": true, + "/=": true, + "%=": true, + "+=": true, + "-=": true, + "<<=": true, + ">>=": true, + ">>>=": true, + "&=": true, + "^=": true, + "|=": true, + // Function calls + "(": true + }; + + /** + * Determines if Automatic Semicolon Insertion (ASI) occurs between these + * tokens. + * + * @param Object token + * The current token. + * @param Object lastToken + * The last token we added to the pretty printed results. + * + * @returns Boolean + * True if we believe ASI occurs. + */ + function isASI(token, lastToken) { + if (!lastToken) { + return false; + } + if (token.loc.start.line === lastToken.loc.start.line) { + return false; + } + if (PREVENT_ASI_AFTER_TOKENS[ + lastToken.type.label || lastToken.type.keyword + ]) { + return false; + } + if (PREVENT_ASI_BEFORE_TOKENS[token.type.label || token.type.keyword]) { + return false; + } + return true; + } + + /** + * Determine if we have encountered a getter or setter. + * + * @param Object token + * The current token. If this is a getter or setter, it would be the + * property name. + * @param Object lastToken + * The last token we added to the pretty printed results. If this is a + * getter or setter, it would be the `get` or `set` keyword + * respectively. + * @param Array stack + * The stack of open parens/curlies/brackets/etc. + * + * @returns Boolean + * True if this is a getter or setter. + */ + function isGetterOrSetter(token, lastToken, stack) { + return stack[stack.length - 1] == "{" + && lastToken + && lastToken.type.label == "name" + && (lastToken.value == "get" || lastToken.value == "set") + && token.type.label == "name"; + } + + /** + * Determine if we should add a newline after the given token. + * + * @param Object token + * The token we are looking at. + * @param Array stack + * The stack of open parens/curlies/brackets/etc. + * + * @returns Boolean + * True if we should add a newline. + */ + function isLineDelimiter(token, stack) { + if (token.isArrayLiteral) { + return true; + } + var ttl = token.type.label; + var top = stack[stack.length - 1]; + return ttl == ";" && top != "(" + || ttl == "{" + || ttl == "," && top != "(" + || ttl == ":" && (top == "case" || top == "default"); + } + + /** + * Append the necessary whitespace to the result after we have added the given + * token. + * + * @param Object token + * The token that was just added to the result. + * @param Function write + * The function to write to the pretty printed results. + * @param Array stack + * The stack of open parens/curlies/brackets/etc. + * + * @returns Boolean + * Returns true if we added a newline to result, false in all other + * cases. + */ + function appendNewline(token, write, stack) { + if (isLineDelimiter(token, stack)) { + write("\n", token.loc.start.line, token.loc.start.column); + return true; + } + return false; + } + + /** + * Determines if we need to add a space between the last token we added and + * the token we are about to add. + * + * @param Object token + * The token we are about to add to the pretty printed code. + * @param Object lastToken + * The last token added to the pretty printed code. + */ + function needsSpaceAfter(token, lastToken) { + if (lastToken) { + if (lastToken.type.isLoop) { + return true; + } + if (lastToken.type.isAssign) { + return true; + } + if (lastToken.type.binop != null) { + return true; + } + + var ltt = lastToken.type.label; + if (ltt == "?") { + return true; + } + if (ltt == ":") { + return true; + } + if (ltt == ",") { + return true; + } + if (ltt == ";") { + return true; + } + + var ltk = lastToken.type.keyword; + if (ltk != null) { + if (ltk == "break" || ltk == "continue" || ltk == "return") { + return token.type.label != ";"; + } + if (ltk != "debugger" + && ltk != "null" + && ltk != "true" + && ltk != "false" + && ltk != "this" + && ltk != "default") { + return true; + } + } + + if (ltt == ")" && (token.type.label != ")" + && token.type.label != "]" + && token.type.label != ";" + && token.type.label != "," + && token.type.label != ".")) { + return true; + } + } + + if (token.type.isAssign) { + return true; + } + if (token.type.binop != null) { + return true; + } + if (token.type.label == "?") { + return true; + } + + return false; + } + + /** + * Add the required whitespace before this token, whether that is a single + * space, newline, and/or the indent on fresh lines. + * + * @param Object token + * The token we are about to add to the pretty printed code. + * @param Object lastToken + * The last token we added to the pretty printed code. + * @param Boolean addedNewline + * Whether we added a newline after adding the last token to the pretty + * printed code. + * @param Function write + * The function to write pretty printed code to the result SourceNode. + * @param Object options + * The options object. + * @param Number indentLevel + * The number of indents deep we are. + * @param Array stack + * The stack of open curlies, brackets, etc. + */ + function prependWhiteSpace(token, lastToken, addedNewline, write, options, + indentLevel, stack) { + var ttk = token.type.keyword; + var ttl = token.type.label; + var newlineAdded = addedNewline; + var ltt = lastToken ? lastToken.type.label : null; + + // Handle whitespace and newlines after "}" here instead of in + // `isLineDelimiter` because it is only a line delimiter some of the + // time. For example, we don't want to put "else if" on a new line after + // the first if's block. + if (lastToken && ltt == "}") { + if (ttk == "while" && stack[stack.length - 1] == "do") { + write(" ", + lastToken.loc.start.line, + lastToken.loc.start.column); + } else if (ttk == "else" || + ttk == "catch" || + ttk == "finally") { + write(" ", + lastToken.loc.start.line, + lastToken.loc.start.column); + } else if (ttl != "(" && + ttl != ";" && + ttl != "," && + ttl != ")" && + ttl != ".") { + write("\n", + lastToken.loc.start.line, + lastToken.loc.start.column); + newlineAdded = true; + } + } + + if (isGetterOrSetter(token, lastToken, stack)) { + write(" ", + lastToken.loc.start.line, + lastToken.loc.start.column); + } + + if (ttl == ":" && stack[stack.length - 1] == "?") { + write(" ", + lastToken.loc.start.line, + lastToken.loc.start.column); + } + + if (lastToken && ltt != "}" && ttk == "else") { + write(" ", + lastToken.loc.start.line, + lastToken.loc.start.column); + } + + function ensureNewline() { + if (!newlineAdded) { + write("\n", + lastToken.loc.start.line, + lastToken.loc.start.column); + newlineAdded = true; + } + } + + if (isASI(token, lastToken)) { + ensureNewline(); + } + + if (decrementsIndent(ttl, stack)) { + ensureNewline(); + } + + if (newlineAdded) { + if (ttk == "case" || ttk == "default") { + write(repeat(options.indent, indentLevel - 1), + token.loc.start.line, + token.loc.start.column); + } else { + write(repeat(options.indent, indentLevel), + token.loc.start.line, + token.loc.start.column); + } + } else if (needsSpaceAfter(token, lastToken)) { + write(" ", + lastToken.loc.start.line, + lastToken.loc.start.column); + } + } + + /** + * Repeat the `str` string `n` times. + * + * @param String str + * The string to be repeated. + * @param Number n + * The number of times to repeat the string. + * + * @returns String + * The repeated string. + */ + function repeat(str, n) { + var result = ""; + while (n > 0) { + if (n & 1) { + result += str; + } + n >>= 1; + str += str; + } + return result; + } + + /** + * Make sure that we output the escaped character combination inside string + * literals instead of various problematic characters. + */ + var sanitize = (function () { + var escapeCharacters = { + // Backslash + "\\": "\\\\", + // Newlines + "\n": "\\n", + // Carriage return + "\r": "\\r", + // Tab + "\t": "\\t", + // Vertical tab + "\v": "\\v", + // Form feed + "\f": "\\f", + // Null character + "\0": "\\0", + // Single quotes + "'": "\\'" + }; + + var regExpString = "(" + + Object.keys(escapeCharacters) + .map(function (c) { return escapeCharacters[c]; }) + .join("|") + + ")"; + var escapeCharactersRegExp = new RegExp(regExpString, "g"); + + return function (str) { + return str.replace(escapeCharactersRegExp, function (_, c) { + return escapeCharacters[c]; + }); + }; + }()); + /** + * Add the given token to the pretty printed results. + * + * @param Object token + * The token to add. + * @param Function write + * The function to write pretty printed code to the result SourceNode. + */ + function addToken(token, write) { + if (token.type.label == "string") { + write("'" + sanitize(token.value) + "'", + token.loc.start.line, + token.loc.start.column); + } else if (token.type.label == "regexp") { + write(String(token.value.value), + token.loc.start.line, + token.loc.start.column); + } else { + write(String(token.value != null ? token.value : token.type.label), + token.loc.start.line, + token.loc.start.column); + } + } + + /** + * Returns true if the given token type belongs on the stack. + */ + function belongsOnStack(token) { + var ttl = token.type.label; + var ttk = token.type.keyword; + return ttl == "{" + || ttl == "(" + || ttl == "[" + || ttl == "?" + || ttk == "do" + || ttk == "switch" + || ttk == "case" + || ttk == "default"; + } + + /** + * Returns true if the given token should cause us to pop the stack. + */ + function shouldStackPop(token, stack) { + var ttl = token.type.label; + var ttk = token.type.keyword; + var top = stack[stack.length - 1]; + return ttl == "]" + || ttl == ")" + || ttl == "}" + || (ttl == ":" && (top == "case" || top == "default" || top == "?")) + || (ttk == "while" && top == "do"); + } + + /** + * Returns true if the given token type should cause us to decrement the + * indent level. + */ + function decrementsIndent(tokenType, stack) { + return tokenType == "}" + || (tokenType == "]" && stack[stack.length - 1] == "[\n"); + } + + /** + * Returns true if the given token should cause us to increment the indent + * level. + */ + function incrementsIndent(token) { + return token.type.label == "{" + || token.isArrayLiteral + || token.type.keyword == "switch"; + } + + /** + * Add a comment to the pretty printed code. + * + * @param Function write + * The function to write pretty printed code to the result SourceNode. + * @param Number indentLevel + * The number of indents deep we are. + * @param Object options + * The options object. + * @param Boolean block + * True if the comment is a multiline block style comment. + * @param String text + * The text of the comment. + * @param Number line + * The line number to comment appeared on. + * @param Number column + * The column number the comment appeared on. + */ + function addComment(write, indentLevel, options, block, text, line, column) { + var indentString = repeat(options.indent, indentLevel); + + write(indentString, line, column); + if (block) { + write("/*"); + write(text + .split(new RegExp("/\n" + indentString + "/", "g")) + .join("\n" + indentString)); + write("*/"); + } else { + write("//"); + write(text); + } + write("\n"); + } + + /** + * The main function. + * + * @param String input + * The ugly JS code we want to pretty print. + * @param Object options + * The options object. Provides configurability of the pretty + * printing. Properties: + * - url: The URL string of the ugly JS code. + * - indent: The string to indent code by. + * + * @returns Object + * An object with the following properties: + * - code: The pretty printed code string. + * - map: A SourceMapGenerator instance. + */ + return function prettyFast(input, options) { + // The level of indents deep we are. + var indentLevel = 0; + + // We will accumulate the pretty printed code in this SourceNode. + var result = new SourceNode(); + + /** + * Write a pretty printed string to the result SourceNode. + * + * We buffer our writes so that we only create one mapping for each line in + * the source map. This enhances performance by avoiding extraneous mapping + * serialization, and flattening the tree that + * `SourceNode#toStringWithSourceMap` will have to recursively walk. When + * timing how long it takes to pretty print jQuery, this optimization + * brought the time down from ~390 ms to ~190ms! + * + * @param String str + * The string to be added to the result. + * @param Number line + * The line number the string came from in the ugly source. + * @param Number column + * The column number the string came from in the ugly source. + */ + var write = (function () { + var buffer = []; + var bufferLine = -1; + var bufferColumn = -1; + return function write(str, line, column) { + if (line != null && bufferLine === -1) { + bufferLine = line; + } + if (column != null && bufferColumn === -1) { + bufferColumn = column; + } + buffer.push(str); + + if (str == "\n") { + var lineStr = ""; + for (var i = 0, len = buffer.length; i < len; i++) { + lineStr += buffer[i]; + } + result.add(new SourceNode(bufferLine, bufferColumn, options.url, + lineStr)); + buffer.splice(0, buffer.length); + bufferLine = -1; + bufferColumn = -1; + } + }; + }()); + + // Whether or not we added a newline on after we added the last token. + var addedNewline = false; + + // The current token we will be adding to the pretty printed code. + var token; + + // Shorthand for token.type.label, so we don't have to repeatedly access + // properties. + var ttl; + + // Shorthand for token.type.keyword, so we don't have to repeatedly access + // properties. + var ttk; + + // The last token we added to the pretty printed code. + var lastToken; + + // Stack of token types/keywords that can affect whether we want to add a + // newline or a space. We can make that decision based on what token type is + // on the top of the stack. For example, a comma in a parameter list should + // be followed by a space, while a comma in an object literal should be + // followed by a newline. + // + // Strings that go on the stack: + // + // - "{" + // - "(" + // - "[" + // - "[\n" + // - "do" + // - "?" + // - "switch" + // - "case" + // - "default" + // + // The difference between "[" and "[\n" is that "[\n" is used when we are + // treating "[" and "]" tokens as line delimiters and should increment and + // decrement the indent level when we find them. + var stack = []; + + // Pass through acorn's tokenizer and append tokens and comments into a + // single queue to process. For example, the source file: + // + // foo + // // a + // // b + // bar + // + // After this process, tokenQueue has the following token stream: + // + // [ foo, '// a', '// b', bar] + var tokenQueue = []; + + var tokens = acorn.tokenizer(input, { + locations: true, + sourceFile: options.url, + onComment: function (block, text, start, end, startLoc, endLoc) { + tokenQueue.push({ + type: {}, + comment: true, + block: block, + text: text, + loc: { start: startLoc, end: endLoc } + }); + } + }); + + for (;;) { + token = tokens.getToken(); + tokenQueue.push(token); + if (token.type.label == "eof") { + break; + } + } + + for (var i = 0; i < tokenQueue.length; i++) { + token = tokenQueue[i]; + + if (token.comment) { + var commentIndentLevel = indentLevel; + if (lastToken && (lastToken.loc.end.line == token.loc.start.line)) { + commentIndentLevel = 0; + write(" "); + } + addComment(write, commentIndentLevel, options, token.block, token.text, + token.loc.start.line, token.loc.start.column); + addedNewline = true; + continue; + } + + ttk = token.type.keyword; + ttl = token.type.label; + + if (ttl == "eof") { + if (!addedNewline) { + write("\n"); + } + break; + } + + token.isArrayLiteral = isArrayLiteral(token, lastToken); + + if (belongsOnStack(token)) { + if (token.isArrayLiteral) { + stack.push("[\n"); + } else { + stack.push(ttl || ttk); + } + } + + if (decrementsIndent(ttl, stack)) { + indentLevel--; + if (ttl == "}" + && stack.length > 1 + && stack[stack.length - 2] == "switch") { + indentLevel--; + } + } + + prependWhiteSpace(token, lastToken, addedNewline, write, options, + indentLevel, stack); + addToken(token, write); + + // If the next token is going to be a comment starting on the same line, + // then no need to add one here + var nextToken = tokenQueue[i + 1]; + if (!nextToken || !nextToken.comment || token.loc.end.line != nextToken.loc.start.line) { + addedNewline = appendNewline(token, write, stack); + } + + if (shouldStackPop(token, stack)) { + stack.pop(); + if (token == "}" && stack.length + && stack[stack.length - 1] == "switch") { + stack.pop(); + } + } + + if (incrementsIndent(token)) { + indentLevel++; + } + + // Acorn's tokenizer re-uses tokens, so we have to copy the last token on + // every iteration. We follow acorn's lead here, and reuse the lastToken + // object the same way that acorn reuses the token object. This allows us + // to avoid allocations and minimize GC pauses. + if (!lastToken) { + lastToken = { loc: { start: {}, end: {} } }; + } + lastToken.start = token.start; + lastToken.end = token.end; + lastToken.loc.start.line = token.loc.start.line; + lastToken.loc.start.column = token.loc.start.column; + lastToken.loc.end.line = token.loc.end.line; + lastToken.loc.end.column = token.loc.end.column; + lastToken.type = token.type; + lastToken.value = token.value; + lastToken.isArrayLiteral = token.isArrayLiteral; + } + + return result.toStringWithSourceMap({ file: options.url }); + }; + +}.bind(this))); diff --git a/devtools/shared/pretty-fast/tests/unit/head_pretty-fast.js b/devtools/shared/pretty-fast/tests/unit/head_pretty-fast.js new file mode 100644 index 000000000..abde4b197 --- /dev/null +++ b/devtools/shared/pretty-fast/tests/unit/head_pretty-fast.js @@ -0,0 +1,49 @@ +"use strict"; +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cu = Components.utils; +var Cr = Components.results; + +const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {}); + +this.sourceMap = require("source-map"); +this.acorn = require("acorn/acorn"); +this.prettyFast = require("devtools/shared/pretty-fast/pretty-fast"); +const { console } = Cu.import("resource://gre/modules/Console.jsm", {}); + +// Register a console listener, so console messages don't just disappear +// into the ether. +var errorCount = 0; +var listener = { + observe: function (aMessage) { + errorCount++; + try { + // If we've been given an nsIScriptError, then we can print out + // something nicely formatted, for tools like Emacs to pick up. + var scriptError = aMessage.QueryInterface(Ci.nsIScriptError); + dump(aMessage.sourceName + ":" + aMessage.lineNumber + ": " + + scriptErrorFlagsToKind(aMessage.flags) + ": " + + aMessage.errorMessage + "\n"); + var string = aMessage.errorMessage; + } catch (x) { + // Be a little paranoid with message, as the whole goal here is to lose + // no information. + try { + var string = "" + aMessage.message; + } catch (x) { + var string = ""; + } + } + + // Ignored until they are fixed in bug 1242968. + if (string.includes("JavaScript Warning")) { + return; + } + + do_throw("head_pretty-fast.js got console message: " + string + "\n"); + } +}; + +var consoleService = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService); +consoleService.registerListener(listener); + diff --git a/devtools/shared/pretty-fast/tests/unit/test.js b/devtools/shared/pretty-fast/tests/unit/test.js new file mode 100644 index 000000000..b462726a2 --- /dev/null +++ b/devtools/shared/pretty-fast/tests/unit/test.js @@ -0,0 +1,572 @@ +/* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2; fill-column: 80 -*- */ + +"use strict"; + +/* + * Copyright 2013 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE.md or: + * http://opensource.org/licenses/BSD-2-Clause + */ +var prettyFast = this.prettyFast || require("./pretty-fast"); + +var testCases = [ + + { + name: "Simple function", + input: "function foo() { bar(); }", + output: "function foo() {\n" + + " bar();\n" + + "}\n", + mappings: [ + // function foo() { + { + inputLine: 1, + outputLine: 1 + }, + // bar(); + { + inputLine: 1, + outputLine: 2 + }, + // } + { + inputLine: 1, + outputLine: 3 + }, + ] + }, + + { + name: "Nested function", + input: "function foo() { function bar() { debugger; } bar(); }", + output: "function foo() {\n" + + " function bar() {\n" + + " debugger;\n" + + " }\n" + + " bar();\n" + + "}\n", + mappings: [ + // function bar() { + { + inputLine: 1, + outputLine: 2 + }, + // debugger; + { + inputLine: 1, + outputLine: 3 + }, + // bar(); + { + inputLine: 1, + outputLine: 5 + }, + ] + }, + + { + name: "Immediately invoked function expression", + input: "(function(){thingy()}())", + output: "(function () {\n" + + " thingy()\n" + + "}())\n" + }, + + { + name: "Single line comment", + input: "// Comment\n" + + "function foo() { bar(); }\n", + output: "// Comment\n" + + "function foo() {\n" + + " bar();\n" + + "}\n", + mappings: [ + // // Comment + { + inputLine: 1, + outputLine: 1 + } + ] + }, + + { + name: "Multi line comment", + input: "/* Comment\n" + + "more comment */\n" + + "function foo() { bar(); }\n", + output: "/* Comment\n" + + "more comment */\n" + + "function foo() {\n" + + " bar();\n" + + "}\n", + mappings: [ + // /* Comment + { + inputLine: 1, + outputLine: 1 + }, + // \nmore comment */ + { + inputLine: 1, + outputLine: 2 + } + ] + }, + + { + name: "Null assignment", + input: "var i=null;\n", + output: "var i = null;\n", + mappings: [ + { + inputLine: 1, + outputLine: 1 + } + ] + }, + + { + name: "Undefined assignment", + input: "var i=undefined;\n", + output: "var i = undefined;\n" + }, + + { + name: "Void 0 assignment", + input: "var i=void 0;\n", + output: "var i = void 0;\n" + }, + + { + name: "This property access", + input: "var foo=this.foo;\n", + output: "var foo = this.foo;\n" + }, + + { + name: "True assignment", + input: "var foo=true;\n", + output: "var foo = true;\n" + }, + + { + name: "False assignment", + input: "var foo=false;\n", + output: "var foo = false;\n" + }, + + { + name: "For loop", + input: "for (var i = 0; i < n; i++) { console.log(i); }", + output: "for (var i = 0; i < n; i++) {\n" + + " console.log(i);\n" + + "}\n", + mappings: [ + // for (var i = 0; i < n; i++) { + { + inputLine: 1, + outputLine: 1 + }, + // console.log(i); + { + inputLine: 1, + outputLine: 2 + }, + ] + }, + + { + name: "String with semicolon", + input: "var foo = ';';\n", + output: "var foo = ';';\n" + }, + + { + name: "String with quote", + input: "var foo = \"'\";\n", + output: "var foo = '\\'';\n" + }, + + { + name: "Function calls", + input: "var result=func(a,b,c,d);", + output: "var result = func(a, b, c, d);\n" + }, + + { + name: "Regexp", + input: "var r=/foobar/g;", + output: "var r = /foobar/g;\n" + }, + + { + name: "In operator", + input: "if(foo in bar){doThing()}", + output: "if (foo in bar) {\n" + + " doThing()\n" + + "}\n" + }, + + { + name: "With statement", + input: "with(obj){crock()}", + output: "with (obj) {\n" + + " crock()\n" + + "}\n" + }, + + { + name: "New expression", + input: "var foo=new Foo();", + output: "var foo = new Foo();\n" + }, + + { + name: "Continue/break statements", + input: "while(1){if(x){continue}if(y){break}if(z){break foo}}", + output: "while (1) {\n" + + " if (x) {\n" + + " continue\n" + + " }\n" + + " if (y) {\n" + + " break\n" + + " }\n" + + " if (z) {\n" + + " break foo\n" + + " }\n" + + "}\n" + }, + + { + name: "Instanceof", + input: "var a=x instanceof y;", + output: "var a = x instanceof y;\n" + }, + + { + name: "Binary operators", + input: "var a=5*30;var b=5>>3;", + output: "var a = 5 * 30;\n" + + "var b = 5 >> 3;\n" + }, + + { + name: "Delete", + input: "delete obj.prop;", + output: "delete obj.prop;\n" + }, + + { + name: "Try/catch/finally statement", + input: "try{dangerous()}catch(e){handle(e)}finally{cleanup()}", + output: "try {\n" + + " dangerous()\n" + + "} catch (e) {\n" + + " handle(e)\n" + + "} finally {\n" + + " cleanup()\n" + + "}\n" + }, + + { + name: "If/else statement", + input: "if(c){then()}else{other()}", + output: "if (c) {\n" + + " then()\n" + + "} else {\n" + + " other()\n" + + "}\n" + }, + + { + name: "If/else without curlies", + input: "if(c) a else b", + output: "if (c) a else b\n" + }, + + { + name: "Objects", + input: "var o={a:1,\n" + + " b:2};", + output: "var o = {\n" + + " a: 1,\n" + + " b: 2\n" + + "};\n", + mappings: [ + // a: 1, + { + inputLine: 1, + outputLine: 2 + }, + // b: 2 + { + inputLine: 2, + outputLine: 3 + }, + ] + }, + + { + name: "Do/while loop", + input: "do{x}while(y)", + output: "do {\n" + + " x\n" + + "} while (y)\n" + }, + + { + name: "Arrays", + input: "var a=[1,2,3];", + output: "var a = [\n" + + " 1,\n" + + " 2,\n" + + " 3\n" + + "];\n" + }, + + { + name: "Code that relies on ASI", + input: "var foo = 10\n" + + "var bar = 20\n" + + "function g() {\n" + + " a()\n" + + " b()\n" + + "}", + output: "var foo = 10\n" + + "var bar = 20\n" + + "function g() {\n" + + " a()\n" + + " b()\n" + + "}\n" + }, + + { + name: "Ternary operator", + input: "bar?baz:bang;", + output: "bar ? baz : bang;\n" + }, + + { + name: "Switch statements", + input: "switch(x){case a:foo();break;default:bar()}", + output: "switch (x) {\n" + + " case a:\n" + + " foo();\n" + + " break;\n" + + " default:\n" + + " bar()\n" + + "}\n" + }, + + { + name: "Multiple single line comments", + input: "function f() {\n" + + " // a\n" + + " // b\n" + + " // c\n" + + "}\n", + output: "function f() {\n" + + " // a\n" + + " // b\n" + + " // c\n" + + "}\n", + }, + + { + name: "Indented multiline comment", + input: "function foo() {\n" + + " /**\n" + + " * java doc style comment\n" + + " * more comment\n" + + " */\n" + + " bar();\n" + + "}\n", + output: "function foo() {\n" + + " /**\n" + + " * java doc style comment\n" + + " * more comment\n" + + " */\n" + + " bar();\n" + + "}\n", + }, + + { + name: "ASI return", + input: "function f() {\n" + + " return\n" + + " {}\n" + + "}\n", + output: "function f() {\n" + + " return\n" + + " {\n" + + " }\n" + + "}\n", + }, + + { + name: "Non-ASI property access", + input: "[1,2,3]\n" + + "[0]", + output: "[\n" + + " 1,\n" + + " 2,\n" + + " 3\n" + + "]\n" + + "[0]\n" + }, + + { + name: "Non-ASI in", + input: "'x'\n" + + "in foo", + output: "'x' in foo\n" + }, + + { + name: "Non-ASI function call", + input: "f\n" + + "()", + output: "f()\n" + }, + + { + name: "Non-ASI new", + input: "new\n" + + "F()", + output: "new F()\n" + }, + + { + name: "Getter and setter literals", + input: "var obj={get foo(){return this._foo},set foo(v){this._foo=v}}", + output: "var obj = {\n" + + " get foo() {\n" + + " return this._foo\n" + + " },\n" + + " set foo(v) {\n" + + " this._foo = v\n" + + " }\n" + + "}\n" + }, + + { + name: "Escaping backslashes in strings", + input: "'\\\\'\n", + output: "'\\\\'\n" + }, + + { + name: "Escaping carriage return in strings", + input: "'\\r'\n", + output: "'\\r'\n" + }, + + { + name: "Escaping tab in strings", + input: "'\\t'\n", + output: "'\\t'\n" + }, + + { + name: "Escaping vertical tab in strings", + input: "'\\v'\n", + output: "'\\v'\n" + }, + + { + name: "Escaping form feed in strings", + input: "'\\f'\n", + output: "'\\f'\n" + }, + + { + name: "Escaping null character in strings", + input: "'\\0'\n", + output: "'\\0'\n" + }, + + { + name: "Bug 977082 - space between grouping operator and dot notation", + input: "JSON.stringify(3).length;\n" + + "([1,2,3]).length;\n" + + "(new Date()).toLocaleString();\n", + output: "JSON.stringify(3).length;\n" + + "([1,\n" + + "2,\n" + + "3]).length;\n" + + "(new Date()).toLocaleString();\n" + }, + + { + name: "Bug 975477 don't move end of line comments to next line", + input: "switch (request.action) {\n" + + " case 'show': //$NON-NLS-0$\n" + + " if (localStorage.hideicon !== 'true') { //$NON-NLS-0$\n" + + " chrome.pageAction.show(sender.tab.id);\n" + + " }\n" + + " break;\n" + + " case 'hide': /*Multiline\n" + + " Comment */" + + " break;\n" + + " default:\n" + + " console.warn('unknown request'); //$NON-NLS-0$\n" + + " // don't respond if you don't understand the message.\n" + + " return;\n" + + "}\n", + output: "switch (request.action) {\n" + + " case 'show': //$NON-NLS-0$\n" + + " if (localStorage.hideicon !== 'true') { //$NON-NLS-0$\n" + + " chrome.pageAction.show(sender.tab.id);\n" + + " }\n" + + " break;\n" + + " case 'hide': /*Multiline\n" + + " Comment */\n" + + " break;\n" + + " default:\n" + + " console.warn('unknown request'); //$NON-NLS-0$\n" + + " // don't respond if you don't understand the message.\n" + + " return;\n" + + "}\n" + } + +]; + +var sourceMap = this.sourceMap || require("source-map"); + +function run_test() { + testCases.forEach(function (test) { + console.log(test.name); + + var actual = prettyFast(test.input, { + indent: " ", + url: "test.js" + }); + + if (actual.code !== test.output) { + throw new Error("Expected:\n" + test.output + + "\nGot:\n" + actual.code); + } + + if (test.mappings) { + var smc = new sourceMap.SourceMapConsumer(actual.map.toJSON()); + test.mappings.forEach(function (m) { + var query = { line: m.outputLine, column: 0 }; + var original = smc.originalPositionFor(query); + if (original.line != m.inputLine) { + throw new Error("Querying:\n" + JSON.stringify(query, null, 2) + "\n" + + "Expected line:\n" + m.inputLine + "\n" + + "Got:\n" + JSON.stringify(original, null, 2)); + } + }); + } + }); + console.log("✓ All tests pass!"); +} + +// Only run the tests if this is node and we are running this file +// directly. (Firefox's test runner will import this test file, and then call +// run_test itself.) +if (typeof require == "function" && typeof module == "object" + && require.main === module) { + run_test(); +} diff --git a/devtools/shared/pretty-fast/tests/unit/xpcshell.ini b/devtools/shared/pretty-fast/tests/unit/xpcshell.ini new file mode 100644 index 000000000..cb92b1825 --- /dev/null +++ b/devtools/shared/pretty-fast/tests/unit/xpcshell.ini @@ -0,0 +1,8 @@ +[DEFAULT] +tags = devtools +head = head_pretty-fast.js +tail = +firefox-appdir = browser +skip-if = toolkit == 'android' + +[test.js] diff --git a/devtools/shared/protocol.js b/devtools/shared/protocol.js new file mode 100644 index 000000000..4035d5016 --- /dev/null +++ b/devtools/shared/protocol.js @@ -0,0 +1,1517 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +var promise = require("promise"); +var defer = require("devtools/shared/defer"); +var {Class} = require("sdk/core/heritage"); +var {EventTarget} = require("sdk/event/target"); +var events = require("sdk/event/core"); +var object = require("sdk/util/object"); +var {getStack, callFunctionWithAsyncStack} = require("devtools/shared/platform/stack"); + +exports.emit = events.emit; + +/** + * Types: named marshallers/demarshallers. + * + * Types provide a 'write' function that takes a js representation and + * returns a protocol representation, and a "read" function that + * takes a protocol representation and returns a js representation. + * + * The read and write methods are also passed a context object that + * represent the actor or front requesting the translation. + * + * Types are referred to with a typestring. Basic types are + * registered by name using addType, and more complex types can + * be generated by adding detail to the type name. + */ + +var types = Object.create(null); +exports.types = types; + +var registeredTypes = types.registeredTypes = new Map(); +var registeredLifetimes = types.registeredLifetimes = new Map(); + +/** + * Return the type object associated with a given typestring. + * If passed a type object, it will be returned unchanged. + * + * Types can be registered with addType, or can be created on + * the fly with typestrings. Examples: + * + * boolean + * threadActor + * threadActor#detail + * array:threadActor + * array:array:threadActor#detail + * + * @param [typestring|type] type + * Either a typestring naming a type or a type object. + * + * @returns a type object. + */ +types.getType = function (type) { + if (!type) { + return types.Primitive; + } + + if (typeof (type) !== "string") { + return type; + } + + // If already registered, we're done here. + let reg = registeredTypes.get(type); + if (reg) return reg; + + // New type, see if it's a collection/lifetime type: + let sep = type.indexOf(":"); + if (sep >= 0) { + let collection = type.substring(0, sep); + let subtype = types.getType(type.substring(sep + 1)); + + if (collection === "array") { + return types.addArrayType(subtype); + } else if (collection === "nullable") { + return types.addNullableType(subtype); + } + + if (registeredLifetimes.has(collection)) { + return types.addLifetimeType(collection, subtype); + } + + throw Error("Unknown collection type: " + collection); + } + + // Not a collection, might be actor detail + let pieces = type.split("#", 2); + if (pieces.length > 1) { + return types.addActorDetail(type, pieces[0], pieces[1]); + } + + // Might be a lazily-loaded type + if (type === "longstring") { + require("devtools/shared/specs/string"); + return registeredTypes.get("longstring"); + } + + throw Error("Unknown type: " + type); +}; + +/** + * Don't allow undefined when writing primitive types to packets. If + * you want to allow undefined, use a nullable type. + */ +function identityWrite(v) { + if (v === undefined) { + throw Error("undefined passed where a value is required"); + } + // This has to handle iterator->array conversion because arrays of + // primitive types pass through here. + if (v && typeof (v) === "object" && Symbol.iterator in v) { + return [...v]; + } + return v; +} + +/** + * Add a type to the type system. + * + * When registering a type, you can provide `read` and `write` methods. + * + * The `read` method will be passed a JS object value from the JSON + * packet and must return a native representation. The `write` method will + * be passed a native representation and should provide a JSONable value. + * + * These methods will both be passed a context. The context is the object + * performing or servicing the request - on the server side it will be + * an Actor, on the client side it will be a Front. + * + * @param typestring name + * Name to register + * @param object typeObject + * An object whose properties will be stored in the type, including + * the `read` and `write` methods. + * @param object options + * Can specify `thawed` to prevent the type from being frozen. + * + * @returns a type object that can be used in protocol definitions. + */ +types.addType = function (name, typeObject = {}, options = {}) { + if (registeredTypes.has(name)) { + throw Error("Type '" + name + "' already exists."); + } + + let type = object.merge({ + toString() { return "[protocol type:" + name + "]";}, + name: name, + primitive: !(typeObject.read || typeObject.write), + read: identityWrite, + write: identityWrite + }, typeObject); + + registeredTypes.set(name, type); + + return type; +}; + +/** + * Remove a type previously registered with the system. + * Primarily useful for types registered by addons. + */ +types.removeType = function (name) { + // This type may still be referenced by other types, make sure + // those references don't work. + let type = registeredTypes.get(name); + + type.name = "DEFUNCT:" + name; + type.category = "defunct"; + type.primitive = false; + type.read = type.write = function () { throw new Error("Using defunct type: " + name); }; + + registeredTypes.delete(name); +}; + +/** + * Add an array type to the type system. + * + * getType() will call this function if provided an "array:" + * typestring. + * + * @param type subtype + * The subtype to be held by the array. + */ +types.addArrayType = function (subtype) { + subtype = types.getType(subtype); + + let name = "array:" + subtype.name; + + // Arrays of primitive types are primitive types themselves. + if (subtype.primitive) { + return types.addType(name); + } + return types.addType(name, { + category: "array", + read: (v, ctx) => [...v].map(i => subtype.read(i, ctx)), + write: (v, ctx) => [...v].map(i => subtype.write(i, ctx)) + }); +}; + +/** + * Add a dict type to the type system. This allows you to serialize + * a JS object that contains non-primitive subtypes. + * + * Properties of the value that aren't included in the specializations + * will be serialized as primitive values. + * + * @param object specializations + * A dict of property names => type + */ +types.addDictType = function (name, specializations) { + return types.addType(name, { + category: "dict", + specializations: specializations, + read: (v, ctx) => { + let ret = {}; + for (let prop in v) { + if (prop in specializations) { + ret[prop] = types.getType(specializations[prop]).read(v[prop], ctx); + } else { + ret[prop] = v[prop]; + } + } + return ret; + }, + + write: (v, ctx) => { + let ret = {}; + for (let prop in v) { + if (prop in specializations) { + ret[prop] = types.getType(specializations[prop]).write(v[prop], ctx); + } else { + ret[prop] = v[prop]; + } + } + return ret; + } + }); +}; + +/** + * Register an actor type with the type system. + * + * Types are marshalled differently when communicating server->client + * than they are when communicating client->server. The server needs + * to provide useful information to the client, so uses the actor's + * `form` method to get a json representation of the actor. When + * making a request from the client we only need the actor ID string. + * + * This function can be called before the associated actor has been + * constructed, but the read and write methods won't work until + * the associated addActorImpl or addActorFront methods have been + * called during actor/front construction. + * + * @param string name + * The typestring to register. + */ +types.addActorType = function (name) { + let type = types.addType(name, { + _actor: true, + category: "actor", + read: (v, ctx, detail) => { + // If we're reading a request on the server side, just + // find the actor registered with this actorID. + if (ctx instanceof Actor) { + return ctx.conn.getActor(v); + } + + // Reading a response on the client side, check for an + // existing front on the connection, and create the front + // if it isn't found. + let actorID = typeof (v) === "string" ? v : v.actor; + let front = ctx.conn.getActor(actorID); + if (!front) { + front = new type.frontClass(ctx.conn); + front.actorID = actorID; + ctx.marshallPool().manage(front); + } + + v = type.formType(detail).read(v, front, detail); + front.form(v, detail, ctx); + + return front; + }, + write: (v, ctx, detail) => { + // If returning a response from the server side, make sure + // the actor is added to a parent object and return its form. + if (v instanceof Actor) { + if (!v.actorID) { + ctx.marshallPool().manage(v); + } + return type.formType(detail).write(v.form(detail), ctx, detail); + } + + // Writing a request from the client side, just send the actor id. + return v.actorID; + }, + formType: (detail) => { + if (!("formType" in type.actorSpec)) { + return types.Primitive; + } + + let formAttr = "formType"; + if (detail) { + formAttr += "#" + detail; + } + + if (!(formAttr in type.actorSpec)) { + throw new Error("No type defined for " + formAttr); + } + + return type.actorSpec[formAttr]; + } + }); + return type; +}; + +types.addNullableType = function (subtype) { + subtype = types.getType(subtype); + return types.addType("nullable:" + subtype.name, { + category: "nullable", + read: (value, ctx) => { + if (value == null) { + return value; + } + return subtype.read(value, ctx); + }, + write: (value, ctx) => { + if (value == null) { + return value; + } + return subtype.write(value, ctx); + } + }); +}; + +/** + * Register an actor detail type. This is just like an actor type, but + * will pass a detail hint to the actor's form method during serialization/ + * deserialization. + * + * This is called by getType() when passed an 'actorType#detail' string. + * + * @param string name + * The typestring to register this type as. + * @param type actorType + * The actor type you'll be detailing. + * @param string detail + * The detail to pass. + */ +types.addActorDetail = function (name, actorType, detail) { + actorType = types.getType(actorType); + if (!actorType._actor) { + throw Error("Details only apply to actor types, tried to add detail '" + detail + "'' to " + actorType.name + "\n"); + } + return types.addType(name, { + _actor: true, + category: "detail", + read: (v, ctx) => actorType.read(v, ctx, detail), + write: (v, ctx) => actorType.write(v, ctx, detail) + }); +}; + +/** + * Register an actor lifetime. This lets the type system find a parent + * actor that differs from the actor fulfilling the request. + * + * @param string name + * The lifetime name to use in typestrings. + * @param string prop + * The property of the actor that holds the parent that should be used. + */ +types.addLifetime = function (name, prop) { + if (registeredLifetimes.has(name)) { + throw Error("Lifetime '" + name + "' already registered."); + } + registeredLifetimes.set(name, prop); +}; + +/** + * Remove a previously-registered lifetime. Useful for lifetimes registered + * in addons. + */ +types.removeLifetime = function (name) { + registeredLifetimes.delete(name); +}; + +/** + * Register a lifetime type. This creates an actor type tied to the given + * lifetime. + * + * This is called by getType() when passed a ':' + * typestring. + * + * @param string lifetime + * A lifetime string previously regisered with addLifetime() + * @param type subtype + * An actor type + */ +types.addLifetimeType = function (lifetime, subtype) { + subtype = types.getType(subtype); + if (!subtype._actor) { + throw Error("Lifetimes only apply to actor types, tried to apply lifetime '" + lifetime + "'' to " + subtype.name); + } + let prop = registeredLifetimes.get(lifetime); + return types.addType(lifetime + ":" + subtype.name, { + category: "lifetime", + read: (value, ctx) => subtype.read(value, ctx[prop]), + write: (value, ctx) => subtype.write(value, ctx[prop]) + }); +}; + +// Add a few named primitive types. +types.Primitive = types.addType("primitive"); +types.String = types.addType("string"); +types.Number = types.addType("number"); +types.Boolean = types.addType("boolean"); +types.JSON = types.addType("json"); + +/** + * Request/Response templates and generation + * + * Request packets are specified as json templates with + * Arg and Option placeholders where arguments should be + * placed. + * + * Reponse packets are also specified as json templates, + * with a RetVal placeholder where the return value should be + * placed. + */ + +/** + * Placeholder for simple arguments. + * + * @param number index + * The argument index to place at this position. + * @param type type + * The argument should be marshalled as this type. + * @constructor + */ +var Arg = Class({ + initialize: function (index, type) { + this.index = index; + this.type = types.getType(type); + }, + + write: function (arg, ctx) { + return this.type.write(arg, ctx); + }, + + read: function (v, ctx, outArgs) { + outArgs[this.index] = this.type.read(v, ctx); + }, + + describe: function () { + return { + _arg: this.index, + type: this.type.name, + }; + } +}); +exports.Arg = Arg; + +/** + * Placeholder for an options argument value that should be hoisted + * into the packet. + * + * If provided in a method specification: + * + * { optionArg: Option(1)} + * + * Then arguments[1].optionArg will be placed in the packet in this + * value's place. + * + * @param number index + * The argument index of the options value. + * @param type type + * The argument should be marshalled as this type. + * @constructor + */ +var Option = Class({ + extends: Arg, + initialize: function (index, type) { + Arg.prototype.initialize.call(this, index, type); + }, + + write: function (arg, ctx, name) { + // Ignore if arg is undefined or null; allow other falsy values + if (arg == undefined || arg[name] == undefined) { + return undefined; + } + let v = arg[name]; + return this.type.write(v, ctx); + }, + read: function (v, ctx, outArgs, name) { + if (outArgs[this.index] === undefined) { + outArgs[this.index] = {}; + } + if (v === undefined) { + return; + } + outArgs[this.index][name] = this.type.read(v, ctx); + }, + + describe: function () { + return { + _option: this.index, + type: this.type.name, + }; + } +}); + +exports.Option = Option; + +/** + * Placeholder for return values in a response template. + * + * @param type type + * The return value should be marshalled as this type. + */ +var RetVal = Class({ + initialize: function (type) { + this.type = types.getType(type); + }, + + write: function (v, ctx) { + return this.type.write(v, ctx); + }, + + read: function (v, ctx) { + return this.type.read(v, ctx); + }, + + describe: function () { + return { + _retval: this.type.name + }; + } +}); + +exports.RetVal = RetVal; + +/* Template handling functions */ + +/** + * Get the value at a given path, or undefined if not found. + */ +function getPath(obj, path) { + for (let name of path) { + if (!(name in obj)) { + return undefined; + } + obj = obj[name]; + } + return obj; +} + +/** + * Find Placeholders in the template and save them along with their + * paths. + */ +function findPlaceholders(template, constructor, path = [], placeholders = []) { + if (!template || typeof (template) != "object") { + return placeholders; + } + + if (template instanceof constructor) { + placeholders.push({ placeholder: template, path: [...path] }); + return placeholders; + } + + for (let name in template) { + path.push(name); + findPlaceholders(template[name], constructor, path, placeholders); + path.pop(); + } + + return placeholders; +} + + +function describeTemplate(template) { + return JSON.parse(JSON.stringify(template, (key, value) => { + if (value.describe) { + return value.describe(); + } + return value; + })); +} + +/** + * Manages a request template. + * + * @param object template + * The request template. + * @construcor + */ +var Request = Class({ + initialize: function (template = {}) { + this.type = template.type; + this.template = template; + this.args = findPlaceholders(template, Arg); + }, + + /** + * Write a request. + * + * @param array fnArgs + * The function arguments to place in the request. + * @param object ctx + * The object making the request. + * @returns a request packet. + */ + write: function (fnArgs, ctx) { + let str = JSON.stringify(this.template, (key, value) => { + if (value instanceof Arg) { + return value.write(value.index in fnArgs ? fnArgs[value.index] : undefined, + ctx, key); + } + return value; + }); + return JSON.parse(str); + }, + + /** + * Read a request. + * + * @param object packet + * The request packet. + * @param object ctx + * The object making the request. + * @returns an arguments array + */ + read: function (packet, ctx) { + let fnArgs = []; + for (let templateArg of this.args) { + let arg = templateArg.placeholder; + let path = templateArg.path; + let name = path[path.length - 1]; + arg.read(getPath(packet, path), ctx, fnArgs, name); + } + return fnArgs; + }, + + describe: function () { return describeTemplate(this.template); } +}); + +/** + * Manages a response template. + * + * @param object template + * The response template. + * @construcor + */ +var Response = Class({ + initialize: function (template = {}) { + this.template = template; + let placeholders = findPlaceholders(template, RetVal); + if (placeholders.length > 1) { + throw Error("More than one RetVal specified in response"); + } + let placeholder = placeholders.shift(); + if (placeholder) { + this.retVal = placeholder.placeholder; + this.path = placeholder.path; + } + }, + + /** + * Write a response for the given return value. + * + * @param val ret + * The return value. + * @param object ctx + * The object writing the response. + */ + write: function (ret, ctx) { + return JSON.parse(JSON.stringify(this.template, function (key, value) { + if (value instanceof RetVal) { + return value.write(ret, ctx); + } + return value; + })); + }, + + /** + * Read a return value from the given response. + * + * @param object packet + * The response packet. + * @param object ctx + * The object reading the response. + */ + read: function (packet, ctx) { + if (!this.retVal) { + return undefined; + } + let v = getPath(packet, this.path); + return this.retVal.read(v, ctx); + }, + + describe: function () { return describeTemplate(this.template); } +}); + +/** + * Actor and Front implementations + */ + +/** + * A protocol object that can manage the lifetime of other protocol + * objects. + */ +var Pool = Class({ + extends: EventTarget, + + /** + * Pools are used on both sides of the connection to help coordinate + * lifetimes. + * + * @param optional conn + * Either a DebuggerServerConnection or a DebuggerClient. Must have + * addActorPool, removeActorPool, and poolFor. + * conn can be null if the subclass provides a conn property. + * @constructor + */ + initialize: function (conn) { + if (conn) { + this.conn = conn; + } + }, + + /** + * Return the parent pool for this client. + */ + parent: function () { return this.conn.poolFor(this.actorID); }, + + /** + * Override this if you want actors returned by this actor + * to belong to a different actor by default. + */ + marshallPool: function () { return this; }, + + /** + * Pool is the base class for all actors, even leaf nodes. + * If the child map is actually referenced, go ahead and create + * the stuff needed by the pool. + */ + __poolMap: null, + get _poolMap() { + if (this.__poolMap) return this.__poolMap; + this.__poolMap = new Map(); + this.conn.addActorPool(this); + return this.__poolMap; + }, + + /** + * Add an actor as a child of this pool. + */ + manage: function (actor) { + if (!actor.actorID) { + actor.actorID = this.conn.allocID(actor.actorPrefix || actor.typeName); + } + + this._poolMap.set(actor.actorID, actor); + return actor; + }, + + /** + * Remove an actor as a child of this pool. + */ + unmanage: function (actor) { + this.__poolMap && this.__poolMap.delete(actor.actorID); + }, + + // true if the given actor ID exists in the pool. + has: function (actorID) { + return this.__poolMap && this._poolMap.has(actorID); + }, + + // The actor for a given actor id stored in this pool + actor: function (actorID) { + return this.__poolMap ? this._poolMap.get(actorID) : null; + }, + + // Same as actor, should update debugger connection to use 'actor' + // and then remove this. + get: function (actorID) { + return this.__poolMap ? this._poolMap.get(actorID) : null; + }, + + // True if this pool has no children. + isEmpty: function () { + return !this.__poolMap || this._poolMap.size == 0; + }, + + /** + * Destroy this item, removing it from a parent if it has one, + * and destroying all children if necessary. + */ + destroy: function () { + let parent = this.parent(); + if (parent) { + parent.unmanage(this); + } + if (!this.__poolMap) { + return; + } + for (let actor of this.__poolMap.values()) { + // Self-owned actors are ok, but don't need destroying twice. + if (actor === this) { + continue; + } + let destroy = actor.destroy; + if (destroy) { + // Disconnect destroy while we're destroying in case of (misbehaving) + // circular ownership. + actor.destroy = null; + destroy.call(actor); + actor.destroy = destroy; + } + } + this.conn.removeActorPool(this, true); + this.__poolMap.clear(); + this.__poolMap = null; + }, + + /** + * For getting along with the debugger server pools, should be removable + * eventually. + */ + cleanup: function () { + this.destroy(); + } +}); +exports.Pool = Pool; + +/** + * An actor in the actor tree. + */ +var Actor = Class({ + extends: Pool, + + // Will contain the actor's ID + actorID: null, + + /** + * Initialize an actor. + * + * @param optional conn + * Either a DebuggerServerConnection or a DebuggerClient. Must have + * addActorPool, removeActorPool, and poolFor. + * conn can be null if the subclass provides a conn property. + * @constructor + */ + initialize: function (conn) { + Pool.prototype.initialize.call(this, conn); + + // Forward events to the connection. + if (this._actorSpec && this._actorSpec.events) { + for (let key of this._actorSpec.events.keys()) { + let name = key; + let sendEvent = this._sendEvent.bind(this, name); + this.on(name, (...args) => { + sendEvent.apply(null, args); + }); + } + } + }, + + toString: function () { return "[Actor " + this.typeName + "/" + this.actorID + "]"; }, + + _sendEvent: function (name, ...args) { + if (!this._actorSpec.events.has(name)) { + // It's ok to emit events that don't go over the wire. + return; + } + let request = this._actorSpec.events.get(name); + let packet; + try { + packet = request.write(args, this); + } catch (ex) { + console.error("Error sending event: " + name); + throw ex; + } + packet.from = packet.from || this.actorID; + this.conn.send(packet); + }, + + destroy: function () { + Pool.prototype.destroy.call(this); + this.actorID = null; + }, + + /** + * Override this method in subclasses to serialize the actor. + * @param [optional] string hint + * Optional string to customize the form. + * @returns A jsonable object. + */ + form: function (hint) { + return { actor: this.actorID }; + }, + + writeError: function (error) { + console.error(error); + if (error.stack) { + dump(error.stack); + } + this.conn.send({ + from: this.actorID, + error: error.error || "unknownError", + message: error.message + }); + }, + + _queueResponse: function (create) { + let pending = this._pendingResponse || promise.resolve(null); + let response = create(pending); + this._pendingResponse = response; + } +}); +exports.Actor = Actor; + +/** + * Tags a prtotype method as an actor method implementation. + * + * @param function fn + * The implementation function, will be returned. + * @param spec + * The method specification, with the following (optional) properties: + * request (object): a request template. + * response (object): a response template. + * oneway (bool): 'true' if no response should be sent. + */ +exports.method = function (fn, spec = {}) { + fn._methodSpec = Object.freeze(spec); + if (spec.request) Object.freeze(spec.request); + if (spec.response) Object.freeze(spec.response); + return fn; +}; + +/** + * Generates an actor specification from an actor description. + */ +var generateActorSpec = function (actorDesc) { + let actorSpec = { + typeName: actorDesc.typeName, + methods: [] + }; + + // Find method and form specifications attached to properties. + for (let name of Object.getOwnPropertyNames(actorDesc)) { + let desc = Object.getOwnPropertyDescriptor(actorDesc, name); + if (!desc.value) { + continue; + } + + if (name.startsWith("formType")) { + if (typeof (desc.value) === "string") { + actorSpec[name] = types.getType(desc.value); + } else if (desc.value.name && registeredTypes.has(desc.value.name)) { + actorSpec[name] = desc.value; + } else { + // Shorthand for a newly-registered DictType. + actorSpec[name] = types.addDictType(actorDesc.typeName + "__" + name, desc.value); + } + } + + if (desc.value._methodSpec) { + let methodSpec = desc.value._methodSpec; + let spec = {}; + spec.name = methodSpec.name || name; + spec.request = Request(object.merge({type: spec.name}, methodSpec.request || undefined)); + spec.response = Response(methodSpec.response || undefined); + spec.release = methodSpec.release; + spec.oneway = methodSpec.oneway; + + actorSpec.methods.push(spec); + } + } + + // Find additional method specifications + if (actorDesc.methods) { + for (let name in actorDesc.methods) { + let methodSpec = actorDesc.methods[name]; + let spec = {}; + + spec.name = methodSpec.name || name; + spec.request = Request(object.merge({type: spec.name}, methodSpec.request || undefined)); + spec.response = Response(methodSpec.response || undefined); + spec.release = methodSpec.release; + spec.oneway = methodSpec.oneway; + + actorSpec.methods.push(spec); + } + } + + // Find event specifications + if (actorDesc.events) { + actorSpec.events = new Map(); + for (let name in actorDesc.events) { + let eventRequest = actorDesc.events[name]; + Object.freeze(eventRequest); + actorSpec.events.set(name, Request(object.merge({type: name}, eventRequest))); + } + } + + if (!registeredTypes.has(actorSpec.typeName)) { + types.addActorType(actorSpec.typeName); + } + registeredTypes.get(actorSpec.typeName).actorSpec = actorSpec; + + return actorSpec; +}; +exports.generateActorSpec = generateActorSpec; + +/** + * Generates request handlers as described by the given actor specification on + * the given actor prototype. Returns the actor prototype. + */ +var generateRequestHandlers = function (actorSpec, actorProto) { + if (actorProto._actorSpec) { + throw new Error("actorProto called twice on the same actor prototype!"); + } + + actorProto.typeName = actorSpec.typeName; + + // Generate request handlers for each method definition + actorProto.requestTypes = Object.create(null); + actorSpec.methods.forEach(spec => { + let handler = function (packet, conn) { + try { + let args; + try { + args = spec.request.read(packet, this); + } catch (ex) { + console.error("Error reading request: " + packet.type); + throw ex; + } + + let ret = this[spec.name].apply(this, args); + + let sendReturn = (ret) => { + if (spec.oneway) { + // No need to send a response. + return; + } + + let response; + try { + response = spec.response.write(ret, this); + } catch (ex) { + console.error("Error writing response to: " + spec.name); + throw ex; + } + response.from = this.actorID; + // If spec.release has been specified, destroy the object. + if (spec.release) { + try { + this.destroy(); + } catch (e) { + this.writeError(e); + return; + } + } + + conn.send(response); + }; + + this._queueResponse(p => { + return p + .then(() => ret) + .then(sendReturn) + .then(null, this.writeError.bind(this)); + }); + } catch (e) { + this._queueResponse(p => { + return p.then(() => this.writeError(e)); + }); + } + }; + + actorProto.requestTypes[spec.request.type] = handler; + }); + + actorProto._actorSpec = actorSpec; + + return actorProto; +}; + +/** + * THIS METHOD IS DEPRECATED, AND PRESERVED ONLY FOR ADD-ONS. IT SHOULD NOT BE + * USED INSIDE THE TREE. + * + * Create an actor class for the given actor prototype. + * + * @param object actorProto + * The actor prototype. Must have a 'typeName' property, + * should have method definitions, can have event definitions. + */ +exports.ActorClass = function (actorProto) { + return ActorClassWithSpec(generateActorSpec(actorProto), actorProto); +}; + +/** + * THIS METHOD IS DEPRECATED, AND PRESERVED ONLY FOR ADD-ONS. IT SHOULD NOT BE + * USED INSIDE THE TREE. + * + * Create an actor class for the given actor specification and prototype. + * + * @param object actorSpec + * The actor specification. Must have a 'typeName' property. + * @param object actorProto + * The actor prototype. Should have method definitions, can have event + * definitions. + */ +var ActorClassWithSpec = function (actorSpec, actorProto) { + if (!actorSpec.typeName) { + throw Error("Actor specification must have a typeName member."); + } + + actorProto.extends = Actor; + let cls = Class(generateRequestHandlers(actorSpec, actorProto)); + + return cls; +}; +exports.ActorClassWithSpec = ActorClassWithSpec; + +/** + * Base class for client-side actor fronts. + */ +var Front = Class({ + extends: Pool, + + actorID: null, + + /** + * The base class for client-side actor fronts. + * + * @param optional conn + * Either a DebuggerServerConnection or a DebuggerClient. Must have + * addActorPool, removeActorPool, and poolFor. + * conn can be null if the subclass provides a conn property. + * @param optional form + * The json form provided by the server. + * @constructor + */ + initialize: function (conn = null, form = null, detail = null, context = null) { + Pool.prototype.initialize.call(this, conn); + this._requests = []; + + // protocol.js no longer uses this data in the constructor, only external + // uses do. External usage of manually-constructed fronts will be + // drastically reduced if we convert the root and tab actors to + // protocol.js, in which case this can probably go away. + if (form) { + this.actorID = form.actor; + form = types.getType(this.typeName).formType(detail).read(form, this, detail); + this.form(form, detail, context); + } + }, + + destroy: function () { + // Reject all outstanding requests, they won't make sense after + // the front is destroyed. + while (this._requests && this._requests.length > 0) { + let { deferred, to, type, stack } = this._requests.shift(); + let msg = "Connection closed, pending request to " + to + + ", type " + type + " failed" + + "\n\nRequest stack:\n" + stack.formattedStack; + deferred.reject(new Error(msg)); + } + Pool.prototype.destroy.call(this); + this.actorID = null; + }, + + manage: function (front) { + if (!front.actorID) { + throw new Error("Can't manage front without an actor ID.\n" + + "Ensure server supports " + front.typeName + "."); + } + return Pool.prototype.manage.call(this, front); + }, + + /** + * @returns a promise that will resolve to the actorID this front + * represents. + */ + actor: function () { return promise.resolve(this.actorID); }, + + toString: function () { return "[Front for " + this.typeName + "/" + this.actorID + "]"; }, + + /** + * Update the actor from its representation. + * Subclasses should override this. + */ + form: function (form) {}, + + /** + * Send a packet on the connection. + */ + send: function (packet) { + if (packet.to) { + this.conn._transport.send(packet); + } else { + this.actor().then(actorID => { + packet.to = actorID; + this.conn._transport.send(packet); + }).then(null, e => console.error(e)); + } + }, + + /** + * Send a two-way request on the connection. + */ + request: function (packet) { + let deferred = defer(); + // Save packet basics for debugging + let { to, type } = packet; + this._requests.push({ + deferred, + to: to || this.actorID, + type, + stack: getStack(), + }); + this.send(packet); + return deferred.promise; + }, + + /** + * Handler for incoming packets from the client's actor. + */ + onPacket: function (packet) { + // Pick off event packets + let type = packet.type || undefined; + if (this._clientSpec.events && this._clientSpec.events.has(type)) { + let event = this._clientSpec.events.get(packet.type); + let args; + try { + args = event.request.read(packet, this); + } catch (ex) { + console.error("Error reading event: " + packet.type); + console.exception(ex); + throw ex; + } + if (event.pre) { + let results = event.pre.map(pre => pre.apply(this, args)); + + // Check to see if any of the preEvents returned a promise -- if so, + // wait for their resolution before emitting. Otherwise, emit synchronously. + if (results.some(result => result && typeof result.then === "function")) { + promise.all(results).then(() => events.emit.apply(null, [this, event.name].concat(args))); + return; + } + } + + events.emit.apply(null, [this, event.name].concat(args)); + return; + } + + // Remaining packets must be responses. + if (this._requests.length === 0) { + let msg = "Unexpected packet " + this.actorID + ", " + JSON.stringify(packet); + let err = Error(msg); + console.error(err); + throw err; + } + + let { deferred, stack } = this._requests.shift(); + callFunctionWithAsyncStack(() => { + if (packet.error) { + // "Protocol error" is here to avoid TBPL heuristics. See also + // https://dxr.mozilla.org/webtools-central/source/tbpl/php/inc/GeneralErrorFilter.php + let message; + if (packet.error && packet.message) { + message = "Protocol error (" + packet.error + "): " + packet.message; + } else { + message = packet.error; + } + deferred.reject(message); + } else { + deferred.resolve(packet); + } + }, stack, "DevTools RDP"); + } +}); +exports.Front = Front; + +/** + * A method tagged with preEvent will be called after recieving a packet + * for that event, and before the front emits the event. + */ +exports.preEvent = function (eventName, fn) { + fn._preEvent = eventName; + return fn; +}; + +/** + * Mark a method as a custom front implementation, replacing the generated + * front method. + * + * @param function fn + * The front implementation, will be returned. + * @param object options + * Options object: + * impl (string): If provided, the generated front method will be + * stored as this property on the prototype. + */ +exports.custom = function (fn, options = {}) { + fn._customFront = options; + return fn; +}; + +function prototypeOf(obj) { + return typeof (obj) === "function" ? obj.prototype : obj; +} + +/** + * Generates request methods as described by the given actor specification on + * the given front prototype. Returns the front prototype. + */ +var generateRequestMethods = function (actorSpec, frontProto) { + if (frontProto._actorSpec) { + throw new Error("frontProto called twice on the same front prototype!"); + } + + frontProto.typeName = actorSpec.typeName; + + // Generate request methods. + let methods = actorSpec.methods; + methods.forEach(spec => { + let name = spec.name; + + // If there's already a property by this name in the front, it must + // be a custom front method. + if (name in frontProto) { + let custom = frontProto[spec.name]._customFront; + if (custom === undefined) { + throw Error("Existing method for " + spec.name + " not marked customFront while processing " + actorType.typeName + "."); + } + // If the user doesn't need the impl don't generate it. + if (!custom.impl) { + return; + } + name = custom.impl; + } + + frontProto[name] = function (...args) { + let packet; + try { + packet = spec.request.write(args, this); + } catch (ex) { + console.error("Error writing request: " + name); + throw ex; + } + if (spec.oneway) { + // Fire-and-forget oneway packets. + this.send(packet); + return undefined; + } + + return this.request(packet).then(response => { + let ret; + try { + ret = spec.response.read(response, this); + } catch (ex) { + console.error("Error reading response to: " + name); + throw ex; + } + return ret; + }); + }; + + // Release methods should call the destroy function on return. + if (spec.release) { + let fn = frontProto[name]; + frontProto[name] = function (...args) { + return fn.apply(this, args).then(result => { + this.destroy(); + return result; + }); + }; + } + }); + + + // Process event specifications + frontProto._clientSpec = {}; + + let events = actorSpec.events; + if (events) { + // This actor has events, scan the prototype for preEvent handlers... + let preHandlers = new Map(); + for (let name of Object.getOwnPropertyNames(frontProto)) { + let desc = Object.getOwnPropertyDescriptor(frontProto, name); + if (!desc.value) { + continue; + } + if (desc.value._preEvent) { + let preEvent = desc.value._preEvent; + if (!events.has(preEvent)) { + throw Error("preEvent for event that doesn't exist: " + preEvent); + } + let handlers = preHandlers.get(preEvent); + if (!handlers) { + handlers = []; + preHandlers.set(preEvent, handlers); + } + handlers.push(desc.value); + } + } + + frontProto._clientSpec.events = new Map(); + + for (let [name, request] of events) { + frontProto._clientSpec.events.set(request.type, { + name: name, + request: request, + pre: preHandlers.get(name) + }); + } + } + + frontProto._actorSpec = actorSpec; + + return frontProto; +}; + +/** + * Create a front class for the given actor class and front prototype. + * + * @param ActorClass actorType + * The actor class you're creating a front for. + * @param object frontProto + * The front prototype. Must have a 'typeName' property, + * should have method definitions, can have event definitions. + */ +exports.FrontClass = function (actorType, frontProto) { + return FrontClassWithSpec(prototypeOf(actorType)._actorSpec, frontProto); +}; + +/** + * Create a front class for the given actor specification and front prototype. + * + * @param object actorSpec + * The actor specification you're creating a front for. + * @param object proto + * The object prototype. Must have a 'typeName' property, + * should have method definitions, can have event definitions. + */ +var FrontClassWithSpec = function (actorSpec, frontProto) { + frontProto.extends = Front; + let cls = Class(generateRequestMethods(actorSpec, frontProto)); + + if (!registeredTypes.has(actorSpec.typeName)) { + types.addActorType(actorSpec.typeName); + } + registeredTypes.get(actorSpec.typeName).frontClass = cls; + + return cls; +}; +exports.FrontClassWithSpec = FrontClassWithSpec; + +exports.dumpActorSpec = function (type) { + let actorSpec = type.actorSpec; + let ret = { + category: "actor", + typeName: type.name, + methods: [], + events: {} + }; + + for (let method of actorSpec.methods) { + ret.methods.push({ + name: method.name, + release: method.release || undefined, + oneway: method.oneway || undefined, + request: method.request.describe(), + response: method.response.describe() + }); + } + + if (actorSpec.events) { + for (let [name, request] of actorSpec.events) { + ret.events[name] = request.describe(); + } + } + + + JSON.stringify(ret); + + return ret; +}; + +exports.dumpProtocolSpec = function () { + let ret = { + types: {}, + }; + + for (let [name, type] of registeredTypes) { + // Force lazy instantiation if needed. + type = types.getType(name); + let category = type.category || undefined; + if (category === "dict") { + ret.types[name] = { + category: "dict", + typeName: name, + specializations: type.specializations + }; + } else if (category === "actor") { + ret.types[name] = exports.dumpActorSpec(type); + } + } + + return ret; +}; diff --git a/devtools/shared/qrcode/decoder/LICENSE b/devtools/shared/qrcode/decoder/LICENSE new file mode 100644 index 000000000..261eeb9e9 --- /dev/null +++ b/devtools/shared/qrcode/decoder/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/devtools/shared/qrcode/decoder/index.js b/devtools/shared/qrcode/decoder/index.js new file mode 100644 index 000000000..28a46de0f --- /dev/null +++ b/devtools/shared/qrcode/decoder/index.js @@ -0,0 +1,2375 @@ +/* + Ported to JavaScript by Lazar Laszlo 2011 + + lazarsoft@gmail.com, www.lazarsoft.info +*/ +/* +* +* Copyright 2007 ZXing authors +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +var imgU8 = null; + +var imgU32 = null; + +var imgWidth = 0; + +var imgHeight = 0; + +var maxImgSize = 1024 * 1024; + +var sizeOfDataLengthInfo = [ [ 10, 9, 8, 8 ], [ 12, 11, 16, 10 ], [ 14, 13, 16, 12 ] ]; + +var GridSampler = {}; + +GridSampler.checkAndNudgePoints = function(image, points) { + let width = imgWidth; + let height = imgHeight; + let nudged = true; + for (let offset = 0; offset < points.length && nudged; offset += 2) { + let x = Math.floor(points[offset]); + let y = Math.floor(points[offset + 1]); + if (x < -1 || x > width || y < -1 || y > height) { + throw "Error.checkAndNudgePoints "; + } + nudged = false; + if (x == -1) { + points[offset] = 0; + nudged = true; + } else if (x == width) { + points[offset] = width - 1; + nudged = true; + } + if (y == -1) { + points[offset + 1] = 0; + nudged = true; + } else if (y == height) { + points[offset + 1] = height - 1; + nudged = true; + } + } + nudged = true; + for (let offset = points.length - 2; offset >= 0 && nudged; offset -= 2) { + let x = Math.floor(points[offset]); + let y = Math.floor(points[offset + 1]); + if (x < -1 || x > width || y < -1 || y > height) { + throw "Error.checkAndNudgePoints "; + } + nudged = false; + if (x == -1) { + points[offset] = 0; + nudged = true; + } else if (x == width) { + points[offset] = width - 1; + nudged = true; + } + if (y == -1) { + points[offset + 1] = 0; + nudged = true; + } else if (y == height) { + points[offset + 1] = height - 1; + nudged = true; + } + } +}; + +GridSampler.sampleGrid3 = function(image, dimension, transform) { + let bits = new BitMatrix(dimension); + let points = new Array(dimension << 1); + for (let y = 0; y < dimension; y++) { + let max = points.length; + let iValue = y + 0.5; + for (let x = 0; x < max; x += 2) { + points[x] = (x >> 1) + 0.5; + points[x + 1] = iValue; + } + transform.transformPoints1(points); + GridSampler.checkAndNudgePoints(image, points); + try { + for (let x = 0; x < max; x += 2) { + let xpoint = Math.floor(points[x]) * 4 + Math.floor(points[x + 1]) * imgWidth * 4; + let bit = image[Math.floor(points[x]) + imgWidth * Math.floor(points[x + 1])]; + imgU8[xpoint] = bit ? 255 : 0; + imgU8[xpoint + 1] = bit ? 255 : 0; + imgU8[xpoint + 2] = 0; + imgU8[xpoint + 3] = 255; + if (bit) bits.set_Renamed(x >> 1, y); + } + } catch (aioobe) { + throw "Error.checkAndNudgePoints"; + } + } + return bits; +}; + +GridSampler.sampleGridx = function(image, dimension, p1ToX, p1ToY, p2ToX, p2ToY, p3ToX, p3ToY, p4ToX, p4ToY, p1FromX, p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p4FromY) { + let transform = PerspectiveTransform.quadrilateralToQuadrilateral(p1ToX, p1ToY, p2ToX, p2ToY, p3ToX, p3ToY, p4ToX, p4ToY, p1FromX, p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p4FromY); + return GridSampler.sampleGrid3(image, dimension, transform); +}; + +function ECB(count, dataCodewords) { + this.count = count; + this.dataCodewords = dataCodewords; + this.__defineGetter__("Count", function() { + return this.count; + }); + this.__defineGetter__("DataCodewords", function() { + return this.dataCodewords; + }); +} + +function ECBlocks(ecCodewordsPerBlock, ecBlocks1, ecBlocks2) { + this.ecCodewordsPerBlock = ecCodewordsPerBlock; + if (ecBlocks2) this.ecBlocks = new Array(ecBlocks1, ecBlocks2); else this.ecBlocks = new Array(ecBlocks1); + this.__defineGetter__("ECCodewordsPerBlock", function() { + return this.ecCodewordsPerBlock; + }); + this.__defineGetter__("TotalECCodewords", function() { + return this.ecCodewordsPerBlock * this.NumBlocks; + }); + this.__defineGetter__("NumBlocks", function() { + let total = 0; + for (let i = 0; i < this.ecBlocks.length; i++) { + total += this.ecBlocks[i].length; + } + return total; + }); + this.getECBlocks = function() { + return this.ecBlocks; + }; +} + +function Version(versionNumber, alignmentPatternCenters, ecBlocks1, ecBlocks2, ecBlocks3, ecBlocks4) { + this.versionNumber = versionNumber; + this.alignmentPatternCenters = alignmentPatternCenters; + this.ecBlocks = new Array(ecBlocks1, ecBlocks2, ecBlocks3, ecBlocks4); + let total = 0; + let ecCodewords = ecBlocks1.ECCodewordsPerBlock; + let ecbArray = ecBlocks1.getECBlocks(); + for (let i = 0; i < ecbArray.length; i++) { + let ecBlock = ecbArray[i]; + total += ecBlock.Count * (ecBlock.DataCodewords + ecCodewords); + } + this.totalCodewords = total; + this.__defineGetter__("VersionNumber", function() { + return this.versionNumber; + }); + this.__defineGetter__("AlignmentPatternCenters", function() { + return this.alignmentPatternCenters; + }); + this.__defineGetter__("TotalCodewords", function() { + return this.totalCodewords; + }); + this.__defineGetter__("DimensionForVersion", function() { + return 17 + 4 * this.versionNumber; + }); + this.buildFunctionPattern = function() { + let dimension = this.DimensionForVersion; + let bitMatrix = new BitMatrix(dimension); + bitMatrix.setRegion(0, 0, 9, 9); + bitMatrix.setRegion(dimension - 8, 0, 8, 9); + bitMatrix.setRegion(0, dimension - 8, 9, 8); + let max = this.alignmentPatternCenters.length; + for (let x = 0; x < max; x++) { + let i = this.alignmentPatternCenters[x] - 2; + for (let y = 0; y < max; y++) { + if (x === 0 && (y === 0 || y === max - 1) || x === max - 1 && y === 0) { + continue; + } + bitMatrix.setRegion(this.alignmentPatternCenters[y] - 2, i, 5, 5); + } + } + bitMatrix.setRegion(6, 9, 1, dimension - 17); + bitMatrix.setRegion(9, 6, dimension - 17, 1); + if (this.versionNumber > 6) { + bitMatrix.setRegion(dimension - 11, 0, 3, 6); + bitMatrix.setRegion(0, dimension - 11, 6, 3); + } + return bitMatrix; + }; + this.getECBlocksForLevel = function(ecLevel) { + return this.ecBlocks[ecLevel.ordinal()]; + }; +} + +Version.VERSION_DECODE_INFO = new Array(31892, 34236, 39577, 42195, 48118, 51042, 55367, 58893, 63784, 68472, 70749, 76311, 79154, 84390, 87683, 92361, 96236, 102084, 102881, 110507, 110734, 117786, 119615, 126325, 127568, 133589, 136944, 141498, 145311, 150283, 152622, 158308, 161089, 167017); + +Version.VERSIONS = buildVersions(); + +Version.getVersionForNumber = function(versionNumber) { + if (versionNumber < 1 || versionNumber > 40) { + throw "ArgumentException"; + } + return Version.VERSIONS[versionNumber - 1]; +}; + +Version.getProvisionalVersionForDimension = function(dimension) { + if (dimension % 4 != 1) { + throw "Error getProvisionalVersionForDimension"; + } + try { + return Version.getVersionForNumber(dimension - 17 >> 2); + } catch (iae) { + throw "Error getVersionForNumber"; + } +}; + +Version.decodeVersionInformation = function(versionBits) { + let bestDifference = 4294967295; + let bestVersion = 0; + for (let i = 0; i < Version.VERSION_DECODE_INFO.length; i++) { + let targetVersion = Version.VERSION_DECODE_INFO[i]; + if (targetVersion == versionBits) { + return this.getVersionForNumber(i + 7); + } + let bitsDifference = FormatInformation.numBitsDiffering(versionBits, targetVersion); + if (bitsDifference < bestDifference) { + bestVersion = i + 7; + bestDifference = bitsDifference; + } + } + if (bestDifference <= 3) { + return this.getVersionForNumber(bestVersion); + } + return null; +}; + +function buildVersions() { + return new Array(new Version(1, new Array(), new ECBlocks(7, new ECB(1, 19)), new ECBlocks(10, new ECB(1, 16)), new ECBlocks(13, new ECB(1, 13)), new ECBlocks(17, new ECB(1, 9))), new Version(2, new Array(6, 18), new ECBlocks(10, new ECB(1, 34)), new ECBlocks(16, new ECB(1, 28)), new ECBlocks(22, new ECB(1, 22)), new ECBlocks(28, new ECB(1, 16))), new Version(3, new Array(6, 22), new ECBlocks(15, new ECB(1, 55)), new ECBlocks(26, new ECB(1, 44)), new ECBlocks(18, new ECB(2, 17)), new ECBlocks(22, new ECB(2, 13))), new Version(4, new Array(6, 26), new ECBlocks(20, new ECB(1, 80)), new ECBlocks(18, new ECB(2, 32)), new ECBlocks(26, new ECB(2, 24)), new ECBlocks(16, new ECB(4, 9))), new Version(5, new Array(6, 30), new ECBlocks(26, new ECB(1, 108)), new ECBlocks(24, new ECB(2, 43)), new ECBlocks(18, new ECB(2, 15), new ECB(2, 16)), new ECBlocks(22, new ECB(2, 11), new ECB(2, 12))), new Version(6, new Array(6, 34), new ECBlocks(18, new ECB(2, 68)), new ECBlocks(16, new ECB(4, 27)), new ECBlocks(24, new ECB(4, 19)), new ECBlocks(28, new ECB(4, 15))), new Version(7, new Array(6, 22, 38), new ECBlocks(20, new ECB(2, 78)), new ECBlocks(18, new ECB(4, 31)), new ECBlocks(18, new ECB(2, 14), new ECB(4, 15)), new ECBlocks(26, new ECB(4, 13), new ECB(1, 14))), new Version(8, new Array(6, 24, 42), new ECBlocks(24, new ECB(2, 97)), new ECBlocks(22, new ECB(2, 38), new ECB(2, 39)), new ECBlocks(22, new ECB(4, 18), new ECB(2, 19)), new ECBlocks(26, new ECB(4, 14), new ECB(2, 15))), new Version(9, new Array(6, 26, 46), new ECBlocks(30, new ECB(2, 116)), new ECBlocks(22, new ECB(3, 36), new ECB(2, 37)), new ECBlocks(20, new ECB(4, 16), new ECB(4, 17)), new ECBlocks(24, new ECB(4, 12), new ECB(4, 13))), new Version(10, new Array(6, 28, 50), new ECBlocks(18, new ECB(2, 68), new ECB(2, 69)), new ECBlocks(26, new ECB(4, 43), new ECB(1, 44)), new ECBlocks(24, new ECB(6, 19), new ECB(2, 20)), new ECBlocks(28, new ECB(6, 15), new ECB(2, 16))), new Version(11, new Array(6, 30, 54), new ECBlocks(20, new ECB(4, 81)), new ECBlocks(30, new ECB(1, 50), new ECB(4, 51)), new ECBlocks(28, new ECB(4, 22), new ECB(4, 23)), new ECBlocks(24, new ECB(3, 12), new ECB(8, 13))), new Version(12, new Array(6, 32, 58), new ECBlocks(24, new ECB(2, 92), new ECB(2, 93)), new ECBlocks(22, new ECB(6, 36), new ECB(2, 37)), new ECBlocks(26, new ECB(4, 20), new ECB(6, 21)), new ECBlocks(28, new ECB(7, 14), new ECB(4, 15))), new Version(13, new Array(6, 34, 62), new ECBlocks(26, new ECB(4, 107)), new ECBlocks(22, new ECB(8, 37), new ECB(1, 38)), new ECBlocks(24, new ECB(8, 20), new ECB(4, 21)), new ECBlocks(22, new ECB(12, 11), new ECB(4, 12))), new Version(14, new Array(6, 26, 46, 66), new ECBlocks(30, new ECB(3, 115), new ECB(1, 116)), new ECBlocks(24, new ECB(4, 40), new ECB(5, 41)), new ECBlocks(20, new ECB(11, 16), new ECB(5, 17)), new ECBlocks(24, new ECB(11, 12), new ECB(5, 13))), new Version(15, new Array(6, 26, 48, 70), new ECBlocks(22, new ECB(5, 87), new ECB(1, 88)), new ECBlocks(24, new ECB(5, 41), new ECB(5, 42)), new ECBlocks(30, new ECB(5, 24), new ECB(7, 25)), new ECBlocks(24, new ECB(11, 12), new ECB(7, 13))), new Version(16, new Array(6, 26, 50, 74), new ECBlocks(24, new ECB(5, 98), new ECB(1, 99)), new ECBlocks(28, new ECB(7, 45), new ECB(3, 46)), new ECBlocks(24, new ECB(15, 19), new ECB(2, 20)), new ECBlocks(30, new ECB(3, 15), new ECB(13, 16))), new Version(17, new Array(6, 30, 54, 78), new ECBlocks(28, new ECB(1, 107), new ECB(5, 108)), new ECBlocks(28, new ECB(10, 46), new ECB(1, 47)), new ECBlocks(28, new ECB(1, 22), new ECB(15, 23)), new ECBlocks(28, new ECB(2, 14), new ECB(17, 15))), new Version(18, new Array(6, 30, 56, 82), new ECBlocks(30, new ECB(5, 120), new ECB(1, 121)), new ECBlocks(26, new ECB(9, 43), new ECB(4, 44)), new ECBlocks(28, new ECB(17, 22), new ECB(1, 23)), new ECBlocks(28, new ECB(2, 14), new ECB(19, 15))), new Version(19, new Array(6, 30, 58, 86), new ECBlocks(28, new ECB(3, 113), new ECB(4, 114)), new ECBlocks(26, new ECB(3, 44), new ECB(11, 45)), new ECBlocks(26, new ECB(17, 21), new ECB(4, 22)), new ECBlocks(26, new ECB(9, 13), new ECB(16, 14))), new Version(20, new Array(6, 34, 62, 90), new ECBlocks(28, new ECB(3, 107), new ECB(5, 108)), new ECBlocks(26, new ECB(3, 41), new ECB(13, 42)), new ECBlocks(30, new ECB(15, 24), new ECB(5, 25)), new ECBlocks(28, new ECB(15, 15), new ECB(10, 16))), new Version(21, new Array(6, 28, 50, 72, 94), new ECBlocks(28, new ECB(4, 116), new ECB(4, 117)), new ECBlocks(26, new ECB(17, 42)), new ECBlocks(28, new ECB(17, 22), new ECB(6, 23)), new ECBlocks(30, new ECB(19, 16), new ECB(6, 17))), new Version(22, new Array(6, 26, 50, 74, 98), new ECBlocks(28, new ECB(2, 111), new ECB(7, 112)), new ECBlocks(28, new ECB(17, 46)), new ECBlocks(30, new ECB(7, 24), new ECB(16, 25)), new ECBlocks(24, new ECB(34, 13))), new Version(23, new Array(6, 30, 54, 74, 102), new ECBlocks(30, new ECB(4, 121), new ECB(5, 122)), new ECBlocks(28, new ECB(4, 47), new ECB(14, 48)), new ECBlocks(30, new ECB(11, 24), new ECB(14, 25)), new ECBlocks(30, new ECB(16, 15), new ECB(14, 16))), new Version(24, new Array(6, 28, 54, 80, 106), new ECBlocks(30, new ECB(6, 117), new ECB(4, 118)), new ECBlocks(28, new ECB(6, 45), new ECB(14, 46)), new ECBlocks(30, new ECB(11, 24), new ECB(16, 25)), new ECBlocks(30, new ECB(30, 16), new ECB(2, 17))), new Version(25, new Array(6, 32, 58, 84, 110), new ECBlocks(26, new ECB(8, 106), new ECB(4, 107)), new ECBlocks(28, new ECB(8, 47), new ECB(13, 48)), new ECBlocks(30, new ECB(7, 24), new ECB(22, 25)), new ECBlocks(30, new ECB(22, 15), new ECB(13, 16))), new Version(26, new Array(6, 30, 58, 86, 114), new ECBlocks(28, new ECB(10, 114), new ECB(2, 115)), new ECBlocks(28, new ECB(19, 46), new ECB(4, 47)), new ECBlocks(28, new ECB(28, 22), new ECB(6, 23)), new ECBlocks(30, new ECB(33, 16), new ECB(4, 17))), new Version(27, new Array(6, 34, 62, 90, 118), new ECBlocks(30, new ECB(8, 122), new ECB(4, 123)), new ECBlocks(28, new ECB(22, 45), new ECB(3, 46)), new ECBlocks(30, new ECB(8, 23), new ECB(26, 24)), new ECBlocks(30, new ECB(12, 15), new ECB(28, 16))), new Version(28, new Array(6, 26, 50, 74, 98, 122), new ECBlocks(30, new ECB(3, 117), new ECB(10, 118)), new ECBlocks(28, new ECB(3, 45), new ECB(23, 46)), new ECBlocks(30, new ECB(4, 24), new ECB(31, 25)), new ECBlocks(30, new ECB(11, 15), new ECB(31, 16))), new Version(29, new Array(6, 30, 54, 78, 102, 126), new ECBlocks(30, new ECB(7, 116), new ECB(7, 117)), new ECBlocks(28, new ECB(21, 45), new ECB(7, 46)), new ECBlocks(30, new ECB(1, 23), new ECB(37, 24)), new ECBlocks(30, new ECB(19, 15), new ECB(26, 16))), new Version(30, new Array(6, 26, 52, 78, 104, 130), new ECBlocks(30, new ECB(5, 115), new ECB(10, 116)), new ECBlocks(28, new ECB(19, 47), new ECB(10, 48)), new ECBlocks(30, new ECB(15, 24), new ECB(25, 25)), new ECBlocks(30, new ECB(23, 15), new ECB(25, 16))), new Version(31, new Array(6, 30, 56, 82, 108, 134), new ECBlocks(30, new ECB(13, 115), new ECB(3, 116)), new ECBlocks(28, new ECB(2, 46), new ECB(29, 47)), new ECBlocks(30, new ECB(42, 24), new ECB(1, 25)), new ECBlocks(30, new ECB(23, 15), new ECB(28, 16))), new Version(32, new Array(6, 34, 60, 86, 112, 138), new ECBlocks(30, new ECB(17, 115)), new ECBlocks(28, new ECB(10, 46), new ECB(23, 47)), new ECBlocks(30, new ECB(10, 24), new ECB(35, 25)), new ECBlocks(30, new ECB(19, 15), new ECB(35, 16))), new Version(33, new Array(6, 30, 58, 86, 114, 142), new ECBlocks(30, new ECB(17, 115), new ECB(1, 116)), new ECBlocks(28, new ECB(14, 46), new ECB(21, 47)), new ECBlocks(30, new ECB(29, 24), new ECB(19, 25)), new ECBlocks(30, new ECB(11, 15), new ECB(46, 16))), new Version(34, new Array(6, 34, 62, 90, 118, 146), new ECBlocks(30, new ECB(13, 115), new ECB(6, 116)), new ECBlocks(28, new ECB(14, 46), new ECB(23, 47)), new ECBlocks(30, new ECB(44, 24), new ECB(7, 25)), new ECBlocks(30, new ECB(59, 16), new ECB(1, 17))), new Version(35, new Array(6, 30, 54, 78, 102, 126, 150), new ECBlocks(30, new ECB(12, 121), new ECB(7, 122)), new ECBlocks(28, new ECB(12, 47), new ECB(26, 48)), new ECBlocks(30, new ECB(39, 24), new ECB(14, 25)), new ECBlocks(30, new ECB(22, 15), new ECB(41, 16))), new Version(36, new Array(6, 24, 50, 76, 102, 128, 154), new ECBlocks(30, new ECB(6, 121), new ECB(14, 122)), new ECBlocks(28, new ECB(6, 47), new ECB(34, 48)), new ECBlocks(30, new ECB(46, 24), new ECB(10, 25)), new ECBlocks(30, new ECB(2, 15), new ECB(64, 16))), new Version(37, new Array(6, 28, 54, 80, 106, 132, 158), new ECBlocks(30, new ECB(17, 122), new ECB(4, 123)), new ECBlocks(28, new ECB(29, 46), new ECB(14, 47)), new ECBlocks(30, new ECB(49, 24), new ECB(10, 25)), new ECBlocks(30, new ECB(24, 15), new ECB(46, 16))), new Version(38, new Array(6, 32, 58, 84, 110, 136, 162), new ECBlocks(30, new ECB(4, 122), new ECB(18, 123)), new ECBlocks(28, new ECB(13, 46), new ECB(32, 47)), new ECBlocks(30, new ECB(48, 24), new ECB(14, 25)), new ECBlocks(30, new ECB(42, 15), new ECB(32, 16))), new Version(39, new Array(6, 26, 54, 82, 110, 138, 166), new ECBlocks(30, new ECB(20, 117), new ECB(4, 118)), new ECBlocks(28, new ECB(40, 47), new ECB(7, 48)), new ECBlocks(30, new ECB(43, 24), new ECB(22, 25)), new ECBlocks(30, new ECB(10, 15), new ECB(67, 16))), new Version(40, new Array(6, 30, 58, 86, 114, 142, 170), new ECBlocks(30, new ECB(19, 118), new ECB(6, 119)), new ECBlocks(28, new ECB(18, 47), new ECB(31, 48)), new ECBlocks(30, new ECB(34, 24), new ECB(34, 25)), new ECBlocks(30, new ECB(20, 15), new ECB(61, 16)))); +} + +function PerspectiveTransform(a11, a21, a31, a12, a22, a32, a13, a23, a33) { + this.a11 = a11; + this.a12 = a12; + this.a13 = a13; + this.a21 = a21; + this.a22 = a22; + this.a23 = a23; + this.a31 = a31; + this.a32 = a32; + this.a33 = a33; + this.transformPoints1 = function(points) { + let max = points.length; + let a11 = this.a11; + let a12 = this.a12; + let a13 = this.a13; + let a21 = this.a21; + let a22 = this.a22; + let a23 = this.a23; + let a31 = this.a31; + let a32 = this.a32; + let a33 = this.a33; + for (let i = 0; i < max; i += 2) { + let x = points[i]; + let y = points[i + 1]; + let denominator = a13 * x + a23 * y + a33; + points[i] = (a11 * x + a21 * y + a31) / denominator; + points[i + 1] = (a12 * x + a22 * y + a32) / denominator; + } + }; + this.transformPoints2 = function(xValues, yValues) { + let n = xValues.length; + for (let i = 0; i < n; i++) { + let x = xValues[i]; + let y = yValues[i]; + let denominator = this.a13 * x + this.a23 * y + this.a33; + xValues[i] = (this.a11 * x + this.a21 * y + this.a31) / denominator; + yValues[i] = (this.a12 * x + this.a22 * y + this.a32) / denominator; + } + }; + this.buildAdjoint = function() { + return new PerspectiveTransform(this.a22 * this.a33 - this.a23 * this.a32, this.a23 * this.a31 - this.a21 * this.a33, this.a21 * this.a32 - this.a22 * this.a31, this.a13 * this.a32 - this.a12 * this.a33, this.a11 * this.a33 - this.a13 * this.a31, this.a12 * this.a31 - this.a11 * this.a32, this.a12 * this.a23 - this.a13 * this.a22, this.a13 * this.a21 - this.a11 * this.a23, this.a11 * this.a22 - this.a12 * this.a21); + }; + this.times = function(other) { + return new PerspectiveTransform(this.a11 * other.a11 + this.a21 * other.a12 + this.a31 * other.a13, this.a11 * other.a21 + this.a21 * other.a22 + this.a31 * other.a23, this.a11 * other.a31 + this.a21 * other.a32 + this.a31 * other.a33, this.a12 * other.a11 + this.a22 * other.a12 + this.a32 * other.a13, this.a12 * other.a21 + this.a22 * other.a22 + this.a32 * other.a23, this.a12 * other.a31 + this.a22 * other.a32 + this.a32 * other.a33, this.a13 * other.a11 + this.a23 * other.a12 + this.a33 * other.a13, this.a13 * other.a21 + this.a23 * other.a22 + this.a33 * other.a23, this.a13 * other.a31 + this.a23 * other.a32 + this.a33 * other.a33); + }; +} + +PerspectiveTransform.quadrilateralToQuadrilateral = function(x0, y0, x1, y1, x2, y2, x3, y3, x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p) { + let qToS = this.quadrilateralToSquare(x0, y0, x1, y1, x2, y2, x3, y3); + let sToQ = this.squareToQuadrilateral(x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p); + return sToQ.times(qToS); +}; + +PerspectiveTransform.squareToQuadrilateral = function(x0, y0, x1, y1, x2, y2, x3, y3) { + let dy2 = y3 - y2; + let dy3 = y0 - y1 + y2 - y3; + if (dy2 === 0 && dy3 === 0) { + return new PerspectiveTransform(x1 - x0, x2 - x1, x0, y1 - y0, y2 - y1, y0, 0, 0, 1); + } else { + let dx1 = x1 - x2; + let dx2 = x3 - x2; + let dx3 = x0 - x1 + x2 - x3; + let dy1 = y1 - y2; + let denominator = dx1 * dy2 - dx2 * dy1; + let a13 = (dx3 * dy2 - dx2 * dy3) / denominator; + let a23 = (dx1 * dy3 - dx3 * dy1) / denominator; + return new PerspectiveTransform(x1 - x0 + a13 * x1, x3 - x0 + a23 * x3, x0, y1 - y0 + a13 * y1, y3 - y0 + a23 * y3, y0, a13, a23, 1); + } +}; + +PerspectiveTransform.quadrilateralToSquare = function(x0, y0, x1, y1, x2, y2, x3, y3) { + return this.squareToQuadrilateral(x0, y0, x1, y1, x2, y2, x3, y3).buildAdjoint(); +}; + +function DetectorResult(bits, points) { + this.bits = bits; + this.points = points; +} + +function Detector(image) { + this.image = image; + this.resultPointCallback = null; + this.sizeOfBlackWhiteBlackRun = function(fromX, fromY, toX, toY) { + let steep = Math.abs(toY - fromY) > Math.abs(toX - fromX); + if (steep) { + let temp = fromX; + fromX = fromY; + fromY = temp; + temp = toX; + toX = toY; + toY = temp; + } + let dx = Math.abs(toX - fromX); + let dy = Math.abs(toY - fromY); + let error = -dx >> 1; + let ystep = fromY < toY ? 1 : -1; + let xstep = fromX < toX ? 1 : -1; + let state = 0; + for (let x = fromX, y = fromY; x != toX; x += xstep) { + let realX = steep ? y : x; + let realY = steep ? x : y; + if (state == 1) { + if (this.image[realX + realY * imgWidth]) { + state++; + } + } else { + if (!this.image[realX + realY * imgWidth]) { + state++; + } + } + if (state == 3) { + let diffX = x - fromX; + let diffY = y - fromY; + return Math.sqrt(diffX * diffX + diffY * diffY); + } + error += dy; + if (error > 0) { + if (y == toY) { + break; + } + y += ystep; + error -= dx; + } + } + let diffX2 = toX - fromX; + let diffY2 = toY - fromY; + return Math.sqrt(diffX2 * diffX2 + diffY2 * diffY2); + }; + this.sizeOfBlackWhiteBlackRunBothWays = function(fromX, fromY, toX, toY) { + let result = this.sizeOfBlackWhiteBlackRun(fromX, fromY, toX, toY); + let scale = 1; + let otherToX = fromX - (toX - fromX); + if (otherToX < 0) { + scale = fromX / (fromX - otherToX); + otherToX = 0; + } else if (otherToX >= imgWidth) { + scale = (imgWidth - 1 - fromX) / (otherToX - fromX); + otherToX = imgWidth - 1; + } + let otherToY = Math.floor(fromY - (toY - fromY) * scale); + scale = 1; + if (otherToY < 0) { + scale = fromY / (fromY - otherToY); + otherToY = 0; + } else if (otherToY >= imgHeight) { + scale = (imgHeight - 1 - fromY) / (otherToY - fromY); + otherToY = imgHeight - 1; + } + otherToX = Math.floor(fromX + (otherToX - fromX) * scale); + result += this.sizeOfBlackWhiteBlackRun(fromX, fromY, otherToX, otherToY); + return result - 1; + }; + this.calculateModuleSizeOneWay = function(pattern, otherPattern) { + let moduleSizeEst1 = this.sizeOfBlackWhiteBlackRunBothWays(Math.floor(pattern.X), Math.floor(pattern.Y), Math.floor(otherPattern.X), Math.floor(otherPattern.Y)); + let moduleSizeEst2 = this.sizeOfBlackWhiteBlackRunBothWays(Math.floor(otherPattern.X), Math.floor(otherPattern.Y), Math.floor(pattern.X), Math.floor(pattern.Y)); + if (isNaN(moduleSizeEst1)) { + return moduleSizeEst2 / 7; + } + if (isNaN(moduleSizeEst2)) { + return moduleSizeEst1 / 7; + } + return (moduleSizeEst1 + moduleSizeEst2) / 14; + }; + this.calculateModuleSize = function(topLeft, topRight, bottomLeft) { + return (this.calculateModuleSizeOneWay(topLeft, topRight) + this.calculateModuleSizeOneWay(topLeft, bottomLeft)) / 2; + }; + this.distance = function(pattern1, pattern2) { + let xDiff = pattern1.X - pattern2.X; + let yDiff = pattern1.Y - pattern2.Y; + return Math.sqrt(xDiff * xDiff + yDiff * yDiff); + }; + this.computeDimension = function(topLeft, topRight, bottomLeft, moduleSize) { + let tltrCentersDimension = Math.round(this.distance(topLeft, topRight) / moduleSize); + let tlblCentersDimension = Math.round(this.distance(topLeft, bottomLeft) / moduleSize); + let dimension = (tltrCentersDimension + tlblCentersDimension >> 1) + 7; + switch (dimension & 3) { + case 0: + dimension++; + break; + + case 2: + dimension--; + break; + + case 3: + throw "Error"; + } + return dimension; + }; + this.findAlignmentInRegion = function(overallEstModuleSize, estAlignmentX, estAlignmentY, allowanceFactor) { + let allowance = Math.floor(allowanceFactor * overallEstModuleSize); + let alignmentAreaLeftX = Math.max(0, estAlignmentX - allowance); + let alignmentAreaRightX = Math.min(imgWidth - 1, estAlignmentX + allowance); + if (alignmentAreaRightX - alignmentAreaLeftX < overallEstModuleSize * 3) { + throw "Error"; + } + let alignmentAreaTopY = Math.max(0, estAlignmentY - allowance); + let alignmentAreaBottomY = Math.min(imgHeight - 1, estAlignmentY + allowance); + let alignmentFinder = new AlignmentPatternFinder(this.image, alignmentAreaLeftX, alignmentAreaTopY, alignmentAreaRightX - alignmentAreaLeftX, alignmentAreaBottomY - alignmentAreaTopY, overallEstModuleSize, this.resultPointCallback); + return alignmentFinder.find(); + }; + this.createTransform = function(topLeft, topRight, bottomLeft, alignmentPattern, dimension) { + let dimMinusThree = dimension - 3.5; + let bottomRightX; + let bottomRightY; + let sourceBottomRightX; + let sourceBottomRightY; + if (alignmentPattern !== null) { + bottomRightX = alignmentPattern.X; + bottomRightY = alignmentPattern.Y; + sourceBottomRightX = sourceBottomRightY = dimMinusThree - 3; + } else { + bottomRightX = topRight.X - topLeft.X + bottomLeft.X; + bottomRightY = topRight.Y - topLeft.Y + bottomLeft.Y; + sourceBottomRightX = sourceBottomRightY = dimMinusThree; + } + let transform = PerspectiveTransform.quadrilateralToQuadrilateral(3.5, 3.5, dimMinusThree, 3.5, sourceBottomRightX, sourceBottomRightY, 3.5, dimMinusThree, topLeft.X, topLeft.Y, topRight.X, topRight.Y, bottomRightX, bottomRightY, bottomLeft.X, bottomLeft.Y); + return transform; + }; + this.sampleGrid = function(image, transform, dimension) { + let sampler = GridSampler; + return sampler.sampleGrid3(image, dimension, transform); + }; + this.processFinderPatternInfo = function(info) { + let topLeft = info.TopLeft; + let topRight = info.TopRight; + let bottomLeft = info.BottomLeft; + let moduleSize = this.calculateModuleSize(topLeft, topRight, bottomLeft); + if (moduleSize < 1) { + throw "Error"; + } + let dimension = this.computeDimension(topLeft, topRight, bottomLeft, moduleSize); + let provisionalVersion = Version.getProvisionalVersionForDimension(dimension); + let modulesBetweenFPCenters = provisionalVersion.DimensionForVersion - 7; + let alignmentPattern = null; + if (provisionalVersion.AlignmentPatternCenters.length > 0) { + let bottomRightX = topRight.X - topLeft.X + bottomLeft.X; + let bottomRightY = topRight.Y - topLeft.Y + bottomLeft.Y; + let correctionToTopLeft = 1 - 3 / modulesBetweenFPCenters; + let estAlignmentX = Math.floor(topLeft.X + correctionToTopLeft * (bottomRightX - topLeft.X)); + let estAlignmentY = Math.floor(topLeft.Y + correctionToTopLeft * (bottomRightY - topLeft.Y)); + for (let i = 4; i <= 16; i <<= 1) { + alignmentPattern = this.findAlignmentInRegion(moduleSize, estAlignmentX, estAlignmentY, i); + break; + } + } + let transform = this.createTransform(topLeft, topRight, bottomLeft, alignmentPattern, dimension); + let bits = this.sampleGrid(this.image, transform, dimension); + let points; + if (alignmentPattern === null) { + points = new Array(bottomLeft, topLeft, topRight); + } else { + points = new Array(bottomLeft, topLeft, topRight, alignmentPattern); + } + return new DetectorResult(bits, points); + }; + this.detect = function() { + let info = new FinderPatternFinder().findFinderPattern(this.image); + return this.processFinderPatternInfo(info); + }; +} + +var FORMAT_INFO_MASK_QR = 21522; + +var FORMAT_INFO_DECODE_LOOKUP = new Array(new Array(21522, 0), new Array(20773, 1), new Array(24188, 2), new Array(23371, 3), new Array(17913, 4), new Array(16590, 5), new Array(20375, 6), new Array(19104, 7), new Array(30660, 8), new Array(29427, 9), new Array(32170, 10), new Array(30877, 11), new Array(26159, 12), new Array(25368, 13), new Array(27713, 14), new Array(26998, 15), new Array(5769, 16), new Array(5054, 17), new Array(7399, 18), new Array(6608, 19), new Array(1890, 20), new Array(597, 21), new Array(3340, 22), new Array(2107, 23), new Array(13663, 24), new Array(12392, 25), new Array(16177, 26), new Array(14854, 27), new Array(9396, 28), new Array(8579, 29), new Array(11994, 30), new Array(11245, 31)); + +var BITS_SET_IN_HALF_BYTE = new Array(0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4); + +function FormatInformation(formatInfo) { + this.errorCorrectionLevel = ErrorCorrectionLevel.forBits(formatInfo >> 3 & 3); + this.dataMask = formatInfo & 7; + this.__defineGetter__("ErrorCorrectionLevel", function() { + return this.errorCorrectionLevel; + }); + this.__defineGetter__("DataMask", function() { + return this.dataMask; + }); + this.GetHashCode = function() { + return this.errorCorrectionLevel.ordinal() << 3 | this.dataMask; + }; + this.Equals = function(o) { + let other = o; + return this.errorCorrectionLevel == other.errorCorrectionLevel && this.dataMask == other.dataMask; + }; +} + +FormatInformation.numBitsDiffering = function(a, b) { + a ^= b; + return BITS_SET_IN_HALF_BYTE[a & 15] + BITS_SET_IN_HALF_BYTE[URShift(a, 4) & 15] + BITS_SET_IN_HALF_BYTE[URShift(a, 8) & 15] + BITS_SET_IN_HALF_BYTE[URShift(a, 12) & 15] + BITS_SET_IN_HALF_BYTE[URShift(a, 16) & 15] + BITS_SET_IN_HALF_BYTE[URShift(a, 20) & 15] + BITS_SET_IN_HALF_BYTE[URShift(a, 24) & 15] + BITS_SET_IN_HALF_BYTE[URShift(a, 28) & 15]; +}; + +FormatInformation.decodeFormatInformation = function(maskedFormatInfo) { + let formatInfo = FormatInformation.doDecodeFormatInformation(maskedFormatInfo); + if (formatInfo !== null) { + return formatInfo; + } + return FormatInformation.doDecodeFormatInformation(maskedFormatInfo ^ FORMAT_INFO_MASK_QR); +}; + +FormatInformation.doDecodeFormatInformation = function(maskedFormatInfo) { + let bestDifference = 4294967295; + let bestFormatInfo = 0; + for (let i = 0; i < FORMAT_INFO_DECODE_LOOKUP.length; i++) { + let decodeInfo = FORMAT_INFO_DECODE_LOOKUP[i]; + let targetInfo = decodeInfo[0]; + if (targetInfo == maskedFormatInfo) { + return new FormatInformation(decodeInfo[1]); + } + let bitsDifference = this.numBitsDiffering(maskedFormatInfo, targetInfo); + if (bitsDifference < bestDifference) { + bestFormatInfo = decodeInfo[1]; + bestDifference = bitsDifference; + } + } + if (bestDifference <= 3) { + return new FormatInformation(bestFormatInfo); + } + return null; +}; + +function ErrorCorrectionLevel(ordinal, bits, name) { + this.ordinal_Renamed_Field = ordinal; + this.bits = bits; + this.name = name; + this.__defineGetter__("Bits", function() { + return this.bits; + }); + this.__defineGetter__("Name", function() { + return this.name; + }); + this.ordinal = function() { + return this.ordinal_Renamed_Field; + }; +} + +var L = new ErrorCorrectionLevel(0, 1, "L"); + +var M = new ErrorCorrectionLevel(1, 0, "M"); + +var Q = new ErrorCorrectionLevel(2, 3, "Q"); + +var H = new ErrorCorrectionLevel(3, 2, "H"); + +var FOR_BITS = new Array(M, L, H, Q); + +ErrorCorrectionLevel.forBits = function(bits) { + if (bits < 0 || bits >= FOR_BITS.length) { + throw "ArgumentException"; + } + return FOR_BITS[bits]; +}; + +function BitMatrix(width, height) { + if (!height) height = width; + if (width < 1 || height < 1) { + throw "Both dimensions must be greater than 0"; + } + this.width = width; + this.height = height; + let rowSize = width >> 5; + if ((width & 31) !== 0) { + rowSize++; + } + this.rowSize = rowSize; + this.bits = new Array(rowSize * height); + for (let i = 0; i < this.bits.length; i++) this.bits[i] = 0; + this.__defineGetter__("Width", function() { + return this.width; + }); + this.__defineGetter__("Height", function() { + return this.height; + }); + this.__defineGetter__("Dimension", function() { + if (this.width != this.height) { + throw "Can't call getDimension() on a non-square matrix"; + } + return this.width; + }); + this.get_Renamed = function(x, y) { + let offset = y * this.rowSize + (x >> 5); + return (URShift(this.bits[offset], x & 31) & 1) !== 0; + }; + this.set_Renamed = function(x, y) { + let offset = y * this.rowSize + (x >> 5); + this.bits[offset] |= 1 << (x & 31); + }; + this.flip = function(x, y) { + let offset = y * this.rowSize + (x >> 5); + this.bits[offset] ^= 1 << (x & 31); + }; + this.clear = function() { + let max = this.bits.length; + for (let i = 0; i < max; i++) { + this.bits[i] = 0; + } + }; + this.setRegion = function(left, top, width, height) { + if (top < 0 || left < 0) { + throw "Left and top must be nonnegative"; + } + if (height < 1 || width < 1) { + throw "Height and width must be at least 1"; + } + let right = left + width; + let bottom = top + height; + if (bottom > this.height || right > this.width) { + throw "The region must fit inside the matrix"; + } + for (let y = top; y < bottom; y++) { + let offset = y * this.rowSize; + for (let x = left; x < right; x++) { + this.bits[offset + (x >> 5)] |= 1 << (x & 31); + } + } + }; +} + +function DataBlock(numDataCodewords, codewords) { + this.numDataCodewords = numDataCodewords; + this.codewords = codewords; + this.__defineGetter__("NumDataCodewords", function() { + return this.numDataCodewords; + }); + this.__defineGetter__("Codewords", function() { + return this.codewords; + }); +} + +DataBlock.getDataBlocks = function(rawCodewords, version, ecLevel) { + if (rawCodewords.length != version.TotalCodewords) { + throw "ArgumentException"; + } + let ecBlocks = version.getECBlocksForLevel(ecLevel); + let totalBlocks = 0; + let ecBlockArray = ecBlocks.getECBlocks(); + for (let i = 0; i < ecBlockArray.length; i++) { + totalBlocks += ecBlockArray[i].Count; + } + let result = new Array(totalBlocks); + let numResultBlocks = 0; + for (let j = 0; j < ecBlockArray.length; j++) { + let ecBlock = ecBlockArray[j]; + for (let i = 0; i < ecBlock.Count; i++) { + let numDataCodewords = ecBlock.DataCodewords; + let numBlockCodewords = ecBlocks.ECCodewordsPerBlock + numDataCodewords; + result[numResultBlocks++] = new DataBlock(numDataCodewords, new Array(numBlockCodewords)); + } + } + let shorterBlocksTotalCodewords = result[0].codewords.length; + let longerBlocksStartAt = result.length - 1; + while (longerBlocksStartAt >= 0) { + let numCodewords = result[longerBlocksStartAt].codewords.length; + if (numCodewords == shorterBlocksTotalCodewords) { + break; + } + longerBlocksStartAt--; + } + longerBlocksStartAt++; + let shorterBlocksNumDataCodewords = shorterBlocksTotalCodewords - ecBlocks.ECCodewordsPerBlock; + let rawCodewordsOffset = 0; + for (let i = 0; i < shorterBlocksNumDataCodewords; i++) { + for (let j = 0; j < numResultBlocks; j++) { + result[j].codewords[i] = rawCodewords[rawCodewordsOffset++]; + } + } + for (let j = longerBlocksStartAt; j < numResultBlocks; j++) { + result[j].codewords[shorterBlocksNumDataCodewords] = rawCodewords[rawCodewordsOffset++]; + } + let max = result[0].codewords.length; + for (let i = shorterBlocksNumDataCodewords; i < max; i++) { + for (let j = 0; j < numResultBlocks; j++) { + let iOffset = j < longerBlocksStartAt ? i : i + 1; + result[j].codewords[iOffset] = rawCodewords[rawCodewordsOffset++]; + } + } + return result; +}; + +var DataMask = {}; + +function BitMatrixParser(bitMatrix) { + let dimension = bitMatrix.Dimension; + if (dimension < 21 || (dimension & 3) != 1) { + throw "Error BitMatrixParser"; + } + this.bitMatrix = bitMatrix; + this.parsedVersion = null; + this.parsedFormatInfo = null; + this.copyBit = function(i, j, versionBits) { + return this.bitMatrix.get_Renamed(i, j) ? versionBits << 1 | 1 : versionBits << 1; + }; + this.readFormatInformation = function() { + if (this.parsedFormatInfo !== null) { + return this.parsedFormatInfo; + } + let formatInfoBits = 0; + for (let i = 0; i < 6; i++) { + formatInfoBits = this.copyBit(i, 8, formatInfoBits); + } + formatInfoBits = this.copyBit(7, 8, formatInfoBits); + formatInfoBits = this.copyBit(8, 8, formatInfoBits); + formatInfoBits = this.copyBit(8, 7, formatInfoBits); + for (let j = 5; j >= 0; j--) { + formatInfoBits = this.copyBit(8, j, formatInfoBits); + } + this.parsedFormatInfo = FormatInformation.decodeFormatInformation(formatInfoBits); + if (this.parsedFormatInfo !== null) { + return this.parsedFormatInfo; + } + let dimension = this.bitMatrix.Dimension; + formatInfoBits = 0; + let iMin = dimension - 8; + for (let i = dimension - 1; i >= iMin; i--) { + formatInfoBits = this.copyBit(i, 8, formatInfoBits); + } + for (let j = dimension - 7; j < dimension; j++) { + formatInfoBits = this.copyBit(8, j, formatInfoBits); + } + this.parsedFormatInfo = FormatInformation.decodeFormatInformation(formatInfoBits); + if (this.parsedFormatInfo !== null) { + return this.parsedFormatInfo; + } + throw "Error readFormatInformation"; + }; + this.readVersion = function() { + if (this.parsedVersion !== null) { + return this.parsedVersion; + } + let dimension = this.bitMatrix.Dimension; + let provisionalVersion = dimension - 17 >> 2; + if (provisionalVersion <= 6) { + return Version.getVersionForNumber(provisionalVersion); + } + let versionBits = 0; + let ijMin = dimension - 11; + for (let j = 5; j >= 0; j--) { + for (let i = dimension - 9; i >= ijMin; i--) { + versionBits = this.copyBit(i, j, versionBits); + } + } + this.parsedVersion = Version.decodeVersionInformation(versionBits); + if (this.parsedVersion !== null && this.parsedVersion.DimensionForVersion == dimension) { + return this.parsedVersion; + } + versionBits = 0; + for (let i = 5; i >= 0; i--) { + for (let j = dimension - 9; j >= ijMin; j--) { + versionBits = this.copyBit(i, j, versionBits); + } + } + this.parsedVersion = Version.decodeVersionInformation(versionBits); + if (this.parsedVersion !== null && this.parsedVersion.DimensionForVersion == dimension) { + return this.parsedVersion; + } + throw "Error readVersion"; + }; + this.readCodewords = function() { + let formatInfo = this.readFormatInformation(); + let version = this.readVersion(); + let dataMask = DataMask.forReference(formatInfo.DataMask); + let dimension = this.bitMatrix.Dimension; + dataMask.unmaskBitMatrix(this.bitMatrix, dimension); + let functionPattern = version.buildFunctionPattern(); + let readingUp = true; + let result = new Array(version.TotalCodewords); + let resultOffset = 0; + let currentByte = 0; + let bitsRead = 0; + for (let j = dimension - 1; j > 0; j -= 2) { + if (j == 6) { + j--; + } + for (let count = 0; count < dimension; count++) { + let i = readingUp ? dimension - 1 - count : count; + for (let col = 0; col < 2; col++) { + if (!functionPattern.get_Renamed(j - col, i)) { + bitsRead++; + currentByte <<= 1; + if (this.bitMatrix.get_Renamed(j - col, i)) { + currentByte |= 1; + } + if (bitsRead == 8) { + result[resultOffset++] = currentByte; + bitsRead = 0; + currentByte = 0; + } + } + } + } + readingUp ^= true; + } + if (resultOffset != version.TotalCodewords) { + throw "Error readCodewords"; + } + return result; + }; +} + +DataMask.forReference = function(reference) { + if (reference < 0 || reference > 7) { + throw "System.ArgumentException"; + } + return DataMask.DATA_MASKS[reference]; +}; + +function DataMask000() { + this.unmaskBitMatrix = function(bits, dimension) { + for (let i = 0; i < dimension; i++) { + for (let j = 0; j < dimension; j++) { + if (this.isMasked(i, j)) { + bits.flip(j, i); + } + } + } + }; + this.isMasked = function(i, j) { + return (i + j & 1) === 0; + }; +} + +function DataMask001() { + this.unmaskBitMatrix = function(bits, dimension) { + for (let i = 0; i < dimension; i++) { + for (let j = 0; j < dimension; j++) { + if (this.isMasked(i, j)) { + bits.flip(j, i); + } + } + } + }; + this.isMasked = function(i, j) { + return (i & 1) === 0; + }; +} + +function DataMask010() { + this.unmaskBitMatrix = function(bits, dimension) { + for (let i = 0; i < dimension; i++) { + for (let j = 0; j < dimension; j++) { + if (this.isMasked(i, j)) { + bits.flip(j, i); + } + } + } + }; + this.isMasked = function(i, j) { + return j % 3 === 0; + }; +} + +function DataMask011() { + this.unmaskBitMatrix = function(bits, dimension) { + for (let i = 0; i < dimension; i++) { + for (let j = 0; j < dimension; j++) { + if (this.isMasked(i, j)) { + bits.flip(j, i); + } + } + } + }; + this.isMasked = function(i, j) { + return (i + j) % 3 === 0; + }; +} + +function DataMask100() { + this.unmaskBitMatrix = function(bits, dimension) { + for (let i = 0; i < dimension; i++) { + for (let j = 0; j < dimension; j++) { + if (this.isMasked(i, j)) { + bits.flip(j, i); + } + } + } + }; + this.isMasked = function(i, j) { + return (URShift(i, 1) + j / 3 & 1) === 0; + }; +} + +function DataMask101() { + this.unmaskBitMatrix = function(bits, dimension) { + for (let i = 0; i < dimension; i++) { + for (let j = 0; j < dimension; j++) { + if (this.isMasked(i, j)) { + bits.flip(j, i); + } + } + } + }; + this.isMasked = function(i, j) { + let temp = i * j; + return (temp & 1) + temp % 3 === 0; + }; +} + +function DataMask110() { + this.unmaskBitMatrix = function(bits, dimension) { + for (let i = 0; i < dimension; i++) { + for (let j = 0; j < dimension; j++) { + if (this.isMasked(i, j)) { + bits.flip(j, i); + } + } + } + }; + this.isMasked = function(i, j) { + let temp = i * j; + return ((temp & 1) + temp % 3 & 1) === 0; + }; +} + +function DataMask111() { + this.unmaskBitMatrix = function(bits, dimension) { + for (let i = 0; i < dimension; i++) { + for (let j = 0; j < dimension; j++) { + if (this.isMasked(i, j)) { + bits.flip(j, i); + } + } + } + }; + this.isMasked = function(i, j) { + return ((i + j & 1) + i * j % 3 & 1) === 0; + }; +} + +DataMask.DATA_MASKS = new Array(new DataMask000(), new DataMask001(), new DataMask010(), new DataMask011(), new DataMask100(), new DataMask101(), new DataMask110(), new DataMask111()); + +function ReedSolomonDecoder(field) { + this.field = field; + this.decode = function(received, twoS) { + let poly = new GF256Poly(this.field, received); + let syndromeCoefficients = new Array(twoS); + for (let i = 0; i < syndromeCoefficients.length; i++) syndromeCoefficients[i] = 0; + let dataMatrix = false; + let noError = true; + for (let i = 0; i < twoS; i++) { + let value = poly.evaluateAt(this.field.exp(dataMatrix ? i + 1 : i)); + syndromeCoefficients[syndromeCoefficients.length - 1 - i] = value; + if (value !== 0) { + noError = false; + } + } + if (noError) { + return; + } + let syndrome = new GF256Poly(this.field, syndromeCoefficients); + let sigmaOmega = this.runEuclideanAlgorithm(this.field.buildMonomial(twoS, 1), syndrome, twoS); + let sigma = sigmaOmega[0]; + let omega = sigmaOmega[1]; + let errorLocations = this.findErrorLocations(sigma); + let errorMagnitudes = this.findErrorMagnitudes(omega, errorLocations, dataMatrix); + for (let i = 0; i < errorLocations.length; i++) { + let position = received.length - 1 - this.field.log(errorLocations[i]); + if (position < 0) { + throw "ReedSolomonException Bad error location"; + } + received[position] = GF256.addOrSubtract(received[position], errorMagnitudes[i]); + } + }; + this.runEuclideanAlgorithm = function(a, b, R) { + if (a.Degree < b.Degree) { + let temp = a; + a = b; + b = temp; + } + let rLast = a; + let r = b; + let sLast = this.field.One; + let s = this.field.Zero; + let tLast = this.field.Zero; + let t = this.field.One; + while (r.Degree >= Math.floor(R / 2)) { + let rLastLast = rLast; + let sLastLast = sLast; + let tLastLast = tLast; + rLast = r; + sLast = s; + tLast = t; + if (rLast.Zero) { + throw "r_{i-1} was zero"; + } + r = rLastLast; + let q = this.field.Zero; + let denominatorLeadingTerm = rLast.getCoefficient(rLast.Degree); + let dltInverse = this.field.inverse(denominatorLeadingTerm); + while (r.Degree >= rLast.Degree && !r.Zero) { + let degreeDiff = r.Degree - rLast.Degree; + let scale = this.field.multiply(r.getCoefficient(r.Degree), dltInverse); + q = q.addOrSubtract(this.field.buildMonomial(degreeDiff, scale)); + r = r.addOrSubtract(rLast.multiplyByMonomial(degreeDiff, scale)); + } + s = q.multiply1(sLast).addOrSubtract(sLastLast); + t = q.multiply1(tLast).addOrSubtract(tLastLast); + } + let sigmaTildeAtZero = t.getCoefficient(0); + if (sigmaTildeAtZero === 0) { + throw "ReedSolomonException sigmaTilde(0) was zero"; + } + let inverse = this.field.inverse(sigmaTildeAtZero); + let sigma = t.multiply2(inverse); + let omega = r.multiply2(inverse); + return new Array(sigma, omega); + }; + this.findErrorLocations = function(errorLocator) { + let numErrors = errorLocator.Degree; + if (numErrors == 1) { + return new Array(errorLocator.getCoefficient(1)); + } + let result = new Array(numErrors); + let e = 0; + for (let i = 1; i < 256 && e < numErrors; i++) { + if (errorLocator.evaluateAt(i) === 0) { + result[e] = this.field.inverse(i); + e++; + } + } + if (e != numErrors) { + throw "Error locator degree does not match number of roots"; + } + return result; + }; + this.findErrorMagnitudes = function(errorEvaluator, errorLocations, dataMatrix) { + let s = errorLocations.length; + let result = new Array(s); + for (let i = 0; i < s; i++) { + let xiInverse = this.field.inverse(errorLocations[i]); + let denominator = 1; + for (let j = 0; j < s; j++) { + if (i != j) { + denominator = this.field.multiply(denominator, GF256.addOrSubtract(1, this.field.multiply(errorLocations[j], xiInverse))); + } + } + result[i] = this.field.multiply(errorEvaluator.evaluateAt(xiInverse), this.field.inverse(denominator)); + if (dataMatrix) { + result[i] = this.field.multiply(result[i], xiInverse); + } + } + return result; + }; +} + +function GF256Poly(field, coefficients) { + if (coefficients === null || coefficients.length === 0) { + throw "System.ArgumentException"; + } + this.field = field; + let coefficientsLength = coefficients.length; + if (coefficientsLength > 1 && coefficients[0] === 0) { + let firstNonZero = 1; + while (firstNonZero < coefficientsLength && coefficients[firstNonZero] === 0) { + firstNonZero++; + } + if (firstNonZero == coefficientsLength) { + this.coefficients = field.Zero.coefficients; + } else { + this.coefficients = new Array(coefficientsLength - firstNonZero); + for (let i = 0; i < this.coefficients.length; i++) this.coefficients[i] = 0; + for (let ci = 0; ci < this.coefficients.length; ci++) this.coefficients[ci] = coefficients[firstNonZero + ci]; + } + } else { + this.coefficients = coefficients; + } + this.__defineGetter__("Zero", function() { + return this.coefficients[0] === 0; + }); + this.__defineGetter__("Degree", function() { + return this.coefficients.length - 1; + }); + this.__defineGetter__("Coefficients", function() { + return this.coefficients; + }); + this.getCoefficient = function(degree) { + return this.coefficients[this.coefficients.length - 1 - degree]; + }; + this.evaluateAt = function(a) { + if (a === 0) { + return this.getCoefficient(0); + } + let size = this.coefficients.length; + if (a == 1) { + let result = 0; + for (let i = 0; i < size; i++) { + result = GF256.addOrSubtract(result, this.coefficients[i]); + } + return result; + } + let result2 = this.coefficients[0]; + for (let i = 1; i < size; i++) { + result2 = GF256.addOrSubtract(this.field.multiply(a, result2), this.coefficients[i]); + } + return result2; + }; + this.addOrSubtract = function(other) { + if (this.field != other.field) { + throw "GF256Polys do not have same GF256 field"; + } + if (this.Zero) { + return other; + } + if (other.Zero) { + return this; + } + let smallerCoefficients = this.coefficients; + let largerCoefficients = other.coefficients; + if (smallerCoefficients.length > largerCoefficients.length) { + let temp = smallerCoefficients; + smallerCoefficients = largerCoefficients; + largerCoefficients = temp; + } + let sumDiff = new Array(largerCoefficients.length); + let lengthDiff = largerCoefficients.length - smallerCoefficients.length; + for (let ci = 0; ci < lengthDiff; ci++) sumDiff[ci] = largerCoefficients[ci]; + for (let i = lengthDiff; i < largerCoefficients.length; i++) { + sumDiff[i] = GF256.addOrSubtract(smallerCoefficients[i - lengthDiff], largerCoefficients[i]); + } + return new GF256Poly(field, sumDiff); + }; + this.multiply1 = function(other) { + if (this.field != other.field) { + throw "GF256Polys do not have same GF256 field"; + } + if (this.Zero || other.Zero) { + return this.field.Zero; + } + let aCoefficients = this.coefficients; + let aLength = aCoefficients.length; + let bCoefficients = other.coefficients; + let bLength = bCoefficients.length; + let product = new Array(aLength + bLength - 1); + for (let i = 0; i < aLength; i++) { + let aCoeff = aCoefficients[i]; + for (let j = 0; j < bLength; j++) { + product[i + j] = GF256.addOrSubtract(product[i + j], this.field.multiply(aCoeff, bCoefficients[j])); + } + } + return new GF256Poly(this.field, product); + }; + this.multiply2 = function(scalar) { + if (scalar === 0) { + return this.field.Zero; + } + if (scalar == 1) { + return this; + } + let size = this.coefficients.length; + let product = new Array(size); + for (let i = 0; i < size; i++) { + product[i] = this.field.multiply(this.coefficients[i], scalar); + } + return new GF256Poly(this.field, product); + }; + this.multiplyByMonomial = function(degree, coefficient) { + if (degree < 0) { + throw "System.ArgumentException"; + } + if (coefficient === 0) { + return this.field.Zero; + } + let size = this.coefficients.length; + let product = new Array(size + degree); + for (let i = 0; i < product.length; i++) product[i] = 0; + for (let i = 0; i < size; i++) { + product[i] = this.field.multiply(this.coefficients[i], coefficient); + } + return new GF256Poly(this.field, product); + }; + this.divide = function(other) { + if (this.field != other.field) { + throw "GF256Polys do not have same GF256 field"; + } + if (other.Zero) { + throw "Divide by 0"; + } + let quotient = this.field.Zero; + let remainder = this; + let denominatorLeadingTerm = other.getCoefficient(other.Degree); + let inverseDenominatorLeadingTerm = this.field.inverse(denominatorLeadingTerm); + while (remainder.Degree >= other.Degree && !remainder.Zero) { + let degreeDifference = remainder.Degree - other.Degree; + let scale = this.field.multiply(remainder.getCoefficient(remainder.Degree), inverseDenominatorLeadingTerm); + let term = other.multiplyByMonomial(degreeDifference, scale); + let iterationQuotient = this.field.buildMonomial(degreeDifference, scale); + quotient = quotient.addOrSubtract(iterationQuotient); + remainder = remainder.addOrSubtract(term); + } + return new Array(quotient, remainder); + }; +} + +function GF256(primitive) { + this.expTable = new Array(256); + this.logTable = new Array(256); + let x = 1; + for (let i = 0; i < 256; i++) { + this.expTable[i] = x; + x <<= 1; + if (x >= 256) { + x ^= primitive; + } + } + for (let i = 0; i < 255; i++) { + this.logTable[this.expTable[i]] = i; + } + let at0 = new Array(1); + at0[0] = 0; + this.zero = new GF256Poly(this, new Array(at0)); + let at1 = new Array(1); + at1[0] = 1; + this.one = new GF256Poly(this, new Array(at1)); + this.__defineGetter__("Zero", function() { + return this.zero; + }); + this.__defineGetter__("One", function() { + return this.one; + }); + this.buildMonomial = function(degree, coefficient) { + if (degree < 0) { + throw "System.ArgumentException"; + } + if (coefficient === 0) { + return this.zero; + } + let coefficients = new Array(degree + 1); + for (let i = 0; i < coefficients.length; i++) coefficients[i] = 0; + coefficients[0] = coefficient; + return new GF256Poly(this, coefficients); + }; + this.exp = function(a) { + return this.expTable[a]; + }; + this.log = function(a) { + if (a === 0) { + throw "System.ArgumentException"; + } + return this.logTable[a]; + }; + this.inverse = function(a) { + if (a === 0) { + throw "System.ArithmeticException"; + } + return this.expTable[255 - this.logTable[a]]; + }; + this.multiply = function(a, b) { + if (a === 0 || b === 0) { + return 0; + } + if (a == 1) { + return b; + } + if (b == 1) { + return a; + } + return this.expTable[(this.logTable[a] + this.logTable[b]) % 255]; + }; +} + +GF256.QR_CODE_FIELD = new GF256(285); + +GF256.DATA_MATRIX_FIELD = new GF256(301); + +GF256.addOrSubtract = function(a, b) { + return a ^ b; +}; + +var Decoder = {}; + +Decoder.rsDecoder = new ReedSolomonDecoder(GF256.QR_CODE_FIELD); + +Decoder.correctErrors = function(codewordBytes, numDataCodewords) { + let numCodewords = codewordBytes.length; + let codewordsInts = new Array(numCodewords); + for (let i = 0; i < numCodewords; i++) { + codewordsInts[i] = codewordBytes[i] & 255; + } + let numECCodewords = codewordBytes.length - numDataCodewords; + try { + Decoder.rsDecoder.decode(codewordsInts, numECCodewords); + } catch (rse) { + throw rse; + } + for (let i = 0; i < numDataCodewords; i++) { + codewordBytes[i] = codewordsInts[i]; + } +}; + +Decoder.decode = function(bits) { + let parser = new BitMatrixParser(bits); + let version = parser.readVersion(); + let ecLevel = parser.readFormatInformation().ErrorCorrectionLevel; + let codewords = parser.readCodewords(); + let dataBlocks = DataBlock.getDataBlocks(codewords, version, ecLevel); + let totalBytes = 0; + for (let i = 0; i < dataBlocks.length; i++) { + totalBytes += dataBlocks[i].NumDataCodewords; + } + let resultBytes = new Array(totalBytes); + let resultOffset = 0; + for (let j = 0; j < dataBlocks.length; j++) { + let dataBlock = dataBlocks[j]; + let codewordBytes = dataBlock.Codewords; + let numDataCodewords = dataBlock.NumDataCodewords; + Decoder.correctErrors(codewordBytes, numDataCodewords); + for (let i = 0; i < numDataCodewords; i++) { + resultBytes[resultOffset++] = codewordBytes[i]; + } + } + let reader = new QRCodeDataBlockReader(resultBytes, version.VersionNumber, ecLevel.Bits); + return reader; +}; + +// mozilla: Get access to a window +var Services = require("Services"); + +var DebuggerServer = require("devtools/server/main").DebuggerServer; + +var window = Services.wm.getMostRecentWindow(DebuggerServer.chromeWindowType); + +var document = window.document; + +var Image = window.Image; + +var HTML_NS = "http://www.w3.org/1999/xhtml"; + +var qrcode = {}; + +qrcode.callback = null; + +qrcode.errback = null; + +qrcode.decode = function(src) { + if (arguments.length === 0) { + let canvas_qr = document.getElementById("qr-canvas"); + let context = canvas_qr.getContext("2d"); + imgWidth = canvas_qr.width; + imgHeight = canvas_qr.height; + imgU8 = context.getImageData(0, 0, imgWidth, imgHeight).data; + imgU32 = new Uint32Array(imgU8.buffer); + qrcode.result = qrcode.process(context); + if (qrcode.callback !== null) { + qrcode.callback(qrcode.result); + } + return qrcode.result; + } else { + let image = new Image(); + image.onload = function() { + // mozilla: Use HTML namespace explicitly + let canvas_qr = document.createElementNS(HTML_NS, "canvas"); + let context = canvas_qr.getContext("2d"); + let nheight = image.height; + let nwidth = image.width; + if (image.width * image.height > maxImgSize) { + let ir = image.width / image.height; + nheight = Math.sqrt(maxImgSize / ir); + nwidth = ir * nheight; + } + canvas_qr.width = nwidth; + canvas_qr.height = nheight; + context.drawImage(image, 0, 0, canvas_qr.width, canvas_qr.height); + imgWidth = canvas_qr.width; + imgHeight = canvas_qr.height; + try { + imgU8 = context.getImageData(0, 0, canvas_qr.width, canvas_qr.height).data; + imgU32 = new Uint32Array(imgU8.buffer); + } catch (e) { + qrcode.result = "Cross domain image reading not supported in your browser! Save it to your computer then drag and drop the file!"; + if (qrcode.callback !== null) { + qrcode.callback(qrcode.result); + } + return; + } + try { + qrcode.result = qrcode.process(context); + if (qrcode.callback !== null) { + qrcode.callback(qrcode.result); + } + } catch (e) { + if (qrcode.errback !== null) { + qrcode.errback(e); + } else { + console.error(e); + } + qrcode.result = "error decoding QR Code"; + } + }; + image.src = src; + } +}; + +qrcode.isUrl = function(s) { + let regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/; + return regexp.test(s); +}; + +qrcode.decode_url = function(s) { + let escaped = ""; + try { + escaped = escape(s); + } catch (e) { + console.log(e); + escaped = s; + } + let ret = ""; + try { + ret = decodeURIComponent(escaped); + } catch (e) { + console.log(e); + ret = escaped; + } + return ret; +}; + +qrcode.decode_utf8 = function(s) { + if (qrcode.isUrl(s)) return qrcode.decode_url(s); else return s; +}; + +qrcode.process = function(ctx) { + let image = qrcode.grayScaleToBitmap(qrcode.grayscale()); + let detector = new Detector(image); + let qRCodeMatrix = detector.detect(); + let reader = Decoder.decode(qRCodeMatrix.bits); + let data = reader.DataByte; + let str = ""; + for (let i = 0; i < data.length; i++) { + for (let j = 0; j < data[i].length; j++) str += String.fromCharCode(data[i][j]); + } + return qrcode.decode_utf8(str); +}; + +qrcode.getMiddleBrightnessPerArea = function(image) { + let numSqrtArea = 4; + let areaWidth = Math.floor(imgWidth / numSqrtArea); + let areaHeight = Math.floor(imgHeight / numSqrtArea); + let minmax = new Array(numSqrtArea); + for (let i = 0; i < numSqrtArea; i++) { + minmax[i] = new Array(numSqrtArea); + for (let i2 = 0; i2 < numSqrtArea; i2++) { + minmax[i][i2] = new Array(0, 0); + } + } + for (let ay = 0; ay < numSqrtArea; ay++) { + for (let ax = 0; ax < numSqrtArea; ax++) { + minmax[ax][ay][0] = 255; + for (let dy = 0; dy < areaHeight; dy++) { + for (let dx = 0; dx < areaWidth; dx++) { + let target = image[areaWidth * ax + dx + (areaHeight * ay + dy) * imgWidth]; + if (target < minmax[ax][ay][0]) minmax[ax][ay][0] = target; + if (target > minmax[ax][ay][1]) minmax[ax][ay][1] = target; + } + } + } + } + let middle = new Array(numSqrtArea); + for (let i3 = 0; i3 < numSqrtArea; i3++) { + middle[i3] = new Array(numSqrtArea); + } + for (let ay = 0; ay < numSqrtArea; ay++) { + for (let ax = 0; ax < numSqrtArea; ax++) { + middle[ax][ay] = Math.floor((minmax[ax][ay][0] + minmax[ax][ay][1]) / 2); + } + } + return middle; +}; + +qrcode.grayScaleToBitmap = function(grayScale) { + let middle = qrcode.getMiddleBrightnessPerArea(grayScale); + let sqrtNumArea = middle.length; + let areaWidth = Math.floor(imgWidth / sqrtNumArea); + let areaHeight = Math.floor(imgHeight / sqrtNumArea); + let bitmap = new Array(imgHeight * imgWidth); + for (let ay = 0; ay < sqrtNumArea; ay++) { + for (let ax = 0; ax < sqrtNumArea; ax++) { + for (let dy = 0; dy < areaHeight; dy++) { + for (let dx = 0; dx < areaWidth; dx++) { + bitmap[areaWidth * ax + dx + (areaHeight * ay + dy) * imgWidth] = grayScale[areaWidth * ax + dx + (areaHeight * ay + dy) * imgWidth] < middle[ax][ay] ? true : false; + } + } + } + } + return bitmap; +}; + +qrcode.grayscale = function() { + let ret = new Uint8ClampedArray(imgWidth * imgHeight); + for (let y = 0; y < imgHeight; y++) { + for (let x = 0; x < imgWidth; x++) { + let point = x + y * imgWidth; + let rgba = imgU32[point]; + let p = (rgba & 0xFF) + ((rgba >> 8) & 0xFF) + ((rgba >> 16) & 0xFF); + ret[x + y * imgWidth] = p / 3; + } + } + return ret; +}; + +function URShift(number, bits) { + if (number >= 0) return number >> bits; else return (number >> bits) + (2 << ~bits); +} + +// mozilla: Add module support +module.exports = { + decodeFromURI: function(src, cb, errcb) { + if (cb) { + qrcode.callback = cb; + } + if (errcb) { + qrcode.errback = errcb; + } + return qrcode.decode(src); + }, + decodeFromCanvas: function(canvas, cb) { + let context = canvas.getContext("2d"); + imgWidth = canvas.width; + imgHeight = canvas.height; + imgU8 = context.getImageData(0, 0, imgWidth, imgHeight).data; + imgU32 = new Uint32Array(imgU8.buffer); + let result = qrcode.process(context); + if (cb) { + cb(result); + } + return result; + } +}; + +var MIN_SKIP = 3; + +var MAX_MODULES = 57; + +var INTEGER_MATH_SHIFT = 8; + +var CENTER_QUORUM = 2; + +qrcode.orderBestPatterns = function(patterns) { + function distance(pattern1, pattern2) { + let xDiff = pattern1.X - pattern2.X; + let yDiff = pattern1.Y - pattern2.Y; + return Math.sqrt(xDiff * xDiff + yDiff * yDiff); + } + function crossProductZ(pointA, pointB, pointC) { + let bX = pointB.x; + let bY = pointB.y; + return (pointC.x - bX) * (pointA.y - bY) - (pointC.y - bY) * (pointA.x - bX); + } + let zeroOneDistance = distance(patterns[0], patterns[1]); + let oneTwoDistance = distance(patterns[1], patterns[2]); + let zeroTwoDistance = distance(patterns[0], patterns[2]); + let pointA, pointB, pointC; + if (oneTwoDistance >= zeroOneDistance && oneTwoDistance >= zeroTwoDistance) { + pointB = patterns[0]; + pointA = patterns[1]; + pointC = patterns[2]; + } else if (zeroTwoDistance >= oneTwoDistance && zeroTwoDistance >= zeroOneDistance) { + pointB = patterns[1]; + pointA = patterns[0]; + pointC = patterns[2]; + } else { + pointB = patterns[2]; + pointA = patterns[0]; + pointC = patterns[1]; + } + if (crossProductZ(pointA, pointB, pointC) < 0) { + let temp = pointA; + pointA = pointC; + pointC = temp; + } + patterns[0] = pointA; + patterns[1] = pointB; + patterns[2] = pointC; +}; + +function FinderPattern(posX, posY, estimatedModuleSize) { + this.x = posX; + this.y = posY; + this.count = 1; + this.estimatedModuleSize = estimatedModuleSize; + this.__defineGetter__("EstimatedModuleSize", function() { + return this.estimatedModuleSize; + }); + this.__defineGetter__("Count", function() { + return this.count; + }); + this.__defineGetter__("X", function() { + return this.x; + }); + this.__defineGetter__("Y", function() { + return this.y; + }); + this.incrementCount = function() { + this.count++; + }; + this.aboutEquals = function(moduleSize, i, j) { + if (Math.abs(i - this.y) <= moduleSize && Math.abs(j - this.x) <= moduleSize) { + let moduleSizeDiff = Math.abs(moduleSize - this.estimatedModuleSize); + return moduleSizeDiff <= 1 || moduleSizeDiff / this.estimatedModuleSize <= 1; + } + return false; + }; +} + +function FinderPatternInfo(patternCenters) { + this.bottomLeft = patternCenters[0]; + this.topLeft = patternCenters[1]; + this.topRight = patternCenters[2]; + this.__defineGetter__("BottomLeft", function() { + return this.bottomLeft; + }); + this.__defineGetter__("TopLeft", function() { + return this.topLeft; + }); + this.__defineGetter__("TopRight", function() { + return this.topRight; + }); +} + +function FinderPatternFinder() { + this.image = null; + this.possibleCenters = []; + this.hasSkipped = false; + this.crossCheckStateCount = new Array(0, 0, 0, 0, 0); + this.resultPointCallback = null; + this.__defineGetter__("CrossCheckStateCount", function() { + this.crossCheckStateCount[0] = 0; + this.crossCheckStateCount[1] = 0; + this.crossCheckStateCount[2] = 0; + this.crossCheckStateCount[3] = 0; + this.crossCheckStateCount[4] = 0; + return this.crossCheckStateCount; + }); + this.foundPatternCross = function(stateCount) { + let totalModuleSize = 0; + for (let i = 0; i < 5; i++) { + let count = stateCount[i]; + if (count === 0) { + return false; + } + totalModuleSize += count; + } + if (totalModuleSize < 7) { + return false; + } + let moduleSize = Math.floor((totalModuleSize << INTEGER_MATH_SHIFT) / 7); + let maxVariance = Math.floor(moduleSize / 2); + return Math.abs(moduleSize - (stateCount[0] << INTEGER_MATH_SHIFT)) < maxVariance && Math.abs(moduleSize - (stateCount[1] << INTEGER_MATH_SHIFT)) < maxVariance && Math.abs(3 * moduleSize - (stateCount[2] << INTEGER_MATH_SHIFT)) < 3 * maxVariance && Math.abs(moduleSize - (stateCount[3] << INTEGER_MATH_SHIFT)) < maxVariance && Math.abs(moduleSize - (stateCount[4] << INTEGER_MATH_SHIFT)) < maxVariance; + }; + this.centerFromEnd = function(stateCount, end) { + return end - stateCount[4] - stateCount[3] - stateCount[2] / 2; + }; + this.crossCheckVertical = function(startI, centerJ, maxCount, originalStateCountTotal) { + let image = this.image; + let maxI = imgHeight; + let stateCount = this.CrossCheckStateCount; + let i = startI; + while (i >= 0 && image[centerJ + i * imgWidth]) { + stateCount[2]++; + i--; + } + if (i < 0) { + return NaN; + } + while (i >= 0 && !image[centerJ + i * imgWidth] && stateCount[1] <= maxCount) { + stateCount[1]++; + i--; + } + if (i < 0 || stateCount[1] > maxCount) { + return NaN; + } + while (i >= 0 && image[centerJ + i * imgWidth] && stateCount[0] <= maxCount) { + stateCount[0]++; + i--; + } + if (stateCount[0] > maxCount) { + return NaN; + } + i = startI + 1; + while (i < maxI && image[centerJ + i * imgWidth]) { + stateCount[2]++; + i++; + } + if (i == maxI) { + return NaN; + } + while (i < maxI && !image[centerJ + i * imgWidth] && stateCount[3] < maxCount) { + stateCount[3]++; + i++; + } + if (i == maxI || stateCount[3] >= maxCount) { + return NaN; + } + while (i < maxI && image[centerJ + i * imgWidth] && stateCount[4] < maxCount) { + stateCount[4]++; + i++; + } + if (stateCount[4] >= maxCount) { + return NaN; + } + let stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4]; + if (5 * Math.abs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal) { + return NaN; + } + return this.foundPatternCross(stateCount) ? this.centerFromEnd(stateCount, i) : NaN; + }; + this.crossCheckHorizontal = function(startJ, centerI, maxCount, originalStateCountTotal) { + let image = this.image; + let maxJ = imgWidth; + let stateCount = this.CrossCheckStateCount; + let j = startJ; + while (j >= 0 && image[j + centerI * imgWidth]) { + stateCount[2]++; + j--; + } + if (j < 0) { + return NaN; + } + while (j >= 0 && !image[j + centerI * imgWidth] && stateCount[1] <= maxCount) { + stateCount[1]++; + j--; + } + if (j < 0 || stateCount[1] > maxCount) { + return NaN; + } + while (j >= 0 && image[j + centerI * imgWidth] && stateCount[0] <= maxCount) { + stateCount[0]++; + j--; + } + if (stateCount[0] > maxCount) { + return NaN; + } + j = startJ + 1; + while (j < maxJ && image[j + centerI * imgWidth]) { + stateCount[2]++; + j++; + } + if (j == maxJ) { + return NaN; + } + while (j < maxJ && !image[j + centerI * imgWidth] && stateCount[3] < maxCount) { + stateCount[3]++; + j++; + } + if (j == maxJ || stateCount[3] >= maxCount) { + return NaN; + } + while (j < maxJ && image[j + centerI * imgWidth] && stateCount[4] < maxCount) { + stateCount[4]++; + j++; + } + if (stateCount[4] >= maxCount) { + return NaN; + } + let stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4]; + if (5 * Math.abs(stateCountTotal - originalStateCountTotal) >= originalStateCountTotal) { + return NaN; + } + return this.foundPatternCross(stateCount) ? this.centerFromEnd(stateCount, j) : NaN; + }; + this.handlePossibleCenter = function(stateCount, i, j) { + let stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4]; + let centerJ = this.centerFromEnd(stateCount, j); + let centerI = this.crossCheckVertical(i, Math.floor(centerJ), stateCount[2], stateCountTotal); + if (!isNaN(centerI)) { + centerJ = this.crossCheckHorizontal(Math.floor(centerJ), Math.floor(centerI), stateCount[2], stateCountTotal); + if (!isNaN(centerJ)) { + let estimatedModuleSize = stateCountTotal / 7; + let found = false; + let max = this.possibleCenters.length; + for (let index = 0; index < max; index++) { + let center = this.possibleCenters[index]; + if (center.aboutEquals(estimatedModuleSize, centerI, centerJ)) { + center.incrementCount(); + found = true; + break; + } + } + if (!found) { + let point = new FinderPattern(centerJ, centerI, estimatedModuleSize); + this.possibleCenters.push(point); + if (this.resultPointCallback !== null) { + this.resultPointCallback.foundPossibleResultPoint(point); + } + } + return true; + } + } + return false; + }; + this.selectBestPatterns = function() { + let startSize = this.possibleCenters.length; + if (startSize < 3) { + throw Error("Couldn't find enough finder patterns"); + } + if (startSize > 3) { + let totalModuleSize = 0; + let square = 0; + for (let i = 0; i < startSize; i++) { + let centerValue = this.possibleCenters[i].EstimatedModuleSize; + totalModuleSize += centerValue; + square += centerValue * centerValue; + } + let average = totalModuleSize / startSize; + this.possibleCenters.sort(function(center1, center2) { + let dA = Math.abs(center2.EstimatedModuleSize - average); + let dB = Math.abs(center1.EstimatedModuleSize - average); + if (dA < dB) { + return -1; + } else if (dA == dB) { + return 0; + } else { + return 1; + } + }); + let stdDev = Math.sqrt(square / startSize - average * average); + let limit = Math.max(0.2 * average, stdDev); + for (let i = 0; i < this.possibleCenters.length && this.possibleCenters.length > 3; i++) { + let pattern = this.possibleCenters[i]; + if (Math.abs(pattern.EstimatedModuleSize - average) > limit) { + // mozilla: use splice instead + this.possibleCenters.splice(i, 1); + i--; + } + } + } + if (this.possibleCenters.length > 3) { + this.possibleCenters.sort(function(a, b) { + if (a.count > b.count) { + return -1; + } + if (a.count < b.count) { + return 1; + } + return 0; + }); + } + return new Array(this.possibleCenters[0], this.possibleCenters[1], this.possibleCenters[2]); + }; + this.findRowSkip = function() { + let max = this.possibleCenters.length; + if (max <= 1) { + return 0; + } + let firstConfirmedCenter = null; + for (let i = 0; i < max; i++) { + let center = this.possibleCenters[i]; + if (center.Count >= CENTER_QUORUM) { + if (firstConfirmedCenter === null) { + firstConfirmedCenter = center; + } else { + this.hasSkipped = true; + return Math.floor((Math.abs(firstConfirmedCenter.X - center.X) - Math.abs(firstConfirmedCenter.Y - center.Y)) / 2); + } + } + } + return 0; + }; + this.haveMultiplyConfirmedCenters = function() { + let confirmedCount = 0; + let totalModuleSize = 0; + let max = this.possibleCenters.length; + for (let i = 0; i < max; i++) { + let pattern = this.possibleCenters[i]; + if (pattern.Count >= CENTER_QUORUM) { + confirmedCount++; + totalModuleSize += pattern.EstimatedModuleSize; + } + } + if (confirmedCount < 3) { + return false; + } + let average = totalModuleSize / max; + let totalDeviation = 0; + for (let i = 0; i < max; i++) { + let pattern = this.possibleCenters[i]; + totalDeviation += Math.abs(pattern.EstimatedModuleSize - average); + } + return totalDeviation <= 0.05 * totalModuleSize; + }; + this.findFinderPattern = function(image) { + let tryHarder = false; + this.image = image; + let maxI = imgHeight; + let maxJ = imgWidth; + let iSkip = Math.floor(3 * maxI / (4 * MAX_MODULES)); + if (iSkip < MIN_SKIP || tryHarder) { + iSkip = MIN_SKIP; + } + let done = false; + let stateCount = new Array(5); + for (let i = iSkip - 1; i < maxI && !done; i += iSkip) { + stateCount[0] = 0; + stateCount[1] = 0; + stateCount[2] = 0; + stateCount[3] = 0; + stateCount[4] = 0; + let currentState = 0; + for (let j = 0; j < maxJ; j++) { + if (image[j + i * imgWidth]) { + if ((currentState & 1) == 1) { + currentState++; + } + stateCount[currentState]++; + } else { + if ((currentState & 1) === 0) { + if (currentState == 4) { + if (this.foundPatternCross(stateCount)) { + let confirmed = this.handlePossibleCenter(stateCount, i, j); + if (confirmed) { + iSkip = 2; + if (this.hasSkipped) { + done = this.haveMultiplyConfirmedCenters(); + } else { + let rowSkip = this.findRowSkip(); + if (rowSkip > stateCount[2]) { + i += rowSkip - stateCount[2] - iSkip; + j = maxJ - 1; + } + } + } else { + do { + j++; + } while (j < maxJ && !image[j + i * imgWidth]); + j--; + } + currentState = 0; + stateCount[0] = 0; + stateCount[1] = 0; + stateCount[2] = 0; + stateCount[3] = 0; + stateCount[4] = 0; + } else { + stateCount[0] = stateCount[2]; + stateCount[1] = stateCount[3]; + stateCount[2] = stateCount[4]; + stateCount[3] = 1; + stateCount[4] = 0; + currentState = 3; + } + } else { + stateCount[++currentState]++; + } + } else { + stateCount[currentState]++; + } + } + } + if (this.foundPatternCross(stateCount)) { + let confirmed = this.handlePossibleCenter(stateCount, i, maxJ); + if (confirmed) { + iSkip = stateCount[0]; + if (this.hasSkipped) { + done = this.haveMultiplyConfirmedCenters(); + } + } + } + } + let patternInfo = this.selectBestPatterns(); + qrcode.orderBestPatterns(patternInfo); + return new FinderPatternInfo(patternInfo); + }; +} + +function AlignmentPattern(posX, posY, estimatedModuleSize) { + this.x = posX; + this.y = posY; + this.count = 1; + this.estimatedModuleSize = estimatedModuleSize; + this.__defineGetter__("EstimatedModuleSize", function() { + return this.estimatedModuleSize; + }); + this.__defineGetter__("Count", function() { + return this.count; + }); + this.__defineGetter__("X", function() { + return Math.floor(this.x); + }); + this.__defineGetter__("Y", function() { + return Math.floor(this.y); + }); + this.incrementCount = function() { + this.count++; + }; + this.aboutEquals = function(moduleSize, i, j) { + if (Math.abs(i - this.y) <= moduleSize && Math.abs(j - this.x) <= moduleSize) { + let moduleSizeDiff = Math.abs(moduleSize - this.estimatedModuleSize); + return moduleSizeDiff <= 1 || moduleSizeDiff / this.estimatedModuleSize <= 1; + } + return false; + }; +} + +function AlignmentPatternFinder(image, startX, startY, width, height, moduleSize, resultPointCallback) { + this.image = image; + this.possibleCenters = []; + this.startX = startX; + this.startY = startY; + this.width = width; + this.height = height; + this.moduleSize = moduleSize; + this.crossCheckStateCount = new Array(0, 0, 0); + this.resultPointCallback = resultPointCallback; + this.centerFromEnd = function(stateCount, end) { + return end - stateCount[2] - stateCount[1] / 2; + }; + this.foundPatternCross = function(stateCount) { + let moduleSize = this.moduleSize; + let maxVariance = moduleSize / 2; + for (let i = 0; i < 3; i++) { + if (Math.abs(moduleSize - stateCount[i]) >= maxVariance) { + return false; + } + } + return true; + }; + this.crossCheckVertical = function(startI, centerJ, maxCount, originalStateCountTotal) { + let image = this.image; + let maxI = imgHeight; + let stateCount = this.crossCheckStateCount; + stateCount[0] = 0; + stateCount[1] = 0; + stateCount[2] = 0; + let i = startI; + while (i >= 0 && image[centerJ + i * imgWidth] && stateCount[1] <= maxCount) { + stateCount[1]++; + i--; + } + if (i < 0 || stateCount[1] > maxCount) { + return NaN; + } + while (i >= 0 && !image[centerJ + i * imgWidth] && stateCount[0] <= maxCount) { + stateCount[0]++; + i--; + } + if (stateCount[0] > maxCount) { + return NaN; + } + i = startI + 1; + while (i < maxI && image[centerJ + i * imgWidth] && stateCount[1] <= maxCount) { + stateCount[1]++; + i++; + } + if (i == maxI || stateCount[1] > maxCount) { + return NaN; + } + while (i < maxI && !image[centerJ + i * imgWidth] && stateCount[2] <= maxCount) { + stateCount[2]++; + i++; + } + if (stateCount[2] > maxCount) { + return NaN; + } + let stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2]; + if (5 * Math.abs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal) { + return NaN; + } + return this.foundPatternCross(stateCount) ? this.centerFromEnd(stateCount, i) : NaN; + }; + this.handlePossibleCenter = function(stateCount, i, j) { + let stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2]; + let centerJ = this.centerFromEnd(stateCount, j); + let centerI = this.crossCheckVertical(i, Math.floor(centerJ), 2 * stateCount[1], stateCountTotal); + if (!isNaN(centerI)) { + let estimatedModuleSize = (stateCount[0] + stateCount[1] + stateCount[2]) / 3; + let max = this.possibleCenters.length; + for (let index = 0; index < max; index++) { + let center = this.possibleCenters[index]; + if (center.aboutEquals(estimatedModuleSize, centerI, centerJ)) { + return new AlignmentPattern(centerJ, centerI, estimatedModuleSize); + } + } + let point = new AlignmentPattern(centerJ, centerI, estimatedModuleSize); + this.possibleCenters.push(point); + if (this.resultPointCallback !== null) { + this.resultPointCallback.foundPossibleResultPoint(point); + } + } + return null; + }; + this.find = function() { + let startX = this.startX; + let height = this.height; + let maxJ = startX + width; + let middleI = startY + (height >> 1); + let stateCount = new Array(0, 0, 0); + for (let iGen = 0; iGen < height; iGen++) { + let i = middleI + ((iGen & 1) === 0 ? iGen + 1 >> 1 : -(iGen + 1 >> 1)); + stateCount[0] = 0; + stateCount[1] = 0; + stateCount[2] = 0; + let j = startX; + while (j < maxJ && !image[j + imgWidth * i]) { + j++; + } + let currentState = 0; + while (j < maxJ) { + if (image[j + i * imgWidth]) { + if (currentState == 1) { + stateCount[currentState]++; + } else { + if (currentState == 2) { + if (this.foundPatternCross(stateCount)) { + let confirmed = this.handlePossibleCenter(stateCount, i, j); + if (confirmed !== null) { + return confirmed; + } + } + stateCount[0] = stateCount[2]; + stateCount[1] = 1; + stateCount[2] = 0; + currentState = 1; + } else { + stateCount[++currentState]++; + } + } + } else { + if (currentState == 1) { + currentState++; + } + stateCount[currentState]++; + } + j++; + } + if (this.foundPatternCross(stateCount)) { + let confirmed = this.handlePossibleCenter(stateCount, i, maxJ); + if (confirmed !== null) { + return confirmed; + } + } + } + if (this.possibleCenters.length !== 0) { + return this.possibleCenters[0]; + } + throw "Couldn't find enough alignment patterns"; + }; +} + +function QRCodeDataBlockReader(blocks, version, numErrorCorrectionCode) { + this.blockPointer = 0; + this.bitPointer = 7; + this.dataLength = 0; + this.blocks = blocks; + this.numErrorCorrectionCode = numErrorCorrectionCode; + if (version <= 9) this.dataLengthMode = 0; else if (version >= 10 && version <= 26) this.dataLengthMode = 1; else if (version >= 27 && version <= 40) this.dataLengthMode = 2; + this.getNextBits = function(numBits) { + let bits = 0; + if (numBits < this.bitPointer + 1) { + let mask = 0; + for (let i = 0; i < numBits; i++) { + mask += 1 << i; + } + mask <<= this.bitPointer - numBits + 1; + bits = (this.blocks[this.blockPointer] & mask) >> this.bitPointer - numBits + 1; + this.bitPointer -= numBits; + return bits; + } else if (numBits < this.bitPointer + 1 + 8) { + let mask1 = 0; + for (let i = 0; i < this.bitPointer + 1; i++) { + mask1 += 1 << i; + } + bits = (this.blocks[this.blockPointer] & mask1) << numBits - (this.bitPointer + 1); + this.blockPointer++; + bits += this.blocks[this.blockPointer] >> 8 - (numBits - (this.bitPointer + 1)); + this.bitPointer = this.bitPointer - numBits % 8; + if (this.bitPointer < 0) { + this.bitPointer = 8 + this.bitPointer; + } + return bits; + } else if (numBits < this.bitPointer + 1 + 16) { + let mask1 = 0; + let mask3 = 0; + for (let i = 0; i < this.bitPointer + 1; i++) { + mask1 += 1 << i; + } + let bitsFirstBlock = (this.blocks[this.blockPointer] & mask1) << numBits - (this.bitPointer + 1); + this.blockPointer++; + let bitsSecondBlock = this.blocks[this.blockPointer] << numBits - (this.bitPointer + 1 + 8); + this.blockPointer++; + for (let i = 0; i < numBits - (this.bitPointer + 1 + 8); i++) { + mask3 += 1 << i; + } + mask3 <<= 8 - (numBits - (this.bitPointer + 1 + 8)); + let bitsThirdBlock = (this.blocks[this.blockPointer] & mask3) >> 8 - (numBits - (this.bitPointer + 1 + 8)); + bits = bitsFirstBlock + bitsSecondBlock + bitsThirdBlock; + this.bitPointer = this.bitPointer - (numBits - 8) % 8; + if (this.bitPointer < 0) { + this.bitPointer = 8 + this.bitPointer; + } + return bits; + } else { + return 0; + } + }; + this.NextMode = function() { + if (this.blockPointer > this.blocks.length - this.numErrorCorrectionCode - 2) return 0; else return this.getNextBits(4); + }; + this.getDataLength = function(modeIndicator) { + let index = 0; + while (true) { + if (modeIndicator >> index == 1) break; + index++; + } + return this.getNextBits(sizeOfDataLengthInfo[this.dataLengthMode][index]); + }; + this.getRomanAndFigureString = function(dataLength) { + var length = dataLength; + let intData = 0; + let strData = ""; + let tableRomanAndFigure = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", " ", "$", "%", "*", "+", "-", ".", "/", ":"); + do { + if (length > 1) { + intData = this.getNextBits(11); + let firstLetter = Math.floor(intData / 45); + let secondLetter = intData % 45; + strData += tableRomanAndFigure[firstLetter]; + strData += tableRomanAndFigure[secondLetter]; + length -= 2; + } else if (length == 1) { + intData = this.getNextBits(6); + strData += tableRomanAndFigure[intData]; + length -= 1; + } + } while (length > 0); + return strData; + }; + this.getFigureString = function(dataLength) { + var length = dataLength; + let intData = 0; + let strData = ""; + do { + if (length >= 3) { + intData = this.getNextBits(10); + if (intData < 100) strData += "0"; + if (intData < 10) strData += "0"; + length -= 3; + } else if (length == 2) { + intData = this.getNextBits(7); + if (intData < 10) strData += "0"; + length -= 2; + } else if (length == 1) { + intData = this.getNextBits(4); + length -= 1; + } + strData += intData; + } while (length > 0); + return strData; + }; + this.get8bitByteArray = function(dataLength) { + var length = dataLength; + let intData = 0; + let output = []; + do { + intData = this.getNextBits(8); + output.push(intData); + length--; + } while (length > 0); + return output; + }; + this.getKanjiString = function(dataLength) { + var length = dataLength; + let intData = 0; + let unicodeString = ""; + do { + intData = this.getNextBits(13); + let lowerByte = intData % 192; + let higherByte = intData / 192; + let tempWord = (higherByte << 8) + lowerByte; + let shiftjisWord = 0; + if (tempWord + 33088 <= 40956) { + shiftjisWord = tempWord + 33088; + } else { + shiftjisWord = tempWord + 49472; + } + unicodeString += String.fromCharCode(shiftjisWord); + length--; + } while (length > 0); + return unicodeString; + }; + this.__defineGetter__("DataByte", function() { + let output = []; + let MODE_NUMBER = 1; + let MODE_ROMAN_AND_NUMBER = 2; + let MODE_8BIT_BYTE = 4; + let MODE_KANJI = 8; + do { + let mode = this.NextMode(); + if (mode === 0) { + if (output.length > 0) break; else throw "Empty data block"; + } + if (mode != MODE_NUMBER && mode != MODE_ROMAN_AND_NUMBER && mode != MODE_8BIT_BYTE && mode != MODE_KANJI) { + throw "Invalid mode: " + mode + " in (block:" + this.blockPointer + " bit:" + this.bitPointer + ")"; + } + let dataLength = this.getDataLength(mode); + if (dataLength < 1) { + throw "Invalid data length: " + dataLength; + } + let temp_str; + let ta; + switch (mode) { + case MODE_NUMBER: + temp_str = this.getFigureString(dataLength); + ta = new Array(temp_str.length); + for (let j = 0; j < temp_str.length; j++) ta[j] = temp_str.charCodeAt(j); + output.push(ta); + break; + + case MODE_ROMAN_AND_NUMBER: + temp_str = this.getRomanAndFigureString(dataLength); + ta = new Array(temp_str.length); + for (let j = 0; j < temp_str.length; j++) ta[j] = temp_str.charCodeAt(j); + output.push(ta); + break; + + case MODE_8BIT_BYTE: + let temp_sbyteArray3 = this.get8bitByteArray(dataLength); + output.push(temp_sbyteArray3); + break; + + case MODE_KANJI: + temp_str = this.getKanjiString(dataLength); + output.push(temp_str); + break; + } + } while (true); + return output; + }); +} diff --git a/devtools/shared/qrcode/decoder/moz.build b/devtools/shared/qrcode/decoder/moz.build new file mode 100644 index 000000000..4442a2e90 --- /dev/null +++ b/devtools/shared/qrcode/decoder/moz.build @@ -0,0 +1,9 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +DevToolsModules( + 'index.js', +) diff --git a/devtools/shared/qrcode/encoder/LICENSE b/devtools/shared/qrcode/encoder/LICENSE new file mode 100644 index 000000000..a93630a3b --- /dev/null +++ b/devtools/shared/qrcode/encoder/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2009 Kazuhiko Arase + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/devtools/shared/qrcode/encoder/index.js b/devtools/shared/qrcode/encoder/index.js new file mode 100644 index 000000000..487d0f471 --- /dev/null +++ b/devtools/shared/qrcode/encoder/index.js @@ -0,0 +1,1674 @@ +//--------------------------------------------------------------------- +// +// QR Code Generator for JavaScript +// +// Copyright (c) 2009 Kazuhiko Arase +// +// URL: http://www.d-project.com/ +// +// Licensed under the MIT license: +// http://www.opensource.org/licenses/mit-license.php +// +// The word 'QR Code' is registered trademark of +// DENSO WAVE INCORPORATED +// http://www.denso-wave.com/qrcode/faqpatent-e.html +// +//--------------------------------------------------------------------- + +var qrcode = function() { + + //--------------------------------------------------------------------- + // qrcode + //--------------------------------------------------------------------- + + /** + * qrcode + * @param typeNumber 1 to 10 + * @param errorCorrectLevel 'L','M','Q','H' + */ + var qrcode = function(typeNumber, errorCorrectLevel) { + + var PAD0 = 0xEC; + var PAD1 = 0x11; + + var _typeNumber = typeNumber; + var _errorCorrectLevel = QRErrorCorrectLevel[errorCorrectLevel]; + var _modules = null; + var _moduleCount = 0; + var _dataCache = null; + var _dataList = new Array(); + + var _this = {}; + + var makeImpl = function(test, maskPattern) { + + _moduleCount = _typeNumber * 4 + 17; + _modules = function(moduleCount) { + var modules = new Array(moduleCount); + for (var row = 0; row < moduleCount; row += 1) { + modules[row] = new Array(moduleCount); + for (var col = 0; col < moduleCount; col += 1) { + modules[row][col] = null; + } + } + return modules; + }(_moduleCount); + + setupPositionProbePattern(0, 0); + setupPositionProbePattern(_moduleCount - 7, 0); + setupPositionProbePattern(0, _moduleCount - 7); + setupPositionAdjustPattern(); + setupTimingPattern(); + setupTypeInfo(test, maskPattern); + + if (_typeNumber >= 7) { + setupTypeNumber(test); + } + + if (_dataCache == null) { + _dataCache = createData(_typeNumber, _errorCorrectLevel, _dataList); + } + + mapData(_dataCache, maskPattern); + }; + + var setupPositionProbePattern = function(row, col) { + + for (var r = -1; r <= 7; r += 1) { + + if (row + r <= -1 || _moduleCount <= row + r) continue; + + for (var c = -1; c <= 7; c += 1) { + + if (col + c <= -1 || _moduleCount <= col + c) continue; + + if ( (0 <= r && r <= 6 && (c == 0 || c == 6) ) + || (0 <= c && c <= 6 && (r == 0 || r == 6) ) + || (2 <= r && r <= 4 && 2 <= c && c <= 4) ) { + _modules[row + r][col + c] = true; + } else { + _modules[row + r][col + c] = false; + } + } + } + }; + + var getBestMaskPattern = function() { + + var minLostPoint = 0; + var pattern = 0; + + for (var i = 0; i < 8; i += 1) { + + makeImpl(true, i); + + var lostPoint = QRUtil.getLostPoint(_this); + + if (i == 0 || minLostPoint > lostPoint) { + minLostPoint = lostPoint; + pattern = i; + } + } + + return pattern; + }; + + var setupTimingPattern = function() { + + for (var r = 8; r < _moduleCount - 8; r += 1) { + if (_modules[r][6] != null) { + continue; + } + _modules[r][6] = (r % 2 == 0); + } + + for (var c = 8; c < _moduleCount - 8; c += 1) { + if (_modules[6][c] != null) { + continue; + } + _modules[6][c] = (c % 2 == 0); + } + }; + + var setupPositionAdjustPattern = function() { + + var pos = QRUtil.getPatternPosition(_typeNumber); + + for (var i = 0; i < pos.length; i += 1) { + + for (var j = 0; j < pos.length; j += 1) { + + var row = pos[i]; + var col = pos[j]; + + if (_modules[row][col] != null) { + continue; + } + + for (var r = -2; r <= 2; r += 1) { + + for (var c = -2; c <= 2; c += 1) { + + if (r == -2 || r == 2 || c == -2 || c == 2 + || (r == 0 && c == 0) ) { + _modules[row + r][col + c] = true; + } else { + _modules[row + r][col + c] = false; + } + } + } + } + } + }; + + var setupTypeNumber = function(test) { + + var bits = QRUtil.getBCHTypeNumber(_typeNumber); + + for (var i = 0; i < 18; i += 1) { + var mod = (!test && ( (bits >> i) & 1) == 1); + _modules[Math.floor(i / 3)][i % 3 + _moduleCount - 8 - 3] = mod; + } + + for (var i = 0; i < 18; i += 1) { + var mod = (!test && ( (bits >> i) & 1) == 1); + _modules[i % 3 + _moduleCount - 8 - 3][Math.floor(i / 3)] = mod; + } + }; + + var setupTypeInfo = function(test, maskPattern) { + + var data = (_errorCorrectLevel << 3) | maskPattern; + var bits = QRUtil.getBCHTypeInfo(data); + + // vertical + for (var i = 0; i < 15; i += 1) { + + var mod = (!test && ( (bits >> i) & 1) == 1); + + if (i < 6) { + _modules[i][8] = mod; + } else if (i < 8) { + _modules[i + 1][8] = mod; + } else { + _modules[_moduleCount - 15 + i][8] = mod; + } + } + + // horizontal + for (var i = 0; i < 15; i += 1) { + + var mod = (!test && ( (bits >> i) & 1) == 1); + + if (i < 8) { + _modules[8][_moduleCount - i - 1] = mod; + } else if (i < 9) { + _modules[8][15 - i - 1 + 1] = mod; + } else { + _modules[8][15 - i - 1] = mod; + } + } + + // fixed module + _modules[_moduleCount - 8][8] = (!test); + }; + + var mapData = function(data, maskPattern) { + + var inc = -1; + var row = _moduleCount - 1; + var bitIndex = 7; + var byteIndex = 0; + var maskFunc = QRUtil.getMaskFunction(maskPattern); + + for (var col = _moduleCount - 1; col > 0; col -= 2) { + + if (col == 6) col -= 1; + + while (true) { + + for (var c = 0; c < 2; c += 1) { + + if (_modules[row][col - c] == null) { + + var dark = false; + + if (byteIndex < data.length) { + dark = ( ( (data[byteIndex] >>> bitIndex) & 1) == 1); + } + + var mask = maskFunc(row, col - c); + + if (mask) { + dark = !dark; + } + + _modules[row][col - c] = dark; + bitIndex -= 1; + + if (bitIndex == -1) { + byteIndex += 1; + bitIndex = 7; + } + } + } + + row += inc; + + if (row < 0 || _moduleCount <= row) { + row -= inc; + inc = -inc; + break; + } + } + } + }; + + var createBytes = function(buffer, rsBlocks) { + + var offset = 0; + + var maxDcCount = 0; + var maxEcCount = 0; + + var dcdata = new Array(rsBlocks.length); + var ecdata = new Array(rsBlocks.length); + + for (var r = 0; r < rsBlocks.length; r += 1) { + + var dcCount = rsBlocks[r].dataCount; + var ecCount = rsBlocks[r].totalCount - dcCount; + + maxDcCount = Math.max(maxDcCount, dcCount); + maxEcCount = Math.max(maxEcCount, ecCount); + + dcdata[r] = new Array(dcCount); + + for (var i = 0; i < dcdata[r].length; i += 1) { + dcdata[r][i] = 0xff & buffer.getBuffer()[i + offset]; + } + offset += dcCount; + + var rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount); + var rawPoly = qrPolynomial(dcdata[r], rsPoly.getLength() - 1); + + var modPoly = rawPoly.mod(rsPoly); + ecdata[r] = new Array(rsPoly.getLength() - 1); + for (var i = 0; i < ecdata[r].length; i += 1) { + var modIndex = i + modPoly.getLength() - ecdata[r].length; + ecdata[r][i] = (modIndex >= 0)? modPoly.getAt(modIndex) : 0; + } + } + + var totalCodeCount = 0; + for (var i = 0; i < rsBlocks.length; i += 1) { + totalCodeCount += rsBlocks[i].totalCount; + } + + var data = new Array(totalCodeCount); + var index = 0; + + for (var i = 0; i < maxDcCount; i += 1) { + for (var r = 0; r < rsBlocks.length; r += 1) { + if (i < dcdata[r].length) { + data[index] = dcdata[r][i]; + index += 1; + } + } + } + + for (var i = 0; i < maxEcCount; i += 1) { + for (var r = 0; r < rsBlocks.length; r += 1) { + if (i < ecdata[r].length) { + data[index] = ecdata[r][i]; + index += 1; + } + } + } + + return data; + }; + + var createData = function(typeNumber, errorCorrectLevel, dataList) { + + var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, errorCorrectLevel); + + var buffer = qrBitBuffer(); + + for (var i = 0; i < dataList.length; i += 1) { + var data = dataList[i]; + buffer.put(data.getMode(), 4); + buffer.put(data.getLength(), QRUtil.getLengthInBits(data.getMode(), typeNumber) ); + data.write(buffer); + } + + // calc num max data. + var totalDataCount = 0; + for (var i = 0; i < rsBlocks.length; i += 1) { + totalDataCount += rsBlocks[i].dataCount; + } + + if (buffer.getLengthInBits() > totalDataCount * 8) { + throw new Error('code length overflow. (' + + buffer.getLengthInBits() + + '>' + + totalDataCount * 8 + + ')'); + } + + // end code + if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) { + buffer.put(0, 4); + } + + // padding + while (buffer.getLengthInBits() % 8 != 0) { + buffer.putBit(false); + } + + // padding + while (true) { + + if (buffer.getLengthInBits() >= totalDataCount * 8) { + break; + } + buffer.put(PAD0, 8); + + if (buffer.getLengthInBits() >= totalDataCount * 8) { + break; + } + buffer.put(PAD1, 8); + } + + return createBytes(buffer, rsBlocks); + }; + + _this.addData = function(data) { + var newData = qr8BitByte(data); + _dataList.push(newData); + _dataCache = null; + }; + + _this.isDark = function(row, col) { + if (row < 0 || _moduleCount <= row || col < 0 || _moduleCount <= col) { + throw new Error(row + ',' + col); + } + return _modules[row][col]; + }; + + _this.getModuleCount = function() { + return _moduleCount; + }; + + _this.make = function() { + makeImpl(false, getBestMaskPattern() ); + }; + + _this.createTableTag = function(cellSize, margin) { + + cellSize = cellSize || 2; + margin = (typeof margin == 'undefined')? cellSize * 4 : margin; + + var qrHtml = ''; + + qrHtml += ''; + qrHtml += ''; + + for (var r = 0; r < _this.getModuleCount(); r += 1) { + + qrHtml += ''; + + for (var c = 0; c < _this.getModuleCount(); c += 1) { + qrHtml += ''; + } + + qrHtml += ''; + qrHtml += '
'; + } + + qrHtml += '
'; + + return qrHtml; + }; + + _this.createImgTag = function(cellSize, margin) { + + cellSize = cellSize || 2; + margin = (typeof margin == 'undefined')? cellSize * 4 : margin; + + var size = _this.getModuleCount() * cellSize + margin * 2; + var min = margin; + var max = size - margin; + + return createImgTag(size, size, function(x, y) { + if (min <= x && x < max && min <= y && y < max) { + var c = Math.floor( (x - min) / cellSize); + var r = Math.floor( (y - min) / cellSize); + return _this.isDark(r, c)? 0 : 1; + } else { + return 1; + } + } ); + }; + + _this.createImgData = function(cellSize, margin) { + + cellSize = cellSize || 2; + margin = (typeof margin == 'undefined')? cellSize * 4 : margin; + + var size = _this.getModuleCount() * cellSize + margin * 2; + var min = margin; + var max = size - margin; + + var base64 = createGifData(size, size, function(x, y) { + if (min <= x && x < max && min <= y && y < max) { + var c = Math.floor( (x - min) / cellSize); + var r = Math.floor( (y - min) / cellSize); + return _this.isDark(r, c)? 0 : 1; + } else { + return 1; + } + } ); + + return { + src: 'data:image/gif;base64,' + base64, + width: size, + height: size + }; + }; + + return _this; + }; + + //--------------------------------------------------------------------- + // qrcode.stringToBytes + //--------------------------------------------------------------------- + + qrcode.stringToBytes = function(s) { + var bytes = new Array(); + for (var i = 0; i < s.length; i += 1) { + var c = s.charCodeAt(i); + bytes.push(c & 0xff); + } + return bytes; + }; + + //--------------------------------------------------------------------- + // qrcode.createStringToBytes + //--------------------------------------------------------------------- + + /** + * @param unicodeData base64 string of byte array. + * [16bit Unicode],[16bit Bytes], ... + * @param numChars + */ + qrcode.createStringToBytes = function(unicodeData, numChars) { + + // create conversion map. + + var unicodeMap = function() { + + var bin = base64DecodeInputStream(unicodeData); + var read = function() { + var b = bin.read(); + if (b == -1) throw new Error(); + return b; + }; + + var count = 0; + var unicodeMap = {}; + while (true) { + var b0 = bin.read(); + if (b0 == -1) break; + var b1 = read(); + var b2 = read(); + var b3 = read(); + var k = String.fromCharCode( (b0 << 8) | b1); + var v = (b2 << 8) | b3; + unicodeMap[k] = v; + count += 1; + } + if (count != numChars) { + throw new Error(count + ' != ' + numChars); + } + + return unicodeMap; + }(); + + var unknownChar = '?'.charCodeAt(0); + + return function(s) { + var bytes = new Array(); + for (var i = 0; i < s.length; i += 1) { + var c = s.charCodeAt(i); + if (c < 128) { + bytes.push(c); + } else { + var b = unicodeMap[s.charAt(i)]; + if (typeof b == 'number') { + if ( (b & 0xff) == b) { + // 1byte + bytes.push(b); + } else { + // 2bytes + bytes.push(b >>> 8); + bytes.push(b & 0xff); + } + } else { + bytes.push(unknownChar); + } + } + } + return bytes; + }; + }; + + //--------------------------------------------------------------------- + // QRMode + //--------------------------------------------------------------------- + + var QRMode = { + MODE_NUMBER : 1 << 0, + MODE_ALPHA_NUM : 1 << 1, + MODE_8BIT_BYTE : 1 << 2, + MODE_KANJI : 1 << 3 + }; + + //--------------------------------------------------------------------- + // QRErrorCorrectLevel + //--------------------------------------------------------------------- + + var QRErrorCorrectLevel = { + L : 1, + M : 0, + Q : 3, + H : 2 + }; + // mozilla: Add module support + exports.QRErrorCorrectLevel = QRErrorCorrectLevel; + + //--------------------------------------------------------------------- + // QRMaskPattern + //--------------------------------------------------------------------- + + var QRMaskPattern = { + PATTERN000 : 0, + PATTERN001 : 1, + PATTERN010 : 2, + PATTERN011 : 3, + PATTERN100 : 4, + PATTERN101 : 5, + PATTERN110 : 6, + PATTERN111 : 7 + }; + + //--------------------------------------------------------------------- + // QRUtil + //--------------------------------------------------------------------- + + var QRUtil = function() { + + var PATTERN_POSITION_TABLE = [ + [], + [6, 18], + [6, 22], + [6, 26], + [6, 30], + [6, 34], + [6, 22, 38], + [6, 24, 42], + [6, 26, 46], + [6, 28, 50], + [6, 30, 54], + [6, 32, 58], + [6, 34, 62], + [6, 26, 46, 66], + [6, 26, 48, 70], + [6, 26, 50, 74], + [6, 30, 54, 78], + [6, 30, 56, 82], + [6, 30, 58, 86], + [6, 34, 62, 90], + [6, 28, 50, 72, 94], + [6, 26, 50, 74, 98], + [6, 30, 54, 78, 102], + [6, 28, 54, 80, 106], + [6, 32, 58, 84, 110], + [6, 30, 58, 86, 114], + [6, 34, 62, 90, 118], + [6, 26, 50, 74, 98, 122], + [6, 30, 54, 78, 102, 126], + [6, 26, 52, 78, 104, 130], + [6, 30, 56, 82, 108, 134], + [6, 34, 60, 86, 112, 138], + [6, 30, 58, 86, 114, 142], + [6, 34, 62, 90, 118, 146], + [6, 30, 54, 78, 102, 126, 150], + [6, 24, 50, 76, 102, 128, 154], + [6, 28, 54, 80, 106, 132, 158], + [6, 32, 58, 84, 110, 136, 162], + [6, 26, 54, 82, 110, 138, 166], + [6, 30, 58, 86, 114, 142, 170] + ]; + var G15 = (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0); + var G18 = (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0); + var G15_MASK = (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1); + + var _this = {}; + + var getBCHDigit = function(data) { + var digit = 0; + while (data != 0) { + digit += 1; + data >>>= 1; + } + return digit; + }; + + _this.getBCHTypeInfo = function(data) { + var d = data << 10; + while (getBCHDigit(d) - getBCHDigit(G15) >= 0) { + d ^= (G15 << (getBCHDigit(d) - getBCHDigit(G15) ) ); + } + return ( (data << 10) | d) ^ G15_MASK; + }; + + _this.getBCHTypeNumber = function(data) { + var d = data << 12; + while (getBCHDigit(d) - getBCHDigit(G18) >= 0) { + d ^= (G18 << (getBCHDigit(d) - getBCHDigit(G18) ) ); + } + return (data << 12) | d; + }; + + _this.getPatternPosition = function(typeNumber) { + return PATTERN_POSITION_TABLE[typeNumber - 1]; + }; + + _this.getMaskFunction = function(maskPattern) { + + switch (maskPattern) { + + case QRMaskPattern.PATTERN000 : + return function(i, j) { return (i + j) % 2 == 0; }; + case QRMaskPattern.PATTERN001 : + return function(i, j) { return i % 2 == 0; }; + case QRMaskPattern.PATTERN010 : + return function(i, j) { return j % 3 == 0; }; + case QRMaskPattern.PATTERN011 : + return function(i, j) { return (i + j) % 3 == 0; }; + case QRMaskPattern.PATTERN100 : + return function(i, j) { return (Math.floor(i / 2) + Math.floor(j / 3) ) % 2 == 0; }; + case QRMaskPattern.PATTERN101 : + return function(i, j) { return (i * j) % 2 + (i * j) % 3 == 0; }; + case QRMaskPattern.PATTERN110 : + return function(i, j) { return ( (i * j) % 2 + (i * j) % 3) % 2 == 0; }; + case QRMaskPattern.PATTERN111 : + return function(i, j) { return ( (i * j) % 3 + (i + j) % 2) % 2 == 0; }; + + default : + throw new Error('bad maskPattern:' + maskPattern); + } + }; + + _this.getErrorCorrectPolynomial = function(errorCorrectLength) { + var a = qrPolynomial([1], 0); + for (var i = 0; i < errorCorrectLength; i += 1) { + a = a.multiply(qrPolynomial([1, QRMath.gexp(i)], 0) ); + } + return a; + }; + + _this.getLengthInBits = function(mode, type) { + + if (1 <= type && type < 10) { + + // 1 - 9 + + switch(mode) { + case QRMode.MODE_NUMBER : return 10; + case QRMode.MODE_ALPHA_NUM : return 9; + case QRMode.MODE_8BIT_BYTE : return 8; + case QRMode.MODE_KANJI : return 8; + default : + throw new Error('mode:' + mode); + } + + } else if (type < 27) { + + // 10 - 26 + + switch(mode) { + case QRMode.MODE_NUMBER : return 12; + case QRMode.MODE_ALPHA_NUM : return 11; + case QRMode.MODE_8BIT_BYTE : return 16; + case QRMode.MODE_KANJI : return 10; + default : + throw new Error('mode:' + mode); + } + + } else if (type < 41) { + + // 27 - 40 + + switch(mode) { + case QRMode.MODE_NUMBER : return 14; + case QRMode.MODE_ALPHA_NUM : return 13; + case QRMode.MODE_8BIT_BYTE : return 16; + case QRMode.MODE_KANJI : return 12; + default : + throw new Error('mode:' + mode); + } + + } else { + throw new Error('type:' + type); + } + }; + + _this.getLostPoint = function(qrcode) { + + var moduleCount = qrcode.getModuleCount(); + + var lostPoint = 0; + + // LEVEL1 + + for (var row = 0; row < moduleCount; row += 1) { + for (var col = 0; col < moduleCount; col += 1) { + + var sameCount = 0; + var dark = qrcode.isDark(row, col); + + for (var r = -1; r <= 1; r += 1) { + + if (row + r < 0 || moduleCount <= row + r) { + continue; + } + + for (var c = -1; c <= 1; c += 1) { + + if (col + c < 0 || moduleCount <= col + c) { + continue; + } + + if (r == 0 && c == 0) { + continue; + } + + if (dark == qrcode.isDark(row + r, col + c) ) { + sameCount += 1; + } + } + } + + if (sameCount > 5) { + lostPoint += (3 + sameCount - 5); + } + } + }; + + // LEVEL2 + + for (var row = 0; row < moduleCount - 1; row += 1) { + for (var col = 0; col < moduleCount - 1; col += 1) { + var count = 0; + if (qrcode.isDark(row, col) ) count += 1; + if (qrcode.isDark(row + 1, col) ) count += 1; + if (qrcode.isDark(row, col + 1) ) count += 1; + if (qrcode.isDark(row + 1, col + 1) ) count += 1; + if (count == 0 || count == 4) { + lostPoint += 3; + } + } + } + + // LEVEL3 + + for (var row = 0; row < moduleCount; row += 1) { + for (var col = 0; col < moduleCount - 6; col += 1) { + if (qrcode.isDark(row, col) + && !qrcode.isDark(row, col + 1) + && qrcode.isDark(row, col + 2) + && qrcode.isDark(row, col + 3) + && qrcode.isDark(row, col + 4) + && !qrcode.isDark(row, col + 5) + && qrcode.isDark(row, col + 6) ) { + lostPoint += 40; + } + } + } + + for (var col = 0; col < moduleCount; col += 1) { + for (var row = 0; row < moduleCount - 6; row += 1) { + if (qrcode.isDark(row, col) + && !qrcode.isDark(row + 1, col) + && qrcode.isDark(row + 2, col) + && qrcode.isDark(row + 3, col) + && qrcode.isDark(row + 4, col) + && !qrcode.isDark(row + 5, col) + && qrcode.isDark(row + 6, col) ) { + lostPoint += 40; + } + } + } + + // LEVEL4 + + var darkCount = 0; + + for (var col = 0; col < moduleCount; col += 1) { + for (var row = 0; row < moduleCount; row += 1) { + if (qrcode.isDark(row, col) ) { + darkCount += 1; + } + } + } + + var ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5; + lostPoint += ratio * 10; + + return lostPoint; + }; + + return _this; + }(); + + //--------------------------------------------------------------------- + // QRMath + //--------------------------------------------------------------------- + + var QRMath = function() { + + var EXP_TABLE = new Array(256); + var LOG_TABLE = new Array(256); + + // initialize tables + for (var i = 0; i < 8; i += 1) { + EXP_TABLE[i] = 1 << i; + } + for (var i = 8; i < 256; i += 1) { + EXP_TABLE[i] = EXP_TABLE[i - 4] + ^ EXP_TABLE[i - 5] + ^ EXP_TABLE[i - 6] + ^ EXP_TABLE[i - 8]; + } + for (var i = 0; i < 255; i += 1) { + LOG_TABLE[EXP_TABLE[i] ] = i; + } + + var _this = {}; + + _this.glog = function(n) { + + if (n < 1) { + throw new Error('glog(' + n + ')'); + } + + return LOG_TABLE[n]; + }; + + _this.gexp = function(n) { + + while (n < 0) { + n += 255; + } + + while (n >= 256) { + n -= 255; + } + + return EXP_TABLE[n]; + }; + + return _this; + }(); + + //--------------------------------------------------------------------- + // qrPolynomial + //--------------------------------------------------------------------- + + function qrPolynomial(num, shift) { + + if (typeof num.length == 'undefined') { + throw new Error(num.length + '/' + shift); + } + + var _num = function() { + var offset = 0; + while (offset < num.length && num[offset] == 0) { + offset += 1; + } + var _num = new Array(num.length - offset + shift); + for (var i = 0; i < num.length - offset; i += 1) { + _num[i] = num[i + offset]; + } + return _num; + }(); + + var _this = {}; + + _this.getAt = function(index) { + return _num[index]; + }; + + _this.getLength = function() { + return _num.length; + }; + + _this.multiply = function(e) { + + var num = new Array(_this.getLength() + e.getLength() - 1); + + for (var i = 0; i < _this.getLength(); i += 1) { + for (var j = 0; j < e.getLength(); j += 1) { + num[i + j] ^= QRMath.gexp(QRMath.glog(_this.getAt(i) ) + QRMath.glog(e.getAt(j) ) ); + } + } + + return qrPolynomial(num, 0); + }; + + _this.mod = function(e) { + + if (_this.getLength() - e.getLength() < 0) { + return _this; + } + + var ratio = QRMath.glog(_this.getAt(0) ) - QRMath.glog(e.getAt(0) ); + + var num = new Array(_this.getLength() ); + for (var i = 0; i < _this.getLength(); i += 1) { + num[i] = _this.getAt(i); + } + + for (var i = 0; i < e.getLength(); i += 1) { + num[i] ^= QRMath.gexp(QRMath.glog(e.getAt(i) ) + ratio); + } + + // recursive call + return qrPolynomial(num, 0).mod(e); + }; + + return _this; + }; + + //--------------------------------------------------------------------- + // QRRSBlock + //--------------------------------------------------------------------- + + var QRRSBlock = function() { + + var RS_BLOCK_TABLE = [ + + // L + // M + // Q + // H + + // 1 + [1, 26, 19], + [1, 26, 16], + [1, 26, 13], + [1, 26, 9], + + // 2 + [1, 44, 34], + [1, 44, 28], + [1, 44, 22], + [1, 44, 16], + + // 3 + [1, 70, 55], + [1, 70, 44], + [2, 35, 17], + [2, 35, 13], + + // 4 + [1, 100, 80], + [2, 50, 32], + [2, 50, 24], + [4, 25, 9], + + // 5 + [1, 134, 108], + [2, 67, 43], + [2, 33, 15, 2, 34, 16], + [2, 33, 11, 2, 34, 12], + + // 6 + [2, 86, 68], + [4, 43, 27], + [4, 43, 19], + [4, 43, 15], + + // 7 + [2, 98, 78], + [4, 49, 31], + [2, 32, 14, 4, 33, 15], + [4, 39, 13, 1, 40, 14], + + // 8 + [2, 121, 97], + [2, 60, 38, 2, 61, 39], + [4, 40, 18, 2, 41, 19], + [4, 40, 14, 2, 41, 15], + + // 9 + [2, 146, 116], + [3, 58, 36, 2, 59, 37], + [4, 36, 16, 4, 37, 17], + [4, 36, 12, 4, 37, 13], + + // 10 + [2, 86, 68, 2, 87, 69], + [4, 69, 43, 1, 70, 44], + [6, 43, 19, 2, 44, 20], + [6, 43, 15, 2, 44, 16] + ]; + + var qrRSBlock = function(totalCount, dataCount) { + var _this = {}; + _this.totalCount = totalCount; + _this.dataCount = dataCount; + return _this; + }; + + var _this = {}; + + var getRsBlockTable = function(typeNumber, errorCorrectLevel) { + + switch(errorCorrectLevel) { + case QRErrorCorrectLevel.L : + return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0]; + case QRErrorCorrectLevel.M : + return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1]; + case QRErrorCorrectLevel.Q : + return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2]; + case QRErrorCorrectLevel.H : + return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3]; + default : + return undefined; + } + }; + + _this.getRSBlocks = function(typeNumber, errorCorrectLevel) { + + var rsBlock = getRsBlockTable(typeNumber, errorCorrectLevel); + + if (typeof rsBlock == 'undefined') { + throw new Error('bad rs block @ typeNumber:' + typeNumber + + '/errorCorrectLevel:' + errorCorrectLevel); + } + + var length = rsBlock.length / 3; + + var list = new Array(); + + for (var i = 0; i < length; i += 1) { + + var count = rsBlock[i * 3 + 0]; + var totalCount = rsBlock[i * 3 + 1]; + var dataCount = rsBlock[i * 3 + 2]; + + for (var j = 0; j < count; j += 1) { + list.push(qrRSBlock(totalCount, dataCount) ); + } + } + + return list; + }; + + return _this; + }(); + + // mozilla: Add module support + exports.QRRSBlock = QRRSBlock; + + //--------------------------------------------------------------------- + // qrBitBuffer + //--------------------------------------------------------------------- + + var qrBitBuffer = function() { + + var _buffer = new Array(); + var _length = 0; + + var _this = {}; + + _this.getBuffer = function() { + return _buffer; + }; + + _this.getAt = function(index) { + var bufIndex = Math.floor(index / 8); + return ( (_buffer[bufIndex] >>> (7 - index % 8) ) & 1) == 1; + }; + + _this.put = function(num, length) { + for (var i = 0; i < length; i += 1) { + _this.putBit( ( (num >>> (length - i - 1) ) & 1) == 1); + } + }; + + _this.getLengthInBits = function() { + return _length; + }; + + _this.putBit = function(bit) { + + var bufIndex = Math.floor(_length / 8); + if (_buffer.length <= bufIndex) { + _buffer.push(0); + } + + if (bit) { + _buffer[bufIndex] |= (0x80 >>> (_length % 8) ); + } + + _length += 1; + }; + + return _this; + }; + + //--------------------------------------------------------------------- + // qr8BitByte + //--------------------------------------------------------------------- + + var qr8BitByte = function(data) { + + var _mode = QRMode.MODE_8BIT_BYTE; + var _data = data; + var _bytes = qrcode.stringToBytes(data); + + var _this = {}; + + _this.getMode = function() { + return _mode; + }; + + _this.getLength = function(buffer) { + return _bytes.length; + }; + + _this.write = function(buffer) { + for (var i = 0; i < _bytes.length; i += 1) { + buffer.put(_bytes[i], 8); + } + }; + + return _this; + }; + + //===================================================================== + // GIF Support etc. + // + + //--------------------------------------------------------------------- + // byteArrayOutputStream + //--------------------------------------------------------------------- + + var byteArrayOutputStream = function() { + + var _bytes = new Array(); + + var _this = {}; + + _this.writeByte = function(b) { + _bytes.push(b & 0xff); + }; + + _this.writeShort = function(i) { + _this.writeByte(i); + _this.writeByte(i >>> 8); + }; + + _this.writeBytes = function(b, off, len) { + off = off || 0; + len = len || b.length; + for (var i = 0; i < len; i += 1) { + _this.writeByte(b[i + off]); + } + }; + + _this.writeString = function(s) { + for (var i = 0; i < s.length; i += 1) { + _this.writeByte(s.charCodeAt(i) ); + } + }; + + _this.toByteArray = function() { + return _bytes; + }; + + _this.toString = function() { + var s = ''; + s += '['; + for (var i = 0; i < _bytes.length; i += 1) { + if (i > 0) { + s += ','; + } + s += _bytes[i]; + } + s += ']'; + return s; + }; + + return _this; + }; + + //--------------------------------------------------------------------- + // base64EncodeOutputStream + //--------------------------------------------------------------------- + + var base64EncodeOutputStream = function() { + + var _buffer = 0; + var _buflen = 0; + var _length = 0; + var _base64 = ''; + + var _this = {}; + + var writeEncoded = function(b) { + _base64 += String.fromCharCode(encode(b & 0x3f) ); + }; + + var encode = function(n) { + if (n < 0) { + // error. + } else if (n < 26) { + return 0x41 + n; + } else if (n < 52) { + return 0x61 + (n - 26); + } else if (n < 62) { + return 0x30 + (n - 52); + } else if (n == 62) { + return 0x2b; + } else if (n == 63) { + return 0x2f; + } + throw new Error('n:' + n); + }; + + _this.writeByte = function(n) { + + _buffer = (_buffer << 8) | (n & 0xff); + _buflen += 8; + _length += 1; + + while (_buflen >= 6) { + writeEncoded(_buffer >>> (_buflen - 6) ); + _buflen -= 6; + } + }; + + _this.flush = function() { + + if (_buflen > 0) { + writeEncoded(_buffer << (6 - _buflen) ); + _buffer = 0; + _buflen = 0; + } + + if (_length % 3 != 0) { + // padding + var padlen = 3 - _length % 3; + for (var i = 0; i < padlen; i += 1) { + _base64 += '='; + } + } + }; + + _this.toString = function() { + return _base64; + }; + + return _this; + }; + + //--------------------------------------------------------------------- + // base64DecodeInputStream + //--------------------------------------------------------------------- + + var base64DecodeInputStream = function(str) { + + var _str = str; + var _pos = 0; + var _buffer = 0; + var _buflen = 0; + + var _this = {}; + + _this.read = function() { + + while (_buflen < 8) { + + if (_pos >= _str.length) { + if (_buflen == 0) { + return -1; + } + throw new Error('unexpected end of file./' + _buflen); + } + + var c = _str.charAt(_pos); + _pos += 1; + + if (c == '=') { + _buflen = 0; + return -1; + } else if (c.match(/^\s$/) ) { + // ignore if whitespace. + continue; + } + + _buffer = (_buffer << 6) | decode(c.charCodeAt(0) ); + _buflen += 6; + } + + var n = (_buffer >>> (_buflen - 8) ) & 0xff; + _buflen -= 8; + return n; + }; + + var decode = function(c) { + if (0x41 <= c && c <= 0x5a) { + return c - 0x41; + } else if (0x61 <= c && c <= 0x7a) { + return c - 0x61 + 26; + } else if (0x30 <= c && c <= 0x39) { + return c - 0x30 + 52; + } else if (c == 0x2b) { + return 62; + } else if (c == 0x2f) { + return 63; + } else { + throw new Error('c:' + c); + } + }; + + return _this; + }; + + //--------------------------------------------------------------------- + // gifImage (B/W) + //--------------------------------------------------------------------- + + var gifImage = function(width, height) { + + var _width = width; + var _height = height; + var _data = new Array(width * height); + + var _this = {}; + + _this.setPixel = function(x, y, pixel) { + _data[y * _width + x] = pixel; + }; + + _this.write = function(out) { + + //--------------------------------- + // GIF Signature + + out.writeString('GIF87a'); + + //--------------------------------- + // Screen Descriptor + + out.writeShort(_width); + out.writeShort(_height); + + out.writeByte(0x80); // 2bit + out.writeByte(0); + out.writeByte(0); + + //--------------------------------- + // Global Color Map + + // black + out.writeByte(0x00); + out.writeByte(0x00); + out.writeByte(0x00); + + // white + out.writeByte(0xff); + out.writeByte(0xff); + out.writeByte(0xff); + + //--------------------------------- + // Image Descriptor + + out.writeString(','); + out.writeShort(0); + out.writeShort(0); + out.writeShort(_width); + out.writeShort(_height); + out.writeByte(0); + + //--------------------------------- + // Local Color Map + + //--------------------------------- + // Raster Data + + var lzwMinCodeSize = 2; + var raster = getLZWRaster(lzwMinCodeSize); + + out.writeByte(lzwMinCodeSize); + + var offset = 0; + + while (raster.length - offset > 255) { + out.writeByte(255); + out.writeBytes(raster, offset, 255); + offset += 255; + } + + out.writeByte(raster.length - offset); + out.writeBytes(raster, offset, raster.length - offset); + out.writeByte(0x00); + + //--------------------------------- + // GIF Terminator + out.writeString(';'); + }; + + var bitOutputStream = function(out) { + + var _out = out; + var _bitLength = 0; + var _bitBuffer = 0; + + var _this = {}; + + _this.write = function(data, length) { + + if ( (data >>> length) != 0) { + throw new Error('length over'); + } + + while (_bitLength + length >= 8) { + _out.writeByte(0xff & ( (data << _bitLength) | _bitBuffer) ); + length -= (8 - _bitLength); + data >>>= (8 - _bitLength); + _bitBuffer = 0; + _bitLength = 0; + } + + _bitBuffer = (data << _bitLength) | _bitBuffer; + _bitLength = _bitLength + length; + }; + + _this.flush = function() { + if (_bitLength > 0) { + _out.writeByte(_bitBuffer); + } + }; + + return _this; + }; + + var getLZWRaster = function(lzwMinCodeSize) { + + var clearCode = 1 << lzwMinCodeSize; + var endCode = (1 << lzwMinCodeSize) + 1; + var bitLength = lzwMinCodeSize + 1; + + // Setup LZWTable + var table = lzwTable(); + + for (var i = 0; i < clearCode; i += 1) { + table.add(String.fromCharCode(i) ); + } + table.add(String.fromCharCode(clearCode) ); + table.add(String.fromCharCode(endCode) ); + + var byteOut = byteArrayOutputStream(); + var bitOut = bitOutputStream(byteOut); + + // clear code + bitOut.write(clearCode, bitLength); + + var dataIndex = 0; + + var s = String.fromCharCode(_data[dataIndex]); + dataIndex += 1; + + while (dataIndex < _data.length) { + + var c = String.fromCharCode(_data[dataIndex]); + dataIndex += 1; + + if (table.contains(s + c) ) { + + s = s + c; + + } else { + + bitOut.write(table.indexOf(s), bitLength); + + if (table.size() < 0xfff) { + + if (table.size() == (1 << bitLength) ) { + bitLength += 1; + } + + table.add(s + c); + } + + s = c; + } + } + + bitOut.write(table.indexOf(s), bitLength); + + // end code + bitOut.write(endCode, bitLength); + + bitOut.flush(); + + return byteOut.toByteArray(); + }; + + var lzwTable = function() { + + var _map = {}; + var _size = 0; + + var _this = {}; + + _this.add = function(key) { + if (_this.contains(key) ) { + throw new Error('dup key:' + key); + } + _map[key] = _size; + _size += 1; + }; + + _this.size = function() { + return _size; + }; + + _this.indexOf = function(key) { + return _map[key]; + }; + + _this.contains = function(key) { + return typeof _map[key] != 'undefined'; + }; + + return _this; + }; + + return _this; + }; + + var createGifData = function(width, height, getPixel) { + + var gif = gifImage(width, height); + for (var y = 0; y < height; y += 1) { + for (var x = 0; x < width; x += 1) { + gif.setPixel(x, y, getPixel(x, y) ); + } + } + + var b = byteArrayOutputStream(); + gif.write(b); + + var base64 = base64EncodeOutputStream(); + var bytes = b.toByteArray(); + for (var i = 0; i < bytes.length; i += 1) { + base64.writeByte(bytes[i]); + } + base64.flush(); + return base64; + + }; + + var createImgTag = function(width, height, getPixel, alt) { + + var base64 = createGifData(width, height, getPixel); + var img = ''; + img += ' require("./encoder/index").Encoder +}); +Object.defineProperty(this, "QRRSBlock", { + get: () => require("./encoder/index").QRRSBlock +}); +Object.defineProperty(this, "QRErrorCorrectLevel", { + get: () => require("./encoder/index").QRErrorCorrectLevel +}); +Object.defineProperty(this, "decoder", { + get: () => { + // Some applications don't ship the decoder, see moz.build + try { + return require("./decoder/index"); + } catch (e) { + return null; + } + } +}); + +/** + * There are many "versions" of QR codes, which describes how many dots appear + * in the resulting image, thus limiting the amount of data that can be + * represented. + * + * The encoder used here allows for versions 1 - 10 (more dots for larger + * versions). + * + * It expects you to pick a version large enough to contain your message. Here + * we search for the mimimum version based on the message length. + * @param string message + * Text to encode + * @param string quality + * Quality level: L, M, Q, H + * @return integer + */ +exports.findMinimumVersion = function (message, quality) { + let msgLength = message.length; + let qualityLevel = QRErrorCorrectLevel[quality]; + for (let version = 1; version <= 10; version++) { + let rsBlocks = QRRSBlock.getRSBlocks(version, qualityLevel); + let maxLength = rsBlocks.reduce((prev, block) => { + return prev + block.dataCount; + }, 0); + // Remove two bytes to fit header info + maxLength -= 2; + if (msgLength <= maxLength) { + return version; + } + } + throw new Error("Message too large"); +}; + +/** + * Simple wrapper around the underlying encoder's API. + * @param string message + * Text to encode + * @param string quality (optional) + Quality level: L, M, Q, H + * @param integer version (optional) + * QR code "version" large enough to contain the message + * @return object with the following fields: + * * src: an image encoded a data URI + * * height: image height + * * width: image width + */ +exports.encodeToDataURI = function (message, quality, version) { + quality = quality || "H"; + version = version || exports.findMinimumVersion(message, quality); + let encoder = new Encoder(version, quality); + encoder.addData(message); + encoder.make(); + return encoder.createImgData(); +}; + +/** + * Simple wrapper around the underlying decoder's API. + * @param string URI + * URI of an image of a QR code + * @return Promise + * The promise will be resolved with a string, which is the data inside + * the QR code. + */ +exports.decodeFromURI = function (URI) { + if (!decoder) { + return promise.reject(); + } + let deferred = defer(); + decoder.decodeFromURI(URI, deferred.resolve, deferred.reject); + return deferred.promise; +}; + +/** + * Decode a QR code that has been drawn to a canvas element. + * @param Canvas canvas + * element to read from + * @return string + * The data inside the QR code + */ +exports.decodeFromCanvas = function (canvas) { + if (!decoder) { + throw new Error("Decoder not available"); + } + return decoder.decodeFromCanvas(canvas); +}; diff --git a/devtools/shared/qrcode/moz.build b/devtools/shared/qrcode/moz.build new file mode 100644 index 000000000..68a093b1c --- /dev/null +++ b/devtools/shared/qrcode/moz.build @@ -0,0 +1,22 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +DIRS += [ + 'encoder' +] + +# Save file size on Fennec until there are active plans to use the decoder there +if CONFIG['MOZ_BUILD_APP'] != 'mobile/android': + DIRS += [ + 'decoder' + ] + +DevToolsModules( + 'index.js', +) + +XPCSHELL_TESTS_MANIFESTS += ['tests/unit/xpcshell.ini'] +MOCHITEST_CHROME_MANIFESTS += ['tests/mochitest/chrome.ini'] diff --git a/devtools/shared/qrcode/tests/mochitest/chrome.ini b/devtools/shared/qrcode/tests/mochitest/chrome.ini new file mode 100644 index 000000000..f73f845e7 --- /dev/null +++ b/devtools/shared/qrcode/tests/mochitest/chrome.ini @@ -0,0 +1,5 @@ +[DEFAULT] +skip-if = os == 'android' +tags = devtools + +[test_decode.html] diff --git a/devtools/shared/qrcode/tests/mochitest/test_decode.html b/devtools/shared/qrcode/tests/mochitest/test_decode.html new file mode 100644 index 000000000..d7bf4dfb1 --- /dev/null +++ b/devtools/shared/qrcode/tests/mochitest/test_decode.html @@ -0,0 +1,68 @@ + + + + + + Test decoding a simple message + + + + + + +

+ +
+
+ + diff --git a/devtools/shared/qrcode/tests/unit/test_encode.js b/devtools/shared/qrcode/tests/unit/test_encode.js new file mode 100644 index 000000000..92455eb6a --- /dev/null +++ b/devtools/shared/qrcode/tests/unit/test_encode.js @@ -0,0 +1,27 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +/** + * Test encoding a simple message. + */ + +var { utils: Cu } = Components; +const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {}); + +const QR = require("devtools/shared/qrcode/index"); + +function run_test() { + let imgData = QR.encodeToDataURI("HELLO", "L"); + do_check_eq(imgData.src, + "data:image/gif;base64,R0lGODdhOgA6AIAAAAAAAP///ywAAAAAOgA6AAAC" + + "/4yPqcvtD6OctNqLs968+w+G4gKU5nkaKKquLuW+QVy2tAkDTj3rfQts8CRDko" + + "+HPPoYRUgy9YsyldDm44mLWhHYZM6W7WaDqyCRGkZDySxpRGw2sqvLt1q5w/fo" + + "XyE6vnUQOJUHBlinMGh046V1F5PDqNcoqcgBOWKBKbK2N+aY+Ih49VkmqMcl2l" + + "dkhZUK1umE6jZXJ2ZJaujZaRqH4bpb2uZrJxvIt4Ebe9qoYYrJOsw8apz2bCut" + + "m9kqDcw52uuImyr5Oh1KXH1jrn2anuunywtODU/o2c6teceW39ZcLFg/fNMo1b" + + "t3jVw2dwTPwJq1KYG3gAklCgu37yGxeScYKyiCc+7DR34hPVQiuQ7UhJMagyEb" + + "lymmzJk0a9q8iTOnzp0NCgAAOw=="); + do_check_eq(imgData.width, 58); + do_check_eq(imgData.height, 58); +} diff --git a/devtools/shared/qrcode/tests/unit/xpcshell.ini b/devtools/shared/qrcode/tests/unit/xpcshell.ini new file mode 100644 index 000000000..f265ea382 --- /dev/null +++ b/devtools/shared/qrcode/tests/unit/xpcshell.ini @@ -0,0 +1,7 @@ +[DEFAULT] +tags = devtools +head = +tail = +firefox-appdir = browser + +[test_encode.js] diff --git a/devtools/shared/security/auth.js b/devtools/shared/security/auth.js new file mode 100644 index 000000000..9272f602e --- /dev/null +++ b/devtools/shared/security/auth.js @@ -0,0 +1,653 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +var { Ci, Cc } = require("chrome"); +var Services = require("Services"); +var promise = require("promise"); +var defer = require("devtools/shared/defer"); +var DevToolsUtils = require("devtools/shared/DevToolsUtils"); +var { dumpn, dumpv } = DevToolsUtils; +loader.lazyRequireGetter(this, "prompt", + "devtools/shared/security/prompt"); +loader.lazyRequireGetter(this, "cert", + "devtools/shared/security/cert"); +loader.lazyRequireGetter(this, "asyncStorage", + "devtools/shared/async-storage"); +const { Task } = require("devtools/shared/task"); + +/** + * A simple enum-like object with keys mirrored to values. + * This makes comparison to a specfic value simpler without having to repeat and + * mis-type the value. + */ +function createEnum(obj) { + for (let key in obj) { + obj[key] = key; + } + return obj; +} + +/** + * |allowConnection| implementations can return various values as their |result| + * field to indicate what action to take. By specifying these, we can + * centralize the common actions available, while still allowing embedders to + * present their UI in whatever way they choose. + */ +var AuthenticationResult = exports.AuthenticationResult = createEnum({ + + /** + * Close all listening sockets, and disable them from opening again. + */ + DISABLE_ALL: null, + + /** + * Deny the current connection. + */ + DENY: null, + + /** + * Additional data needs to be exchanged before a result can be determined. + */ + PENDING: null, + + /** + * Allow the current connection. + */ + ALLOW: null, + + /** + * Allow the current connection, and persist this choice for future + * connections from the same client. This requires a trustable mechanism to + * identify the client in the future, such as the cert used during OOB_CERT. + */ + ALLOW_PERSIST: null + +}); + +/** + * An |Authenticator| implements an authentication mechanism via various hooks + * in the client and server debugger socket connection path (see socket.js). + * + * |Authenticator|s are stateless objects. Each hook method is passed the state + * it needs by the client / server code in socket.js. + * + * Separate instances of the |Authenticator| are created for each use (client + * connection, server listener) in case some methods are customized by the + * embedder for a given use case. + */ +var Authenticators = {}; + +/** + * The Prompt authenticator displays a server-side user prompt that includes + * connection details, and asks the user to verify the connection. There are + * no cryptographic properties at work here, so it is up to the user to be sure + * that the client can be trusted. + */ +var Prompt = Authenticators.Prompt = {}; + +Prompt.mode = "PROMPT"; + +Prompt.Client = function () {}; +Prompt.Client.prototype = { + + mode: Prompt.mode, + + /** + * When client is about to make a new connection, verify that the connection settings + * are compatible with this authenticator. + * @throws if validation requirements are not met + */ + validateSettings() {}, + + /** + * When client has just made a new socket connection, validate the connection + * to ensure it meets the authenticator's policies. + * + * @param host string + * The host name or IP address of the debugger server. + * @param port number + * The port number of the debugger server. + * @param encryption boolean (optional) + * Whether the server requires encryption. Defaults to false. + * @param cert object (optional) + * The server's cert details. + * @param s nsISocketTransport + * Underlying socket transport, in case more details are needed. + * @return boolean + * Whether the connection is valid. + */ + validateConnection() { + return true; + }, + + /** + * Work with the server to complete any additional steps required by this + * authenticator's policies. + * + * Debugging commences after this hook completes successfully. + * + * @param host string + * The host name or IP address of the debugger server. + * @param port number + * The port number of the debugger server. + * @param encryption boolean (optional) + * Whether the server requires encryption. Defaults to false. + * @param transport DebuggerTransport + * A transport that can be used to communicate with the server. + * @return A promise can be used if there is async behavior. + */ + authenticate() {}, + +}; + +Prompt.Server = function () {}; +Prompt.Server.prototype = { + + mode: Prompt.mode, + + /** + * Verify that listener settings are appropriate for this authentication mode. + * + * @param listener SocketListener + * The socket listener about to be opened. + * @throws if validation requirements are not met + */ + validateOptions() {}, + + /** + * Augment options on the listening socket about to be opened. + * + * @param listener SocketListener + * The socket listener about to be opened. + * @param socket nsIServerSocket + * The socket that is about to start listening. + */ + augmentSocketOptions() {}, + + /** + * Augment the service discovery advertisement with any additional data needed + * to support this authentication mode. + * + * @param listener SocketListener + * The socket listener that was just opened. + * @param advertisement object + * The advertisement being built. + */ + augmentAdvertisement(listener, advertisement) { + advertisement.authentication = Prompt.mode; + }, + + /** + * Determine whether a connection the server should be allowed or not based on + * this authenticator's policies. + * + * @param session object + * In PROMPT mode, the |session| includes: + * { + * client: { + * host, + * port + * }, + * server: { + * host, + * port + * }, + * transport + * } + * @return An AuthenticationResult value. + * A promise that will be resolved to the above is also allowed. + */ + authenticate({ client, server }) { + if (!Services.prefs.getBoolPref("devtools.debugger.prompt-connection")) { + return AuthenticationResult.ALLOW; + } + return this.allowConnection({ + authentication: this.mode, + client, + server + }); + }, + + /** + * Prompt the user to accept or decline the incoming connection. The default + * implementation is used unless this is overridden on a particular + * authenticator instance. + * + * It is expected that the implementation of |allowConnection| will show a + * prompt to the user so that they can allow or deny the connection. + * + * @param session object + * In PROMPT mode, the |session| includes: + * { + * authentication: "PROMPT", + * client: { + * host, + * port + * }, + * server: { + * host, + * port + * } + * } + * @return An AuthenticationResult value. + * A promise that will be resolved to the above is also allowed. + */ + allowConnection: prompt.Server.defaultAllowConnection, + +}; + +/** + * The out-of-band (OOB) cert authenticator is based on self-signed X.509 certs + * at both the client and server end. + * + * The user is first prompted to verify the connection, similar to the prompt + * method above. This prompt may display cert fingerprints if desired. + * + * Assuming the user approves the connection, further UI is used to assist the + * user in tranferring out-of-band (OOB) verification of the client's + * certificate. For example, this could take the form of a QR code that the + * client displays which is then scanned by a camera on the server. + * + * Since it is assumed that an attacker can't forge the client's X.509 cert, the + * user may also choose to always allow a client, which would permit immediate + * connections in the future with no user interaction needed. + * + * See docs/wifi.md for details of the authentication design. + */ +var OOBCert = Authenticators.OOBCert = {}; + +OOBCert.mode = "OOB_CERT"; + +OOBCert.Client = function () {}; +OOBCert.Client.prototype = { + + mode: OOBCert.mode, + + /** + * When client is about to make a new connection, verify that the connection settings + * are compatible with this authenticator. + * @throws if validation requirements are not met + */ + validateSettings({ encryption }) { + if (!encryption) { + throw new Error(`${OOBCert.mode} authentication requires encryption.`); + } + }, + + /** + * When client has just made a new socket connection, validate the connection + * to ensure it meets the authenticator's policies. + * + * @param host string + * The host name or IP address of the debugger server. + * @param port number + * The port number of the debugger server. + * @param encryption boolean (optional) + * Whether the server requires encryption. Defaults to false. + * @param cert object (optional) + * The server's cert details. + * @param socket nsISocketTransport + * Underlying socket transport, in case more details are needed. + * @return boolean + * Whether the connection is valid. + */ + validateConnection({ cert, socket }) { + // Step B.7 + // Client verifies that Server's cert matches hash(ServerCert) from the + // advertisement + dumpv("Validate server cert hash"); + let serverCert = socket.securityInfo.QueryInterface(Ci.nsISSLStatusProvider) + .SSLStatus.serverCert; + let advertisedCert = cert; + if (serverCert.sha256Fingerprint != advertisedCert.sha256) { + dumpn("Server cert hash doesn't match advertisement"); + return false; + } + return true; + }, + + /** + * Work with the server to complete any additional steps required by this + * authenticator's policies. + * + * Debugging commences after this hook completes successfully. + * + * @param host string + * The host name or IP address of the debugger server. + * @param port number + * The port number of the debugger server. + * @param encryption boolean (optional) + * Whether the server requires encryption. Defaults to false. + * @param cert object (optional) + * The server's cert details. + * @param transport DebuggerTransport + * A transport that can be used to communicate with the server. + * @return A promise can be used if there is async behavior. + */ + authenticate({ host, port, cert, transport }) { + let deferred = defer(); + let oobData; + + let activeSendDialog; + let closeDialog = () => { + // Close any prompts the client may have been showing from previous + // authentication steps + if (activeSendDialog && activeSendDialog.close) { + activeSendDialog.close(); + activeSendDialog = null; + } + }; + + transport.hooks = { + onPacket: Task.async(function* (packet) { + closeDialog(); + let { authResult } = packet; + switch (authResult) { + case AuthenticationResult.PENDING: + // Step B.8 + // Client creates hash(ClientCert) + K(random 128-bit number) + oobData = yield this._createOOB(); + activeSendDialog = this.sendOOB({ + host, + port, + cert, + authResult, + oob: oobData + }); + break; + case AuthenticationResult.ALLOW: + // Step B.12 + // Client verifies received value matches K + if (packet.k != oobData.k) { + transport.close(new Error("Auth secret mismatch")); + return; + } + // Step B.13 + // Debugging begins + transport.hooks = null; + deferred.resolve(transport); + break; + case AuthenticationResult.ALLOW_PERSIST: + // Server previously persisted Client as allowed + // Step C.5 + // Debugging begins + transport.hooks = null; + deferred.resolve(transport); + break; + default: + transport.close(new Error("Invalid auth result: " + authResult)); + return; + } + }.bind(this)), + onClosed(reason) { + closeDialog(); + // Transport died before auth completed + transport.hooks = null; + deferred.reject(reason); + } + }; + transport.ready(); + return deferred.promise; + }, + + /** + * Create the package of data that needs to be transferred across the OOB + * channel. + */ + _createOOB: Task.async(function* () { + let clientCert = yield cert.local.getOrCreate(); + return { + sha256: clientCert.sha256Fingerprint, + k: this._createRandom() + }; + }), + + _createRandom() { + const length = 16; // 16 bytes / 128 bits + let rng = Cc["@mozilla.org/security/random-generator;1"] + .createInstance(Ci.nsIRandomGenerator); + let bytes = rng.generateRandomBytes(length); + return bytes.map(byte => byte.toString(16)).join(""); + }, + + /** + * Send data across the OOB channel to the server to authenticate the devices. + * + * @param host string + * The host name or IP address of the debugger server. + * @param port number + * The port number of the debugger server. + * @param cert object (optional) + * The server's cert details. + * @param authResult AuthenticationResult + * Authentication result sent from the server. + * @param oob object (optional) + * The token data to be transferred during OOB_CERT step 8: + * * sha256: hash(ClientCert) + * * k : K(random 128-bit number) + * @return object containing: + * * close: Function to hide the notification + */ + sendOOB: prompt.Client.defaultSendOOB, + +}; + +OOBCert.Server = function () {}; +OOBCert.Server.prototype = { + + mode: OOBCert.mode, + + /** + * Verify that listener settings are appropriate for this authentication mode. + * + * @param listener SocketListener + * The socket listener about to be opened. + * @throws if validation requirements are not met + */ + validateOptions(listener) { + if (!listener.encryption) { + throw new Error(OOBCert.mode + " authentication requires encryption."); + } + }, + + /** + * Augment options on the listening socket about to be opened. + * + * @param listener SocketListener + * The socket listener about to be opened. + * @param socket nsIServerSocket + * The socket that is about to start listening. + */ + augmentSocketOptions(listener, socket) { + let requestCert = Ci.nsITLSServerSocket.REQUIRE_ALWAYS; + socket.setRequestClientCertificate(requestCert); + }, + + /** + * Augment the service discovery advertisement with any additional data needed + * to support this authentication mode. + * + * @param listener SocketListener + * The socket listener that was just opened. + * @param advertisement object + * The advertisement being built. + */ + augmentAdvertisement(listener, advertisement) { + advertisement.authentication = OOBCert.mode; + // Step A.4 + // Server announces itself via service discovery + // Announcement contains hash(ServerCert) as additional data + advertisement.cert = listener.cert; + }, + + /** + * Determine whether a connection the server should be allowed or not based on + * this authenticator's policies. + * + * @param session object + * In OOB_CERT mode, the |session| includes: + * { + * client: { + * host, + * port, + * cert: { + * sha256 + * }, + * }, + * server: { + * host, + * port, + * cert: { + * sha256 + * } + * }, + * transport + * } + * @return An AuthenticationResult value. + * A promise that will be resolved to the above is also allowed. + */ + authenticate: Task.async(function* ({ client, server, transport }) { + // Step B.3 / C.3 + // TLS connection established, authentication begins + const storageKey = `devtools.auth.${this.mode}.approved-clients`; + let approvedClients = (yield asyncStorage.getItem(storageKey)) || {}; + // Step C.4 + // Server sees that ClientCert is from a known client via hash(ClientCert) + if (approvedClients[client.cert.sha256]) { + let authResult = AuthenticationResult.ALLOW_PERSIST; + transport.send({ authResult }); + // Step C.5 + // Debugging begins + return authResult; + } + + // Step B.4 + // Server sees that ClientCert is from a unknown client + // Tell client they are unknown and should display OOB client UX + transport.send({ + authResult: AuthenticationResult.PENDING + }); + + // Step B.5 + // User is shown a Allow / Deny / Always Allow prompt on the Server + // with Client name and hash(ClientCert) + let authResult = yield this.allowConnection({ + authentication: this.mode, + client, + server + }); + + switch (authResult) { + case AuthenticationResult.ALLOW_PERSIST: + case AuthenticationResult.ALLOW: + break; // Further processing + default: + return authResult; // Abort for any negative results + } + + // Examine additional data for authentication + let oob = yield this.receiveOOB(); + if (!oob) { + dumpn("Invalid OOB data received"); + return AuthenticationResult.DENY; + } + + let { sha256, k } = oob; + // The OOB auth prompt should have transferred: + // hash(ClientCert) + K(random 128-bit number) + // from the client. + if (!sha256 || !k) { + dumpn("Invalid OOB data received"); + return AuthenticationResult.DENY; + } + + // Step B.10 + // Server verifies that Client's cert matches hash(ClientCert) from + // out-of-band channel + if (client.cert.sha256 != sha256) { + dumpn("Client cert hash doesn't match OOB data"); + return AuthenticationResult.DENY; + } + + // Step B.11 + // Server sends K to Client over TLS connection + transport.send({ authResult, k }); + + // Persist Client if we want to always allow in the future + if (authResult === AuthenticationResult.ALLOW_PERSIST) { + approvedClients[client.cert.sha256] = true; + yield asyncStorage.setItem(storageKey, approvedClients); + } + + // Client may decide to abort if K does not match. + // Server's portion of authentication is now complete. + + // Step B.13 + // Debugging begins + return authResult; + }), + + /** + * Prompt the user to accept or decline the incoming connection. The default + * implementation is used unless this is overridden on a particular + * authenticator instance. + * + * It is expected that the implementation of |allowConnection| will show a + * prompt to the user so that they can allow or deny the connection. + * + * @param session object + * In OOB_CERT mode, the |session| includes: + * { + * authentication: "OOB_CERT", + * client: { + * host, + * port, + * cert: { + * sha256 + * }, + * }, + * server: { + * host, + * port, + * cert: { + * sha256 + * } + * } + * } + * @return An AuthenticationResult value. + * A promise that will be resolved to the above is also allowed. + */ + allowConnection: prompt.Server.defaultAllowConnection, + + /** + * The user must transfer some data through some out of band mechanism from + * the client to the server to authenticate the devices. + * + * @return An object containing: + * * sha256: hash(ClientCert) + * * k : K(random 128-bit number) + * A promise that will be resolved to the above is also allowed. + */ + receiveOOB: prompt.Server.defaultReceiveOOB, + +}; + +exports.Authenticators = { + get(mode) { + if (!mode) { + mode = Prompt.mode; + } + for (let key in Authenticators) { + let auth = Authenticators[key]; + if (auth.mode === mode) { + return auth; + } + } + throw new Error("Unknown authenticator mode: " + mode); + } +}; diff --git a/devtools/shared/security/cert.js b/devtools/shared/security/cert.js new file mode 100644 index 000000000..7dbeded63 --- /dev/null +++ b/devtools/shared/security/cert.js @@ -0,0 +1,67 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +var { Ci, Cc } = require("chrome"); +var promise = require("promise"); +var defer = require("devtools/shared/defer"); +var DevToolsUtils = require("devtools/shared/DevToolsUtils"); +DevToolsUtils.defineLazyGetter(this, "localCertService", () => { + // Ensure PSM is initialized to support TLS sockets + Cc["@mozilla.org/psm;1"].getService(Ci.nsISupports); + return Cc["@mozilla.org/security/local-cert-service;1"] + .getService(Ci.nsILocalCertService); +}); + +const localCertName = "devtools"; + +exports.local = { + + /** + * Get or create a new self-signed X.509 cert to represent this device for + * DevTools purposes over a secure transport, like TLS. + * + * The cert is stored permanently in the profile's key store after first use, + * and is valid for 1 year. If an expired or otherwise invalid cert is found, + * it is removed and a new one is made. + * + * @return promise + */ + getOrCreate() { + let deferred = defer(); + localCertService.getOrCreateCert(localCertName, { + handleCert: function (cert, rv) { + if (rv) { + deferred.reject(rv); + return; + } + deferred.resolve(cert); + } + }); + return deferred.promise; + }, + + /** + * Remove the DevTools self-signed X.509 cert for this device. + * + * @return promise + */ + remove() { + let deferred = defer(); + localCertService.removeCert(localCertName, { + handleCert: function (rv) { + if (rv) { + deferred.reject(rv); + return; + } + deferred.resolve(); + } + }); + return deferred.promise; + } + +}; diff --git a/devtools/shared/security/docs/wifi.md b/devtools/shared/security/docs/wifi.md new file mode 100644 index 000000000..9ba94fc82 --- /dev/null +++ b/devtools/shared/security/docs/wifi.md @@ -0,0 +1,154 @@ +Overview +-------- + +### Remote Debugging Today + +Connecting to the Dev Tools debugging server on a remote device (like +B2G) via USB (which requires ADB) is too complex to setup and use. +Dealing with ADB is confusing, especially on Windows and Linux where +there are driver issues / udev rules to set up first. We have made +various attempts to simplify this and probably will continue to try our +best, but it doesn't seem like the UX will ever be great with ADB +involved. + +### Wi-Fi + +We're interested in making the debugging server available over Wi-Fi, +mainly in an attempt to simplify the UX. This of course presents new +security challenges to address, but we must also keep in mind that **if +our plan to address security results in a complex UX, then it may not be +a net gain over the USB & ADB route**. + +To be clear, we are not trying to expose ADB over Wi-Fi at all, only the +Dev Tools debugging server. + +### Security + +TLS is used to provide encryption of the data in transit. Both parties +use self-signed certs to identify themselves. There is a one-time setup +process to authenticate a new device. This is explained in many more +details later on in this document. + +Definitions +----------- + +- **Device / Server**: Firefox OS phone (or Fennec, remote Firefox, + etc.) +- **Computer / Client**: Machine running desktop Firefox w/ WebIDE + +Proposal +-------- + +This proposal uses TLS with self-signed certs to allow Clients to +connect to Servers through an encrypted, authenticated channel. After the +first connection from a new Client, the Client is saved on the Server +(if the user wants to always allow) and can connect freely in the future +(assuming Wi-Fi debugging is still enabled). + +### Default State + +The device does not listen over Wi-Fi at all by default. + +### Part A: Enabling Wi-Fi Debugging + +1. User goes to Developer menu on Device +2. User checks "DevTools over Wi-Fi" to enable the feature + - Persistent notification displayed in notification bar reminding + user that this is enabled + +3. Device begins listening on random TCP socket via Wi-Fi only +4. Device announces itself via service discovery + - Announcements only go to the local LAN / same subnet + - The announcement contains hash(DeviceCert) as additional data + +The Device remains listening as long as the feature is enabled. + +### Part B: Using Wi-Fi Debugging (new computer) + +Here are the details of connecting from a new computer to the device: + +1. Computer detects Device as available for connection via service + discovery +2. User chooses device to start connection on Computer +3. TLS connection established, authentication begins +4. Device sees that ComputerCert is from an unknown client (since it is + new) +5. User is shown an Allow / Deny / Always Allow prompt on the Device + with Computer name and hash(ComputerCert) + - If Deny is chosen, the connection is terminated and exponential + backoff begins (larger with each successive Deny) + - If Allow is chosen, the connection proceeds, but nothing is + stored for the future + - If Always Allow is chosen, the connection proceeds, and + hash(ComputerCert) is saved for future attempts + +6. Device waits for out-of-band data +7. Computer verifies that Device's cert matches hash(DeviceCert) from + the advertisement +8. Computer creates hash(ComputerCert) and K(random 128-bit number) +9. Out-of-band channel is used to move result of step 8 from Computer + to Device + - For Firefox Desktop -\> Firefox OS, Desktop will make a QR code, + and FxOS will scan it + - For non-mobile servers, some other approach is likely needed, + perhaps a short code form for the user to transfer + +10. Device verifies that Computer's cert matches hash(ComputerCert) from + out-of-band channel +11. Device sends K to Computer over the TLS connection +12. Computer verifies received value matches K +13. Debugging begins + +### Part C: Using Wi-Fi Debugging (known computer) + +Here are the details of connecting from a known computer (saved via +Always Allow) to the device: + +1. Computer detects Device as available for connection via service + discovery +2. User choose device to start connection on Computer +3. TLS connection established, authentication begins +4. Device sees that ComputerCert is from a known client via + hash(ComputerCert) +5. Debugging begins + +### Other Details + +- When there is a socket listening for connections, they will only be + accepted via Wi-Fi + - The socket will only listen on the external, Wi-Fi interface + - This is to ensure local apps can't connect to the socket +- Socket remains listening as long as the feature is enabled + +### UX + +This design seems convenient and of relatively low burden on the user. +If they choose to save the Computer for future connections, it becomes a +one click connection from Computer to Device, as it is over USB today. + +### Possible Attacks + +Someone could try to DoS the phone via many connection attempts. The +exponential backoff should mitigate this concern. ([bug +1022692](https://bugzilla.mozilla.org/show_bug.cgi?id=1022692)) + +### Comparison to ADB + +While it would be nice if we could instead leverage ADB here, that +doesn’t seem viable because: + +- ADB comes with a lot of setup / troubleshooting pain + - Users don’t understand it or why it is needed for us + - Each OS has several UX issues with ADB that make it annoying to + use +- ADB has a much larger attack surface area, simply because it has + many more lower level functions than the Developer Tools protocol we + are exposing here + +Acknowledgments +--------------- + +- J. Ryan Stinnett started this project from the DevTools team +- Brian Warner created many of the specific details of the authentication + protocol +- Trevor Perrin helped vet the authentication protocol diff --git a/devtools/shared/security/moz.build b/devtools/shared/security/moz.build new file mode 100644 index 000000000..f4fd1ca1a --- /dev/null +++ b/devtools/shared/security/moz.build @@ -0,0 +1,15 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +MOCHITEST_CHROME_MANIFESTS += ['tests/chrome/chrome.ini'] +XPCSHELL_TESTS_MANIFESTS += ['tests/unit/xpcshell.ini'] + +DevToolsModules( + 'auth.js', + 'cert.js', + 'prompt.js', + 'socket.js', +) diff --git a/devtools/shared/security/prompt.js b/devtools/shared/security/prompt.js new file mode 100644 index 000000000..aad9b7211 --- /dev/null +++ b/devtools/shared/security/prompt.js @@ -0,0 +1,179 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public +* License, v. 2.0. If a copy of the MPL was not distributed with this +* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +var { Ci } = require("chrome"); +var Services = require("Services"); +var DevToolsUtils = require("devtools/shared/DevToolsUtils"); +loader.lazyRequireGetter(this, "DebuggerSocket", + "devtools/shared/security/socket", true); +loader.lazyRequireGetter(this, "AuthenticationResult", + "devtools/shared/security/auth", true); + +const {LocalizationHelper} = require("devtools/shared/l10n"); +const L10N = new LocalizationHelper("devtools/shared/locales/debugger.properties"); + +var Client = exports.Client = {}; +var Server = exports.Server = {}; + +/** + * During OOB_CERT authentication, a notification dialog like this is used to + * to display a token which the user must transfer through some mechanism to the + * server to authenticate the devices. + * + * This implementation presents the token as text for the user to transfer + * manually. For a mobile device, you should override this implementation with + * something more convenient, such as displaying a QR code. + * + * @param host string + * The host name or IP address of the debugger server. + * @param port number + * The port number of the debugger server. + * @param cert object (optional) + * The server's cert details. + * @param authResult AuthenticationResult + * Authentication result sent from the server. + * @param oob object (optional) + * The token data to be transferred during OOB_CERT step 8: + * * sha256: hash(ClientCert) + * * k : K(random 128-bit number) + * @return object containing: + * * close: Function to hide the notification + */ +Client.defaultSendOOB = ({ authResult, oob }) => { + // Only show in the PENDING state + if (authResult != AuthenticationResult.PENDING) { + throw new Error("Expected PENDING result, got " + authResult); + } + let title = L10N.getStr("clientSendOOBTitle"); + let header = L10N.getStr("clientSendOOBHeader"); + let hashMsg = L10N.getFormatStr("clientSendOOBHash", oob.sha256); + let token = oob.sha256.replace(/:/g, "").toLowerCase() + oob.k; + let tokenMsg = L10N.getFormatStr("clientSendOOBToken", token); + let msg = `${header}\n\n${hashMsg}\n${tokenMsg}`; + let prompt = Services.prompt; + let flags = prompt.BUTTON_POS_0 * prompt.BUTTON_TITLE_CANCEL; + + // Listen for the window our prompt opens, so we can close it programatically + let promptWindow; + let windowListener = { + onOpenWindow(xulWindow) { + let win = xulWindow.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDOMWindow); + win.addEventListener("load", function listener() { + win.removeEventListener("load", listener, false); + if (win.document.documentElement.getAttribute("id") != "commonDialog") { + return; + } + // Found the window + promptWindow = win; + Services.wm.removeListener(windowListener); + }, false); + }, + onCloseWindow() {}, + onWindowTitleChange() {} + }; + Services.wm.addListener(windowListener); + + // nsIPrompt is typically a blocking API, so |executeSoon| to get around this + DevToolsUtils.executeSoon(() => { + prompt.confirmEx(null, title, msg, flags, null, null, null, null, + { value: false }); + }); + + return { + close() { + if (!promptWindow) { + return; + } + promptWindow.document.documentElement.acceptDialog(); + promptWindow = null; + } + }; +}; + +/** + * Prompt the user to accept or decline the incoming connection. This is the + * default implementation that products embedding the debugger server may + * choose to override. This can be overridden via |allowConnection| on the + * socket's authenticator instance. + * + * @param session object + * The session object will contain at least the following fields: + * { + * authentication, + * client: { + * host, + * port + * }, + * server: { + * host, + * port + * } + * } + * Specific authentication modes may include additional fields. Check + * the different |allowConnection| methods in ./auth.js. + * @return An AuthenticationResult value. + * A promise that will be resolved to the above is also allowed. + */ +Server.defaultAllowConnection = ({ client, server }) => { + let title = L10N.getStr("remoteIncomingPromptTitle"); + let header = L10N.getStr("remoteIncomingPromptHeader"); + let clientEndpoint = `${client.host}:${client.port}`; + let clientMsg = L10N.getFormatStr("remoteIncomingPromptClientEndpoint", clientEndpoint); + let serverEndpoint = `${server.host}:${server.port}`; + let serverMsg = L10N.getFormatStr("remoteIncomingPromptServerEndpoint", serverEndpoint); + let footer = L10N.getStr("remoteIncomingPromptFooter"); + let msg = `${header}\n\n${clientMsg}\n${serverMsg}\n\n${footer}`; + let disableButton = L10N.getStr("remoteIncomingPromptDisable"); + let prompt = Services.prompt; + let flags = prompt.BUTTON_POS_0 * prompt.BUTTON_TITLE_OK + + prompt.BUTTON_POS_1 * prompt.BUTTON_TITLE_CANCEL + + prompt.BUTTON_POS_2 * prompt.BUTTON_TITLE_IS_STRING + + prompt.BUTTON_POS_1_DEFAULT; + let result = prompt.confirmEx(null, title, msg, flags, null, null, + disableButton, null, { value: false }); + if (result === 0) { + return AuthenticationResult.ALLOW; + } + if (result === 2) { + return AuthenticationResult.DISABLE_ALL; + } + return AuthenticationResult.DENY; +}; + +/** + * During OOB_CERT authentication, the user must transfer some data through some + * out of band mechanism from the client to the server to authenticate the + * devices. + * + * This implementation prompts the user for a token as constructed by + * |Client.defaultSendOOB| that the user needs to transfer manually. For a + * mobile device, you should override this implementation with something more + * convenient, such as reading a QR code. + * + * @return An object containing: + * * sha256: hash(ClientCert) + * * k : K(random 128-bit number) + * A promise that will be resolved to the above is also allowed. + */ +Server.defaultReceiveOOB = () => { + let title = L10N.getStr("serverReceiveOOBTitle"); + let msg = L10N.getStr("serverReceiveOOBBody"); + let input = { value: null }; + let prompt = Services.prompt; + let result = prompt.prompt(null, title, msg, input, null, { value: false }); + if (!result) { + return null; + } + // Re-create original object from token + input = input.value.trim(); + let sha256 = input.substring(0, 64); + sha256 = sha256.replace(/\w{2}/g, "$&:").slice(0, -1).toUpperCase(); + let k = input.substring(64); + return { sha256, k }; +}; diff --git a/devtools/shared/security/socket.js b/devtools/shared/security/socket.js new file mode 100644 index 000000000..068a8ea81 --- /dev/null +++ b/devtools/shared/security/socket.js @@ -0,0 +1,793 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +var { Ci, Cc, CC, Cr, Cu } = require("chrome"); + +// Ensure PSM is initialized to support TLS sockets +Cc["@mozilla.org/psm;1"].getService(Ci.nsISupports); + +var Services = require("Services"); +var promise = require("promise"); +var defer = require("devtools/shared/defer"); +var DevToolsUtils = require("devtools/shared/DevToolsUtils"); +var { dumpn, dumpv } = DevToolsUtils; +loader.lazyRequireGetter(this, "WebSocketServer", + "devtools/server/websocket-server"); +loader.lazyRequireGetter(this, "DebuggerTransport", + "devtools/shared/transport/transport", true); +loader.lazyRequireGetter(this, "WebSocketDebuggerTransport", + "devtools/shared/transport/websocket-transport"); +loader.lazyRequireGetter(this, "DebuggerServer", + "devtools/server/main", true); +loader.lazyRequireGetter(this, "discovery", + "devtools/shared/discovery/discovery"); +loader.lazyRequireGetter(this, "cert", + "devtools/shared/security/cert"); +loader.lazyRequireGetter(this, "Authenticators", + "devtools/shared/security/auth", true); +loader.lazyRequireGetter(this, "AuthenticationResult", + "devtools/shared/security/auth", true); + +DevToolsUtils.defineLazyGetter(this, "nsFile", () => { + return CC("@mozilla.org/file/local;1", "nsIFile", "initWithPath"); +}); + +DevToolsUtils.defineLazyGetter(this, "socketTransportService", () => { + return Cc["@mozilla.org/network/socket-transport-service;1"] + .getService(Ci.nsISocketTransportService); +}); + +DevToolsUtils.defineLazyGetter(this, "certOverrideService", () => { + return Cc["@mozilla.org/security/certoverride;1"] + .getService(Ci.nsICertOverrideService); +}); + +DevToolsUtils.defineLazyGetter(this, "nssErrorsService", () => { + return Cc["@mozilla.org/nss_errors_service;1"] + .getService(Ci.nsINSSErrorsService); +}); + +const { Task } = require("devtools/shared/task"); + +var DebuggerSocket = {}; + +/** + * Connects to a debugger server socket. + * + * @param host string + * The host name or IP address of the debugger server. + * @param port number + * The port number of the debugger server. + * @param encryption boolean (optional) + * Whether the server requires encryption. Defaults to false. + * @param webSocket boolean (optional) + * Whether to use WebSocket protocol to connect. Defaults to false. + * @param authenticator Authenticator (optional) + * |Authenticator| instance matching the mode in use by the server. + * Defaults to a PROMPT instance if not supplied. + * @param cert object (optional) + * The server's cert details. Used with OOB_CERT authentication. + * @return promise + * Resolved to a DebuggerTransport instance. + */ +DebuggerSocket.connect = Task.async(function* (settings) { + // Default to PROMPT |Authenticator| instance if not supplied + if (!settings.authenticator) { + settings.authenticator = new (Authenticators.get().Client)(); + } + _validateSettings(settings); + let { host, port, encryption, authenticator, cert } = settings; + let transport = yield _getTransport(settings); + yield authenticator.authenticate({ + host, + port, + encryption, + cert, + transport + }); + transport.connectionSettings = settings; + return transport; +}); + +/** + * Validate that the connection settings have been set to a supported configuration. + */ +function _validateSettings(settings) { + let { encryption, webSocket, authenticator } = settings; + + if (webSocket && encryption) { + throw new Error("Encryption not supported on WebSocket transport"); + } + authenticator.validateSettings(settings); +} + +/** + * Try very hard to create a DevTools transport, potentially making several + * connect attempts in the process. + * + * @param host string + * The host name or IP address of the debugger server. + * @param port number + * The port number of the debugger server. + * @param encryption boolean (optional) + * Whether the server requires encryption. Defaults to false. + * @param webSocket boolean (optional) + * Whether to use WebSocket protocol to connect to the server. Defaults to false. + * @param authenticator Authenticator + * |Authenticator| instance matching the mode in use by the server. + * Defaults to a PROMPT instance if not supplied. + * @param cert object (optional) + * The server's cert details. Used with OOB_CERT authentication. + * @return transport DebuggerTransport + * A possible DevTools transport (if connection succeeded and streams + * are actually alive and working) + */ +var _getTransport = Task.async(function* (settings) { + let { host, port, encryption, webSocket } = settings; + + if (webSocket) { + // Establish a connection and wait until the WebSocket is ready to send and receive + let socket = yield new Promise((resolve, reject) => { + let s = new WebSocket(`ws://${host}:${port}`); + s.onopen = () => resolve(s); + s.onerror = err => reject(err); + }); + + return new WebSocketDebuggerTransport(socket); + } + + let attempt = yield _attemptTransport(settings); + if (attempt.transport) { + return attempt.transport; // Success + } + + // If the server cert failed validation, store a temporary override and make + // a second attempt. + if (encryption && attempt.certError) { + _storeCertOverride(attempt.s, host, port); + } else { + throw new Error("Connection failed"); + } + + attempt = yield _attemptTransport(settings); + if (attempt.transport) { + return attempt.transport; // Success + } + + throw new Error("Connection failed even after cert override"); +}); + +/** + * Make a single attempt to connect and create a DevTools transport. This could + * fail if the remote host is unreachable, for example. If there is security + * error due to the use of self-signed certs, you should make another attempt + * after storing a cert override. + * + * @param host string + * The host name or IP address of the debugger server. + * @param port number + * The port number of the debugger server. + * @param encryption boolean (optional) + * Whether the server requires encryption. Defaults to false. + * @param authenticator Authenticator + * |Authenticator| instance matching the mode in use by the server. + * Defaults to a PROMPT instance if not supplied. + * @param cert object (optional) + * The server's cert details. Used with OOB_CERT authentication. + * @return transport DebuggerTransport + * A possible DevTools transport (if connection succeeded and streams + * are actually alive and working) + * @return certError boolean + * Flag noting if cert trouble caused the streams to fail + * @return s nsISocketTransport + * Underlying socket transport, in case more details are needed. + */ +var _attemptTransport = Task.async(function* (settings) { + let { authenticator } = settings; + // _attemptConnect only opens the streams. Any failures at that stage + // aborts the connection process immedidately. + let { s, input, output } = yield _attemptConnect(settings); + + // Check if the input stream is alive. If encryption is enabled, we need to + // watch out for cert errors by testing the input stream. + let alive, certError; + try { + let results = yield _isInputAlive(input); + alive = results.alive; + certError = results.certError; + } catch (e) { + // For other unexpected errors, like NS_ERROR_CONNECTION_REFUSED, we reach + // this block. + input.close(); + output.close(); + throw e; + } + dumpv("Server cert accepted? " + !certError); + + // The |Authenticator| examines the connection as well and may determine it + // should be dropped. + alive = alive && authenticator.validateConnection({ + host: settings.host, + port: settings.port, + encryption: settings.encryption, + cert: settings.cert, + socket: s + }); + + let transport; + if (alive) { + transport = new DebuggerTransport(input, output); + } else { + // Something went wrong, close the streams. + input.close(); + output.close(); + } + + return { transport, certError, s }; +}); + +/** + * Try to connect to a remote server socket. + * + * If successsful, the socket transport and its opened streams are returned. + * Typically, this will only fail if the host / port is unreachable. Other + * problems, such as security errors, will allow this stage to succeed, but then + * fail later when the streams are actually used. + * @return s nsISocketTransport + * Underlying socket transport, in case more details are needed. + * @return input nsIAsyncInputStream + * The socket's input stream. + * @return output nsIAsyncOutputStream + * The socket's output stream. + */ +var _attemptConnect = Task.async(function* ({ host, port, encryption }) { + let s; + if (encryption) { + s = socketTransportService.createTransport(["ssl"], 1, host, port, null); + } else { + s = socketTransportService.createTransport(null, 0, host, port, null); + } + // By default the CONNECT socket timeout is very long, 65535 seconds, + // so that if we race to be in CONNECT state while the server socket is still + // initializing, the connection is stuck in connecting state for 18.20 hours! + s.setTimeout(Ci.nsISocketTransport.TIMEOUT_CONNECT, 2); + + // If encrypting, load the client cert now, so we can deliver it at just the + // right time. + let clientCert; + if (encryption) { + clientCert = yield cert.local.getOrCreate(); + } + + let deferred = defer(); + let input; + let output; + // Delay opening the input stream until the transport has fully connected. + // The goal is to avoid showing the user a client cert UI prompt when + // encryption is used. This prompt is shown when the client opens the input + // stream and does not know which client cert to present to the server. To + // specify a client cert programmatically, we need to access the transport's + // nsISSLSocketControl interface, which is not accessible until the transport + // has connected. + s.setEventSink({ + onTransportStatus(transport, status) { + if (status != Ci.nsISocketTransport.STATUS_CONNECTING_TO) { + return; + } + if (encryption) { + let sslSocketControl = + transport.securityInfo.QueryInterface(Ci.nsISSLSocketControl); + sslSocketControl.clientCert = clientCert; + } + try { + input = s.openInputStream(0, 0, 0); + } catch (e) { + deferred.reject(e); + } + deferred.resolve({ s, input, output }); + } + }, Services.tm.currentThread); + + // openOutputStream may throw NS_ERROR_NOT_INITIALIZED if we hit some race + // where the nsISocketTransport gets shutdown in between its instantiation and + // the call to this method. + try { + output = s.openOutputStream(0, 0, 0); + } catch (e) { + deferred.reject(e); + } + + deferred.promise.catch(e => { + if (input) { + input.close(); + } + if (output) { + output.close(); + } + DevToolsUtils.reportException("_attemptConnect", e); + }); + + return deferred.promise; +}); + +/** + * Check if the input stream is alive. For an encrypted connection, it may not + * be if the client refuses the server's cert. A cert error is expected on + * first connection to a new host because the cert is self-signed. + */ +function _isInputAlive(input) { + let deferred = defer(); + input.asyncWait({ + onInputStreamReady(stream) { + try { + stream.available(); + deferred.resolve({ alive: true }); + } catch (e) { + try { + // getErrorClass may throw if you pass a non-NSS error + let errorClass = nssErrorsService.getErrorClass(e.result); + if (errorClass === Ci.nsINSSErrorsService.ERROR_CLASS_BAD_CERT) { + deferred.resolve({ certError: true }); + } else { + deferred.reject(e); + } + } catch (nssErr) { + deferred.reject(e); + } + } + } + }, 0, 0, Services.tm.currentThread); + return deferred.promise; +} + +/** + * To allow the connection to proceed with self-signed cert, we store a cert + * override. This implies that we take on the burden of authentication for + * these connections. + */ +function _storeCertOverride(s, host, port) { + let cert = s.securityInfo.QueryInterface(Ci.nsISSLStatusProvider) + .SSLStatus.serverCert; + let overrideBits = Ci.nsICertOverrideService.ERROR_UNTRUSTED | + Ci.nsICertOverrideService.ERROR_MISMATCH; + certOverrideService.rememberValidityOverride(host, port, cert, overrideBits, + true /* temporary */); +} + +/** + * Creates a new socket listener for remote connections to the DebuggerServer. + * This helps contain and organize the parts of the server that may differ or + * are particular to one given listener mechanism vs. another. + */ +function SocketListener() {} + +SocketListener.prototype = { + + /* Socket Options */ + + /** + * The port or path to listen on. + * + * If given an integer, the port to listen on. Use -1 to choose any available + * port. Otherwise, the path to the unix socket domain file to listen on. + */ + portOrPath: null, + + /** + * Controls whether this listener is announced via the service discovery + * mechanism. + */ + discoverable: false, + + /** + * Controls whether this listener's transport uses encryption. + */ + encryption: false, + + /** + * Controls the |Authenticator| used, which hooks various socket steps to + * implement an authentication policy. It is expected that different use + * cases may override pieces of the |Authenticator|. See auth.js. + * + * Here we set the default |Authenticator|, which is |Prompt|. + */ + authenticator: new (Authenticators.get().Server)(), + + /** + * Validate that all options have been set to a supported configuration. + */ + _validateOptions: function () { + if (this.portOrPath === null) { + throw new Error("Must set a port / path to listen on."); + } + if (this.discoverable && !Number(this.portOrPath)) { + throw new Error("Discovery only supported for TCP sockets."); + } + if (this.encryption && this.webSocket) { + throw new Error("Encryption not supported on WebSocket transport"); + } + this.authenticator.validateOptions(this); + }, + + /** + * Listens on the given port or socket file for remote debugger connections. + */ + open: function () { + this._validateOptions(); + DebuggerServer._addListener(this); + + let flags = Ci.nsIServerSocket.KeepWhenOffline; + // A preference setting can force binding on the loopback interface. + if (Services.prefs.getBoolPref("devtools.debugger.force-local")) { + flags |= Ci.nsIServerSocket.LoopbackOnly; + } + + let self = this; + return Task.spawn(function* () { + let backlog = 4; + self._socket = self._createSocketInstance(); + if (self.isPortBased) { + let port = Number(self.portOrPath); + self._socket.initSpecialConnection(port, flags, backlog); + } else { + let file = nsFile(self.portOrPath); + if (file.exists()) { + file.remove(false); + } + self._socket.initWithFilename(file, parseInt("666", 8), backlog); + } + yield self._setAdditionalSocketOptions(); + self._socket.asyncListen(self); + dumpn("Socket listening on: " + (self.port || self.portOrPath)); + }).then(() => { + this._advertise(); + }).catch(e => { + dumpn("Could not start debugging listener on '" + this.portOrPath + + "': " + e); + this.close(); + }); + }, + + _advertise: function () { + if (!this.discoverable || !this.port) { + return; + } + + let advertisement = { + port: this.port, + encryption: this.encryption, + }; + + this.authenticator.augmentAdvertisement(this, advertisement); + + discovery.addService("devtools", advertisement); + }, + + _createSocketInstance: function () { + if (this.encryption) { + return Cc["@mozilla.org/network/tls-server-socket;1"] + .createInstance(Ci.nsITLSServerSocket); + } + return Cc["@mozilla.org/network/server-socket;1"] + .createInstance(Ci.nsIServerSocket); + }, + + _setAdditionalSocketOptions: Task.async(function* () { + if (this.encryption) { + this._socket.serverCert = yield cert.local.getOrCreate(); + this._socket.setSessionCache(false); + this._socket.setSessionTickets(false); + let requestCert = Ci.nsITLSServerSocket.REQUEST_NEVER; + this._socket.setRequestClientCertificate(requestCert); + } + this.authenticator.augmentSocketOptions(this, this._socket); + }), + + /** + * Closes the SocketListener. Notifies the server to remove the listener from + * the set of active SocketListeners. + */ + close: function () { + if (this.discoverable && this.port) { + discovery.removeService("devtools"); + } + if (this._socket) { + this._socket.close(); + this._socket = null; + } + DebuggerServer._removeListener(this); + }, + + get host() { + if (!this._socket) { + return null; + } + if (Services.prefs.getBoolPref("devtools.debugger.force-local")) { + return "127.0.0.1"; + } + return "0.0.0.0"; + }, + + /** + * Gets whether this listener uses a port number vs. a path. + */ + get isPortBased() { + return !!Number(this.portOrPath); + }, + + /** + * Gets the port that a TCP socket listener is listening on, or null if this + * is not a TCP socket (so there is no port). + */ + get port() { + if (!this.isPortBased || !this._socket) { + return null; + } + return this._socket.port; + }, + + get cert() { + if (!this._socket || !this._socket.serverCert) { + return null; + } + return { + sha256: this._socket.serverCert.sha256Fingerprint + }; + }, + + // nsIServerSocketListener implementation + + onSocketAccepted: + DevToolsUtils.makeInfallible(function (socket, socketTransport) { + new ServerSocketConnection(this, socketTransport); + }, "SocketListener.onSocketAccepted"), + + onStopListening: function (socket, status) { + dumpn("onStopListening, status: " + status); + } + +}; + +// Client must complete TLS handshake within this window (ms) +loader.lazyGetter(this, "HANDSHAKE_TIMEOUT", () => { + return Services.prefs.getIntPref("devtools.remote.tls-handshake-timeout"); +}); + +/** + * A |ServerSocketConnection| is created by a |SocketListener| for each accepted + * incoming socket. This is a short-lived object used to implement + * authentication and verify encryption prior to handing off the connection to + * the |DebuggerServer|. + */ +function ServerSocketConnection(listener, socketTransport) { + this._listener = listener; + this._socketTransport = socketTransport; + this._handle(); +} + +ServerSocketConnection.prototype = { + + get authentication() { + return this._listener.authenticator.mode; + }, + + get host() { + return this._socketTransport.host; + }, + + get port() { + return this._socketTransport.port; + }, + + get cert() { + if (!this._clientCert) { + return null; + } + return { + sha256: this._clientCert.sha256Fingerprint + }; + }, + + get address() { + return this.host + ":" + this.port; + }, + + get client() { + let client = { + host: this.host, + port: this.port + }; + if (this.cert) { + client.cert = this.cert; + } + return client; + }, + + get server() { + let server = { + host: this._listener.host, + port: this._listener.port + }; + if (this._listener.cert) { + server.cert = this._listener.cert; + } + return server; + }, + + /** + * This is the main authentication workflow. If any pieces reject a promise, + * the connection is denied. If the entire process resolves successfully, + * the connection is finally handed off to the |DebuggerServer|. + */ + _handle() { + dumpn("Debugging connection starting authentication on " + this.address); + let self = this; + Task.spawn(function* () { + self._listenForTLSHandshake(); + yield self._createTransport(); + yield self._awaitTLSHandshake(); + yield self._authenticate(); + }).then(() => this.allow()).catch(e => this.deny(e)); + }, + + /** + * We need to open the streams early on, as that is required in the case of + * TLS sockets to keep the handshake moving. + */ + _createTransport: Task.async(function* () { + let input = this._socketTransport.openInputStream(0, 0, 0); + let output = this._socketTransport.openOutputStream(0, 0, 0); + + if (this._listener.webSocket) { + let socket = yield WebSocketServer.accept(this._socketTransport, input, output); + this._transport = new WebSocketDebuggerTransport(socket); + } else { + this._transport = new DebuggerTransport(input, output); + } + + // Start up the transport to observe the streams in case they are closed + // early. This allows us to clean up our state as well. + this._transport.hooks = { + onClosed: reason => { + this.deny(reason); + } + }; + this._transport.ready(); + }), + + /** + * Set the socket's security observer, which receives an event via the + * |onHandshakeDone| callback when the TLS handshake completes. + */ + _setSecurityObserver(observer) { + if (!this._socketTransport || !this._socketTransport.securityInfo) { + return; + } + let connectionInfo = this._socketTransport.securityInfo + .QueryInterface(Ci.nsITLSServerConnectionInfo); + connectionInfo.setSecurityObserver(observer); + }, + + /** + * When encryption is used, we wait for the client to complete the TLS + * handshake before proceeding. The handshake details are validated in + * |onHandshakeDone|. + */ + _listenForTLSHandshake() { + this._handshakeDeferred = defer(); + if (!this._listener.encryption) { + this._handshakeDeferred.resolve(); + return; + } + this._setSecurityObserver(this); + this._handshakeTimeout = setTimeout(this._onHandshakeTimeout.bind(this), + HANDSHAKE_TIMEOUT); + }, + + _awaitTLSHandshake() { + return this._handshakeDeferred.promise; + }, + + _onHandshakeTimeout() { + dumpv("Client failed to complete TLS handshake"); + this._handshakeDeferred.reject(Cr.NS_ERROR_NET_TIMEOUT); + }, + + // nsITLSServerSecurityObserver implementation + onHandshakeDone(socket, clientStatus) { + clearTimeout(this._handshakeTimeout); + this._setSecurityObserver(null); + dumpv("TLS version: " + clientStatus.tlsVersionUsed.toString(16)); + dumpv("TLS cipher: " + clientStatus.cipherName); + dumpv("TLS key length: " + clientStatus.keyLength); + dumpv("TLS MAC length: " + clientStatus.macLength); + this._clientCert = clientStatus.peerCert; + /* + * TODO: These rules should be really be set on the TLS socket directly, but + * this would need more platform work to expose it via XPCOM. + * + * Enforcing cipher suites here would be a bad idea, as we want TLS + * cipher negotiation to work correctly. The server already allows only + * Gecko's normal set of cipher suites. + */ + if (clientStatus.tlsVersionUsed < Ci.nsITLSClientStatus.TLS_VERSION_1_2) { + this._handshakeDeferred.reject(Cr.NS_ERROR_CONNECTION_REFUSED); + return; + } + + this._handshakeDeferred.resolve(); + }, + + _authenticate: Task.async(function* () { + let result = yield this._listener.authenticator.authenticate({ + client: this.client, + server: this.server, + transport: this._transport + }); + switch (result) { + case AuthenticationResult.DISABLE_ALL: + DebuggerServer.closeAllListeners(); + Services.prefs.setBoolPref("devtools.debugger.remote-enabled", false); + return promise.reject(Cr.NS_ERROR_CONNECTION_REFUSED); + case AuthenticationResult.DENY: + return promise.reject(Cr.NS_ERROR_CONNECTION_REFUSED); + case AuthenticationResult.ALLOW: + case AuthenticationResult.ALLOW_PERSIST: + return promise.resolve(); + default: + return promise.reject(Cr.NS_ERROR_CONNECTION_REFUSED); + } + }), + + deny(result) { + if (this._destroyed) { + return; + } + let errorName = result; + for (let name in Cr) { + if (Cr[name] === result) { + errorName = name; + break; + } + } + dumpn("Debugging connection denied on " + this.address + + " (" + errorName + ")"); + if (this._transport) { + this._transport.hooks = null; + this._transport.close(result); + } + this._socketTransport.close(result); + this.destroy(); + }, + + allow() { + if (this._destroyed) { + return; + } + dumpn("Debugging connection allowed on " + this.address); + DebuggerServer._onConnection(this._transport); + this.destroy(); + }, + + destroy() { + this._destroyed = true; + clearTimeout(this._handshakeTimeout); + this._setSecurityObserver(null); + this._listener = null; + this._socketTransport = null; + this._transport = null; + this._clientCert = null; + } + +}; + +DebuggerSocket.createListener = function () { + return new SocketListener(); +}; + +exports.DebuggerSocket = DebuggerSocket; diff --git a/devtools/shared/security/tests/chrome/chrome.ini b/devtools/shared/security/tests/chrome/chrome.ini new file mode 100644 index 000000000..581251103 --- /dev/null +++ b/devtools/shared/security/tests/chrome/chrome.ini @@ -0,0 +1,4 @@ +[DEFAULT] +tags = devtools + +[test_websocket-transport.html] diff --git a/devtools/shared/security/tests/chrome/test_websocket-transport.html b/devtools/shared/security/tests/chrome/test_websocket-transport.html new file mode 100644 index 000000000..542206ecf --- /dev/null +++ b/devtools/shared/security/tests/chrome/test_websocket-transport.html @@ -0,0 +1,76 @@ + + + + + Test the WebSocket debugger transport + + + + + + + + diff --git a/devtools/shared/security/tests/unit/.eslintrc.js b/devtools/shared/security/tests/unit/.eslintrc.js new file mode 100644 index 000000000..59adf410a --- /dev/null +++ b/devtools/shared/security/tests/unit/.eslintrc.js @@ -0,0 +1,6 @@ +"use strict"; + +module.exports = { + // Extend from the common devtools xpcshell eslintrc config. + "extends": "../../../../.eslintrc.xpcshell.js" +}; diff --git a/devtools/shared/security/tests/unit/head_dbg.js b/devtools/shared/security/tests/unit/head_dbg.js new file mode 100644 index 000000000..f3b2a9a97 --- /dev/null +++ b/devtools/shared/security/tests/unit/head_dbg.js @@ -0,0 +1,96 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cu = Components.utils; +var Cr = Components.results; +var CC = Components.Constructor; + +const { require } = + Cu.import("resource://devtools/shared/Loader.jsm", {}); +const promise = require("promise"); +const defer = require("devtools/shared/defer"); +const { Task } = require("devtools/shared/task"); + +const Services = require("Services"); +const DevToolsUtils = require("devtools/shared/DevToolsUtils"); +const xpcInspector = require("xpcInspector"); +const { DebuggerServer } = require("devtools/server/main"); +const { DebuggerClient } = require("devtools/shared/client/main"); + +// We do not want to log packets by default, because in some tests, +// we can be sending large amounts of data. The test harness has +// trouble dealing with logging all the data, and we end up with +// intermittent time outs (e.g. bug 775924). +// Services.prefs.setBoolPref("devtools.debugger.log", true); +// Services.prefs.setBoolPref("devtools.debugger.log.verbose", true); +// Enable remote debugging for the relevant tests. +Services.prefs.setBoolPref("devtools.debugger.remote-enabled", true); +// Fast timeout for TLS tests +Services.prefs.setIntPref("devtools.remote.tls-handshake-timeout", 1000); + +// Convert an nsIScriptError 'aFlags' value into an appropriate string. +function scriptErrorFlagsToKind(aFlags) { + var kind; + if (aFlags & Ci.nsIScriptError.warningFlag) + kind = "warning"; + if (aFlags & Ci.nsIScriptError.exceptionFlag) + kind = "exception"; + else + kind = "error"; + + if (aFlags & Ci.nsIScriptError.strictFlag) + kind = "strict " + kind; + + return kind; +} + +// Register a console listener, so console messages don't just disappear +// into the ether. +var errorCount = 0; +var listener = { + observe: function (aMessage) { + errorCount++; + try { + // If we've been given an nsIScriptError, then we can print out + // something nicely formatted, for tools like Emacs to pick up. + var scriptError = aMessage.QueryInterface(Ci.nsIScriptError); + dump(aMessage.sourceName + ":" + aMessage.lineNumber + ": " + + scriptErrorFlagsToKind(aMessage.flags) + ": " + + aMessage.errorMessage + "\n"); + var string = aMessage.errorMessage; + } catch (x) { + // Be a little paranoid with message, as the whole goal here is to lose + // no information. + try { + var string = "" + aMessage.message; + } catch (x) { + var string = ""; + } + } + + // Make sure we exit all nested event loops so that the test can finish. + while (xpcInspector.eventLoopNestLevel > 0) { + xpcInspector.exitNestedEventLoop(); + } + + // Print in most cases, but ignore the "strict" messages + if (!(aMessage.flags & Ci.nsIScriptError.strictFlag)) { + do_print("head_dbg.js got console message: " + string + "\n"); + } + } +}; + +var consoleService = Cc["@mozilla.org/consoleservice;1"] + .getService(Ci.nsIConsoleService); +consoleService.registerListener(listener); + +/** + * Initialize the testing debugger server. + */ +function initTestDebuggerServer() { + DebuggerServer.registerModule("xpcshell-test/testactors"); + DebuggerServer.init(); +} diff --git a/devtools/shared/security/tests/unit/test_encryption.js b/devtools/shared/security/tests/unit/test_encryption.js new file mode 100644 index 000000000..e7fc80f5d --- /dev/null +++ b/devtools/shared/security/tests/unit/test_encryption.js @@ -0,0 +1,110 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test basic functionality of DevTools client and server TLS encryption mode +function run_test() { + // Need profile dir to store the key / cert + do_get_profile(); + // Ensure PSM is initialized + Cc["@mozilla.org/psm;1"].getService(Ci.nsISupports); + run_next_test(); +} + +function connectClient(client) { + let deferred = defer(); + client.connect(() => { + client.listTabs(deferred.resolve); + }); + return deferred.promise; +} + +add_task(function* () { + initTestDebuggerServer(); +}); + +// Client w/ encryption connects successfully to server w/ encryption +add_task(function* () { + equal(DebuggerServer.listeningSockets, 0, "0 listening sockets"); + + let AuthenticatorType = DebuggerServer.Authenticators.get("PROMPT"); + let authenticator = new AuthenticatorType.Server(); + authenticator.allowConnection = () => { + return DebuggerServer.AuthenticationResult.ALLOW; + }; + + let listener = DebuggerServer.createListener(); + ok(listener, "Socket listener created"); + listener.portOrPath = -1; + listener.authenticator = authenticator; + listener.encryption = true; + yield listener.open(); + equal(DebuggerServer.listeningSockets, 1, "1 listening socket"); + + let transport = yield DebuggerClient.socketConnect({ + host: "127.0.0.1", + port: listener.port, + encryption: true + }); + ok(transport, "Client transport created"); + + let client = new DebuggerClient(transport); + let onUnexpectedClose = () => { + do_throw("Closed unexpectedly"); + }; + client.addListener("closed", onUnexpectedClose); + yield connectClient(client); + + // Send a message the server will echo back + let message = "secrets"; + let reply = yield client.request({ + to: "root", + type: "echo", + message + }); + equal(reply.message, message, "Encrypted echo matches"); + + client.removeListener("closed", onUnexpectedClose); + transport.close(); + listener.close(); + equal(DebuggerServer.listeningSockets, 0, "0 listening sockets"); +}); + +// Client w/o encryption fails to connect to server w/ encryption +add_task(function* () { + equal(DebuggerServer.listeningSockets, 0, "0 listening sockets"); + + let AuthenticatorType = DebuggerServer.Authenticators.get("PROMPT"); + let authenticator = new AuthenticatorType.Server(); + authenticator.allowConnection = () => { + return DebuggerServer.AuthenticationResult.ALLOW; + }; + + let listener = DebuggerServer.createListener(); + ok(listener, "Socket listener created"); + listener.portOrPath = -1; + listener.authenticator = authenticator; + listener.encryption = true; + yield listener.open(); + equal(DebuggerServer.listeningSockets, 1, "1 listening socket"); + + try { + yield DebuggerClient.socketConnect({ + host: "127.0.0.1", + port: listener.port + // encryption: false is the default + }); + } catch (e) { + ok(true, "Client failed to connect as expected"); + listener.close(); + equal(DebuggerServer.listeningSockets, 0, "0 listening sockets"); + return; + } + + do_throw("Connection unexpectedly succeeded"); +}); + +add_task(function* () { + DebuggerServer.destroy(); +}); diff --git a/devtools/shared/security/tests/unit/test_oob_cert_auth.js b/devtools/shared/security/tests/unit/test_oob_cert_auth.js new file mode 100644 index 000000000..1e820af52 --- /dev/null +++ b/devtools/shared/security/tests/unit/test_oob_cert_auth.js @@ -0,0 +1,261 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +var cert = require("devtools/shared/security/cert"); + +// Test basic functionality of DevTools client and server OOB_CERT auth (used +// with WiFi debugging) +function run_test() { + // Need profile dir to store the key / cert + do_get_profile(); + // Ensure PSM is initialized + Cc["@mozilla.org/psm;1"].getService(Ci.nsISupports); + run_next_test(); +} + +function connectClient(client) { + return client.connect(() => { + return client.listTabs(); + }); +} + +add_task(function* () { + initTestDebuggerServer(); +}); + +// Client w/ OOB_CERT auth connects successfully to server w/ OOB_CERT auth +add_task(function* () { + equal(DebuggerServer.listeningSockets, 0, "0 listening sockets"); + + // Grab our cert, instead of relying on a discovery advertisement + let serverCert = yield cert.local.getOrCreate(); + + let oobData = defer(); + let AuthenticatorType = DebuggerServer.Authenticators.get("OOB_CERT"); + let serverAuth = new AuthenticatorType.Server(); + serverAuth.allowConnection = () => { + return DebuggerServer.AuthenticationResult.ALLOW; + }; + serverAuth.receiveOOB = () => oobData.promise; // Skip prompt for tests + + let listener = DebuggerServer.createListener(); + ok(listener, "Socket listener created"); + listener.portOrPath = -1; + listener.encryption = true; + listener.authenticator = serverAuth; + yield listener.open(); + equal(DebuggerServer.listeningSockets, 1, "1 listening socket"); + + let clientAuth = new AuthenticatorType.Client(); + clientAuth.sendOOB = ({ oob }) => { + do_print(oob); + // Pass to server, skipping prompt for tests + oobData.resolve(oob); + }; + + let transport = yield DebuggerClient.socketConnect({ + host: "127.0.0.1", + port: listener.port, + encryption: true, + authenticator: clientAuth, + cert: { + sha256: serverCert.sha256Fingerprint + } + }); + ok(transport, "Client transport created"); + + let client = new DebuggerClient(transport); + let onUnexpectedClose = () => { + do_throw("Closed unexpectedly"); + }; + client.addListener("closed", onUnexpectedClose); + yield connectClient(client); + + // Send a message the server will echo back + let message = "secrets"; + let reply = yield client.request({ + to: "root", + type: "echo", + message + }); + equal(reply.message, message, "Encrypted echo matches"); + + client.removeListener("closed", onUnexpectedClose); + transport.close(); + listener.close(); + equal(DebuggerServer.listeningSockets, 0, "0 listening sockets"); +}); + +// Client w/o OOB_CERT auth fails to connect to server w/ OOB_CERT auth +add_task(function* () { + equal(DebuggerServer.listeningSockets, 0, "0 listening sockets"); + + let oobData = defer(); + let AuthenticatorType = DebuggerServer.Authenticators.get("OOB_CERT"); + let serverAuth = new AuthenticatorType.Server(); + serverAuth.allowConnection = () => { + return DebuggerServer.AuthenticationResult.ALLOW; + }; + serverAuth.receiveOOB = () => oobData.promise; // Skip prompt for tests + + let listener = DebuggerServer.createListener(); + ok(listener, "Socket listener created"); + listener.portOrPath = -1; + listener.encryption = true; + listener.authenticator = serverAuth; + yield listener.open(); + equal(DebuggerServer.listeningSockets, 1, "1 listening socket"); + + // This will succeed, but leaves the client in confused state, and no data is + // actually accessible + let transport = yield DebuggerClient.socketConnect({ + host: "127.0.0.1", + port: listener.port, + encryption: true + // authenticator: PROMPT is the default + }); + + // Attempt to use the transport + let deferred = defer(); + let client = new DebuggerClient(transport); + client.onPacket = packet => { + // Client did not authenticate, so it ends up seeing the server's auth data + // which is effectively malformed data from the client's perspective + ok(!packet.from && packet.authResult, "Got auth packet instead of data"); + deferred.resolve(); + }; + client.connect(); + yield deferred.promise; + + // Try to send a message the server will echo back + let message = "secrets"; + try { + yield client.request({ + to: "root", + type: "echo", + message + }); + } catch (e) { + ok(true, "Sending a message failed"); + transport.close(); + listener.close(); + equal(DebuggerServer.listeningSockets, 0, "0 listening sockets"); + return; + } + + do_throw("Connection unexpectedly succeeded"); +}); + +// Client w/ invalid K value fails to connect +add_task(function* () { + equal(DebuggerServer.listeningSockets, 0, "0 listening sockets"); + + // Grab our cert, instead of relying on a discovery advertisement + let serverCert = yield cert.local.getOrCreate(); + + let oobData = defer(); + let AuthenticatorType = DebuggerServer.Authenticators.get("OOB_CERT"); + let serverAuth = new AuthenticatorType.Server(); + serverAuth.allowConnection = () => { + return DebuggerServer.AuthenticationResult.ALLOW; + }; + serverAuth.receiveOOB = () => oobData.promise; // Skip prompt for tests + + let clientAuth = new AuthenticatorType.Client(); + clientAuth.sendOOB = ({ oob }) => { + do_print(oob); + do_print("Modifying K value, should fail"); + // Pass to server, skipping prompt for tests + oobData.resolve({ + k: oob.k + 1, + sha256: oob.sha256 + }); + }; + + let listener = DebuggerServer.createListener(); + ok(listener, "Socket listener created"); + listener.portOrPath = -1; + listener.encryption = true; + listener.authenticator = serverAuth; + yield listener.open(); + equal(DebuggerServer.listeningSockets, 1, "1 listening socket"); + + try { + yield DebuggerClient.socketConnect({ + host: "127.0.0.1", + port: listener.port, + encryption: true, + authenticator: clientAuth, + cert: { + sha256: serverCert.sha256Fingerprint + } + }); + } catch (e) { + ok(true, "Client failed to connect as expected"); + listener.close(); + equal(DebuggerServer.listeningSockets, 0, "0 listening sockets"); + return; + } + + do_throw("Connection unexpectedly succeeded"); +}); + +// Client w/ invalid cert hash fails to connect +add_task(function* () { + equal(DebuggerServer.listeningSockets, 0, "0 listening sockets"); + + // Grab our cert, instead of relying on a discovery advertisement + let serverCert = yield cert.local.getOrCreate(); + + let oobData = defer(); + let AuthenticatorType = DebuggerServer.Authenticators.get("OOB_CERT"); + let serverAuth = new AuthenticatorType.Server(); + serverAuth.allowConnection = () => { + return DebuggerServer.AuthenticationResult.ALLOW; + }; + serverAuth.receiveOOB = () => oobData.promise; // Skip prompt for tests + + let clientAuth = new AuthenticatorType.Client(); + clientAuth.sendOOB = ({ oob }) => { + do_print(oob); + do_print("Modifying cert hash, should fail"); + // Pass to server, skipping prompt for tests + oobData.resolve({ + k: oob.k, + sha256: oob.sha256 + 1 + }); + }; + + let listener = DebuggerServer.createListener(); + ok(listener, "Socket listener created"); + listener.portOrPath = -1; + listener.encryption = true; + listener.authenticator = serverAuth; + yield listener.open(); + equal(DebuggerServer.listeningSockets, 1, "1 listening socket"); + + try { + yield DebuggerClient.socketConnect({ + host: "127.0.0.1", + port: listener.port, + encryption: true, + authenticator: clientAuth, + cert: { + sha256: serverCert.sha256Fingerprint + } + }); + } catch (e) { + ok(true, "Client failed to connect as expected"); + listener.close(); + equal(DebuggerServer.listeningSockets, 0, "0 listening sockets"); + return; + } + + do_throw("Connection unexpectedly succeeded"); +}); + +add_task(function* () { + DebuggerServer.destroy(); +}); diff --git a/devtools/shared/security/tests/unit/testactors.js b/devtools/shared/security/tests/unit/testactors.js new file mode 100644 index 000000000..80d5d4e18 --- /dev/null +++ b/devtools/shared/security/tests/unit/testactors.js @@ -0,0 +1,131 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +const { ActorPool, appendExtraActors, createExtraActors } = + require("devtools/server/actors/common"); +const { RootActor } = require("devtools/server/actors/root"); +const { ThreadActor } = require("devtools/server/actors/script"); +const { DebuggerServer } = require("devtools/server/main"); +const promise = require("promise"); + +var gTestGlobals = []; +DebuggerServer.addTestGlobal = function (aGlobal) { + gTestGlobals.push(aGlobal); +}; + +// A mock tab list, for use by tests. This simply presents each global in +// gTestGlobals as a tab, and the list is fixed: it never calls its +// onListChanged handler. +// +// As implemented now, we consult gTestGlobals when we're constructed, not +// when we're iterated over, so tests have to add their globals before the +// root actor is created. +function TestTabList(aConnection) { + this.conn = aConnection; + + // An array of actors for each global added with + // DebuggerServer.addTestGlobal. + this._tabActors = []; + + // A pool mapping those actors' names to the actors. + this._tabActorPool = new ActorPool(aConnection); + + for (let global of gTestGlobals) { + let actor = new TestTabActor(aConnection, global); + actor.selected = false; + this._tabActors.push(actor); + this._tabActorPool.addActor(actor); + } + if (this._tabActors.length > 0) { + this._tabActors[0].selected = true; + } + + aConnection.addActorPool(this._tabActorPool); +} + +TestTabList.prototype = { + constructor: TestTabList, + getList: function () { + return promise.resolve([...this._tabActors]); + } +}; + +function createRootActor(aConnection) { + let root = new RootActor(aConnection, { + tabList: new TestTabList(aConnection), + globalActorFactories: DebuggerServer.globalActorFactories + }); + root.applicationType = "xpcshell-tests"; + return root; +} + +function TestTabActor(aConnection, aGlobal) { + this.conn = aConnection; + this._global = aGlobal; + this._threadActor = new ThreadActor(this, this._global); + this.conn.addActor(this._threadActor); + this._attached = false; + this._extraActors = {}; +} + +TestTabActor.prototype = { + constructor: TestTabActor, + actorPrefix: "TestTabActor", + + get window() { + return { wrappedJSObject: this._global }; + }, + + get url() { + return this._global.__name; + }, + + form: function () { + let response = { actor: this.actorID, title: this._global.__name }; + + // Walk over tab actors added by extensions and add them to a new ActorPool. + let actorPool = new ActorPool(this.conn); + this._createExtraActors(DebuggerServer.tabActorFactories, actorPool); + if (!actorPool.isEmpty()) { + this._tabActorPool = actorPool; + this.conn.addActorPool(this._tabActorPool); + } + + this._appendExtraActors(response); + + return response; + }, + + onAttach: function (aRequest) { + this._attached = true; + + let response = { type: "tabAttached", threadActor: this._threadActor.actorID }; + this._appendExtraActors(response); + + return response; + }, + + onDetach: function (aRequest) { + if (!this._attached) { + return { "error":"wrongState" }; + } + return { type: "detached" }; + }, + + /* Support for DebuggerServer.addTabActor. */ + _createExtraActors: createExtraActors, + _appendExtraActors: appendExtraActors +}; + +TestTabActor.prototype.requestTypes = { + "attach": TestTabActor.prototype.onAttach, + "detach": TestTabActor.prototype.onDetach +}; + +exports.register = function (handle) { + handle.setRootActor(createRootActor); +}; + +exports.unregister = function (handle) { + handle.setRootActor(null); +}; diff --git a/devtools/shared/security/tests/unit/xpcshell.ini b/devtools/shared/security/tests/unit/xpcshell.ini new file mode 100644 index 000000000..f2b3e7151 --- /dev/null +++ b/devtools/shared/security/tests/unit/xpcshell.ini @@ -0,0 +1,12 @@ +[DEFAULT] +tags = devtools +head = head_dbg.js +tail = +firefox-appdir = browser + +support-files= + testactors.js + +[test_encryption.js] +[test_oob_cert_auth.js] +skip-if = (toolkit == 'android' && !debug) # Bug 1141544: Re-enable when buildbot tests are gone diff --git a/devtools/shared/shims/Console.jsm b/devtools/shared/shims/Console.jsm new file mode 100644 index 000000000..0bfdcb867 --- /dev/null +++ b/devtools/shared/shims/Console.jsm @@ -0,0 +1,35 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * This file only exists to support add-ons which import this module at a + * specific path. + */ + +const Cu = Components.utils; + +const { Services } = Cu.import("resource://gre/modules/Services.jsm", {}); + +const WARNING_PREF = "devtools.migration.warnings"; +if (Services.prefs.getBoolPref(WARNING_PREF)) { + const { Deprecated } = Cu.import("resource://gre/modules/Deprecated.jsm", {}); + Deprecated.warning("This path to Console.jsm is deprecated. Please use " + + "Cu.import(\"resource://gre/modules/Console.jsm\") " + + "to load this module.", + "https://bugzil.la/912121"); +} + +this.EXPORTED_SYMBOLS = [ + "console", + "ConsoleAPI" +]; + +const module = + Cu.import("resource://gre/modules/Console.jsm", {}); + +for (let symbol of this.EXPORTED_SYMBOLS) { + this[symbol] = module[symbol]; +} diff --git a/devtools/shared/shims/Loader.jsm b/devtools/shared/shims/Loader.jsm new file mode 100644 index 000000000..8504e08d0 --- /dev/null +++ b/devtools/shared/shims/Loader.jsm @@ -0,0 +1,38 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * This file only exists to support add-ons which import this module at a + * specific path. + */ + +const Cu = Components.utils; + +const { Services } = Cu.import("resource://gre/modules/Services.jsm", {}); + +const WARNING_PREF = "devtools.migration.warnings"; +if (Services.prefs.getBoolPref(WARNING_PREF)) { + const { Deprecated } = Cu.import("resource://gre/modules/Deprecated.jsm", {}); + Deprecated.warning("This path to Loader.jsm is deprecated. Please use " + + "Cu.import(\"resource://devtools/shared/" + + "Loader.jsm\") to load this module.", + "https://bugzil.la/912121"); +} + +this.EXPORTED_SYMBOLS = [ + "DevToolsLoader", + "devtools", + "BuiltinProvider", + "require", + "loader" +]; + +const module = + Cu.import("resource://devtools/shared/Loader.jsm", {}); + +for (let symbol of this.EXPORTED_SYMBOLS) { + this[symbol] = module[symbol]; +} diff --git a/devtools/shared/shims/Simulator.jsm b/devtools/shared/shims/Simulator.jsm new file mode 100644 index 000000000..7fd4fef53 --- /dev/null +++ b/devtools/shared/shims/Simulator.jsm @@ -0,0 +1,34 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * This file only exists to support add-ons which import this module at a + * specific path. + */ + +const Cu = Components.utils; + +const { Services } = Cu.import("resource://gre/modules/Services.jsm", {}); + +const WARNING_PREF = "devtools.migration.warnings"; +if (Services.prefs.getBoolPref(WARNING_PREF)) { + const { Deprecated } = Cu.import("resource://gre/modules/Deprecated.jsm", {}); + Deprecated.warning("This path to Simulator.jsm is deprecated. Please use " + + "Cu.import(\"resource://devtools/shared/" + + "apps/Simulator.jsm\") to load this module.", + "https://bugzil.la/912121"); +} + +this.EXPORTED_SYMBOLS = [ + "Simulator", +]; + +const module = + Cu.import("resource://devtools/shared/apps/Simulator.jsm", {}); + +for (let symbol of this.EXPORTED_SYMBOLS) { + this[symbol] = module[symbol]; +} diff --git a/devtools/shared/shims/dbg-client.jsm b/devtools/shared/shims/dbg-client.jsm new file mode 100644 index 000000000..ec3d500cd --- /dev/null +++ b/devtools/shared/shims/dbg-client.jsm @@ -0,0 +1,43 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * This file only exists to support add-ons which import this module at a + * specific path. + */ + +const Cu = Components.utils; + +const { Services } = Cu.import("resource://gre/modules/Services.jsm", {}); + +const WARNING_PREF = "devtools.migration.warnings"; +if (Services.prefs.getBoolPref(WARNING_PREF)) { + const { Deprecated } = Cu.import("resource://gre/modules/Deprecated.jsm", {}); + Deprecated.warning("dbg-client.jsm is deprecated. Please use " + + "require(\"devtools/shared/client/main\") to load this " + + "module.", "https://bugzil.la/912121"); +} + +const { require } = + Cu.import("resource://devtools/shared/Loader.jsm", {}); + +this.EXPORTED_SYMBOLS = ["DebuggerTransport", + "DebuggerClient", + "RootClient", + "LongStringClient", + "EnvironmentClient", + "ObjectClient"]; + +var client = require("devtools/shared/client/main"); + +this.DebuggerClient = client.DebuggerClient; +this.RootClient = client.RootClient; +this.LongStringClient = client.LongStringClient; +this.EnvironmentClient = client.EnvironmentClient; +this.ObjectClient = client.ObjectClient; + +this.DebuggerTransport = + require("devtools/shared/transport/transport").DebuggerTransport; diff --git a/devtools/shared/shims/event-emitter.js b/devtools/shared/shims/event-emitter.js new file mode 100644 index 000000000..6b3672162 --- /dev/null +++ b/devtools/shared/shims/event-emitter.js @@ -0,0 +1,42 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * This file only exists to support add-ons which import this module at a + * specific path. + */ + +(function (factory) { // Module boilerplate + if (this.module && module.id.indexOf("event-emitter") >= 0) { // require + factory.call(this, require, exports, module); + } else { // Cu.import + const Cu = Components.utils; + const { require } = + Cu.import("resource://devtools/shared/Loader.jsm", {}); + this.isWorker = false; + this.promise = Cu.import("resource://gre/modules/Promise.jsm", {}).Promise; + factory.call(this, require, this, { exports: this }); + this.EXPORTED_SYMBOLS = ["EventEmitter"]; + } +}).call(this, function (require, exports, module) { + const { Cu } = require("chrome"); + const Services = require("Services"); + const WARNING_PREF = "devtools.migration.warnings"; + // Cu and Services aren't accessible from workers + if (Cu && Services && Services.prefs && + Services.prefs.getBoolPref(WARNING_PREF)) { + const { Deprecated } = + Cu.import("resource://gre/modules/Deprecated.jsm", {}); + Deprecated.warning("This path to event-emitter.js is deprecated. Please " + + "use require(\"devtools/shared/event-emitter\") to " + + "load this module.", + "https://bugzil.la/912121"); + } + + const EventEmitter = require("devtools/shared/event-emitter"); + this.EventEmitter = EventEmitter; + module.exports = EventEmitter; +}); diff --git a/devtools/shared/shims/moz.build b/devtools/shared/shims/moz.build new file mode 100644 index 000000000..bee1c82ac --- /dev/null +++ b/devtools/shared/shims/moz.build @@ -0,0 +1,31 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +# Unlike most DevTools build files, this file does not use DevToolsModules +# because these files are here for add-on compatibility, and so they must be +# installed to previously defined locations. + +# These shims for legacy paths expect to be installed as if they were part of +# /toolkit modules. Disable any DIST_SUBDIR from parent files here. +DIST_SUBDIR = '' + +EXTRA_JS_MODULES.devtools += [ + 'Console.jsm', + 'dbg-client.jsm', + 'event-emitter.js', + 'Loader.jsm', + 'Simulator.jsm', +] + +# Extra compatibility layer for transitional URLs used for part of 44 cycle +EXTRA_JS_MODULES.devtools.shared += [ + 'Console.jsm', + 'Loader.jsm', +] + +EXTRA_JS_MODULES.devtools.shared.apps += [ + 'Simulator.jsm', +] diff --git a/devtools/shared/sourcemap/UPGRADING.md b/devtools/shared/sourcemap/UPGRADING.md new file mode 100644 index 000000000..5a257f7e4 --- /dev/null +++ b/devtools/shared/sourcemap/UPGRADING.md @@ -0,0 +1,13 @@ +Rather than make changes to the built files here, make them upstream and then +upgrade our tree's copy of the built files. + +To upgrade the source-map library: + + $ git clone https://github.com/mozilla/source-map.git + $ cd source-map + $ git checkout + $ npm install + $ npm run-script build -or- nodejs Makefile.dryice.js (if you have issues with npm) + $ cp dist/source-map.js /path/to/mozilla-central/devtools/shared/sourcemap/source-map.js + $ cp dist/test/* /path/to/mozilla-central/devtools/shared/sourcemap/tests/unit/ + diff --git a/devtools/shared/sourcemap/moz.build b/devtools/shared/sourcemap/moz.build new file mode 100644 index 000000000..459749645 --- /dev/null +++ b/devtools/shared/sourcemap/moz.build @@ -0,0 +1,11 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +XPCSHELL_TESTS_MANIFESTS += ['tests/unit/xpcshell.ini'] + +DevToolsModules( + 'source-map.js' +) diff --git a/devtools/shared/sourcemap/source-map.js b/devtools/shared/sourcemap/source-map.js new file mode 100644 index 000000000..45400893c --- /dev/null +++ b/devtools/shared/sourcemap/source-map.js @@ -0,0 +1,3006 @@ +(function webpackUniversalModuleDefinition(root, factory) { + if(typeof exports === 'object' && typeof module === 'object') + module.exports = factory(); + else if(typeof define === 'function' && define.amd) + define([], factory); + else if(typeof exports === 'object') + exports["sourceMap"] = factory(); + else + root["sourceMap"] = factory(); +})(this, function() { +return /******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; + +/******/ // The require function +/******/ function __webpack_require__(moduleId) { + +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; + +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; + +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); + +/******/ // Flag the module as loaded +/******/ module.loaded = true; + +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } + + +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; + +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; + +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; + +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + /* + * Copyright 2009-2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE.txt or: + * http://opensource.org/licenses/BSD-3-Clause + */ + exports.SourceMapGenerator = __webpack_require__(1).SourceMapGenerator; + exports.SourceMapConsumer = __webpack_require__(7).SourceMapConsumer; + exports.SourceNode = __webpack_require__(10).SourceNode; + + +/***/ }, +/* 1 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var base64VLQ = __webpack_require__(2); + var util = __webpack_require__(4); + var ArraySet = __webpack_require__(5).ArraySet; + var MappingList = __webpack_require__(6).MappingList; + + /** + * An instance of the SourceMapGenerator represents a source map which is + * being built incrementally. You may pass an object with the following + * properties: + * + * - file: The filename of the generated source. + * - sourceRoot: A root for all relative URLs in this source map. + */ + function SourceMapGenerator(aArgs) { + if (!aArgs) { + aArgs = {}; + } + this._file = util.getArg(aArgs, 'file', null); + this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null); + this._skipValidation = util.getArg(aArgs, 'skipValidation', false); + this._sources = new ArraySet(); + this._names = new ArraySet(); + this._mappings = new MappingList(); + this._sourcesContents = null; + } + + SourceMapGenerator.prototype._version = 3; + + /** + * Creates a new SourceMapGenerator based on a SourceMapConsumer + * + * @param aSourceMapConsumer The SourceMap. + */ + SourceMapGenerator.fromSourceMap = + function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) { + var sourceRoot = aSourceMapConsumer.sourceRoot; + var generator = new SourceMapGenerator({ + file: aSourceMapConsumer.file, + sourceRoot: sourceRoot + }); + aSourceMapConsumer.eachMapping(function (mapping) { + var newMapping = { + generated: { + line: mapping.generatedLine, + column: mapping.generatedColumn + } + }; + + if (mapping.source != null) { + newMapping.source = mapping.source; + if (sourceRoot != null) { + newMapping.source = util.relative(sourceRoot, newMapping.source); + } + + newMapping.original = { + line: mapping.originalLine, + column: mapping.originalColumn + }; + + if (mapping.name != null) { + newMapping.name = mapping.name; + } + } + + generator.addMapping(newMapping); + }); + aSourceMapConsumer.sources.forEach(function (sourceFile) { + var content = aSourceMapConsumer.sourceContentFor(sourceFile); + if (content != null) { + generator.setSourceContent(sourceFile, content); + } + }); + return generator; + }; + + /** + * Add a single mapping from original source line and column to the generated + * source's line and column for this source map being created. The mapping + * object should have the following properties: + * + * - generated: An object with the generated line and column positions. + * - original: An object with the original line and column positions. + * - source: The original source file (relative to the sourceRoot). + * - name: An optional original token name for this mapping. + */ + SourceMapGenerator.prototype.addMapping = + function SourceMapGenerator_addMapping(aArgs) { + var generated = util.getArg(aArgs, 'generated'); + var original = util.getArg(aArgs, 'original', null); + var source = util.getArg(aArgs, 'source', null); + var name = util.getArg(aArgs, 'name', null); + + if (!this._skipValidation) { + this._validateMapping(generated, original, source, name); + } + + if (source != null && !this._sources.has(source)) { + this._sources.add(source); + } + + if (name != null && !this._names.has(name)) { + this._names.add(name); + } + + this._mappings.add({ + generatedLine: generated.line, + generatedColumn: generated.column, + originalLine: original != null && original.line, + originalColumn: original != null && original.column, + source: source, + name: name + }); + }; + + /** + * Set the source content for a source file. + */ + SourceMapGenerator.prototype.setSourceContent = + function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) { + var source = aSourceFile; + if (this._sourceRoot != null) { + source = util.relative(this._sourceRoot, source); + } + + if (aSourceContent != null) { + // Add the source content to the _sourcesContents map. + // Create a new _sourcesContents map if the property is null. + if (!this._sourcesContents) { + this._sourcesContents = {}; + } + this._sourcesContents[util.toSetString(source)] = aSourceContent; + } else if (this._sourcesContents) { + // Remove the source file from the _sourcesContents map. + // If the _sourcesContents map is empty, set the property to null. + delete this._sourcesContents[util.toSetString(source)]; + if (Object.keys(this._sourcesContents).length === 0) { + this._sourcesContents = null; + } + } + }; + + /** + * Applies the mappings of a sub-source-map for a specific source file to the + * source map being generated. Each mapping to the supplied source file is + * rewritten using the supplied source map. Note: The resolution for the + * resulting mappings is the minimium of this map and the supplied map. + * + * @param aSourceMapConsumer The source map to be applied. + * @param aSourceFile Optional. The filename of the source file. + * If omitted, SourceMapConsumer's file property will be used. + * @param aSourceMapPath Optional. The dirname of the path to the source map + * to be applied. If relative, it is relative to the SourceMapConsumer. + * This parameter is needed when the two source maps aren't in the same + * directory, and the source map to be applied contains relative source + * paths. If so, those relative source paths need to be rewritten + * relative to the SourceMapGenerator. + */ + SourceMapGenerator.prototype.applySourceMap = + function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) { + var sourceFile = aSourceFile; + // If aSourceFile is omitted, we will use the file property of the SourceMap + if (aSourceFile == null) { + if (aSourceMapConsumer.file == null) { + throw new Error( + 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' + + 'or the source map\'s "file" property. Both were omitted.' + ); + } + sourceFile = aSourceMapConsumer.file; + } + var sourceRoot = this._sourceRoot; + // Make "sourceFile" relative if an absolute Url is passed. + if (sourceRoot != null) { + sourceFile = util.relative(sourceRoot, sourceFile); + } + // Applying the SourceMap can add and remove items from the sources and + // the names array. + var newSources = new ArraySet(); + var newNames = new ArraySet(); + + // Find mappings for the "sourceFile" + this._mappings.unsortedForEach(function (mapping) { + if (mapping.source === sourceFile && mapping.originalLine != null) { + // Check if it can be mapped by the source map, then update the mapping. + var original = aSourceMapConsumer.originalPositionFor({ + line: mapping.originalLine, + column: mapping.originalColumn + }); + if (original.source != null) { + // Copy mapping + mapping.source = original.source; + if (aSourceMapPath != null) { + mapping.source = util.join(aSourceMapPath, mapping.source) + } + if (sourceRoot != null) { + mapping.source = util.relative(sourceRoot, mapping.source); + } + mapping.originalLine = original.line; + mapping.originalColumn = original.column; + if (original.name != null) { + mapping.name = original.name; + } + } + } + + var source = mapping.source; + if (source != null && !newSources.has(source)) { + newSources.add(source); + } + + var name = mapping.name; + if (name != null && !newNames.has(name)) { + newNames.add(name); + } + + }, this); + this._sources = newSources; + this._names = newNames; + + // Copy sourcesContents of applied map. + aSourceMapConsumer.sources.forEach(function (sourceFile) { + var content = aSourceMapConsumer.sourceContentFor(sourceFile); + if (content != null) { + if (aSourceMapPath != null) { + sourceFile = util.join(aSourceMapPath, sourceFile); + } + if (sourceRoot != null) { + sourceFile = util.relative(sourceRoot, sourceFile); + } + this.setSourceContent(sourceFile, content); + } + }, this); + }; + + /** + * A mapping can have one of the three levels of data: + * + * 1. Just the generated position. + * 2. The Generated position, original position, and original source. + * 3. Generated and original position, original source, as well as a name + * token. + * + * To maintain consistency, we validate that any new mapping being added falls + * in to one of these categories. + */ + SourceMapGenerator.prototype._validateMapping = + function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource, + aName) { + if (aGenerated && 'line' in aGenerated && 'column' in aGenerated + && aGenerated.line > 0 && aGenerated.column >= 0 + && !aOriginal && !aSource && !aName) { + // Case 1. + return; + } + else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated + && aOriginal && 'line' in aOriginal && 'column' in aOriginal + && aGenerated.line > 0 && aGenerated.column >= 0 + && aOriginal.line > 0 && aOriginal.column >= 0 + && aSource) { + // Cases 2 and 3. + return; + } + else { + throw new Error('Invalid mapping: ' + JSON.stringify({ + generated: aGenerated, + source: aSource, + original: aOriginal, + name: aName + })); + } + }; + + /** + * Serialize the accumulated mappings in to the stream of base 64 VLQs + * specified by the source map format. + */ + SourceMapGenerator.prototype._serializeMappings = + function SourceMapGenerator_serializeMappings() { + var previousGeneratedColumn = 0; + var previousGeneratedLine = 1; + var previousOriginalColumn = 0; + var previousOriginalLine = 0; + var previousName = 0; + var previousSource = 0; + var result = ''; + var mapping; + var nameIdx; + var sourceIdx; + + var mappings = this._mappings.toArray(); + for (var i = 0, len = mappings.length; i < len; i++) { + mapping = mappings[i]; + + if (mapping.generatedLine !== previousGeneratedLine) { + previousGeneratedColumn = 0; + while (mapping.generatedLine !== previousGeneratedLine) { + result += ';'; + previousGeneratedLine++; + } + } + else { + if (i > 0) { + if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) { + continue; + } + result += ','; + } + } + + result += base64VLQ.encode(mapping.generatedColumn + - previousGeneratedColumn); + previousGeneratedColumn = mapping.generatedColumn; + + if (mapping.source != null) { + sourceIdx = this._sources.indexOf(mapping.source); + result += base64VLQ.encode(sourceIdx - previousSource); + previousSource = sourceIdx; + + // lines are stored 0-based in SourceMap spec version 3 + result += base64VLQ.encode(mapping.originalLine - 1 + - previousOriginalLine); + previousOriginalLine = mapping.originalLine - 1; + + result += base64VLQ.encode(mapping.originalColumn + - previousOriginalColumn); + previousOriginalColumn = mapping.originalColumn; + + if (mapping.name != null) { + nameIdx = this._names.indexOf(mapping.name); + result += base64VLQ.encode(nameIdx - previousName); + previousName = nameIdx; + } + } + } + + return result; + }; + + SourceMapGenerator.prototype._generateSourcesContent = + function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) { + return aSources.map(function (source) { + if (!this._sourcesContents) { + return null; + } + if (aSourceRoot != null) { + source = util.relative(aSourceRoot, source); + } + var key = util.toSetString(source); + return Object.prototype.hasOwnProperty.call(this._sourcesContents, + key) + ? this._sourcesContents[key] + : null; + }, this); + }; + + /** + * Externalize the source map. + */ + SourceMapGenerator.prototype.toJSON = + function SourceMapGenerator_toJSON() { + var map = { + version: this._version, + sources: this._sources.toArray(), + names: this._names.toArray(), + mappings: this._serializeMappings() + }; + if (this._file != null) { + map.file = this._file; + } + if (this._sourceRoot != null) { + map.sourceRoot = this._sourceRoot; + } + if (this._sourcesContents) { + map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot); + } + + return map; + }; + + /** + * Render the source map being generated to a string. + */ + SourceMapGenerator.prototype.toString = + function SourceMapGenerator_toString() { + return JSON.stringify(this.toJSON()); + }; + + exports.SourceMapGenerator = SourceMapGenerator; + } + + +/***/ }, +/* 2 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + * + * Based on the Base 64 VLQ implementation in Closure Compiler: + * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java + * + * Copyright 2011 The Closure Compiler Authors. All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + { + var base64 = __webpack_require__(3); + + // A single base 64 digit can contain 6 bits of data. For the base 64 variable + // length quantities we use in the source map spec, the first bit is the sign, + // the next four bits are the actual value, and the 6th bit is the + // continuation bit. The continuation bit tells us whether there are more + // digits in this value following this digit. + // + // Continuation + // | Sign + // | | + // V V + // 101011 + + var VLQ_BASE_SHIFT = 5; + + // binary: 100000 + var VLQ_BASE = 1 << VLQ_BASE_SHIFT; + + // binary: 011111 + var VLQ_BASE_MASK = VLQ_BASE - 1; + + // binary: 100000 + var VLQ_CONTINUATION_BIT = VLQ_BASE; + + /** + * Converts from a two-complement value to a value where the sign bit is + * placed in the least significant bit. For example, as decimals: + * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary) + * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary) + */ + function toVLQSigned(aValue) { + return aValue < 0 + ? ((-aValue) << 1) + 1 + : (aValue << 1) + 0; + } + + /** + * Converts to a two-complement value from a value where the sign bit is + * placed in the least significant bit. For example, as decimals: + * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1 + * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2 + */ + function fromVLQSigned(aValue) { + var isNegative = (aValue & 1) === 1; + var shifted = aValue >> 1; + return isNegative + ? -shifted + : shifted; + } + + /** + * Returns the base 64 VLQ encoded value. + */ + exports.encode = function base64VLQ_encode(aValue) { + var encoded = ""; + var digit; + + var vlq = toVLQSigned(aValue); + + do { + digit = vlq & VLQ_BASE_MASK; + vlq >>>= VLQ_BASE_SHIFT; + if (vlq > 0) { + // There are still more digits in this value, so we must make sure the + // continuation bit is marked. + digit |= VLQ_CONTINUATION_BIT; + } + encoded += base64.encode(digit); + } while (vlq > 0); + + return encoded; + }; + + /** + * Decodes the next base 64 VLQ value from the given string and returns the + * value and the rest of the string via the out parameter. + */ + exports.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) { + var strLen = aStr.length; + var result = 0; + var shift = 0; + var continuation, digit; + + do { + if (aIndex >= strLen) { + throw new Error("Expected more digits in base 64 VLQ value."); + } + + digit = base64.decode(aStr.charCodeAt(aIndex++)); + if (digit === -1) { + throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1)); + } + + continuation = !!(digit & VLQ_CONTINUATION_BIT); + digit &= VLQ_BASE_MASK; + result = result + (digit << shift); + shift += VLQ_BASE_SHIFT; + } while (continuation); + + aOutParam.value = fromVLQSigned(result); + aOutParam.rest = aIndex; + }; + } + + +/***/ }, +/* 3 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split(''); + + /** + * Encode an integer in the range of 0 to 63 to a single base 64 digit. + */ + exports.encode = function (number) { + if (0 <= number && number < intToCharMap.length) { + return intToCharMap[number]; + } + throw new TypeError("Must be between 0 and 63: " + number); + }; + + /** + * Decode a single base 64 character code digit to an integer. Returns -1 on + * failure. + */ + exports.decode = function (charCode) { + var bigA = 65; // 'A' + var bigZ = 90; // 'Z' + + var littleA = 97; // 'a' + var littleZ = 122; // 'z' + + var zero = 48; // '0' + var nine = 57; // '9' + + var plus = 43; // '+' + var slash = 47; // '/' + + var littleOffset = 26; + var numberOffset = 52; + + // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ + if (bigA <= charCode && charCode <= bigZ) { + return (charCode - bigA); + } + + // 26 - 51: abcdefghijklmnopqrstuvwxyz + if (littleA <= charCode && charCode <= littleZ) { + return (charCode - littleA + littleOffset); + } + + // 52 - 61: 0123456789 + if (zero <= charCode && charCode <= nine) { + return (charCode - zero + numberOffset); + } + + // 62: + + if (charCode == plus) { + return 62; + } + + // 63: / + if (charCode == slash) { + return 63; + } + + // Invalid base64 digit. + return -1; + }; + } + + +/***/ }, +/* 4 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + /** + * This is a helper function for getting values from parameter/options + * objects. + * + * @param args The object we are extracting values from + * @param name The name of the property we are getting. + * @param defaultValue An optional value to return if the property is missing + * from the object. If this is not specified and the property is missing, an + * error will be thrown. + */ + function getArg(aArgs, aName, aDefaultValue) { + if (aName in aArgs) { + return aArgs[aName]; + } else if (arguments.length === 3) { + return aDefaultValue; + } else { + throw new Error('"' + aName + '" is a required argument.'); + } + } + exports.getArg = getArg; + + var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.]*)(?::(\d+))?(\S*)$/; + var dataUrlRegexp = /^data:.+\,.+$/; + + function urlParse(aUrl) { + var match = aUrl.match(urlRegexp); + if (!match) { + return null; + } + return { + scheme: match[1], + auth: match[2], + host: match[3], + port: match[4], + path: match[5] + }; + } + exports.urlParse = urlParse; + + function urlGenerate(aParsedUrl) { + var url = ''; + if (aParsedUrl.scheme) { + url += aParsedUrl.scheme + ':'; + } + url += '//'; + if (aParsedUrl.auth) { + url += aParsedUrl.auth + '@'; + } + if (aParsedUrl.host) { + url += aParsedUrl.host; + } + if (aParsedUrl.port) { + url += ":" + aParsedUrl.port + } + if (aParsedUrl.path) { + url += aParsedUrl.path; + } + return url; + } + exports.urlGenerate = urlGenerate; + + /** + * Normalizes a path, or the path portion of a URL: + * + * - Replaces consequtive slashes with one slash. + * - Removes unnecessary '.' parts. + * - Removes unnecessary '/..' parts. + * + * Based on code in the Node.js 'path' core module. + * + * @param aPath The path or url to normalize. + */ + function normalize(aPath) { + var path = aPath; + var url = urlParse(aPath); + if (url) { + if (!url.path) { + return aPath; + } + path = url.path; + } + var isAbsolute = exports.isAbsolute(path); + + var parts = path.split(/\/+/); + for (var part, up = 0, i = parts.length - 1; i >= 0; i--) { + part = parts[i]; + if (part === '.') { + parts.splice(i, 1); + } else if (part === '..') { + up++; + } else if (up > 0) { + if (part === '') { + // The first part is blank if the path is absolute. Trying to go + // above the root is a no-op. Therefore we can remove all '..' parts + // directly after the root. + parts.splice(i + 1, up); + up = 0; + } else { + parts.splice(i, 2); + up--; + } + } + } + path = parts.join('/'); + + if (path === '') { + path = isAbsolute ? '/' : '.'; + } + + if (url) { + url.path = path; + return urlGenerate(url); + } + return path; + } + exports.normalize = normalize; + + /** + * Joins two paths/URLs. + * + * @param aRoot The root path or URL. + * @param aPath The path or URL to be joined with the root. + * + * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a + * scheme-relative URL: Then the scheme of aRoot, if any, is prepended + * first. + * - Otherwise aPath is a path. If aRoot is a URL, then its path portion + * is updated with the result and aRoot is returned. Otherwise the result + * is returned. + * - If aPath is absolute, the result is aPath. + * - Otherwise the two paths are joined with a slash. + * - Joining for example 'http://' and 'www.example.com' is also supported. + */ + function join(aRoot, aPath) { + if (aRoot === "") { + aRoot = "."; + } + if (aPath === "") { + aPath = "."; + } + var aPathUrl = urlParse(aPath); + var aRootUrl = urlParse(aRoot); + if (aRootUrl) { + aRoot = aRootUrl.path || '/'; + } + + // `join(foo, '//www.example.org')` + if (aPathUrl && !aPathUrl.scheme) { + if (aRootUrl) { + aPathUrl.scheme = aRootUrl.scheme; + } + return urlGenerate(aPathUrl); + } + + if (aPathUrl || aPath.match(dataUrlRegexp)) { + return aPath; + } + + // `join('http://', 'www.example.com')` + if (aRootUrl && !aRootUrl.host && !aRootUrl.path) { + aRootUrl.host = aPath; + return urlGenerate(aRootUrl); + } + + var joined = aPath.charAt(0) === '/' + ? aPath + : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath); + + if (aRootUrl) { + aRootUrl.path = joined; + return urlGenerate(aRootUrl); + } + return joined; + } + exports.join = join; + + exports.isAbsolute = function (aPath) { + return aPath.charAt(0) === '/' || !!aPath.match(urlRegexp); + }; + + /** + * Make a path relative to a URL or another path. + * + * @param aRoot The root path or URL. + * @param aPath The path or URL to be made relative to aRoot. + */ + function relative(aRoot, aPath) { + if (aRoot === "") { + aRoot = "."; + } + + aRoot = aRoot.replace(/\/$/, ''); + + // It is possible for the path to be above the root. In this case, simply + // checking whether the root is a prefix of the path won't work. Instead, we + // need to remove components from the root one by one, until either we find + // a prefix that fits, or we run out of components to remove. + var level = 0; + while (aPath.indexOf(aRoot + '/') !== 0) { + var index = aRoot.lastIndexOf("/"); + if (index < 0) { + return aPath; + } + + // If the only part of the root that is left is the scheme (i.e. http://, + // file:///, etc.), one or more slashes (/), or simply nothing at all, we + // have exhausted all components, so the path is not relative to the root. + aRoot = aRoot.slice(0, index); + if (aRoot.match(/^([^\/]+:\/)?\/*$/)) { + return aPath; + } + + ++level; + } + + // Make sure we add a "../" for each component we removed from the root. + return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1); + } + exports.relative = relative; + + /** + * Because behavior goes wacky when you set `__proto__` on objects, we + * have to prefix all the strings in our set with an arbitrary character. + * + * See https://github.com/mozilla/source-map/pull/31 and + * https://github.com/mozilla/source-map/issues/30 + * + * @param String aStr + */ + function toSetString(aStr) { + return '$' + aStr; + } + exports.toSetString = toSetString; + + function fromSetString(aStr) { + return aStr.substr(1); + } + exports.fromSetString = fromSetString; + + /** + * Comparator between two mappings where the original positions are compared. + * + * Optionally pass in `true` as `onlyCompareGenerated` to consider two + * mappings with the same original source/line/column, but different generated + * line and column the same. Useful when searching for a mapping with a + * stubbed out mapping. + */ + function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) { + var cmp = mappingA.source - mappingB.source; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0 || onlyCompareOriginal) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + return mappingA.name - mappingB.name; + } + exports.compareByOriginalPositions = compareByOriginalPositions; + + /** + * Comparator between two mappings with deflated source and name indices where + * the generated positions are compared. + * + * Optionally pass in `true` as `onlyCompareGenerated` to consider two + * mappings with the same generated line and column, but different + * source/name/original line and column the same. Useful when searching for a + * mapping with a stubbed out mapping. + */ + function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) { + var cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0 || onlyCompareGenerated) { + return cmp; + } + + cmp = mappingA.source - mappingB.source; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0) { + return cmp; + } + + return mappingA.name - mappingB.name; + } + exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated; + + function strcmp(aStr1, aStr2) { + if (aStr1 === aStr2) { + return 0; + } + + if (aStr1 > aStr2) { + return 1; + } + + return -1; + } + + /** + * Comparator between two mappings with inflated source and name strings where + * the generated positions are compared. + */ + function compareByGeneratedPositionsInflated(mappingA, mappingB) { + var cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0) { + return cmp; + } + + cmp = strcmp(mappingA.source, mappingB.source); + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0) { + return cmp; + } + + return strcmp(mappingA.name, mappingB.name); + } + exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated; + } + + +/***/ }, +/* 5 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var util = __webpack_require__(4); + + /** + * A data structure which is a combination of an array and a set. Adding a new + * member is O(1), testing for membership is O(1), and finding the index of an + * element is O(1). Removing elements from the set is not supported. Only + * strings are supported for membership. + */ + function ArraySet() { + this._array = []; + this._set = {}; + } + + /** + * Static method for creating ArraySet instances from an existing array. + */ + ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) { + var set = new ArraySet(); + for (var i = 0, len = aArray.length; i < len; i++) { + set.add(aArray[i], aAllowDuplicates); + } + return set; + }; + + /** + * Return how many unique items are in this ArraySet. If duplicates have been + * added, than those do not count towards the size. + * + * @returns Number + */ + ArraySet.prototype.size = function ArraySet_size() { + return Object.getOwnPropertyNames(this._set).length; + }; + + /** + * Add the given string to this set. + * + * @param String aStr + */ + ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) { + var sStr = util.toSetString(aStr); + var isDuplicate = this._set.hasOwnProperty(sStr); + var idx = this._array.length; + if (!isDuplicate || aAllowDuplicates) { + this._array.push(aStr); + } + if (!isDuplicate) { + this._set[sStr] = idx; + } + }; + + /** + * Is the given string a member of this set? + * + * @param String aStr + */ + ArraySet.prototype.has = function ArraySet_has(aStr) { + var sStr = util.toSetString(aStr); + return this._set.hasOwnProperty(sStr); + }; + + /** + * What is the index of the given string in the array? + * + * @param String aStr + */ + ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) { + var sStr = util.toSetString(aStr); + if (this._set.hasOwnProperty(sStr)) { + return this._set[sStr]; + } + throw new Error('"' + aStr + '" is not in the set.'); + }; + + /** + * What is the element at the given index? + * + * @param Number aIdx + */ + ArraySet.prototype.at = function ArraySet_at(aIdx) { + if (aIdx >= 0 && aIdx < this._array.length) { + return this._array[aIdx]; + } + throw new Error('No element indexed by ' + aIdx); + }; + + /** + * Returns the array representation of this set (which has the proper indices + * indicated by indexOf). Note that this is a copy of the internal array used + * for storing the members so that no one can mess with internal state. + */ + ArraySet.prototype.toArray = function ArraySet_toArray() { + return this._array.slice(); + }; + + exports.ArraySet = ArraySet; + } + + +/***/ }, +/* 6 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2014 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var util = __webpack_require__(4); + + /** + * Determine whether mappingB is after mappingA with respect to generated + * position. + */ + function generatedPositionAfter(mappingA, mappingB) { + // Optimized for most common case + var lineA = mappingA.generatedLine; + var lineB = mappingB.generatedLine; + var columnA = mappingA.generatedColumn; + var columnB = mappingB.generatedColumn; + return lineB > lineA || lineB == lineA && columnB >= columnA || + util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0; + } + + /** + * A data structure to provide a sorted view of accumulated mappings in a + * performance conscious manner. It trades a neglibable overhead in general + * case for a large speedup in case of mappings being added in order. + */ + function MappingList() { + this._array = []; + this._sorted = true; + // Serves as infimum + this._last = {generatedLine: -1, generatedColumn: 0}; + } + + /** + * Iterate through internal items. This method takes the same arguments that + * `Array.prototype.forEach` takes. + * + * NOTE: The order of the mappings is NOT guaranteed. + */ + MappingList.prototype.unsortedForEach = + function MappingList_forEach(aCallback, aThisArg) { + this._array.forEach(aCallback, aThisArg); + }; + + /** + * Add the given source mapping. + * + * @param Object aMapping + */ + MappingList.prototype.add = function MappingList_add(aMapping) { + if (generatedPositionAfter(this._last, aMapping)) { + this._last = aMapping; + this._array.push(aMapping); + } else { + this._sorted = false; + this._array.push(aMapping); + } + }; + + /** + * Returns the flat, sorted array of mappings. The mappings are sorted by + * generated position. + * + * WARNING: This method returns internal data without copying, for + * performance. The return value must NOT be mutated, and should be treated as + * an immutable borrow. If you want to take ownership, you must make your own + * copy. + */ + MappingList.prototype.toArray = function MappingList_toArray() { + if (!this._sorted) { + this._array.sort(util.compareByGeneratedPositionsInflated); + this._sorted = true; + } + return this._array; + }; + + exports.MappingList = MappingList; + } + + +/***/ }, +/* 7 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var util = __webpack_require__(4); + var binarySearch = __webpack_require__(8); + var ArraySet = __webpack_require__(5).ArraySet; + var base64VLQ = __webpack_require__(2); + var quickSort = __webpack_require__(9).quickSort; + + function SourceMapConsumer(aSourceMap) { + var sourceMap = aSourceMap; + if (typeof aSourceMap === 'string') { + sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); + } + + return sourceMap.sections != null + ? new IndexedSourceMapConsumer(sourceMap) + : new BasicSourceMapConsumer(sourceMap); + } + + SourceMapConsumer.fromSourceMap = function(aSourceMap) { + return BasicSourceMapConsumer.fromSourceMap(aSourceMap); + } + + /** + * The version of the source mapping spec that we are consuming. + */ + SourceMapConsumer.prototype._version = 3; + + // `__generatedMappings` and `__originalMappings` are arrays that hold the + // parsed mapping coordinates from the source map's "mappings" attribute. They + // are lazily instantiated, accessed via the `_generatedMappings` and + // `_originalMappings` getters respectively, and we only parse the mappings + // and create these arrays once queried for a source location. We jump through + // these hoops because there can be many thousands of mappings, and parsing + // them is expensive, so we only want to do it if we must. + // + // Each object in the arrays is of the form: + // + // { + // generatedLine: The line number in the generated code, + // generatedColumn: The column number in the generated code, + // source: The path to the original source file that generated this + // chunk of code, + // originalLine: The line number in the original source that + // corresponds to this chunk of generated code, + // originalColumn: The column number in the original source that + // corresponds to this chunk of generated code, + // name: The name of the original symbol which generated this chunk of + // code. + // } + // + // All properties except for `generatedLine` and `generatedColumn` can be + // `null`. + // + // `_generatedMappings` is ordered by the generated positions. + // + // `_originalMappings` is ordered by the original positions. + + SourceMapConsumer.prototype.__generatedMappings = null; + Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', { + get: function () { + if (!this.__generatedMappings) { + this._parseMappings(this._mappings, this.sourceRoot); + } + + return this.__generatedMappings; + } + }); + + SourceMapConsumer.prototype.__originalMappings = null; + Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', { + get: function () { + if (!this.__originalMappings) { + this._parseMappings(this._mappings, this.sourceRoot); + } + + return this.__originalMappings; + } + }); + + SourceMapConsumer.prototype._charIsMappingSeparator = + function SourceMapConsumer_charIsMappingSeparator(aStr, index) { + var c = aStr.charAt(index); + return c === ";" || c === ","; + }; + + /** + * Parse the mappings in a string in to a data structure which we can easily + * query (the ordered arrays in the `this.__generatedMappings` and + * `this.__originalMappings` properties). + */ + SourceMapConsumer.prototype._parseMappings = + function SourceMapConsumer_parseMappings(aStr, aSourceRoot) { + throw new Error("Subclasses must implement _parseMappings"); + }; + + SourceMapConsumer.GENERATED_ORDER = 1; + SourceMapConsumer.ORIGINAL_ORDER = 2; + + SourceMapConsumer.GREATEST_LOWER_BOUND = 1; + SourceMapConsumer.LEAST_UPPER_BOUND = 2; + + /** + * Iterate over each mapping between an original source/line/column and a + * generated line/column in this source map. + * + * @param Function aCallback + * The function that is called with each mapping. + * @param Object aContext + * Optional. If specified, this object will be the value of `this` every + * time that `aCallback` is called. + * @param aOrder + * Either `SourceMapConsumer.GENERATED_ORDER` or + * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to + * iterate over the mappings sorted by the generated file's line/column + * order or the original's source/line/column order, respectively. Defaults to + * `SourceMapConsumer.GENERATED_ORDER`. + */ + SourceMapConsumer.prototype.eachMapping = + function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) { + var context = aContext || null; + var order = aOrder || SourceMapConsumer.GENERATED_ORDER; + + var mappings; + switch (order) { + case SourceMapConsumer.GENERATED_ORDER: + mappings = this._generatedMappings; + break; + case SourceMapConsumer.ORIGINAL_ORDER: + mappings = this._originalMappings; + break; + default: + throw new Error("Unknown order of iteration."); + } + + var sourceRoot = this.sourceRoot; + mappings.map(function (mapping) { + var source = mapping.source === null ? null : this._sources.at(mapping.source); + if (source != null && sourceRoot != null) { + source = util.join(sourceRoot, source); + } + return { + source: source, + generatedLine: mapping.generatedLine, + generatedColumn: mapping.generatedColumn, + originalLine: mapping.originalLine, + originalColumn: mapping.originalColumn, + name: mapping.name === null ? null : this._names.at(mapping.name) + }; + }, this).forEach(aCallback, context); + }; + + /** + * Returns all generated line and column information for the original source, + * line, and column provided. If no column is provided, returns all mappings + * corresponding to a either the line we are searching for or the next + * closest line that has any mappings. Otherwise, returns all mappings + * corresponding to the given line and either the column we are searching for + * or the next closest column that has any offsets. + * + * The only argument is an object with the following properties: + * + * - source: The filename of the original source. + * - line: The line number in the original source. + * - column: Optional. the column number in the original source. + * + * and an array of objects is returned, each with the following properties: + * + * - line: The line number in the generated source, or null. + * - column: The column number in the generated source, or null. + */ + SourceMapConsumer.prototype.allGeneratedPositionsFor = + function SourceMapConsumer_allGeneratedPositionsFor(aArgs) { + var line = util.getArg(aArgs, 'line'); + + // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping + // returns the index of the closest mapping less than the needle. By + // setting needle.originalColumn to 0, we thus find the last mapping for + // the given line, provided such a mapping exists. + var needle = { + source: util.getArg(aArgs, 'source'), + originalLine: line, + originalColumn: util.getArg(aArgs, 'column', 0) + }; + + if (this.sourceRoot != null) { + needle.source = util.relative(this.sourceRoot, needle.source); + } + if (!this._sources.has(needle.source)) { + return []; + } + needle.source = this._sources.indexOf(needle.source); + + var mappings = []; + + var index = this._findMapping(needle, + this._originalMappings, + "originalLine", + "originalColumn", + util.compareByOriginalPositions, + binarySearch.LEAST_UPPER_BOUND); + if (index >= 0) { + var mapping = this._originalMappings[index]; + + if (aArgs.column === undefined) { + var originalLine = mapping.originalLine; + + // Iterate until either we run out of mappings, or we run into + // a mapping for a different line than the one we found. Since + // mappings are sorted, this is guaranteed to find all mappings for + // the line we found. + while (mapping && mapping.originalLine === originalLine) { + mappings.push({ + line: util.getArg(mapping, 'generatedLine', null), + column: util.getArg(mapping, 'generatedColumn', null), + lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) + }); + + mapping = this._originalMappings[++index]; + } + } else { + var originalColumn = mapping.originalColumn; + + // Iterate until either we run out of mappings, or we run into + // a mapping for a different line than the one we were searching for. + // Since mappings are sorted, this is guaranteed to find all mappings for + // the line we are searching for. + while (mapping && + mapping.originalLine === line && + mapping.originalColumn == originalColumn) { + mappings.push({ + line: util.getArg(mapping, 'generatedLine', null), + column: util.getArg(mapping, 'generatedColumn', null), + lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) + }); + + mapping = this._originalMappings[++index]; + } + } + } + + return mappings; + }; + + exports.SourceMapConsumer = SourceMapConsumer; + + /** + * A BasicSourceMapConsumer instance represents a parsed source map which we can + * query for information about the original file positions by giving it a file + * position in the generated source. + * + * The only parameter is the raw source map (either as a JSON string, or + * already parsed to an object). According to the spec, source maps have the + * following attributes: + * + * - version: Which version of the source map spec this map is following. + * - sources: An array of URLs to the original source files. + * - names: An array of identifiers which can be referrenced by individual mappings. + * - sourceRoot: Optional. The URL root from which all sources are relative. + * - sourcesContent: Optional. An array of contents of the original source files. + * - mappings: A string of base64 VLQs which contain the actual mappings. + * - file: Optional. The generated file this source map is associated with. + * + * Here is an example source map, taken from the source map spec[0]: + * + * { + * version : 3, + * file: "out.js", + * sourceRoot : "", + * sources: ["foo.js", "bar.js"], + * names: ["src", "maps", "are", "fun"], + * mappings: "AA,AB;;ABCDE;" + * } + * + * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1# + */ + function BasicSourceMapConsumer(aSourceMap) { + var sourceMap = aSourceMap; + if (typeof aSourceMap === 'string') { + sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); + } + + var version = util.getArg(sourceMap, 'version'); + var sources = util.getArg(sourceMap, 'sources'); + // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which + // requires the array) to play nice here. + var names = util.getArg(sourceMap, 'names', []); + var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null); + var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null); + var mappings = util.getArg(sourceMap, 'mappings'); + var file = util.getArg(sourceMap, 'file', null); + + // Once again, Sass deviates from the spec and supplies the version as a + // string rather than a number, so we use loose equality checking here. + if (version != this._version) { + throw new Error('Unsupported version: ' + version); + } + + sources = sources + // Some source maps produce relative source paths like "./foo.js" instead of + // "foo.js". Normalize these first so that future comparisons will succeed. + // See bugzil.la/1090768. + .map(util.normalize) + // Always ensure that absolute sources are internally stored relative to + // the source root, if the source root is absolute. Not doing this would + // be particularly problematic when the source root is a prefix of the + // source (valid, but why??). See github issue #199 and bugzil.la/1188982. + .map(function (source) { + return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source) + ? util.relative(sourceRoot, source) + : source; + }); + + // Pass `true` below to allow duplicate names and sources. While source maps + // are intended to be compressed and deduplicated, the TypeScript compiler + // sometimes generates source maps with duplicates in them. See Github issue + // #72 and bugzil.la/889492. + this._names = ArraySet.fromArray(names, true); + this._sources = ArraySet.fromArray(sources, true); + + this.sourceRoot = sourceRoot; + this.sourcesContent = sourcesContent; + this._mappings = mappings; + this.file = file; + } + + BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype); + BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer; + + /** + * Create a BasicSourceMapConsumer from a SourceMapGenerator. + * + * @param SourceMapGenerator aSourceMap + * The source map that will be consumed. + * @returns BasicSourceMapConsumer + */ + BasicSourceMapConsumer.fromSourceMap = + function SourceMapConsumer_fromSourceMap(aSourceMap) { + var smc = Object.create(BasicSourceMapConsumer.prototype); + + var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true); + var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true); + smc.sourceRoot = aSourceMap._sourceRoot; + smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(), + smc.sourceRoot); + smc.file = aSourceMap._file; + + // Because we are modifying the entries (by converting string sources and + // names to indices into the sources and names ArraySets), we have to make + // a copy of the entry or else bad things happen. Shared mutable state + // strikes again! See github issue #191. + + var generatedMappings = aSourceMap._mappings.toArray().slice(); + var destGeneratedMappings = smc.__generatedMappings = []; + var destOriginalMappings = smc.__originalMappings = []; + + for (var i = 0, length = generatedMappings.length; i < length; i++) { + var srcMapping = generatedMappings[i]; + var destMapping = new Mapping; + destMapping.generatedLine = srcMapping.generatedLine; + destMapping.generatedColumn = srcMapping.generatedColumn; + + if (srcMapping.source) { + destMapping.source = sources.indexOf(srcMapping.source); + destMapping.originalLine = srcMapping.originalLine; + destMapping.originalColumn = srcMapping.originalColumn; + + if (srcMapping.name) { + destMapping.name = names.indexOf(srcMapping.name); + } + + destOriginalMappings.push(destMapping); + } + + destGeneratedMappings.push(destMapping); + } + + quickSort(smc.__originalMappings, util.compareByOriginalPositions); + + return smc; + }; + + /** + * The version of the source mapping spec that we are consuming. + */ + BasicSourceMapConsumer.prototype._version = 3; + + /** + * The list of original sources. + */ + Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', { + get: function () { + return this._sources.toArray().map(function (s) { + return this.sourceRoot != null ? util.join(this.sourceRoot, s) : s; + }, this); + } + }); + + /** + * Provide the JIT with a nice shape / hidden class. + */ + function Mapping() { + this.generatedLine = 0; + this.generatedColumn = 0; + this.source = null; + this.originalLine = null; + this.originalColumn = null; + this.name = null; + } + + /** + * Parse the mappings in a string in to a data structure which we can easily + * query (the ordered arrays in the `this.__generatedMappings` and + * `this.__originalMappings` properties). + */ + BasicSourceMapConsumer.prototype._parseMappings = + function SourceMapConsumer_parseMappings(aStr, aSourceRoot) { + var generatedLine = 1; + var previousGeneratedColumn = 0; + var previousOriginalLine = 0; + var previousOriginalColumn = 0; + var previousSource = 0; + var previousName = 0; + var length = aStr.length; + var index = 0; + var cachedSegments = {}; + var temp = {}; + var originalMappings = []; + var generatedMappings = []; + var mapping, str, segment, end, value; + + while (index < length) { + if (aStr.charAt(index) === ';') { + generatedLine++; + index++; + previousGeneratedColumn = 0; + } + else if (aStr.charAt(index) === ',') { + index++; + } + else { + mapping = new Mapping(); + mapping.generatedLine = generatedLine; + + // Because each offset is encoded relative to the previous one, + // many segments often have the same encoding. We can exploit this + // fact by caching the parsed variable length fields of each segment, + // allowing us to avoid a second parse if we encounter the same + // segment again. + for (end = index; end < length; end++) { + if (this._charIsMappingSeparator(aStr, end)) { + break; + } + } + str = aStr.slice(index, end); + + segment = cachedSegments[str]; + if (segment) { + index += str.length; + } else { + segment = []; + while (index < end) { + base64VLQ.decode(aStr, index, temp); + value = temp.value; + index = temp.rest; + segment.push(value); + } + + if (segment.length === 2) { + throw new Error('Found a source, but no line and column'); + } + + if (segment.length === 3) { + throw new Error('Found a source and line, but no column'); + } + + cachedSegments[str] = segment; + } + + // Generated column. + mapping.generatedColumn = previousGeneratedColumn + segment[0]; + previousGeneratedColumn = mapping.generatedColumn; + + if (segment.length > 1) { + // Original source. + mapping.source = previousSource + segment[1]; + previousSource += segment[1]; + + // Original line. + mapping.originalLine = previousOriginalLine + segment[2]; + previousOriginalLine = mapping.originalLine; + // Lines are stored 0-based + mapping.originalLine += 1; + + // Original column. + mapping.originalColumn = previousOriginalColumn + segment[3]; + previousOriginalColumn = mapping.originalColumn; + + if (segment.length > 4) { + // Original name. + mapping.name = previousName + segment[4]; + previousName += segment[4]; + } + } + + generatedMappings.push(mapping); + if (typeof mapping.originalLine === 'number') { + originalMappings.push(mapping); + } + } + } + + quickSort(generatedMappings, util.compareByGeneratedPositionsDeflated); + this.__generatedMappings = generatedMappings; + + quickSort(originalMappings, util.compareByOriginalPositions); + this.__originalMappings = originalMappings; + }; + + /** + * Find the mapping that best matches the hypothetical "needle" mapping that + * we are searching for in the given "haystack" of mappings. + */ + BasicSourceMapConsumer.prototype._findMapping = + function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName, + aColumnName, aComparator, aBias) { + // To return the position we are searching for, we must first find the + // mapping for the given position and then return the opposite position it + // points to. Because the mappings are sorted, we can use binary search to + // find the best mapping. + + if (aNeedle[aLineName] <= 0) { + throw new TypeError('Line must be greater than or equal to 1, got ' + + aNeedle[aLineName]); + } + if (aNeedle[aColumnName] < 0) { + throw new TypeError('Column must be greater than or equal to 0, got ' + + aNeedle[aColumnName]); + } + + return binarySearch.search(aNeedle, aMappings, aComparator, aBias); + }; + + /** + * Compute the last column for each generated mapping. The last column is + * inclusive. + */ + BasicSourceMapConsumer.prototype.computeColumnSpans = + function SourceMapConsumer_computeColumnSpans() { + for (var index = 0; index < this._generatedMappings.length; ++index) { + var mapping = this._generatedMappings[index]; + + // Mappings do not contain a field for the last generated columnt. We + // can come up with an optimistic estimate, however, by assuming that + // mappings are contiguous (i.e. given two consecutive mappings, the + // first mapping ends where the second one starts). + if (index + 1 < this._generatedMappings.length) { + var nextMapping = this._generatedMappings[index + 1]; + + if (mapping.generatedLine === nextMapping.generatedLine) { + mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1; + continue; + } + } + + // The last mapping for each line spans the entire line. + mapping.lastGeneratedColumn = Infinity; + } + }; + + /** + * Returns the original source, line, and column information for the generated + * source's line and column positions provided. The only argument is an object + * with the following properties: + * + * - line: The line number in the generated source. + * - column: The column number in the generated source. + * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or + * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. + * + * and an object is returned with the following properties: + * + * - source: The original source file, or null. + * - line: The line number in the original source, or null. + * - column: The column number in the original source, or null. + * - name: The original identifier, or null. + */ + BasicSourceMapConsumer.prototype.originalPositionFor = + function SourceMapConsumer_originalPositionFor(aArgs) { + var needle = { + generatedLine: util.getArg(aArgs, 'line'), + generatedColumn: util.getArg(aArgs, 'column') + }; + + var index = this._findMapping( + needle, + this._generatedMappings, + "generatedLine", + "generatedColumn", + util.compareByGeneratedPositionsDeflated, + util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND) + ); + + if (index >= 0) { + var mapping = this._generatedMappings[index]; + + if (mapping.generatedLine === needle.generatedLine) { + var source = util.getArg(mapping, 'source', null); + if (source !== null) { + source = this._sources.at(source); + if (this.sourceRoot != null) { + source = util.join(this.sourceRoot, source); + } + } + var name = util.getArg(mapping, 'name', null); + if (name !== null) { + name = this._names.at(name); + } + return { + source: source, + line: util.getArg(mapping, 'originalLine', null), + column: util.getArg(mapping, 'originalColumn', null), + name: name + }; + } + } + + return { + source: null, + line: null, + column: null, + name: null + }; + }; + + /** + * Return true if we have the source content for every source in the source + * map, false otherwise. + */ + BasicSourceMapConsumer.prototype.hasContentsOfAllSources = + function BasicSourceMapConsumer_hasContentsOfAllSources() { + if (!this.sourcesContent) { + return false; + } + return this.sourcesContent.length >= this._sources.size() && + !this.sourcesContent.some(function (sc) { return sc == null; }); + }; + + /** + * Returns the original source content. The only argument is the url of the + * original source file. Returns null if no original source content is + * availible. + */ + BasicSourceMapConsumer.prototype.sourceContentFor = + function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) { + if (!this.sourcesContent) { + return null; + } + + if (this.sourceRoot != null) { + aSource = util.relative(this.sourceRoot, aSource); + } + + if (this._sources.has(aSource)) { + return this.sourcesContent[this._sources.indexOf(aSource)]; + } + + var url; + if (this.sourceRoot != null + && (url = util.urlParse(this.sourceRoot))) { + // XXX: file:// URIs and absolute paths lead to unexpected behavior for + // many users. We can help them out when they expect file:// URIs to + // behave like it would if they were running a local HTTP server. See + // https://bugzilla.mozilla.org/show_bug.cgi?id=885597. + var fileUriAbsPath = aSource.replace(/^file:\/\//, ""); + if (url.scheme == "file" + && this._sources.has(fileUriAbsPath)) { + return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)] + } + + if ((!url.path || url.path == "/") + && this._sources.has("/" + aSource)) { + return this.sourcesContent[this._sources.indexOf("/" + aSource)]; + } + } + + // This function is used recursively from + // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we + // don't want to throw if we can't find the source - we just want to + // return null, so we provide a flag to exit gracefully. + if (nullOnMissing) { + return null; + } + else { + throw new Error('"' + aSource + '" is not in the SourceMap.'); + } + }; + + /** + * Returns the generated line and column information for the original source, + * line, and column positions provided. The only argument is an object with + * the following properties: + * + * - source: The filename of the original source. + * - line: The line number in the original source. + * - column: The column number in the original source. + * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or + * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. + * + * and an object is returned with the following properties: + * + * - line: The line number in the generated source, or null. + * - column: The column number in the generated source, or null. + */ + BasicSourceMapConsumer.prototype.generatedPositionFor = + function SourceMapConsumer_generatedPositionFor(aArgs) { + var source = util.getArg(aArgs, 'source'); + if (this.sourceRoot != null) { + source = util.relative(this.sourceRoot, source); + } + if (!this._sources.has(source)) { + return { + line: null, + column: null, + lastColumn: null + }; + } + source = this._sources.indexOf(source); + + var needle = { + source: source, + originalLine: util.getArg(aArgs, 'line'), + originalColumn: util.getArg(aArgs, 'column') + }; + + var index = this._findMapping( + needle, + this._originalMappings, + "originalLine", + "originalColumn", + util.compareByOriginalPositions, + util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND) + ); + + if (index >= 0) { + var mapping = this._originalMappings[index]; + + if (mapping.source === needle.source) { + return { + line: util.getArg(mapping, 'generatedLine', null), + column: util.getArg(mapping, 'generatedColumn', null), + lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) + }; + } + } + + return { + line: null, + column: null, + lastColumn: null + }; + }; + + exports.BasicSourceMapConsumer = BasicSourceMapConsumer; + + /** + * An IndexedSourceMapConsumer instance represents a parsed source map which + * we can query for information. It differs from BasicSourceMapConsumer in + * that it takes "indexed" source maps (i.e. ones with a "sections" field) as + * input. + * + * The only parameter is a raw source map (either as a JSON string, or already + * parsed to an object). According to the spec for indexed source maps, they + * have the following attributes: + * + * - version: Which version of the source map spec this map is following. + * - file: Optional. The generated file this source map is associated with. + * - sections: A list of section definitions. + * + * Each value under the "sections" field has two fields: + * - offset: The offset into the original specified at which this section + * begins to apply, defined as an object with a "line" and "column" + * field. + * - map: A source map definition. This source map could also be indexed, + * but doesn't have to be. + * + * Instead of the "map" field, it's also possible to have a "url" field + * specifying a URL to retrieve a source map from, but that's currently + * unsupported. + * + * Here's an example source map, taken from the source map spec[0], but + * modified to omit a section which uses the "url" field. + * + * { + * version : 3, + * file: "app.js", + * sections: [{ + * offset: {line:100, column:10}, + * map: { + * version : 3, + * file: "section.js", + * sources: ["foo.js", "bar.js"], + * names: ["src", "maps", "are", "fun"], + * mappings: "AAAA,E;;ABCDE;" + * } + * }], + * } + * + * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt + */ + function IndexedSourceMapConsumer(aSourceMap) { + var sourceMap = aSourceMap; + if (typeof aSourceMap === 'string') { + sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); + } + + var version = util.getArg(sourceMap, 'version'); + var sections = util.getArg(sourceMap, 'sections'); + + if (version != this._version) { + throw new Error('Unsupported version: ' + version); + } + + this._sources = new ArraySet(); + this._names = new ArraySet(); + + var lastOffset = { + line: -1, + column: 0 + }; + this._sections = sections.map(function (s) { + if (s.url) { + // The url field will require support for asynchronicity. + // See https://github.com/mozilla/source-map/issues/16 + throw new Error('Support for url field in sections not implemented.'); + } + var offset = util.getArg(s, 'offset'); + var offsetLine = util.getArg(offset, 'line'); + var offsetColumn = util.getArg(offset, 'column'); + + if (offsetLine < lastOffset.line || + (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) { + throw new Error('Section offsets must be ordered and non-overlapping.'); + } + lastOffset = offset; + + return { + generatedOffset: { + // The offset fields are 0-based, but we use 1-based indices when + // encoding/decoding from VLQ. + generatedLine: offsetLine + 1, + generatedColumn: offsetColumn + 1 + }, + consumer: new SourceMapConsumer(util.getArg(s, 'map')) + } + }); + } + + IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype); + IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer; + + /** + * The version of the source mapping spec that we are consuming. + */ + IndexedSourceMapConsumer.prototype._version = 3; + + /** + * The list of original sources. + */ + Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', { + get: function () { + var sources = []; + for (var i = 0; i < this._sections.length; i++) { + for (var j = 0; j < this._sections[i].consumer.sources.length; j++) { + sources.push(this._sections[i].consumer.sources[j]); + } + } + return sources; + } + }); + + /** + * Returns the original source, line, and column information for the generated + * source's line and column positions provided. The only argument is an object + * with the following properties: + * + * - line: The line number in the generated source. + * - column: The column number in the generated source. + * + * and an object is returned with the following properties: + * + * - source: The original source file, or null. + * - line: The line number in the original source, or null. + * - column: The column number in the original source, or null. + * - name: The original identifier, or null. + */ + IndexedSourceMapConsumer.prototype.originalPositionFor = + function IndexedSourceMapConsumer_originalPositionFor(aArgs) { + var needle = { + generatedLine: util.getArg(aArgs, 'line'), + generatedColumn: util.getArg(aArgs, 'column') + }; + + // Find the section containing the generated position we're trying to map + // to an original position. + var sectionIndex = binarySearch.search(needle, this._sections, + function(needle, section) { + var cmp = needle.generatedLine - section.generatedOffset.generatedLine; + if (cmp) { + return cmp; + } + + return (needle.generatedColumn - + section.generatedOffset.generatedColumn); + }); + var section = this._sections[sectionIndex]; + + if (!section) { + return { + source: null, + line: null, + column: null, + name: null + }; + } + + return section.consumer.originalPositionFor({ + line: needle.generatedLine - + (section.generatedOffset.generatedLine - 1), + column: needle.generatedColumn - + (section.generatedOffset.generatedLine === needle.generatedLine + ? section.generatedOffset.generatedColumn - 1 + : 0), + bias: aArgs.bias + }); + }; + + /** + * Return true if we have the source content for every source in the source + * map, false otherwise. + */ + IndexedSourceMapConsumer.prototype.hasContentsOfAllSources = + function IndexedSourceMapConsumer_hasContentsOfAllSources() { + return this._sections.every(function (s) { + return s.consumer.hasContentsOfAllSources(); + }); + }; + + /** + * Returns the original source content. The only argument is the url of the + * original source file. Returns null if no original source content is + * available. + */ + IndexedSourceMapConsumer.prototype.sourceContentFor = + function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) { + for (var i = 0; i < this._sections.length; i++) { + var section = this._sections[i]; + + var content = section.consumer.sourceContentFor(aSource, true); + if (content) { + return content; + } + } + if (nullOnMissing) { + return null; + } + else { + throw new Error('"' + aSource + '" is not in the SourceMap.'); + } + }; + + /** + * Returns the generated line and column information for the original source, + * line, and column positions provided. The only argument is an object with + * the following properties: + * + * - source: The filename of the original source. + * - line: The line number in the original source. + * - column: The column number in the original source. + * + * and an object is returned with the following properties: + * + * - line: The line number in the generated source, or null. + * - column: The column number in the generated source, or null. + */ + IndexedSourceMapConsumer.prototype.generatedPositionFor = + function IndexedSourceMapConsumer_generatedPositionFor(aArgs) { + for (var i = 0; i < this._sections.length; i++) { + var section = this._sections[i]; + + // Only consider this section if the requested source is in the list of + // sources of the consumer. + if (section.consumer.sources.indexOf(util.getArg(aArgs, 'source')) === -1) { + continue; + } + var generatedPosition = section.consumer.generatedPositionFor(aArgs); + if (generatedPosition) { + var ret = { + line: generatedPosition.line + + (section.generatedOffset.generatedLine - 1), + column: generatedPosition.column + + (section.generatedOffset.generatedLine === generatedPosition.line + ? section.generatedOffset.generatedColumn - 1 + : 0) + }; + return ret; + } + } + + return { + line: null, + column: null + }; + }; + + /** + * Parse the mappings in a string in to a data structure which we can easily + * query (the ordered arrays in the `this.__generatedMappings` and + * `this.__originalMappings` properties). + */ + IndexedSourceMapConsumer.prototype._parseMappings = + function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) { + this.__generatedMappings = []; + this.__originalMappings = []; + for (var i = 0; i < this._sections.length; i++) { + var section = this._sections[i]; + var sectionMappings = section.consumer._generatedMappings; + for (var j = 0; j < sectionMappings.length; j++) { + var mapping = sectionMappings[i]; + + var source = section.consumer._sources.at(mapping.source); + if (section.consumer.sourceRoot !== null) { + source = util.join(section.consumer.sourceRoot, source); + } + this._sources.add(source); + source = this._sources.indexOf(source); + + var name = section.consumer._names.at(mapping.name); + this._names.add(name); + name = this._names.indexOf(name); + + // The mappings coming from the consumer for the section have + // generated positions relative to the start of the section, so we + // need to offset them to be relative to the start of the concatenated + // generated file. + var adjustedMapping = { + source: source, + generatedLine: mapping.generatedLine + + (section.generatedOffset.generatedLine - 1), + generatedColumn: mapping.column + + (section.generatedOffset.generatedLine === mapping.generatedLine) + ? section.generatedOffset.generatedColumn - 1 + : 0, + originalLine: mapping.originalLine, + originalColumn: mapping.originalColumn, + name: name + }; + + this.__generatedMappings.push(adjustedMapping); + if (typeof adjustedMapping.originalLine === 'number') { + this.__originalMappings.push(adjustedMapping); + } + } + } + + quickSort(this.__generatedMappings, util.compareByGeneratedPositionsDeflated); + quickSort(this.__originalMappings, util.compareByOriginalPositions); + }; + + exports.IndexedSourceMapConsumer = IndexedSourceMapConsumer; + } + + +/***/ }, +/* 8 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + exports.GREATEST_LOWER_BOUND = 1; + exports.LEAST_UPPER_BOUND = 2; + + /** + * Recursive implementation of binary search. + * + * @param aLow Indices here and lower do not contain the needle. + * @param aHigh Indices here and higher do not contain the needle. + * @param aNeedle The element being searched for. + * @param aHaystack The non-empty array being searched. + * @param aCompare Function which takes two elements and returns -1, 0, or 1. + * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or + * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + */ + function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) { + // This function terminates when one of the following is true: + // + // 1. We find the exact element we are looking for. + // + // 2. We did not find the exact element, but we can return the index of + // the next-closest element. + // + // 3. We did not find the exact element, and there is no next-closest + // element than the one we are searching for, so we return -1. + var mid = Math.floor((aHigh - aLow) / 2) + aLow; + var cmp = aCompare(aNeedle, aHaystack[mid], true); + if (cmp === 0) { + // Found the element we are looking for. + return mid; + } + else if (cmp > 0) { + // Our needle is greater than aHaystack[mid]. + if (aHigh - mid > 1) { + // The element is in the upper half. + return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias); + } + + // The exact needle element was not found in this haystack. Determine if + // we are in termination case (3) or (2) and return the appropriate thing. + if (aBias == exports.LEAST_UPPER_BOUND) { + return aHigh < aHaystack.length ? aHigh : -1; + } else { + return mid; + } + } + else { + // Our needle is less than aHaystack[mid]. + if (mid - aLow > 1) { + // The element is in the lower half. + return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias); + } + + // we are in termination case (3) or (2) and return the appropriate thing. + if (aBias == exports.LEAST_UPPER_BOUND) { + return mid; + } else { + return aLow < 0 ? -1 : aLow; + } + } + } + + /** + * This is an implementation of binary search which will always try and return + * the index of the closest element if there is no exact hit. This is because + * mappings between original and generated line/col pairs are single points, + * and there is an implicit region between each of them, so a miss just means + * that you aren't on the very start of a region. + * + * @param aNeedle The element you are looking for. + * @param aHaystack The array that is being searched. + * @param aCompare A function which takes the needle and an element in the + * array and returns -1, 0, or 1 depending on whether the needle is less + * than, equal to, or greater than the element, respectively. + * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or + * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'. + */ + exports.search = function search(aNeedle, aHaystack, aCompare, aBias) { + if (aHaystack.length === 0) { + return -1; + } + + var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, + aCompare, aBias || exports.GREATEST_LOWER_BOUND); + if (index < 0) { + return -1; + } + + // We have found either the exact element, or the next-closest element than + // the one we are searching for. However, there may be more than one such + // element. Make sure we always return the smallest of these. + while (index - 1 >= 0) { + if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) { + break; + } + --index; + } + + return index; + }; + } + + +/***/ }, +/* 9 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + // It turns out that some (most?) JavaScript engines don't self-host + // `Array.prototype.sort`. This makes sense because C++ will likely remain + // faster than JS when doing raw CPU-intensive sorting. However, when using a + // custom comparator function, calling back and forth between the VM's C++ and + // JIT'd JS is rather slow *and* loses JIT type information, resulting in + // worse generated code for the comparator function than would be optimal. In + // fact, when sorting with a comparator, these costs outweigh the benefits of + // sorting in C++. By using our own JS-implemented Quick Sort (below), we get + // a ~3500ms mean speed-up in `bench/bench.html`. + + /** + * Swap the elements indexed by `x` and `y` in the array `ary`. + * + * @param {Array} ary + * The array. + * @param {Number} x + * The index of the first item. + * @param {Number} y + * The index of the second item. + */ + function swap(ary, x, y) { + var temp = ary[x]; + ary[x] = ary[y]; + ary[y] = temp; + } + + /** + * Returns a random integer within the range `low .. high` inclusive. + * + * @param {Number} low + * The lower bound on the range. + * @param {Number} high + * The upper bound on the range. + */ + function randomIntInRange(low, high) { + return Math.round(low + (Math.random() * (high - low))); + } + + /** + * The Quick Sort algorithm. + * + * @param {Array} ary + * An array to sort. + * @param {function} comparator + * Function to use to compare two items. + * @param {Number} p + * Start index of the array + * @param {Number} r + * End index of the array + */ + function doQuickSort(ary, comparator, p, r) { + // If our lower bound is less than our upper bound, we (1) partition the + // array into two pieces and (2) recurse on each half. If it is not, this is + // the empty array and our base case. + + if (p < r) { + // (1) Partitioning. + // + // The partitioning chooses a pivot between `p` and `r` and moves all + // elements that are less than or equal to the pivot to the before it, and + // all the elements that are greater than it after it. The effect is that + // once partition is done, the pivot is in the exact place it will be when + // the array is put in sorted order, and it will not need to be moved + // again. This runs in O(n) time. + + // Always choose a random pivot so that an input array which is reverse + // sorted does not cause O(n^2) running time. + var pivotIndex = randomIntInRange(p, r); + var i = p - 1; + + swap(ary, pivotIndex, r); + var pivot = ary[r]; + + // Immediately after `j` is incremented in this loop, the following hold + // true: + // + // * Every element in `ary[p .. i]` is less than or equal to the pivot. + // + // * Every element in `ary[i+1 .. j-1]` is greater than the pivot. + for (var j = p; j < r; j++) { + if (comparator(ary[j], pivot) <= 0) { + i += 1; + swap(ary, i, j); + } + } + + swap(ary, i + 1, j); + var q = i + 1; + + // (2) Recurse on each half. + + doQuickSort(ary, comparator, p, q - 1); + doQuickSort(ary, comparator, q + 1, r); + } + } + + /** + * Sort the given array in-place with the given comparator function. + * + * @param {Array} ary + * An array to sort. + * @param {function} comparator + * Function to use to compare two items. + */ + exports.quickSort = function (ary, comparator) { + doQuickSort(ary, comparator, 0, ary.length - 1); + }; + } + + +/***/ }, +/* 10 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var SourceMapGenerator = __webpack_require__(1).SourceMapGenerator; + var util = __webpack_require__(4); + + // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other + // operating systems these days (capturing the result). + var REGEX_NEWLINE = /(\r?\n)/; + + // Newline character code for charCodeAt() comparisons + var NEWLINE_CODE = 10; + + // Private symbol for identifying `SourceNode`s when multiple versions of + // the source-map library are loaded. This MUST NOT CHANGE across + // versions! + var isSourceNode = "$$$isSourceNode$$$"; + + /** + * SourceNodes provide a way to abstract over interpolating/concatenating + * snippets of generated JavaScript source code while maintaining the line and + * column information associated with the original source code. + * + * @param aLine The original line number. + * @param aColumn The original column number. + * @param aSource The original source's filename. + * @param aChunks Optional. An array of strings which are snippets of + * generated JS, or other SourceNodes. + * @param aName The original identifier. + */ + function SourceNode(aLine, aColumn, aSource, aChunks, aName) { + this.children = []; + this.sourceContents = {}; + this.line = aLine == null ? null : aLine; + this.column = aColumn == null ? null : aColumn; + this.source = aSource == null ? null : aSource; + this.name = aName == null ? null : aName; + this[isSourceNode] = true; + if (aChunks != null) this.add(aChunks); + } + + /** + * Creates a SourceNode from generated code and a SourceMapConsumer. + * + * @param aGeneratedCode The generated code + * @param aSourceMapConsumer The SourceMap for the generated code + * @param aRelativePath Optional. The path that relative sources in the + * SourceMapConsumer should be relative to. + */ + SourceNode.fromStringWithSourceMap = + function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) { + // The SourceNode we want to fill with the generated code + // and the SourceMap + var node = new SourceNode(); + + // All even indices of this array are one line of the generated code, + // while all odd indices are the newlines between two adjacent lines + // (since `REGEX_NEWLINE` captures its match). + // Processed fragments are removed from this array, by calling `shiftNextLine`. + var remainingLines = aGeneratedCode.split(REGEX_NEWLINE); + var shiftNextLine = function() { + var lineContents = remainingLines.shift(); + // The last line of a file might not have a newline. + var newLine = remainingLines.shift() || ""; + return lineContents + newLine; + }; + + // We need to remember the position of "remainingLines" + var lastGeneratedLine = 1, lastGeneratedColumn = 0; + + // The generate SourceNodes we need a code range. + // To extract it current and last mapping is used. + // Here we store the last mapping. + var lastMapping = null; + + aSourceMapConsumer.eachMapping(function (mapping) { + if (lastMapping !== null) { + // We add the code from "lastMapping" to "mapping": + // First check if there is a new line in between. + if (lastGeneratedLine < mapping.generatedLine) { + var code = ""; + // Associate first line with "lastMapping" + addMappingWithCode(lastMapping, shiftNextLine()); + lastGeneratedLine++; + lastGeneratedColumn = 0; + // The remaining code is added without mapping + } else { + // There is no new line in between. + // Associate the code between "lastGeneratedColumn" and + // "mapping.generatedColumn" with "lastMapping" + var nextLine = remainingLines[0]; + var code = nextLine.substr(0, mapping.generatedColumn - + lastGeneratedColumn); + remainingLines[0] = nextLine.substr(mapping.generatedColumn - + lastGeneratedColumn); + lastGeneratedColumn = mapping.generatedColumn; + addMappingWithCode(lastMapping, code); + // No more remaining code, continue + lastMapping = mapping; + return; + } + } + // We add the generated code until the first mapping + // to the SourceNode without any mapping. + // Each line is added as separate string. + while (lastGeneratedLine < mapping.generatedLine) { + node.add(shiftNextLine()); + lastGeneratedLine++; + } + if (lastGeneratedColumn < mapping.generatedColumn) { + var nextLine = remainingLines[0]; + node.add(nextLine.substr(0, mapping.generatedColumn)); + remainingLines[0] = nextLine.substr(mapping.generatedColumn); + lastGeneratedColumn = mapping.generatedColumn; + } + lastMapping = mapping; + }, this); + // We have processed all mappings. + if (remainingLines.length > 0) { + if (lastMapping) { + // Associate the remaining code in the current line with "lastMapping" + addMappingWithCode(lastMapping, shiftNextLine()); + } + // and add the remaining lines without any mapping + node.add(remainingLines.join("")); + } + + // Copy sourcesContent into SourceNode + aSourceMapConsumer.sources.forEach(function (sourceFile) { + var content = aSourceMapConsumer.sourceContentFor(sourceFile); + if (content != null) { + if (aRelativePath != null) { + sourceFile = util.join(aRelativePath, sourceFile); + } + node.setSourceContent(sourceFile, content); + } + }); + + return node; + + function addMappingWithCode(mapping, code) { + if (mapping === null || mapping.source === undefined) { + node.add(code); + } else { + var source = aRelativePath + ? util.join(aRelativePath, mapping.source) + : mapping.source; + node.add(new SourceNode(mapping.originalLine, + mapping.originalColumn, + source, + code, + mapping.name)); + } + } + }; + + /** + * Add a chunk of generated JS to this source node. + * + * @param aChunk A string snippet of generated JS code, another instance of + * SourceNode, or an array where each member is one of those things. + */ + SourceNode.prototype.add = function SourceNode_add(aChunk) { + if (Array.isArray(aChunk)) { + aChunk.forEach(function (chunk) { + this.add(chunk); + }, this); + } + else if (aChunk[isSourceNode] || typeof aChunk === "string") { + if (aChunk) { + this.children.push(aChunk); + } + } + else { + throw new TypeError( + "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk + ); + } + return this; + }; + + /** + * Add a chunk of generated JS to the beginning of this source node. + * + * @param aChunk A string snippet of generated JS code, another instance of + * SourceNode, or an array where each member is one of those things. + */ + SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) { + if (Array.isArray(aChunk)) { + for (var i = aChunk.length-1; i >= 0; i--) { + this.prepend(aChunk[i]); + } + } + else if (aChunk[isSourceNode] || typeof aChunk === "string") { + this.children.unshift(aChunk); + } + else { + throw new TypeError( + "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk + ); + } + return this; + }; + + /** + * Walk over the tree of JS snippets in this node and its children. The + * walking function is called once for each snippet of JS and is passed that + * snippet and the its original associated source's line/column location. + * + * @param aFn The traversal function. + */ + SourceNode.prototype.walk = function SourceNode_walk(aFn) { + var chunk; + for (var i = 0, len = this.children.length; i < len; i++) { + chunk = this.children[i]; + if (chunk[isSourceNode]) { + chunk.walk(aFn); + } + else { + if (chunk !== '') { + aFn(chunk, { source: this.source, + line: this.line, + column: this.column, + name: this.name }); + } + } + } + }; + + /** + * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between + * each of `this.children`. + * + * @param aSep The separator. + */ + SourceNode.prototype.join = function SourceNode_join(aSep) { + var newChildren; + var i; + var len = this.children.length; + if (len > 0) { + newChildren = []; + for (i = 0; i < len-1; i++) { + newChildren.push(this.children[i]); + newChildren.push(aSep); + } + newChildren.push(this.children[i]); + this.children = newChildren; + } + return this; + }; + + /** + * Call String.prototype.replace on the very right-most source snippet. Useful + * for trimming whitespace from the end of a source node, etc. + * + * @param aPattern The pattern to replace. + * @param aReplacement The thing to replace the pattern with. + */ + SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) { + var lastChild = this.children[this.children.length - 1]; + if (lastChild[isSourceNode]) { + lastChild.replaceRight(aPattern, aReplacement); + } + else if (typeof lastChild === 'string') { + this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement); + } + else { + this.children.push(''.replace(aPattern, aReplacement)); + } + return this; + }; + + /** + * Set the source content for a source file. This will be added to the SourceMapGenerator + * in the sourcesContent field. + * + * @param aSourceFile The filename of the source file + * @param aSourceContent The content of the source file + */ + SourceNode.prototype.setSourceContent = + function SourceNode_setSourceContent(aSourceFile, aSourceContent) { + this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent; + }; + + /** + * Walk over the tree of SourceNodes. The walking function is called for each + * source file content and is passed the filename and source content. + * + * @param aFn The traversal function. + */ + SourceNode.prototype.walkSourceContents = + function SourceNode_walkSourceContents(aFn) { + for (var i = 0, len = this.children.length; i < len; i++) { + if (this.children[i][isSourceNode]) { + this.children[i].walkSourceContents(aFn); + } + } + + var sources = Object.keys(this.sourceContents); + for (var i = 0, len = sources.length; i < len; i++) { + aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]); + } + }; + + /** + * Return the string representation of this source node. Walks over the tree + * and concatenates all the various snippets together to one string. + */ + SourceNode.prototype.toString = function SourceNode_toString() { + var str = ""; + this.walk(function (chunk) { + str += chunk; + }); + return str; + }; + + /** + * Returns the string representation of this source node along with a source + * map. + */ + SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) { + var generated = { + code: "", + line: 1, + column: 0 + }; + var map = new SourceMapGenerator(aArgs); + var sourceMappingActive = false; + var lastOriginalSource = null; + var lastOriginalLine = null; + var lastOriginalColumn = null; + var lastOriginalName = null; + this.walk(function (chunk, original) { + generated.code += chunk; + if (original.source !== null + && original.line !== null + && original.column !== null) { + if(lastOriginalSource !== original.source + || lastOriginalLine !== original.line + || lastOriginalColumn !== original.column + || lastOriginalName !== original.name) { + map.addMapping({ + source: original.source, + original: { + line: original.line, + column: original.column + }, + generated: { + line: generated.line, + column: generated.column + }, + name: original.name + }); + } + lastOriginalSource = original.source; + lastOriginalLine = original.line; + lastOriginalColumn = original.column; + lastOriginalName = original.name; + sourceMappingActive = true; + } else if (sourceMappingActive) { + map.addMapping({ + generated: { + line: generated.line, + column: generated.column + } + }); + lastOriginalSource = null; + sourceMappingActive = false; + } + for (var idx = 0, length = chunk.length; idx < length; idx++) { + if (chunk.charCodeAt(idx) === NEWLINE_CODE) { + generated.line++; + generated.column = 0; + // Mappings end at eol + if (idx + 1 === length) { + lastOriginalSource = null; + sourceMappingActive = false; + } else if (sourceMappingActive) { + map.addMapping({ + source: original.source, + original: { + line: original.line, + column: original.column + }, + generated: { + line: generated.line, + column: generated.column + }, + name: original.name + }); + } + } else { + generated.column++; + } + } + }); + this.walkSourceContents(function (sourceFile, sourceContent) { + map.setSourceContent(sourceFile, sourceContent); + }); + + return { code: generated.code, map: map }; + }; + + exports.SourceNode = SourceNode; + } + + +/***/ } +/******/ ]) +}); +; \ No newline at end of file diff --git a/devtools/shared/sourcemap/tests/unit/head_sourcemap.js b/devtools/shared/sourcemap/tests/unit/head_sourcemap.js new file mode 100644 index 000000000..12d4c078e --- /dev/null +++ b/devtools/shared/sourcemap/tests/unit/head_sourcemap.js @@ -0,0 +1,18 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cu = Components.utils; +var Cr = Components.results; + +function doesNotThrow(f) { + try { + f(); + } catch(e) { + ok(false, e + e.stack); + } +} + +var assert = this; diff --git a/devtools/shared/sourcemap/tests/unit/test_api.js b/devtools/shared/sourcemap/tests/unit/test_api.js new file mode 100644 index 000000000..16520e429 --- /dev/null +++ b/devtools/shared/sourcemap/tests/unit/test_api.js @@ -0,0 +1,3026 @@ +function run_test() { + for (var k in SOURCE_MAP_TEST_MODULE) { + if (/^test/.test(k)) { + SOURCE_MAP_TEST_MODULE[k](assert); + } + } +} + + +var SOURCE_MAP_TEST_MODULE = +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; +/******/ +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.loaded = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2012 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var sourceMap = __webpack_require__(1); + + exports['test that the api is properly exposed in the top level'] = function (assert) { + assert.equal(typeof sourceMap.SourceMapGenerator, "function"); + assert.equal(typeof sourceMap.SourceMapConsumer, "function"); + assert.equal(typeof sourceMap.SourceNode, "function"); + }; + } + + +/***/ }, +/* 1 */ +/***/ function(module, exports, __webpack_require__) { + + /* + * Copyright 2009-2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE.txt or: + * http://opensource.org/licenses/BSD-3-Clause + */ + exports.SourceMapGenerator = __webpack_require__(2).SourceMapGenerator; + exports.SourceMapConsumer = __webpack_require__(8).SourceMapConsumer; + exports.SourceNode = __webpack_require__(11).SourceNode; + + +/***/ }, +/* 2 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var base64VLQ = __webpack_require__(3); + var util = __webpack_require__(5); + var ArraySet = __webpack_require__(6).ArraySet; + var MappingList = __webpack_require__(7).MappingList; + + /** + * An instance of the SourceMapGenerator represents a source map which is + * being built incrementally. You may pass an object with the following + * properties: + * + * - file: The filename of the generated source. + * - sourceRoot: A root for all relative URLs in this source map. + */ + function SourceMapGenerator(aArgs) { + if (!aArgs) { + aArgs = {}; + } + this._file = util.getArg(aArgs, 'file', null); + this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null); + this._skipValidation = util.getArg(aArgs, 'skipValidation', false); + this._sources = new ArraySet(); + this._names = new ArraySet(); + this._mappings = new MappingList(); + this._sourcesContents = null; + } + + SourceMapGenerator.prototype._version = 3; + + /** + * Creates a new SourceMapGenerator based on a SourceMapConsumer + * + * @param aSourceMapConsumer The SourceMap. + */ + SourceMapGenerator.fromSourceMap = + function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) { + var sourceRoot = aSourceMapConsumer.sourceRoot; + var generator = new SourceMapGenerator({ + file: aSourceMapConsumer.file, + sourceRoot: sourceRoot + }); + aSourceMapConsumer.eachMapping(function (mapping) { + var newMapping = { + generated: { + line: mapping.generatedLine, + column: mapping.generatedColumn + } + }; + + if (mapping.source != null) { + newMapping.source = mapping.source; + if (sourceRoot != null) { + newMapping.source = util.relative(sourceRoot, newMapping.source); + } + + newMapping.original = { + line: mapping.originalLine, + column: mapping.originalColumn + }; + + if (mapping.name != null) { + newMapping.name = mapping.name; + } + } + + generator.addMapping(newMapping); + }); + aSourceMapConsumer.sources.forEach(function (sourceFile) { + var content = aSourceMapConsumer.sourceContentFor(sourceFile); + if (content != null) { + generator.setSourceContent(sourceFile, content); + } + }); + return generator; + }; + + /** + * Add a single mapping from original source line and column to the generated + * source's line and column for this source map being created. The mapping + * object should have the following properties: + * + * - generated: An object with the generated line and column positions. + * - original: An object with the original line and column positions. + * - source: The original source file (relative to the sourceRoot). + * - name: An optional original token name for this mapping. + */ + SourceMapGenerator.prototype.addMapping = + function SourceMapGenerator_addMapping(aArgs) { + var generated = util.getArg(aArgs, 'generated'); + var original = util.getArg(aArgs, 'original', null); + var source = util.getArg(aArgs, 'source', null); + var name = util.getArg(aArgs, 'name', null); + + if (!this._skipValidation) { + this._validateMapping(generated, original, source, name); + } + + if (source != null && !this._sources.has(source)) { + this._sources.add(source); + } + + if (name != null && !this._names.has(name)) { + this._names.add(name); + } + + this._mappings.add({ + generatedLine: generated.line, + generatedColumn: generated.column, + originalLine: original != null && original.line, + originalColumn: original != null && original.column, + source: source, + name: name + }); + }; + + /** + * Set the source content for a source file. + */ + SourceMapGenerator.prototype.setSourceContent = + function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) { + var source = aSourceFile; + if (this._sourceRoot != null) { + source = util.relative(this._sourceRoot, source); + } + + if (aSourceContent != null) { + // Add the source content to the _sourcesContents map. + // Create a new _sourcesContents map if the property is null. + if (!this._sourcesContents) { + this._sourcesContents = {}; + } + this._sourcesContents[util.toSetString(source)] = aSourceContent; + } else if (this._sourcesContents) { + // Remove the source file from the _sourcesContents map. + // If the _sourcesContents map is empty, set the property to null. + delete this._sourcesContents[util.toSetString(source)]; + if (Object.keys(this._sourcesContents).length === 0) { + this._sourcesContents = null; + } + } + }; + + /** + * Applies the mappings of a sub-source-map for a specific source file to the + * source map being generated. Each mapping to the supplied source file is + * rewritten using the supplied source map. Note: The resolution for the + * resulting mappings is the minimium of this map and the supplied map. + * + * @param aSourceMapConsumer The source map to be applied. + * @param aSourceFile Optional. The filename of the source file. + * If omitted, SourceMapConsumer's file property will be used. + * @param aSourceMapPath Optional. The dirname of the path to the source map + * to be applied. If relative, it is relative to the SourceMapConsumer. + * This parameter is needed when the two source maps aren't in the same + * directory, and the source map to be applied contains relative source + * paths. If so, those relative source paths need to be rewritten + * relative to the SourceMapGenerator. + */ + SourceMapGenerator.prototype.applySourceMap = + function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) { + var sourceFile = aSourceFile; + // If aSourceFile is omitted, we will use the file property of the SourceMap + if (aSourceFile == null) { + if (aSourceMapConsumer.file == null) { + throw new Error( + 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' + + 'or the source map\'s "file" property. Both were omitted.' + ); + } + sourceFile = aSourceMapConsumer.file; + } + var sourceRoot = this._sourceRoot; + // Make "sourceFile" relative if an absolute Url is passed. + if (sourceRoot != null) { + sourceFile = util.relative(sourceRoot, sourceFile); + } + // Applying the SourceMap can add and remove items from the sources and + // the names array. + var newSources = new ArraySet(); + var newNames = new ArraySet(); + + // Find mappings for the "sourceFile" + this._mappings.unsortedForEach(function (mapping) { + if (mapping.source === sourceFile && mapping.originalLine != null) { + // Check if it can be mapped by the source map, then update the mapping. + var original = aSourceMapConsumer.originalPositionFor({ + line: mapping.originalLine, + column: mapping.originalColumn + }); + if (original.source != null) { + // Copy mapping + mapping.source = original.source; + if (aSourceMapPath != null) { + mapping.source = util.join(aSourceMapPath, mapping.source) + } + if (sourceRoot != null) { + mapping.source = util.relative(sourceRoot, mapping.source); + } + mapping.originalLine = original.line; + mapping.originalColumn = original.column; + if (original.name != null) { + mapping.name = original.name; + } + } + } + + var source = mapping.source; + if (source != null && !newSources.has(source)) { + newSources.add(source); + } + + var name = mapping.name; + if (name != null && !newNames.has(name)) { + newNames.add(name); + } + + }, this); + this._sources = newSources; + this._names = newNames; + + // Copy sourcesContents of applied map. + aSourceMapConsumer.sources.forEach(function (sourceFile) { + var content = aSourceMapConsumer.sourceContentFor(sourceFile); + if (content != null) { + if (aSourceMapPath != null) { + sourceFile = util.join(aSourceMapPath, sourceFile); + } + if (sourceRoot != null) { + sourceFile = util.relative(sourceRoot, sourceFile); + } + this.setSourceContent(sourceFile, content); + } + }, this); + }; + + /** + * A mapping can have one of the three levels of data: + * + * 1. Just the generated position. + * 2. The Generated position, original position, and original source. + * 3. Generated and original position, original source, as well as a name + * token. + * + * To maintain consistency, we validate that any new mapping being added falls + * in to one of these categories. + */ + SourceMapGenerator.prototype._validateMapping = + function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource, + aName) { + if (aGenerated && 'line' in aGenerated && 'column' in aGenerated + && aGenerated.line > 0 && aGenerated.column >= 0 + && !aOriginal && !aSource && !aName) { + // Case 1. + return; + } + else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated + && aOriginal && 'line' in aOriginal && 'column' in aOriginal + && aGenerated.line > 0 && aGenerated.column >= 0 + && aOriginal.line > 0 && aOriginal.column >= 0 + && aSource) { + // Cases 2 and 3. + return; + } + else { + throw new Error('Invalid mapping: ' + JSON.stringify({ + generated: aGenerated, + source: aSource, + original: aOriginal, + name: aName + })); + } + }; + + /** + * Serialize the accumulated mappings in to the stream of base 64 VLQs + * specified by the source map format. + */ + SourceMapGenerator.prototype._serializeMappings = + function SourceMapGenerator_serializeMappings() { + var previousGeneratedColumn = 0; + var previousGeneratedLine = 1; + var previousOriginalColumn = 0; + var previousOriginalLine = 0; + var previousName = 0; + var previousSource = 0; + var result = ''; + var mapping; + var nameIdx; + var sourceIdx; + + var mappings = this._mappings.toArray(); + for (var i = 0, len = mappings.length; i < len; i++) { + mapping = mappings[i]; + + if (mapping.generatedLine !== previousGeneratedLine) { + previousGeneratedColumn = 0; + while (mapping.generatedLine !== previousGeneratedLine) { + result += ';'; + previousGeneratedLine++; + } + } + else { + if (i > 0) { + if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) { + continue; + } + result += ','; + } + } + + result += base64VLQ.encode(mapping.generatedColumn + - previousGeneratedColumn); + previousGeneratedColumn = mapping.generatedColumn; + + if (mapping.source != null) { + sourceIdx = this._sources.indexOf(mapping.source); + result += base64VLQ.encode(sourceIdx - previousSource); + previousSource = sourceIdx; + + // lines are stored 0-based in SourceMap spec version 3 + result += base64VLQ.encode(mapping.originalLine - 1 + - previousOriginalLine); + previousOriginalLine = mapping.originalLine - 1; + + result += base64VLQ.encode(mapping.originalColumn + - previousOriginalColumn); + previousOriginalColumn = mapping.originalColumn; + + if (mapping.name != null) { + nameIdx = this._names.indexOf(mapping.name); + result += base64VLQ.encode(nameIdx - previousName); + previousName = nameIdx; + } + } + } + + return result; + }; + + SourceMapGenerator.prototype._generateSourcesContent = + function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) { + return aSources.map(function (source) { + if (!this._sourcesContents) { + return null; + } + if (aSourceRoot != null) { + source = util.relative(aSourceRoot, source); + } + var key = util.toSetString(source); + return Object.prototype.hasOwnProperty.call(this._sourcesContents, + key) + ? this._sourcesContents[key] + : null; + }, this); + }; + + /** + * Externalize the source map. + */ + SourceMapGenerator.prototype.toJSON = + function SourceMapGenerator_toJSON() { + var map = { + version: this._version, + sources: this._sources.toArray(), + names: this._names.toArray(), + mappings: this._serializeMappings() + }; + if (this._file != null) { + map.file = this._file; + } + if (this._sourceRoot != null) { + map.sourceRoot = this._sourceRoot; + } + if (this._sourcesContents) { + map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot); + } + + return map; + }; + + /** + * Render the source map being generated to a string. + */ + SourceMapGenerator.prototype.toString = + function SourceMapGenerator_toString() { + return JSON.stringify(this.toJSON()); + }; + + exports.SourceMapGenerator = SourceMapGenerator; + } + + +/***/ }, +/* 3 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + * + * Based on the Base 64 VLQ implementation in Closure Compiler: + * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java + * + * Copyright 2011 The Closure Compiler Authors. All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + { + var base64 = __webpack_require__(4); + + // A single base 64 digit can contain 6 bits of data. For the base 64 variable + // length quantities we use in the source map spec, the first bit is the sign, + // the next four bits are the actual value, and the 6th bit is the + // continuation bit. The continuation bit tells us whether there are more + // digits in this value following this digit. + // + // Continuation + // | Sign + // | | + // V V + // 101011 + + var VLQ_BASE_SHIFT = 5; + + // binary: 100000 + var VLQ_BASE = 1 << VLQ_BASE_SHIFT; + + // binary: 011111 + var VLQ_BASE_MASK = VLQ_BASE - 1; + + // binary: 100000 + var VLQ_CONTINUATION_BIT = VLQ_BASE; + + /** + * Converts from a two-complement value to a value where the sign bit is + * placed in the least significant bit. For example, as decimals: + * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary) + * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary) + */ + function toVLQSigned(aValue) { + return aValue < 0 + ? ((-aValue) << 1) + 1 + : (aValue << 1) + 0; + } + + /** + * Converts to a two-complement value from a value where the sign bit is + * placed in the least significant bit. For example, as decimals: + * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1 + * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2 + */ + function fromVLQSigned(aValue) { + var isNegative = (aValue & 1) === 1; + var shifted = aValue >> 1; + return isNegative + ? -shifted + : shifted; + } + + /** + * Returns the base 64 VLQ encoded value. + */ + exports.encode = function base64VLQ_encode(aValue) { + var encoded = ""; + var digit; + + var vlq = toVLQSigned(aValue); + + do { + digit = vlq & VLQ_BASE_MASK; + vlq >>>= VLQ_BASE_SHIFT; + if (vlq > 0) { + // There are still more digits in this value, so we must make sure the + // continuation bit is marked. + digit |= VLQ_CONTINUATION_BIT; + } + encoded += base64.encode(digit); + } while (vlq > 0); + + return encoded; + }; + + /** + * Decodes the next base 64 VLQ value from the given string and returns the + * value and the rest of the string via the out parameter. + */ + exports.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) { + var strLen = aStr.length; + var result = 0; + var shift = 0; + var continuation, digit; + + do { + if (aIndex >= strLen) { + throw new Error("Expected more digits in base 64 VLQ value."); + } + + digit = base64.decode(aStr.charCodeAt(aIndex++)); + if (digit === -1) { + throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1)); + } + + continuation = !!(digit & VLQ_CONTINUATION_BIT); + digit &= VLQ_BASE_MASK; + result = result + (digit << shift); + shift += VLQ_BASE_SHIFT; + } while (continuation); + + aOutParam.value = fromVLQSigned(result); + aOutParam.rest = aIndex; + }; + } + + +/***/ }, +/* 4 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split(''); + + /** + * Encode an integer in the range of 0 to 63 to a single base 64 digit. + */ + exports.encode = function (number) { + if (0 <= number && number < intToCharMap.length) { + return intToCharMap[number]; + } + throw new TypeError("Must be between 0 and 63: " + number); + }; + + /** + * Decode a single base 64 character code digit to an integer. Returns -1 on + * failure. + */ + exports.decode = function (charCode) { + var bigA = 65; // 'A' + var bigZ = 90; // 'Z' + + var littleA = 97; // 'a' + var littleZ = 122; // 'z' + + var zero = 48; // '0' + var nine = 57; // '9' + + var plus = 43; // '+' + var slash = 47; // '/' + + var littleOffset = 26; + var numberOffset = 52; + + // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ + if (bigA <= charCode && charCode <= bigZ) { + return (charCode - bigA); + } + + // 26 - 51: abcdefghijklmnopqrstuvwxyz + if (littleA <= charCode && charCode <= littleZ) { + return (charCode - littleA + littleOffset); + } + + // 52 - 61: 0123456789 + if (zero <= charCode && charCode <= nine) { + return (charCode - zero + numberOffset); + } + + // 62: + + if (charCode == plus) { + return 62; + } + + // 63: / + if (charCode == slash) { + return 63; + } + + // Invalid base64 digit. + return -1; + }; + } + + +/***/ }, +/* 5 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + /** + * This is a helper function for getting values from parameter/options + * objects. + * + * @param args The object we are extracting values from + * @param name The name of the property we are getting. + * @param defaultValue An optional value to return if the property is missing + * from the object. If this is not specified and the property is missing, an + * error will be thrown. + */ + function getArg(aArgs, aName, aDefaultValue) { + if (aName in aArgs) { + return aArgs[aName]; + } else if (arguments.length === 3) { + return aDefaultValue; + } else { + throw new Error('"' + aName + '" is a required argument.'); + } + } + exports.getArg = getArg; + + var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.]*)(?::(\d+))?(\S*)$/; + var dataUrlRegexp = /^data:.+\,.+$/; + + function urlParse(aUrl) { + var match = aUrl.match(urlRegexp); + if (!match) { + return null; + } + return { + scheme: match[1], + auth: match[2], + host: match[3], + port: match[4], + path: match[5] + }; + } + exports.urlParse = urlParse; + + function urlGenerate(aParsedUrl) { + var url = ''; + if (aParsedUrl.scheme) { + url += aParsedUrl.scheme + ':'; + } + url += '//'; + if (aParsedUrl.auth) { + url += aParsedUrl.auth + '@'; + } + if (aParsedUrl.host) { + url += aParsedUrl.host; + } + if (aParsedUrl.port) { + url += ":" + aParsedUrl.port + } + if (aParsedUrl.path) { + url += aParsedUrl.path; + } + return url; + } + exports.urlGenerate = urlGenerate; + + /** + * Normalizes a path, or the path portion of a URL: + * + * - Replaces consequtive slashes with one slash. + * - Removes unnecessary '.' parts. + * - Removes unnecessary '/..' parts. + * + * Based on code in the Node.js 'path' core module. + * + * @param aPath The path or url to normalize. + */ + function normalize(aPath) { + var path = aPath; + var url = urlParse(aPath); + if (url) { + if (!url.path) { + return aPath; + } + path = url.path; + } + var isAbsolute = exports.isAbsolute(path); + + var parts = path.split(/\/+/); + for (var part, up = 0, i = parts.length - 1; i >= 0; i--) { + part = parts[i]; + if (part === '.') { + parts.splice(i, 1); + } else if (part === '..') { + up++; + } else if (up > 0) { + if (part === '') { + // The first part is blank if the path is absolute. Trying to go + // above the root is a no-op. Therefore we can remove all '..' parts + // directly after the root. + parts.splice(i + 1, up); + up = 0; + } else { + parts.splice(i, 2); + up--; + } + } + } + path = parts.join('/'); + + if (path === '') { + path = isAbsolute ? '/' : '.'; + } + + if (url) { + url.path = path; + return urlGenerate(url); + } + return path; + } + exports.normalize = normalize; + + /** + * Joins two paths/URLs. + * + * @param aRoot The root path or URL. + * @param aPath The path or URL to be joined with the root. + * + * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a + * scheme-relative URL: Then the scheme of aRoot, if any, is prepended + * first. + * - Otherwise aPath is a path. If aRoot is a URL, then its path portion + * is updated with the result and aRoot is returned. Otherwise the result + * is returned. + * - If aPath is absolute, the result is aPath. + * - Otherwise the two paths are joined with a slash. + * - Joining for example 'http://' and 'www.example.com' is also supported. + */ + function join(aRoot, aPath) { + if (aRoot === "") { + aRoot = "."; + } + if (aPath === "") { + aPath = "."; + } + var aPathUrl = urlParse(aPath); + var aRootUrl = urlParse(aRoot); + if (aRootUrl) { + aRoot = aRootUrl.path || '/'; + } + + // `join(foo, '//www.example.org')` + if (aPathUrl && !aPathUrl.scheme) { + if (aRootUrl) { + aPathUrl.scheme = aRootUrl.scheme; + } + return urlGenerate(aPathUrl); + } + + if (aPathUrl || aPath.match(dataUrlRegexp)) { + return aPath; + } + + // `join('http://', 'www.example.com')` + if (aRootUrl && !aRootUrl.host && !aRootUrl.path) { + aRootUrl.host = aPath; + return urlGenerate(aRootUrl); + } + + var joined = aPath.charAt(0) === '/' + ? aPath + : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath); + + if (aRootUrl) { + aRootUrl.path = joined; + return urlGenerate(aRootUrl); + } + return joined; + } + exports.join = join; + + exports.isAbsolute = function (aPath) { + return aPath.charAt(0) === '/' || !!aPath.match(urlRegexp); + }; + + /** + * Make a path relative to a URL or another path. + * + * @param aRoot The root path or URL. + * @param aPath The path or URL to be made relative to aRoot. + */ + function relative(aRoot, aPath) { + if (aRoot === "") { + aRoot = "."; + } + + aRoot = aRoot.replace(/\/$/, ''); + + // It is possible for the path to be above the root. In this case, simply + // checking whether the root is a prefix of the path won't work. Instead, we + // need to remove components from the root one by one, until either we find + // a prefix that fits, or we run out of components to remove. + var level = 0; + while (aPath.indexOf(aRoot + '/') !== 0) { + var index = aRoot.lastIndexOf("/"); + if (index < 0) { + return aPath; + } + + // If the only part of the root that is left is the scheme (i.e. http://, + // file:///, etc.), one or more slashes (/), or simply nothing at all, we + // have exhausted all components, so the path is not relative to the root. + aRoot = aRoot.slice(0, index); + if (aRoot.match(/^([^\/]+:\/)?\/*$/)) { + return aPath; + } + + ++level; + } + + // Make sure we add a "../" for each component we removed from the root. + return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1); + } + exports.relative = relative; + + /** + * Because behavior goes wacky when you set `__proto__` on objects, we + * have to prefix all the strings in our set with an arbitrary character. + * + * See https://github.com/mozilla/source-map/pull/31 and + * https://github.com/mozilla/source-map/issues/30 + * + * @param String aStr + */ + function toSetString(aStr) { + return '$' + aStr; + } + exports.toSetString = toSetString; + + function fromSetString(aStr) { + return aStr.substr(1); + } + exports.fromSetString = fromSetString; + + /** + * Comparator between two mappings where the original positions are compared. + * + * Optionally pass in `true` as `onlyCompareGenerated` to consider two + * mappings with the same original source/line/column, but different generated + * line and column the same. Useful when searching for a mapping with a + * stubbed out mapping. + */ + function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) { + var cmp = mappingA.source - mappingB.source; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0 || onlyCompareOriginal) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + return mappingA.name - mappingB.name; + } + exports.compareByOriginalPositions = compareByOriginalPositions; + + /** + * Comparator between two mappings with deflated source and name indices where + * the generated positions are compared. + * + * Optionally pass in `true` as `onlyCompareGenerated` to consider two + * mappings with the same generated line and column, but different + * source/name/original line and column the same. Useful when searching for a + * mapping with a stubbed out mapping. + */ + function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) { + var cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0 || onlyCompareGenerated) { + return cmp; + } + + cmp = mappingA.source - mappingB.source; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0) { + return cmp; + } + + return mappingA.name - mappingB.name; + } + exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated; + + function strcmp(aStr1, aStr2) { + if (aStr1 === aStr2) { + return 0; + } + + if (aStr1 > aStr2) { + return 1; + } + + return -1; + } + + /** + * Comparator between two mappings with inflated source and name strings where + * the generated positions are compared. + */ + function compareByGeneratedPositionsInflated(mappingA, mappingB) { + var cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0) { + return cmp; + } + + cmp = strcmp(mappingA.source, mappingB.source); + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0) { + return cmp; + } + + return strcmp(mappingA.name, mappingB.name); + } + exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated; + } + + +/***/ }, +/* 6 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var util = __webpack_require__(5); + + /** + * A data structure which is a combination of an array and a set. Adding a new + * member is O(1), testing for membership is O(1), and finding the index of an + * element is O(1). Removing elements from the set is not supported. Only + * strings are supported for membership. + */ + function ArraySet() { + this._array = []; + this._set = {}; + } + + /** + * Static method for creating ArraySet instances from an existing array. + */ + ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) { + var set = new ArraySet(); + for (var i = 0, len = aArray.length; i < len; i++) { + set.add(aArray[i], aAllowDuplicates); + } + return set; + }; + + /** + * Return how many unique items are in this ArraySet. If duplicates have been + * added, than those do not count towards the size. + * + * @returns Number + */ + ArraySet.prototype.size = function ArraySet_size() { + return Object.getOwnPropertyNames(this._set).length; + }; + + /** + * Add the given string to this set. + * + * @param String aStr + */ + ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) { + var sStr = util.toSetString(aStr); + var isDuplicate = this._set.hasOwnProperty(sStr); + var idx = this._array.length; + if (!isDuplicate || aAllowDuplicates) { + this._array.push(aStr); + } + if (!isDuplicate) { + this._set[sStr] = idx; + } + }; + + /** + * Is the given string a member of this set? + * + * @param String aStr + */ + ArraySet.prototype.has = function ArraySet_has(aStr) { + var sStr = util.toSetString(aStr); + return this._set.hasOwnProperty(sStr); + }; + + /** + * What is the index of the given string in the array? + * + * @param String aStr + */ + ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) { + var sStr = util.toSetString(aStr); + if (this._set.hasOwnProperty(sStr)) { + return this._set[sStr]; + } + throw new Error('"' + aStr + '" is not in the set.'); + }; + + /** + * What is the element at the given index? + * + * @param Number aIdx + */ + ArraySet.prototype.at = function ArraySet_at(aIdx) { + if (aIdx >= 0 && aIdx < this._array.length) { + return this._array[aIdx]; + } + throw new Error('No element indexed by ' + aIdx); + }; + + /** + * Returns the array representation of this set (which has the proper indices + * indicated by indexOf). Note that this is a copy of the internal array used + * for storing the members so that no one can mess with internal state. + */ + ArraySet.prototype.toArray = function ArraySet_toArray() { + return this._array.slice(); + }; + + exports.ArraySet = ArraySet; + } + + +/***/ }, +/* 7 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2014 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var util = __webpack_require__(5); + + /** + * Determine whether mappingB is after mappingA with respect to generated + * position. + */ + function generatedPositionAfter(mappingA, mappingB) { + // Optimized for most common case + var lineA = mappingA.generatedLine; + var lineB = mappingB.generatedLine; + var columnA = mappingA.generatedColumn; + var columnB = mappingB.generatedColumn; + return lineB > lineA || lineB == lineA && columnB >= columnA || + util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0; + } + + /** + * A data structure to provide a sorted view of accumulated mappings in a + * performance conscious manner. It trades a neglibable overhead in general + * case for a large speedup in case of mappings being added in order. + */ + function MappingList() { + this._array = []; + this._sorted = true; + // Serves as infimum + this._last = {generatedLine: -1, generatedColumn: 0}; + } + + /** + * Iterate through internal items. This method takes the same arguments that + * `Array.prototype.forEach` takes. + * + * NOTE: The order of the mappings is NOT guaranteed. + */ + MappingList.prototype.unsortedForEach = + function MappingList_forEach(aCallback, aThisArg) { + this._array.forEach(aCallback, aThisArg); + }; + + /** + * Add the given source mapping. + * + * @param Object aMapping + */ + MappingList.prototype.add = function MappingList_add(aMapping) { + if (generatedPositionAfter(this._last, aMapping)) { + this._last = aMapping; + this._array.push(aMapping); + } else { + this._sorted = false; + this._array.push(aMapping); + } + }; + + /** + * Returns the flat, sorted array of mappings. The mappings are sorted by + * generated position. + * + * WARNING: This method returns internal data without copying, for + * performance. The return value must NOT be mutated, and should be treated as + * an immutable borrow. If you want to take ownership, you must make your own + * copy. + */ + MappingList.prototype.toArray = function MappingList_toArray() { + if (!this._sorted) { + this._array.sort(util.compareByGeneratedPositionsInflated); + this._sorted = true; + } + return this._array; + }; + + exports.MappingList = MappingList; + } + + +/***/ }, +/* 8 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var util = __webpack_require__(5); + var binarySearch = __webpack_require__(9); + var ArraySet = __webpack_require__(6).ArraySet; + var base64VLQ = __webpack_require__(3); + var quickSort = __webpack_require__(10).quickSort; + + function SourceMapConsumer(aSourceMap) { + var sourceMap = aSourceMap; + if (typeof aSourceMap === 'string') { + sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); + } + + return sourceMap.sections != null + ? new IndexedSourceMapConsumer(sourceMap) + : new BasicSourceMapConsumer(sourceMap); + } + + SourceMapConsumer.fromSourceMap = function(aSourceMap) { + return BasicSourceMapConsumer.fromSourceMap(aSourceMap); + } + + /** + * The version of the source mapping spec that we are consuming. + */ + SourceMapConsumer.prototype._version = 3; + + // `__generatedMappings` and `__originalMappings` are arrays that hold the + // parsed mapping coordinates from the source map's "mappings" attribute. They + // are lazily instantiated, accessed via the `_generatedMappings` and + // `_originalMappings` getters respectively, and we only parse the mappings + // and create these arrays once queried for a source location. We jump through + // these hoops because there can be many thousands of mappings, and parsing + // them is expensive, so we only want to do it if we must. + // + // Each object in the arrays is of the form: + // + // { + // generatedLine: The line number in the generated code, + // generatedColumn: The column number in the generated code, + // source: The path to the original source file that generated this + // chunk of code, + // originalLine: The line number in the original source that + // corresponds to this chunk of generated code, + // originalColumn: The column number in the original source that + // corresponds to this chunk of generated code, + // name: The name of the original symbol which generated this chunk of + // code. + // } + // + // All properties except for `generatedLine` and `generatedColumn` can be + // `null`. + // + // `_generatedMappings` is ordered by the generated positions. + // + // `_originalMappings` is ordered by the original positions. + + SourceMapConsumer.prototype.__generatedMappings = null; + Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', { + get: function () { + if (!this.__generatedMappings) { + this._parseMappings(this._mappings, this.sourceRoot); + } + + return this.__generatedMappings; + } + }); + + SourceMapConsumer.prototype.__originalMappings = null; + Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', { + get: function () { + if (!this.__originalMappings) { + this._parseMappings(this._mappings, this.sourceRoot); + } + + return this.__originalMappings; + } + }); + + SourceMapConsumer.prototype._charIsMappingSeparator = + function SourceMapConsumer_charIsMappingSeparator(aStr, index) { + var c = aStr.charAt(index); + return c === ";" || c === ","; + }; + + /** + * Parse the mappings in a string in to a data structure which we can easily + * query (the ordered arrays in the `this.__generatedMappings` and + * `this.__originalMappings` properties). + */ + SourceMapConsumer.prototype._parseMappings = + function SourceMapConsumer_parseMappings(aStr, aSourceRoot) { + throw new Error("Subclasses must implement _parseMappings"); + }; + + SourceMapConsumer.GENERATED_ORDER = 1; + SourceMapConsumer.ORIGINAL_ORDER = 2; + + SourceMapConsumer.GREATEST_LOWER_BOUND = 1; + SourceMapConsumer.LEAST_UPPER_BOUND = 2; + + /** + * Iterate over each mapping between an original source/line/column and a + * generated line/column in this source map. + * + * @param Function aCallback + * The function that is called with each mapping. + * @param Object aContext + * Optional. If specified, this object will be the value of `this` every + * time that `aCallback` is called. + * @param aOrder + * Either `SourceMapConsumer.GENERATED_ORDER` or + * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to + * iterate over the mappings sorted by the generated file's line/column + * order or the original's source/line/column order, respectively. Defaults to + * `SourceMapConsumer.GENERATED_ORDER`. + */ + SourceMapConsumer.prototype.eachMapping = + function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) { + var context = aContext || null; + var order = aOrder || SourceMapConsumer.GENERATED_ORDER; + + var mappings; + switch (order) { + case SourceMapConsumer.GENERATED_ORDER: + mappings = this._generatedMappings; + break; + case SourceMapConsumer.ORIGINAL_ORDER: + mappings = this._originalMappings; + break; + default: + throw new Error("Unknown order of iteration."); + } + + var sourceRoot = this.sourceRoot; + mappings.map(function (mapping) { + var source = mapping.source === null ? null : this._sources.at(mapping.source); + if (source != null && sourceRoot != null) { + source = util.join(sourceRoot, source); + } + return { + source: source, + generatedLine: mapping.generatedLine, + generatedColumn: mapping.generatedColumn, + originalLine: mapping.originalLine, + originalColumn: mapping.originalColumn, + name: mapping.name === null ? null : this._names.at(mapping.name) + }; + }, this).forEach(aCallback, context); + }; + + /** + * Returns all generated line and column information for the original source, + * line, and column provided. If no column is provided, returns all mappings + * corresponding to a either the line we are searching for or the next + * closest line that has any mappings. Otherwise, returns all mappings + * corresponding to the given line and either the column we are searching for + * or the next closest column that has any offsets. + * + * The only argument is an object with the following properties: + * + * - source: The filename of the original source. + * - line: The line number in the original source. + * - column: Optional. the column number in the original source. + * + * and an array of objects is returned, each with the following properties: + * + * - line: The line number in the generated source, or null. + * - column: The column number in the generated source, or null. + */ + SourceMapConsumer.prototype.allGeneratedPositionsFor = + function SourceMapConsumer_allGeneratedPositionsFor(aArgs) { + var line = util.getArg(aArgs, 'line'); + + // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping + // returns the index of the closest mapping less than the needle. By + // setting needle.originalColumn to 0, we thus find the last mapping for + // the given line, provided such a mapping exists. + var needle = { + source: util.getArg(aArgs, 'source'), + originalLine: line, + originalColumn: util.getArg(aArgs, 'column', 0) + }; + + if (this.sourceRoot != null) { + needle.source = util.relative(this.sourceRoot, needle.source); + } + if (!this._sources.has(needle.source)) { + return []; + } + needle.source = this._sources.indexOf(needle.source); + + var mappings = []; + + var index = this._findMapping(needle, + this._originalMappings, + "originalLine", + "originalColumn", + util.compareByOriginalPositions, + binarySearch.LEAST_UPPER_BOUND); + if (index >= 0) { + var mapping = this._originalMappings[index]; + + if (aArgs.column === undefined) { + var originalLine = mapping.originalLine; + + // Iterate until either we run out of mappings, or we run into + // a mapping for a different line than the one we found. Since + // mappings are sorted, this is guaranteed to find all mappings for + // the line we found. + while (mapping && mapping.originalLine === originalLine) { + mappings.push({ + line: util.getArg(mapping, 'generatedLine', null), + column: util.getArg(mapping, 'generatedColumn', null), + lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) + }); + + mapping = this._originalMappings[++index]; + } + } else { + var originalColumn = mapping.originalColumn; + + // Iterate until either we run out of mappings, or we run into + // a mapping for a different line than the one we were searching for. + // Since mappings are sorted, this is guaranteed to find all mappings for + // the line we are searching for. + while (mapping && + mapping.originalLine === line && + mapping.originalColumn == originalColumn) { + mappings.push({ + line: util.getArg(mapping, 'generatedLine', null), + column: util.getArg(mapping, 'generatedColumn', null), + lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) + }); + + mapping = this._originalMappings[++index]; + } + } + } + + return mappings; + }; + + exports.SourceMapConsumer = SourceMapConsumer; + + /** + * A BasicSourceMapConsumer instance represents a parsed source map which we can + * query for information about the original file positions by giving it a file + * position in the generated source. + * + * The only parameter is the raw source map (either as a JSON string, or + * already parsed to an object). According to the spec, source maps have the + * following attributes: + * + * - version: Which version of the source map spec this map is following. + * - sources: An array of URLs to the original source files. + * - names: An array of identifiers which can be referrenced by individual mappings. + * - sourceRoot: Optional. The URL root from which all sources are relative. + * - sourcesContent: Optional. An array of contents of the original source files. + * - mappings: A string of base64 VLQs which contain the actual mappings. + * - file: Optional. The generated file this source map is associated with. + * + * Here is an example source map, taken from the source map spec[0]: + * + * { + * version : 3, + * file: "out.js", + * sourceRoot : "", + * sources: ["foo.js", "bar.js"], + * names: ["src", "maps", "are", "fun"], + * mappings: "AA,AB;;ABCDE;" + * } + * + * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1# + */ + function BasicSourceMapConsumer(aSourceMap) { + var sourceMap = aSourceMap; + if (typeof aSourceMap === 'string') { + sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); + } + + var version = util.getArg(sourceMap, 'version'); + var sources = util.getArg(sourceMap, 'sources'); + // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which + // requires the array) to play nice here. + var names = util.getArg(sourceMap, 'names', []); + var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null); + var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null); + var mappings = util.getArg(sourceMap, 'mappings'); + var file = util.getArg(sourceMap, 'file', null); + + // Once again, Sass deviates from the spec and supplies the version as a + // string rather than a number, so we use loose equality checking here. + if (version != this._version) { + throw new Error('Unsupported version: ' + version); + } + + sources = sources + // Some source maps produce relative source paths like "./foo.js" instead of + // "foo.js". Normalize these first so that future comparisons will succeed. + // See bugzil.la/1090768. + .map(util.normalize) + // Always ensure that absolute sources are internally stored relative to + // the source root, if the source root is absolute. Not doing this would + // be particularly problematic when the source root is a prefix of the + // source (valid, but why??). See github issue #199 and bugzil.la/1188982. + .map(function (source) { + return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source) + ? util.relative(sourceRoot, source) + : source; + }); + + // Pass `true` below to allow duplicate names and sources. While source maps + // are intended to be compressed and deduplicated, the TypeScript compiler + // sometimes generates source maps with duplicates in them. See Github issue + // #72 and bugzil.la/889492. + this._names = ArraySet.fromArray(names, true); + this._sources = ArraySet.fromArray(sources, true); + + this.sourceRoot = sourceRoot; + this.sourcesContent = sourcesContent; + this._mappings = mappings; + this.file = file; + } + + BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype); + BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer; + + /** + * Create a BasicSourceMapConsumer from a SourceMapGenerator. + * + * @param SourceMapGenerator aSourceMap + * The source map that will be consumed. + * @returns BasicSourceMapConsumer + */ + BasicSourceMapConsumer.fromSourceMap = + function SourceMapConsumer_fromSourceMap(aSourceMap) { + var smc = Object.create(BasicSourceMapConsumer.prototype); + + var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true); + var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true); + smc.sourceRoot = aSourceMap._sourceRoot; + smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(), + smc.sourceRoot); + smc.file = aSourceMap._file; + + // Because we are modifying the entries (by converting string sources and + // names to indices into the sources and names ArraySets), we have to make + // a copy of the entry or else bad things happen. Shared mutable state + // strikes again! See github issue #191. + + var generatedMappings = aSourceMap._mappings.toArray().slice(); + var destGeneratedMappings = smc.__generatedMappings = []; + var destOriginalMappings = smc.__originalMappings = []; + + for (var i = 0, length = generatedMappings.length; i < length; i++) { + var srcMapping = generatedMappings[i]; + var destMapping = new Mapping; + destMapping.generatedLine = srcMapping.generatedLine; + destMapping.generatedColumn = srcMapping.generatedColumn; + + if (srcMapping.source) { + destMapping.source = sources.indexOf(srcMapping.source); + destMapping.originalLine = srcMapping.originalLine; + destMapping.originalColumn = srcMapping.originalColumn; + + if (srcMapping.name) { + destMapping.name = names.indexOf(srcMapping.name); + } + + destOriginalMappings.push(destMapping); + } + + destGeneratedMappings.push(destMapping); + } + + quickSort(smc.__originalMappings, util.compareByOriginalPositions); + + return smc; + }; + + /** + * The version of the source mapping spec that we are consuming. + */ + BasicSourceMapConsumer.prototype._version = 3; + + /** + * The list of original sources. + */ + Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', { + get: function () { + return this._sources.toArray().map(function (s) { + return this.sourceRoot != null ? util.join(this.sourceRoot, s) : s; + }, this); + } + }); + + /** + * Provide the JIT with a nice shape / hidden class. + */ + function Mapping() { + this.generatedLine = 0; + this.generatedColumn = 0; + this.source = null; + this.originalLine = null; + this.originalColumn = null; + this.name = null; + } + + /** + * Parse the mappings in a string in to a data structure which we can easily + * query (the ordered arrays in the `this.__generatedMappings` and + * `this.__originalMappings` properties). + */ + BasicSourceMapConsumer.prototype._parseMappings = + function SourceMapConsumer_parseMappings(aStr, aSourceRoot) { + var generatedLine = 1; + var previousGeneratedColumn = 0; + var previousOriginalLine = 0; + var previousOriginalColumn = 0; + var previousSource = 0; + var previousName = 0; + var length = aStr.length; + var index = 0; + var cachedSegments = {}; + var temp = {}; + var originalMappings = []; + var generatedMappings = []; + var mapping, str, segment, end, value; + + while (index < length) { + if (aStr.charAt(index) === ';') { + generatedLine++; + index++; + previousGeneratedColumn = 0; + } + else if (aStr.charAt(index) === ',') { + index++; + } + else { + mapping = new Mapping(); + mapping.generatedLine = generatedLine; + + // Because each offset is encoded relative to the previous one, + // many segments often have the same encoding. We can exploit this + // fact by caching the parsed variable length fields of each segment, + // allowing us to avoid a second parse if we encounter the same + // segment again. + for (end = index; end < length; end++) { + if (this._charIsMappingSeparator(aStr, end)) { + break; + } + } + str = aStr.slice(index, end); + + segment = cachedSegments[str]; + if (segment) { + index += str.length; + } else { + segment = []; + while (index < end) { + base64VLQ.decode(aStr, index, temp); + value = temp.value; + index = temp.rest; + segment.push(value); + } + + if (segment.length === 2) { + throw new Error('Found a source, but no line and column'); + } + + if (segment.length === 3) { + throw new Error('Found a source and line, but no column'); + } + + cachedSegments[str] = segment; + } + + // Generated column. + mapping.generatedColumn = previousGeneratedColumn + segment[0]; + previousGeneratedColumn = mapping.generatedColumn; + + if (segment.length > 1) { + // Original source. + mapping.source = previousSource + segment[1]; + previousSource += segment[1]; + + // Original line. + mapping.originalLine = previousOriginalLine + segment[2]; + previousOriginalLine = mapping.originalLine; + // Lines are stored 0-based + mapping.originalLine += 1; + + // Original column. + mapping.originalColumn = previousOriginalColumn + segment[3]; + previousOriginalColumn = mapping.originalColumn; + + if (segment.length > 4) { + // Original name. + mapping.name = previousName + segment[4]; + previousName += segment[4]; + } + } + + generatedMappings.push(mapping); + if (typeof mapping.originalLine === 'number') { + originalMappings.push(mapping); + } + } + } + + quickSort(generatedMappings, util.compareByGeneratedPositionsDeflated); + this.__generatedMappings = generatedMappings; + + quickSort(originalMappings, util.compareByOriginalPositions); + this.__originalMappings = originalMappings; + }; + + /** + * Find the mapping that best matches the hypothetical "needle" mapping that + * we are searching for in the given "haystack" of mappings. + */ + BasicSourceMapConsumer.prototype._findMapping = + function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName, + aColumnName, aComparator, aBias) { + // To return the position we are searching for, we must first find the + // mapping for the given position and then return the opposite position it + // points to. Because the mappings are sorted, we can use binary search to + // find the best mapping. + + if (aNeedle[aLineName] <= 0) { + throw new TypeError('Line must be greater than or equal to 1, got ' + + aNeedle[aLineName]); + } + if (aNeedle[aColumnName] < 0) { + throw new TypeError('Column must be greater than or equal to 0, got ' + + aNeedle[aColumnName]); + } + + return binarySearch.search(aNeedle, aMappings, aComparator, aBias); + }; + + /** + * Compute the last column for each generated mapping. The last column is + * inclusive. + */ + BasicSourceMapConsumer.prototype.computeColumnSpans = + function SourceMapConsumer_computeColumnSpans() { + for (var index = 0; index < this._generatedMappings.length; ++index) { + var mapping = this._generatedMappings[index]; + + // Mappings do not contain a field for the last generated columnt. We + // can come up with an optimistic estimate, however, by assuming that + // mappings are contiguous (i.e. given two consecutive mappings, the + // first mapping ends where the second one starts). + if (index + 1 < this._generatedMappings.length) { + var nextMapping = this._generatedMappings[index + 1]; + + if (mapping.generatedLine === nextMapping.generatedLine) { + mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1; + continue; + } + } + + // The last mapping for each line spans the entire line. + mapping.lastGeneratedColumn = Infinity; + } + }; + + /** + * Returns the original source, line, and column information for the generated + * source's line and column positions provided. The only argument is an object + * with the following properties: + * + * - line: The line number in the generated source. + * - column: The column number in the generated source. + * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or + * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. + * + * and an object is returned with the following properties: + * + * - source: The original source file, or null. + * - line: The line number in the original source, or null. + * - column: The column number in the original source, or null. + * - name: The original identifier, or null. + */ + BasicSourceMapConsumer.prototype.originalPositionFor = + function SourceMapConsumer_originalPositionFor(aArgs) { + var needle = { + generatedLine: util.getArg(aArgs, 'line'), + generatedColumn: util.getArg(aArgs, 'column') + }; + + var index = this._findMapping( + needle, + this._generatedMappings, + "generatedLine", + "generatedColumn", + util.compareByGeneratedPositionsDeflated, + util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND) + ); + + if (index >= 0) { + var mapping = this._generatedMappings[index]; + + if (mapping.generatedLine === needle.generatedLine) { + var source = util.getArg(mapping, 'source', null); + if (source !== null) { + source = this._sources.at(source); + if (this.sourceRoot != null) { + source = util.join(this.sourceRoot, source); + } + } + var name = util.getArg(mapping, 'name', null); + if (name !== null) { + name = this._names.at(name); + } + return { + source: source, + line: util.getArg(mapping, 'originalLine', null), + column: util.getArg(mapping, 'originalColumn', null), + name: name + }; + } + } + + return { + source: null, + line: null, + column: null, + name: null + }; + }; + + /** + * Return true if we have the source content for every source in the source + * map, false otherwise. + */ + BasicSourceMapConsumer.prototype.hasContentsOfAllSources = + function BasicSourceMapConsumer_hasContentsOfAllSources() { + if (!this.sourcesContent) { + return false; + } + return this.sourcesContent.length >= this._sources.size() && + !this.sourcesContent.some(function (sc) { return sc == null; }); + }; + + /** + * Returns the original source content. The only argument is the url of the + * original source file. Returns null if no original source content is + * availible. + */ + BasicSourceMapConsumer.prototype.sourceContentFor = + function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) { + if (!this.sourcesContent) { + return null; + } + + if (this.sourceRoot != null) { + aSource = util.relative(this.sourceRoot, aSource); + } + + if (this._sources.has(aSource)) { + return this.sourcesContent[this._sources.indexOf(aSource)]; + } + + var url; + if (this.sourceRoot != null + && (url = util.urlParse(this.sourceRoot))) { + // XXX: file:// URIs and absolute paths lead to unexpected behavior for + // many users. We can help them out when they expect file:// URIs to + // behave like it would if they were running a local HTTP server. See + // https://bugzilla.mozilla.org/show_bug.cgi?id=885597. + var fileUriAbsPath = aSource.replace(/^file:\/\//, ""); + if (url.scheme == "file" + && this._sources.has(fileUriAbsPath)) { + return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)] + } + + if ((!url.path || url.path == "/") + && this._sources.has("/" + aSource)) { + return this.sourcesContent[this._sources.indexOf("/" + aSource)]; + } + } + + // This function is used recursively from + // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we + // don't want to throw if we can't find the source - we just want to + // return null, so we provide a flag to exit gracefully. + if (nullOnMissing) { + return null; + } + else { + throw new Error('"' + aSource + '" is not in the SourceMap.'); + } + }; + + /** + * Returns the generated line and column information for the original source, + * line, and column positions provided. The only argument is an object with + * the following properties: + * + * - source: The filename of the original source. + * - line: The line number in the original source. + * - column: The column number in the original source. + * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or + * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. + * + * and an object is returned with the following properties: + * + * - line: The line number in the generated source, or null. + * - column: The column number in the generated source, or null. + */ + BasicSourceMapConsumer.prototype.generatedPositionFor = + function SourceMapConsumer_generatedPositionFor(aArgs) { + var source = util.getArg(aArgs, 'source'); + if (this.sourceRoot != null) { + source = util.relative(this.sourceRoot, source); + } + if (!this._sources.has(source)) { + return { + line: null, + column: null, + lastColumn: null + }; + } + source = this._sources.indexOf(source); + + var needle = { + source: source, + originalLine: util.getArg(aArgs, 'line'), + originalColumn: util.getArg(aArgs, 'column') + }; + + var index = this._findMapping( + needle, + this._originalMappings, + "originalLine", + "originalColumn", + util.compareByOriginalPositions, + util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND) + ); + + if (index >= 0) { + var mapping = this._originalMappings[index]; + + if (mapping.source === needle.source) { + return { + line: util.getArg(mapping, 'generatedLine', null), + column: util.getArg(mapping, 'generatedColumn', null), + lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) + }; + } + } + + return { + line: null, + column: null, + lastColumn: null + }; + }; + + exports.BasicSourceMapConsumer = BasicSourceMapConsumer; + + /** + * An IndexedSourceMapConsumer instance represents a parsed source map which + * we can query for information. It differs from BasicSourceMapConsumer in + * that it takes "indexed" source maps (i.e. ones with a "sections" field) as + * input. + * + * The only parameter is a raw source map (either as a JSON string, or already + * parsed to an object). According to the spec for indexed source maps, they + * have the following attributes: + * + * - version: Which version of the source map spec this map is following. + * - file: Optional. The generated file this source map is associated with. + * - sections: A list of section definitions. + * + * Each value under the "sections" field has two fields: + * - offset: The offset into the original specified at which this section + * begins to apply, defined as an object with a "line" and "column" + * field. + * - map: A source map definition. This source map could also be indexed, + * but doesn't have to be. + * + * Instead of the "map" field, it's also possible to have a "url" field + * specifying a URL to retrieve a source map from, but that's currently + * unsupported. + * + * Here's an example source map, taken from the source map spec[0], but + * modified to omit a section which uses the "url" field. + * + * { + * version : 3, + * file: "app.js", + * sections: [{ + * offset: {line:100, column:10}, + * map: { + * version : 3, + * file: "section.js", + * sources: ["foo.js", "bar.js"], + * names: ["src", "maps", "are", "fun"], + * mappings: "AAAA,E;;ABCDE;" + * } + * }], + * } + * + * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt + */ + function IndexedSourceMapConsumer(aSourceMap) { + var sourceMap = aSourceMap; + if (typeof aSourceMap === 'string') { + sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); + } + + var version = util.getArg(sourceMap, 'version'); + var sections = util.getArg(sourceMap, 'sections'); + + if (version != this._version) { + throw new Error('Unsupported version: ' + version); + } + + this._sources = new ArraySet(); + this._names = new ArraySet(); + + var lastOffset = { + line: -1, + column: 0 + }; + this._sections = sections.map(function (s) { + if (s.url) { + // The url field will require support for asynchronicity. + // See https://github.com/mozilla/source-map/issues/16 + throw new Error('Support for url field in sections not implemented.'); + } + var offset = util.getArg(s, 'offset'); + var offsetLine = util.getArg(offset, 'line'); + var offsetColumn = util.getArg(offset, 'column'); + + if (offsetLine < lastOffset.line || + (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) { + throw new Error('Section offsets must be ordered and non-overlapping.'); + } + lastOffset = offset; + + return { + generatedOffset: { + // The offset fields are 0-based, but we use 1-based indices when + // encoding/decoding from VLQ. + generatedLine: offsetLine + 1, + generatedColumn: offsetColumn + 1 + }, + consumer: new SourceMapConsumer(util.getArg(s, 'map')) + } + }); + } + + IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype); + IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer; + + /** + * The version of the source mapping spec that we are consuming. + */ + IndexedSourceMapConsumer.prototype._version = 3; + + /** + * The list of original sources. + */ + Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', { + get: function () { + var sources = []; + for (var i = 0; i < this._sections.length; i++) { + for (var j = 0; j < this._sections[i].consumer.sources.length; j++) { + sources.push(this._sections[i].consumer.sources[j]); + } + } + return sources; + } + }); + + /** + * Returns the original source, line, and column information for the generated + * source's line and column positions provided. The only argument is an object + * with the following properties: + * + * - line: The line number in the generated source. + * - column: The column number in the generated source. + * + * and an object is returned with the following properties: + * + * - source: The original source file, or null. + * - line: The line number in the original source, or null. + * - column: The column number in the original source, or null. + * - name: The original identifier, or null. + */ + IndexedSourceMapConsumer.prototype.originalPositionFor = + function IndexedSourceMapConsumer_originalPositionFor(aArgs) { + var needle = { + generatedLine: util.getArg(aArgs, 'line'), + generatedColumn: util.getArg(aArgs, 'column') + }; + + // Find the section containing the generated position we're trying to map + // to an original position. + var sectionIndex = binarySearch.search(needle, this._sections, + function(needle, section) { + var cmp = needle.generatedLine - section.generatedOffset.generatedLine; + if (cmp) { + return cmp; + } + + return (needle.generatedColumn - + section.generatedOffset.generatedColumn); + }); + var section = this._sections[sectionIndex]; + + if (!section) { + return { + source: null, + line: null, + column: null, + name: null + }; + } + + return section.consumer.originalPositionFor({ + line: needle.generatedLine - + (section.generatedOffset.generatedLine - 1), + column: needle.generatedColumn - + (section.generatedOffset.generatedLine === needle.generatedLine + ? section.generatedOffset.generatedColumn - 1 + : 0), + bias: aArgs.bias + }); + }; + + /** + * Return true if we have the source content for every source in the source + * map, false otherwise. + */ + IndexedSourceMapConsumer.prototype.hasContentsOfAllSources = + function IndexedSourceMapConsumer_hasContentsOfAllSources() { + return this._sections.every(function (s) { + return s.consumer.hasContentsOfAllSources(); + }); + }; + + /** + * Returns the original source content. The only argument is the url of the + * original source file. Returns null if no original source content is + * available. + */ + IndexedSourceMapConsumer.prototype.sourceContentFor = + function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) { + for (var i = 0; i < this._sections.length; i++) { + var section = this._sections[i]; + + var content = section.consumer.sourceContentFor(aSource, true); + if (content) { + return content; + } + } + if (nullOnMissing) { + return null; + } + else { + throw new Error('"' + aSource + '" is not in the SourceMap.'); + } + }; + + /** + * Returns the generated line and column information for the original source, + * line, and column positions provided. The only argument is an object with + * the following properties: + * + * - source: The filename of the original source. + * - line: The line number in the original source. + * - column: The column number in the original source. + * + * and an object is returned with the following properties: + * + * - line: The line number in the generated source, or null. + * - column: The column number in the generated source, or null. + */ + IndexedSourceMapConsumer.prototype.generatedPositionFor = + function IndexedSourceMapConsumer_generatedPositionFor(aArgs) { + for (var i = 0; i < this._sections.length; i++) { + var section = this._sections[i]; + + // Only consider this section if the requested source is in the list of + // sources of the consumer. + if (section.consumer.sources.indexOf(util.getArg(aArgs, 'source')) === -1) { + continue; + } + var generatedPosition = section.consumer.generatedPositionFor(aArgs); + if (generatedPosition) { + var ret = { + line: generatedPosition.line + + (section.generatedOffset.generatedLine - 1), + column: generatedPosition.column + + (section.generatedOffset.generatedLine === generatedPosition.line + ? section.generatedOffset.generatedColumn - 1 + : 0) + }; + return ret; + } + } + + return { + line: null, + column: null + }; + }; + + /** + * Parse the mappings in a string in to a data structure which we can easily + * query (the ordered arrays in the `this.__generatedMappings` and + * `this.__originalMappings` properties). + */ + IndexedSourceMapConsumer.prototype._parseMappings = + function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) { + this.__generatedMappings = []; + this.__originalMappings = []; + for (var i = 0; i < this._sections.length; i++) { + var section = this._sections[i]; + var sectionMappings = section.consumer._generatedMappings; + for (var j = 0; j < sectionMappings.length; j++) { + var mapping = sectionMappings[i]; + + var source = section.consumer._sources.at(mapping.source); + if (section.consumer.sourceRoot !== null) { + source = util.join(section.consumer.sourceRoot, source); + } + this._sources.add(source); + source = this._sources.indexOf(source); + + var name = section.consumer._names.at(mapping.name); + this._names.add(name); + name = this._names.indexOf(name); + + // The mappings coming from the consumer for the section have + // generated positions relative to the start of the section, so we + // need to offset them to be relative to the start of the concatenated + // generated file. + var adjustedMapping = { + source: source, + generatedLine: mapping.generatedLine + + (section.generatedOffset.generatedLine - 1), + generatedColumn: mapping.column + + (section.generatedOffset.generatedLine === mapping.generatedLine) + ? section.generatedOffset.generatedColumn - 1 + : 0, + originalLine: mapping.originalLine, + originalColumn: mapping.originalColumn, + name: name + }; + + this.__generatedMappings.push(adjustedMapping); + if (typeof adjustedMapping.originalLine === 'number') { + this.__originalMappings.push(adjustedMapping); + } + } + } + + quickSort(this.__generatedMappings, util.compareByGeneratedPositionsDeflated); + quickSort(this.__originalMappings, util.compareByOriginalPositions); + }; + + exports.IndexedSourceMapConsumer = IndexedSourceMapConsumer; + } + + +/***/ }, +/* 9 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + exports.GREATEST_LOWER_BOUND = 1; + exports.LEAST_UPPER_BOUND = 2; + + /** + * Recursive implementation of binary search. + * + * @param aLow Indices here and lower do not contain the needle. + * @param aHigh Indices here and higher do not contain the needle. + * @param aNeedle The element being searched for. + * @param aHaystack The non-empty array being searched. + * @param aCompare Function which takes two elements and returns -1, 0, or 1. + * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or + * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + */ + function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) { + // This function terminates when one of the following is true: + // + // 1. We find the exact element we are looking for. + // + // 2. We did not find the exact element, but we can return the index of + // the next-closest element. + // + // 3. We did not find the exact element, and there is no next-closest + // element than the one we are searching for, so we return -1. + var mid = Math.floor((aHigh - aLow) / 2) + aLow; + var cmp = aCompare(aNeedle, aHaystack[mid], true); + if (cmp === 0) { + // Found the element we are looking for. + return mid; + } + else if (cmp > 0) { + // Our needle is greater than aHaystack[mid]. + if (aHigh - mid > 1) { + // The element is in the upper half. + return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias); + } + + // The exact needle element was not found in this haystack. Determine if + // we are in termination case (3) or (2) and return the appropriate thing. + if (aBias == exports.LEAST_UPPER_BOUND) { + return aHigh < aHaystack.length ? aHigh : -1; + } else { + return mid; + } + } + else { + // Our needle is less than aHaystack[mid]. + if (mid - aLow > 1) { + // The element is in the lower half. + return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias); + } + + // we are in termination case (3) or (2) and return the appropriate thing. + if (aBias == exports.LEAST_UPPER_BOUND) { + return mid; + } else { + return aLow < 0 ? -1 : aLow; + } + } + } + + /** + * This is an implementation of binary search which will always try and return + * the index of the closest element if there is no exact hit. This is because + * mappings between original and generated line/col pairs are single points, + * and there is an implicit region between each of them, so a miss just means + * that you aren't on the very start of a region. + * + * @param aNeedle The element you are looking for. + * @param aHaystack The array that is being searched. + * @param aCompare A function which takes the needle and an element in the + * array and returns -1, 0, or 1 depending on whether the needle is less + * than, equal to, or greater than the element, respectively. + * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or + * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'. + */ + exports.search = function search(aNeedle, aHaystack, aCompare, aBias) { + if (aHaystack.length === 0) { + return -1; + } + + var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, + aCompare, aBias || exports.GREATEST_LOWER_BOUND); + if (index < 0) { + return -1; + } + + // We have found either the exact element, or the next-closest element than + // the one we are searching for. However, there may be more than one such + // element. Make sure we always return the smallest of these. + while (index - 1 >= 0) { + if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) { + break; + } + --index; + } + + return index; + }; + } + + +/***/ }, +/* 10 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + // It turns out that some (most?) JavaScript engines don't self-host + // `Array.prototype.sort`. This makes sense because C++ will likely remain + // faster than JS when doing raw CPU-intensive sorting. However, when using a + // custom comparator function, calling back and forth between the VM's C++ and + // JIT'd JS is rather slow *and* loses JIT type information, resulting in + // worse generated code for the comparator function than would be optimal. In + // fact, when sorting with a comparator, these costs outweigh the benefits of + // sorting in C++. By using our own JS-implemented Quick Sort (below), we get + // a ~3500ms mean speed-up in `bench/bench.html`. + + /** + * Swap the elements indexed by `x` and `y` in the array `ary`. + * + * @param {Array} ary + * The array. + * @param {Number} x + * The index of the first item. + * @param {Number} y + * The index of the second item. + */ + function swap(ary, x, y) { + var temp = ary[x]; + ary[x] = ary[y]; + ary[y] = temp; + } + + /** + * Returns a random integer within the range `low .. high` inclusive. + * + * @param {Number} low + * The lower bound on the range. + * @param {Number} high + * The upper bound on the range. + */ + function randomIntInRange(low, high) { + return Math.round(low + (Math.random() * (high - low))); + } + + /** + * The Quick Sort algorithm. + * + * @param {Array} ary + * An array to sort. + * @param {function} comparator + * Function to use to compare two items. + * @param {Number} p + * Start index of the array + * @param {Number} r + * End index of the array + */ + function doQuickSort(ary, comparator, p, r) { + // If our lower bound is less than our upper bound, we (1) partition the + // array into two pieces and (2) recurse on each half. If it is not, this is + // the empty array and our base case. + + if (p < r) { + // (1) Partitioning. + // + // The partitioning chooses a pivot between `p` and `r` and moves all + // elements that are less than or equal to the pivot to the before it, and + // all the elements that are greater than it after it. The effect is that + // once partition is done, the pivot is in the exact place it will be when + // the array is put in sorted order, and it will not need to be moved + // again. This runs in O(n) time. + + // Always choose a random pivot so that an input array which is reverse + // sorted does not cause O(n^2) running time. + var pivotIndex = randomIntInRange(p, r); + var i = p - 1; + + swap(ary, pivotIndex, r); + var pivot = ary[r]; + + // Immediately after `j` is incremented in this loop, the following hold + // true: + // + // * Every element in `ary[p .. i]` is less than or equal to the pivot. + // + // * Every element in `ary[i+1 .. j-1]` is greater than the pivot. + for (var j = p; j < r; j++) { + if (comparator(ary[j], pivot) <= 0) { + i += 1; + swap(ary, i, j); + } + } + + swap(ary, i + 1, j); + var q = i + 1; + + // (2) Recurse on each half. + + doQuickSort(ary, comparator, p, q - 1); + doQuickSort(ary, comparator, q + 1, r); + } + } + + /** + * Sort the given array in-place with the given comparator function. + * + * @param {Array} ary + * An array to sort. + * @param {function} comparator + * Function to use to compare two items. + */ + exports.quickSort = function (ary, comparator) { + doQuickSort(ary, comparator, 0, ary.length - 1); + }; + } + + +/***/ }, +/* 11 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var SourceMapGenerator = __webpack_require__(2).SourceMapGenerator; + var util = __webpack_require__(5); + + // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other + // operating systems these days (capturing the result). + var REGEX_NEWLINE = /(\r?\n)/; + + // Newline character code for charCodeAt() comparisons + var NEWLINE_CODE = 10; + + // Private symbol for identifying `SourceNode`s when multiple versions of + // the source-map library are loaded. This MUST NOT CHANGE across + // versions! + var isSourceNode = "$$$isSourceNode$$$"; + + /** + * SourceNodes provide a way to abstract over interpolating/concatenating + * snippets of generated JavaScript source code while maintaining the line and + * column information associated with the original source code. + * + * @param aLine The original line number. + * @param aColumn The original column number. + * @param aSource The original source's filename. + * @param aChunks Optional. An array of strings which are snippets of + * generated JS, or other SourceNodes. + * @param aName The original identifier. + */ + function SourceNode(aLine, aColumn, aSource, aChunks, aName) { + this.children = []; + this.sourceContents = {}; + this.line = aLine == null ? null : aLine; + this.column = aColumn == null ? null : aColumn; + this.source = aSource == null ? null : aSource; + this.name = aName == null ? null : aName; + this[isSourceNode] = true; + if (aChunks != null) this.add(aChunks); + } + + /** + * Creates a SourceNode from generated code and a SourceMapConsumer. + * + * @param aGeneratedCode The generated code + * @param aSourceMapConsumer The SourceMap for the generated code + * @param aRelativePath Optional. The path that relative sources in the + * SourceMapConsumer should be relative to. + */ + SourceNode.fromStringWithSourceMap = + function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) { + // The SourceNode we want to fill with the generated code + // and the SourceMap + var node = new SourceNode(); + + // All even indices of this array are one line of the generated code, + // while all odd indices are the newlines between two adjacent lines + // (since `REGEX_NEWLINE` captures its match). + // Processed fragments are removed from this array, by calling `shiftNextLine`. + var remainingLines = aGeneratedCode.split(REGEX_NEWLINE); + var shiftNextLine = function() { + var lineContents = remainingLines.shift(); + // The last line of a file might not have a newline. + var newLine = remainingLines.shift() || ""; + return lineContents + newLine; + }; + + // We need to remember the position of "remainingLines" + var lastGeneratedLine = 1, lastGeneratedColumn = 0; + + // The generate SourceNodes we need a code range. + // To extract it current and last mapping is used. + // Here we store the last mapping. + var lastMapping = null; + + aSourceMapConsumer.eachMapping(function (mapping) { + if (lastMapping !== null) { + // We add the code from "lastMapping" to "mapping": + // First check if there is a new line in between. + if (lastGeneratedLine < mapping.generatedLine) { + var code = ""; + // Associate first line with "lastMapping" + addMappingWithCode(lastMapping, shiftNextLine()); + lastGeneratedLine++; + lastGeneratedColumn = 0; + // The remaining code is added without mapping + } else { + // There is no new line in between. + // Associate the code between "lastGeneratedColumn" and + // "mapping.generatedColumn" with "lastMapping" + var nextLine = remainingLines[0]; + var code = nextLine.substr(0, mapping.generatedColumn - + lastGeneratedColumn); + remainingLines[0] = nextLine.substr(mapping.generatedColumn - + lastGeneratedColumn); + lastGeneratedColumn = mapping.generatedColumn; + addMappingWithCode(lastMapping, code); + // No more remaining code, continue + lastMapping = mapping; + return; + } + } + // We add the generated code until the first mapping + // to the SourceNode without any mapping. + // Each line is added as separate string. + while (lastGeneratedLine < mapping.generatedLine) { + node.add(shiftNextLine()); + lastGeneratedLine++; + } + if (lastGeneratedColumn < mapping.generatedColumn) { + var nextLine = remainingLines[0]; + node.add(nextLine.substr(0, mapping.generatedColumn)); + remainingLines[0] = nextLine.substr(mapping.generatedColumn); + lastGeneratedColumn = mapping.generatedColumn; + } + lastMapping = mapping; + }, this); + // We have processed all mappings. + if (remainingLines.length > 0) { + if (lastMapping) { + // Associate the remaining code in the current line with "lastMapping" + addMappingWithCode(lastMapping, shiftNextLine()); + } + // and add the remaining lines without any mapping + node.add(remainingLines.join("")); + } + + // Copy sourcesContent into SourceNode + aSourceMapConsumer.sources.forEach(function (sourceFile) { + var content = aSourceMapConsumer.sourceContentFor(sourceFile); + if (content != null) { + if (aRelativePath != null) { + sourceFile = util.join(aRelativePath, sourceFile); + } + node.setSourceContent(sourceFile, content); + } + }); + + return node; + + function addMappingWithCode(mapping, code) { + if (mapping === null || mapping.source === undefined) { + node.add(code); + } else { + var source = aRelativePath + ? util.join(aRelativePath, mapping.source) + : mapping.source; + node.add(new SourceNode(mapping.originalLine, + mapping.originalColumn, + source, + code, + mapping.name)); + } + } + }; + + /** + * Add a chunk of generated JS to this source node. + * + * @param aChunk A string snippet of generated JS code, another instance of + * SourceNode, or an array where each member is one of those things. + */ + SourceNode.prototype.add = function SourceNode_add(aChunk) { + if (Array.isArray(aChunk)) { + aChunk.forEach(function (chunk) { + this.add(chunk); + }, this); + } + else if (aChunk[isSourceNode] || typeof aChunk === "string") { + if (aChunk) { + this.children.push(aChunk); + } + } + else { + throw new TypeError( + "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk + ); + } + return this; + }; + + /** + * Add a chunk of generated JS to the beginning of this source node. + * + * @param aChunk A string snippet of generated JS code, another instance of + * SourceNode, or an array where each member is one of those things. + */ + SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) { + if (Array.isArray(aChunk)) { + for (var i = aChunk.length-1; i >= 0; i--) { + this.prepend(aChunk[i]); + } + } + else if (aChunk[isSourceNode] || typeof aChunk === "string") { + this.children.unshift(aChunk); + } + else { + throw new TypeError( + "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk + ); + } + return this; + }; + + /** + * Walk over the tree of JS snippets in this node and its children. The + * walking function is called once for each snippet of JS and is passed that + * snippet and the its original associated source's line/column location. + * + * @param aFn The traversal function. + */ + SourceNode.prototype.walk = function SourceNode_walk(aFn) { + var chunk; + for (var i = 0, len = this.children.length; i < len; i++) { + chunk = this.children[i]; + if (chunk[isSourceNode]) { + chunk.walk(aFn); + } + else { + if (chunk !== '') { + aFn(chunk, { source: this.source, + line: this.line, + column: this.column, + name: this.name }); + } + } + } + }; + + /** + * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between + * each of `this.children`. + * + * @param aSep The separator. + */ + SourceNode.prototype.join = function SourceNode_join(aSep) { + var newChildren; + var i; + var len = this.children.length; + if (len > 0) { + newChildren = []; + for (i = 0; i < len-1; i++) { + newChildren.push(this.children[i]); + newChildren.push(aSep); + } + newChildren.push(this.children[i]); + this.children = newChildren; + } + return this; + }; + + /** + * Call String.prototype.replace on the very right-most source snippet. Useful + * for trimming whitespace from the end of a source node, etc. + * + * @param aPattern The pattern to replace. + * @param aReplacement The thing to replace the pattern with. + */ + SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) { + var lastChild = this.children[this.children.length - 1]; + if (lastChild[isSourceNode]) { + lastChild.replaceRight(aPattern, aReplacement); + } + else if (typeof lastChild === 'string') { + this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement); + } + else { + this.children.push(''.replace(aPattern, aReplacement)); + } + return this; + }; + + /** + * Set the source content for a source file. This will be added to the SourceMapGenerator + * in the sourcesContent field. + * + * @param aSourceFile The filename of the source file + * @param aSourceContent The content of the source file + */ + SourceNode.prototype.setSourceContent = + function SourceNode_setSourceContent(aSourceFile, aSourceContent) { + this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent; + }; + + /** + * Walk over the tree of SourceNodes. The walking function is called for each + * source file content and is passed the filename and source content. + * + * @param aFn The traversal function. + */ + SourceNode.prototype.walkSourceContents = + function SourceNode_walkSourceContents(aFn) { + for (var i = 0, len = this.children.length; i < len; i++) { + if (this.children[i][isSourceNode]) { + this.children[i].walkSourceContents(aFn); + } + } + + var sources = Object.keys(this.sourceContents); + for (var i = 0, len = sources.length; i < len; i++) { + aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]); + } + }; + + /** + * Return the string representation of this source node. Walks over the tree + * and concatenates all the various snippets together to one string. + */ + SourceNode.prototype.toString = function SourceNode_toString() { + var str = ""; + this.walk(function (chunk) { + str += chunk; + }); + return str; + }; + + /** + * Returns the string representation of this source node along with a source + * map. + */ + SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) { + var generated = { + code: "", + line: 1, + column: 0 + }; + var map = new SourceMapGenerator(aArgs); + var sourceMappingActive = false; + var lastOriginalSource = null; + var lastOriginalLine = null; + var lastOriginalColumn = null; + var lastOriginalName = null; + this.walk(function (chunk, original) { + generated.code += chunk; + if (original.source !== null + && original.line !== null + && original.column !== null) { + if(lastOriginalSource !== original.source + || lastOriginalLine !== original.line + || lastOriginalColumn !== original.column + || lastOriginalName !== original.name) { + map.addMapping({ + source: original.source, + original: { + line: original.line, + column: original.column + }, + generated: { + line: generated.line, + column: generated.column + }, + name: original.name + }); + } + lastOriginalSource = original.source; + lastOriginalLine = original.line; + lastOriginalColumn = original.column; + lastOriginalName = original.name; + sourceMappingActive = true; + } else if (sourceMappingActive) { + map.addMapping({ + generated: { + line: generated.line, + column: generated.column + } + }); + lastOriginalSource = null; + sourceMappingActive = false; + } + for (var idx = 0, length = chunk.length; idx < length; idx++) { + if (chunk.charCodeAt(idx) === NEWLINE_CODE) { + generated.line++; + generated.column = 0; + // Mappings end at eol + if (idx + 1 === length) { + lastOriginalSource = null; + sourceMappingActive = false; + } else if (sourceMappingActive) { + map.addMapping({ + source: original.source, + original: { + line: original.line, + column: original.column + }, + generated: { + line: generated.line, + column: generated.column + }, + name: original.name + }); + } + } else { + generated.column++; + } + } + }); + this.walkSourceContents(function (sourceFile, sourceContent) { + map.setSourceContent(sourceFile, sourceContent); + }); + + return { code: generated.code, map: map }; + }; + + exports.SourceNode = SourceNode; + } + + +/***/ } +/******/ ]); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly8vd2VicGFjay9ib290c3RyYXAgOGQzOTg5ZWJhY2JjMWE2ZTVjNzUiLCJ3ZWJwYWNrOi8vLy4vdGVzdC90ZXN0LWFwaS5qcyIsIndlYnBhY2s6Ly8vLi9zb3VyY2UtbWFwLmpzIiwid2VicGFjazovLy8uL2xpYi9zb3VyY2UtbWFwLWdlbmVyYXRvci5qcyIsIndlYnBhY2s6Ly8vLi9saWIvYmFzZTY0LXZscS5qcyIsIndlYnBhY2s6Ly8vLi9saWIvYmFzZTY0LmpzIiwid2VicGFjazovLy8uL2xpYi91dGlsLmpzIiwid2VicGFjazovLy8uL2xpYi9hcnJheS1zZXQuanMiLCJ3ZWJwYWNrOi8vLy4vbGliL21hcHBpbmctbGlzdC5qcyIsIndlYnBhY2s6Ly8vLi9saWIvc291cmNlLW1hcC1jb25zdW1lci5qcyIsIndlYnBhY2s6Ly8vLi9saWIvYmluYXJ5LXNlYXJjaC5qcyIsIndlYnBhY2s6Ly8vLi9saWIvcXVpY2stc29ydC5qcyIsIndlYnBhY2s6Ly8vLi9saWIvc291cmNlLW5vZGUuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7QUFBQTtBQUNBOztBQUVBO0FBQ0E7O0FBRUE7QUFDQTtBQUNBOztBQUVBO0FBQ0E7QUFDQSx1QkFBZTtBQUNmO0FBQ0E7QUFDQTs7QUFFQTtBQUNBOztBQUVBO0FBQ0E7O0FBRUE7QUFDQTtBQU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FBhdGgsIG1hcHBpbmcuc291cmNlKVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKHNvdXJjZVJvb3QgIT0gbnVsbCkge1xuICAgICAgICAgICAgICBtYXBwaW5nLnNvdXJjZSA9IHV0aWwucmVsYXRpdmUoc291cmNlUm9vdCwgbWFwcGluZy5zb3VyY2UpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgbWFwcGluZy5vcmlnaW5hbExpbmUgPSBvcmlnaW5hbC5saW5lO1xuICAgICAgICAgICAgbWFwcGluZy5vcmlnaW5hbENvbHVtbiA9IG9yaWdpbmFsLmNvbHVtbjtcbiAgICAgICAgICAgIGlmIChvcmlnaW5hbC5uYW1lICE9IG51bGwpIHtcbiAgICAgICAgICAgICAgbWFwcGluZy5uYW1lID0gb3JpZ2luYWwubmFtZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICB2YXIgc291cmNlID0gbWFwcGluZy5zb3VyY2U7XG4gICAgICAgIGlmIChzb3VyY2UgIT0gbnVsbCAmJiAhbmV3U291cmNlcy5oYXMoc291cmNlKSkge1xuICAgICAgICAgIG5ld1NvdXJjZXMuYWRkKHNvdXJjZSk7XG4gICAgICAgIH1cblxuICAgICAgICB2YXIgbmFtZSA9IG1hcHBpbmcubmFtZTtcbiAgICAgICAgaWYgKG5hbWUgIT0gbnVsbCAmJiAhbmV3TmFtZXMuaGFzKG5hbWUpKSB7XG4gICAgICAgICAgbmV3TmFtZXMuYWRkKG5hbWUpO1xuICAgICAgICB9XG5cbiAgICAgIH0sIHRoaXMpO1xuICAgICAgdGhpcy5fc291cmNlcyA9IG5ld1NvdXJjZXM7XG4gICAgICB0aGlzLl9uYW1lcyA9IG5ld05hbWVzO1xuXG4gICAgICAvLyBDb3B5IHNvdXJjZXNDb250ZW50cyBvZiBhcHBsaWVkIG1hcC5cbiAgICAgIGFTb3VyY2VNYXBDb25zdW1lci5zb3VyY2VzLmZvckVhY2goZn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IGkgPSAwLCBsZW4gPSBtYXBwaW5ncy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xuICAgICAgICBtYXBwaW5nID0gbWFwcGluZ3NbaV07XG5cbiAgICAgICAgaWYgKG1hcHBpbmcuZ2VuZXJhdGVkTGluZSAhPT0gcHJldmlvdXNHZW5lcmF0ZWRMaW5lKSB7XG4gICAgICAgICAgcHJldmlvdXNHZW5lcmF0ZWRDb2x1bW4gPSAwO1xuICAgICAgICAgIHdoaWxlIChtYXBwaW5nLmdlbmVyYXRlZExpbmUgIT09IHByZXZpb3VzR2VuZXJhdGVkTGluZSkge1xuICAgICAgICAgICAgcmVzdWx0ICs9ICc7JztcbiAgICAgICAgICAgIHByZXZpb3VzR2VuZXJhdGVkTGluZSsrO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBlbHNlIHtcbiAgICAgICAgICBpZiAoaSA+IDApIHtcbiAgICAgICAgICAgIGlmICghdXRpbC5jb21wYXJlQnlHZW5lcmF0ZWRQb3NpdGlvbnNJbmZsYXRlZChtYXBwaW5nLCBtYXBwaW5nc1tpIC0gMV0pKSB7XG4gICAgICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmVzdWx0ICs9ICcsJztcbiAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICByZXN1bHQgKz0gYmFzZTY0VkxRLmVuY29kZShtYXBwaW5nLmdlbmVyYXRlZENvbHVtblxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAtIHByZXZpb3VzR2VuZXJhdGVkQ29sdW1uKTtcbiAgICAgICAgcHJldmlvdXNHZW5lcmF0ZWRDb2x1bW4gPSBtYXBwaW5nLmdlbmVyYXRlZENvbHVtbjtcblxuICAgICAgICBpZiAobWFwcGluZy5zb3VyY2UgIT0gbnVsbCkge1xuICAgICAgICAgIHNvdXJjZUlkeCA9IHRoaXMuX3NvdXJjZXMuaW5kZXhPZihtYXBwaW5nLnNvdXJjZSk7XG4gICAgICAgICAgcmVzdWx0ICs9IGJhc2U2NFZMUS5lbmNvZGUoc291cmNlSWR4IC0gcHJldmlvdXNTb3VyY2UpO1xuICAgICAgICAgIHByZXZpb3VzU291cmNlID0gc291cmNlSWR4O1xuXG4gICAgICAgICAgLy8gbGluZXMgYXJlIHN0b3JlZCAwLWJhc2VkIGluIFNvdXJjZU1hcCBzcGVjIHZlcnNpb24gM1xuICAgICAgICAgIHJlc3VsdCArPSBiYXNlNjRWTFEuZW5jb2RlKG1hcHBpbmcub3JpZ2luYWxMaW5lIC0gMVxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC0gcHJldmlvdXNPcmlnaW5hbExpbmUpO1xuICAgICAgICAgIHByZXZpb3VzT3JpZ2luYWxMaW5lID0gbWFwcGluZy5vcmlnaW5hbExpbmUgLSAxO1xuXG4gICAgICAgICAgcmVzdWx0ICs9IGJhc2U2NFZMUS5lbmNvZGUobWFwcGluZy5vcmlnaW5hbENvbHVtblxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC0gcHJldmlvdXNPcmlnaW5hbENvbHVtbik7XG4gICAgICAgICAgcHJldmlvdXNPcmlnaW5hbENvbHVtbiA9IG1hcHBpbmcub3JpZ2luYWxDb2x1bW47XG5cbiAgICAgICAgICBpZiAobWFwcGluZy5uYW1lICE9IG51bGwpIHtcbiAgICAgICAgICAgIG5hbWVJZHggPSB0aGlzLl9uYW1lcy5pbmRleE9mKG1hcHBpbmcubmFtZSk7XG4gICAgICAgICAgICByZXN1bHQgKz0gYmFzZTY0VkxRLmVuY29kZShuYW1lSWR4IC0gcHJldmlvdXNOYW1lKTtcbiAgICAgICAgICAgIHByZXZpb3VzTmFtZSA9IG5hbWVJZHg7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG5cbiAgICAgIHJldHVybiByZXN1bHQ7XG4gICAgfTtcblxuICBTb3VyY2VNYXBHZW5lcmF0b3IucHJvdG90eXBlLl9nZW5lcmF0ZVNvdXJjZXNDb250ZW50ID1cbiAgICBmdW5jdGlvbiBTb3VyY2VNYXBHZW5lcmF0b3JfZ2VuZXJhdGVTb3VyY2VzQ29udGVudChhU291cmNlcywgYVNvdXJjZVJvb3QpIHtcbiAgICAgIHJldHVybiBhU291cmNlcy5tYXAoZnVuY3Rpb24gKHNvdXJjZSkge1xuICAgICAgICBpZiAoIXRoaXMuX3NvdXJjZXNDb250ZW50cykge1xuICAgICAgICAgIHJldHVybiBudWxsO1xuICAgICAgICB9XG4gICAgICAgIGlmIChhU291cmNlUm9vdCAhPSBudWxsKSB7XG4gICAgICAgICAgc291cmNlID0gdXRpbC5yZWxhdGl2ZShhU291cmNlUm9vdCwgc291cmNlKTtcbiAgICAgICAgfVxuICAgICAgICB2YXIga2V5ID0gdXRpbC50b1NldFN0cmluZyhzb3VyY2UpO1xuICAgICAgICByZXR1cm4gT2JqZWN0LnByb3RvdHlwZS5oYXNPd25Qcm9wZXJ0eS5jYWxsKHRoaXMuX3NvdXJjZXNDb250ZW50cyxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBrZXkpXG4gICAgICAgICAgPyB0aGlzLl9zb3VyY2VzQ29udGVudHNba2V5XVxuICAgICAgICAgIDogbnVsbDtcbiAgICAgIH0sIHRoaXMpO1xuICAgIH07XG5cbiAgLyoqXG4gICAqIEV4dGVybmFsaXplIHRoZSBzb3VyY2UgbWFwLlxuICAgKi9cbiAgU291cmNlTWFwR2VuZXJhdG9yLnByb3RvdHlwZS50b0pTT04gPVxuICAgIGZ1bmN0aW9uIFNvdXJjZU1hcEdlbmVyYXRvcl90b0pTT04oKSB7XG4gICAgICB2YXIgbWFwID0ge1xuICAgICAgICB2ZXJzaW9uOiB0aGlzLl92ZXJzaW9uLFxuICAgICAgICBzb3VyY2VzOiB0aGlzLl9zb3VyY2VzLnRvQXJyYXkoKSxcbiAgICAgICAgbmFtZXM6IHRoaXMuX25hbWVzL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jYXNlIFNvdXJjZU1hcENvbnN1bWVyLk9SSUdJTkFMX09SREVSOlxuICAgICAgICBtYXBwaW5ncyA9IHRoaXMuX29yaWdpbmFsTWFwcGluZ3M7XG4gICAgICAgIGJyZWFrO1xuICAgICAgZGVmYXVsdDpcbiAgICAgICAgdGhyb3cgbmV3IEVycm9yKFwiVW5rbm93biBvcmRlciBvZiBpdGVyYXRpb24uXCIpO1xuICAgICAgfVxuXG4gICAgICB2YXIgc291cmNlUm9vdCA9IHRoaXMuc291cmNlUm9vdDtcbiAgICAgIG1hcHBpbmdzLm1hcChmdW5jdGlvbiAobWFwcGluZykge1xuICAgICAgICB2YXIgc291cmNlID0gbWFwcGluZy5zb3VyY2UgPT09IG51bGwgPyBudWxsIDogdGhpcy5fc291cmNlcy5hdChtYXBwaW5nLnNvdXJjZSk7XG4gICAgICAgIGlmIChzb3VyY2UgIT0gbnVsbCAmJiBzb3VyY2VSb290ICE9IG51bGwpIHtcbiAgICAgICAgICBzb3VyY2UgPSB1dGlsLmpvaW4oc291cmNlUm9vdCwgc291cmNlKTtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgIHNvdXJjZTogc291cmNlLFxuICAgICAgICAgIGdlbmVyYXRlZExpbmU6IG1hcHBpbmcuZ2VuZXJhdGVkTGluZSxcbiAgICAgICAgICBnZW5lcmF0ZWRDb2x1bW46IG1hcHBpbmcuZ2VuZXJhdGVkQ29sdW1uLFxuICAgICAgICAgIG9yaWdpbmFsTGluZTogbWFwcGluZy5vcmlnaW5hbExpbmUsXG4gICAgICAgICAgb3JpZ2luYWxDb2x1bW46IG1hcHBpbmcub3JpZ2luYWxDb2x1bW4sXG4gICAgICAgICAgbmFtZTogbWFwcGluZy5uYW1lID09PSBudWxsID8gbnVsbCA6IHRoaXMuX25hbWVzLmF0KG1hcHBpbmcubmFtZSlcbiAgICAgICAgfTtcbiAgICAgIH0sIHRoaXMpLmZvckVhY2goYUNhbGxiYWNrLCBjb250ZXh0K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VJvb3QgIT0gbnVsbCkge1xuICAgICAgICBuZWVkbGUuc291cmNlID0gdXRpbC5yZWxhdGl2ZSh0aGlzLnNvdXJjZVJvb3QsIG5lZWRsZS5zb3VyY2UpO1xuICAgICAgfVxuICAgICAgaWYgKCF0aGlzLl9zb3VyY2VzLmhhcyhuZWVkbGUuc291cmNlKSkge1xuICAgICAgICByZXR1cm4gW107XG4gICAgICB9XG4gICAgICBuZWVkbGUuc291cmNlID0gdGhpcy5fc291cmNlcy5pbmRleE9mKG5lZWRsZS5zb3VyY2UpO1xuXG4gICAgICB2YXIgbWFwcGluZ3MgPSBbXTtcblxuICAgICAgdmFyIGluZGV4ID0gdGhpcy5fZmluZE1hcHBpbmcobmVlZGxlLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fb3JpZ2luYWxNYXBwaW5ncyxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwib3JpZ2luYWxMaW5lXCIsXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcIm9yaWdpbmFsQ29sdW1uXCIsXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB1dGlsLmNvbXBhcmVCeU9yaWdpbmFsUG9zaXRpb25zLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYmluYXJ5U2VhcmNoLkxFQVNUX1VQUEVSX0JPVU5EKTtcbiAgICAgIGlmIChpbmRleCA+PSAwKSB7XG4gICAgICAgIHZhciBtYXBwaW5nID0gdGhpcy5fb3JpZ2luYWxNYXBwaW5nc1tpbmRleF07XG5cbiAgICAgICAgaWYgKGFBcmdzLmNvbHVtbiA9PT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgdmFyIG9yaWdpbmFsTGluZSA9IG1hcHBpbmcub3JpZ2luYWxMaW5lO1xuXG4gICAgICAgICAgLy8gSXRlcmF0ZSB1bnRpbCBlaXRoZXIgd2UgcnVuIG91dCBvZiBtYXBwaW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hcklzTWFwcGluZ1NlcGFyYXRvcihhU3RyLCBlbmQpKSB7XG4gICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgICBzdHIgPSBhU3RyLnNsaWNlKGluZGV4LCBlbmQpO1xuXG4gICAgICAgICAgc2VnbWVudCA9IGNhY2hlZFNlZ21lbnRzW3N0cl07XG4gICAgICAgICAgaWYgKHNlZ21lbnQpIHtcbiAgICAgICAgICAgIGluZGV4ICs9IHN0ci5sZW5ndGg7XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHNlZ21lbnQgPSBbXTtcbiAgICAgICAgICAgIHdoaWxlIChpbmRleCA8IGVuZCkge1xuICAgICAgICAgICAgICBiYXNlNjRWTFEuZGVjb2RlKGFTdHIsIGluZGV4LCB0ZW1wKTtcbiAgICAgICAgICAgICAgdmFsdWUgPSB0ZW1wLnZhbHVlO1xuICAgICAgICAgICAgICBpbmRleCA9IHRlbXAucmVzdDtcbiAgICAgICAgICAgICAgc2VnbWVudC5wdXNoKHZhbHVlKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHNlZ21lbnQubGVuZ3RoID09PSAyKSB7XG4gICAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcignRm91bmQgYSBzb3VyY2UsIGJ1dCBubyBsaW5lIGFuZCBjb2x1bW4nKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHNlZ21lbnQubGVuZ3RoID09PSAzKSB7XG4gICAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcignRm91bmQgYSBzb3VyY2UgYW5kIGxpbmUsIGJ1dCBubyBjb2x1bW4nKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgY2FjaGVkU2VnbWVudHNbc3RyXSA9IHNlZ21lbnQ7XG4gICAgICAgICAgfVxuXG4gICAgICAgICAgLy8gR2VuZXJhdGVkIGNvbHVtbi5cbiAgICAgICAgICBtYXBwaW5nLmdlbmVyYXRlZENvbHVtbiA9IHByZXZpb3VzR2VuZXJhdGVkQ29sdW1uICsgc2VnbWVudFswXTtcbiAgICAgICAgICBwcmV2aW91c0dlbmVyYXRlZENvbHVtbiA9IG1hcHBpbmcuZ2VuZXJhdGVkQ29sdW1uO1xuXG4gICAgICAgICAgaWYgKHNlZ21lbnQubGVuZ3RoID4gMSkge1xuICAgICAgICAgICAgLy8gT3JpZ2luYWwgc291cmNlLlxuICAgICAgICAgICAgbWFwcGluZy5zb3VyY2UgPSBwcmV2aW91c1NvdXJjZSArIHNlZ21lbnRbMV07XG4gICAgICAgICAgICBwcmV2aW91c1NvdXJjZSArPSBzZWdtZW50WzFdO1xuXG4gICAgICAgICAgICAvLyBPcmlnaW5hbCBsaW5lLlxuICAgICAgICAgICAgbWFwcGluZy5vcmlnaW5hbExpbmUgPSBwcmV2aW91c09yaWdpbmFsTGluZSArIHNlZ21lbnRbMl07XG4gICAgICAgICAgICBwcmV2aW91c09yaWdpbmFsTGluZSA9IG1hcHBpbmcub3JpZ2luYWxMaW5lO1xuICAgICAgICAgICAgLy8gTGluZXMgYXJlIHN0b3JlZCAwLWJhc2VkXG4gICAgICAgICAgICBtYXBwaW5nLm9yaWdpbmFsTGluZSArPSAxO1xuXG4gICAgICAgICAgICAvLyBPcmlnaW5hbCBjb2x1bW4uXG4gICAgICAgICAgICBtYXBwaW5nLm9yaWdpbmFsQ29sdW1uID0gcHJldmlvdXNPcmlnaW5hbENvbHVtbiArIHNlZ21lbnRbM107XG4gICAgICAgICAgICBwcmV2aW91c09yaWdpbmFsQ29sdW1uID0gbWFwcGluZy5vcmlnaW5hbENvbHVtbjtcblxuICAgICAgICAgICAgaWYgKHNlZ21lbnQubGVuZ3RoID4gNCkge1xuICAgICAgICAgICAgICAvLyBPcmlnaW5hbCBuYW1lLlxuICAgICAgICAgICAgICBtYXBwaW5nLm5hbWUgPSBwcmV2aW91c05hbWUgKyBzZWdtZW50WzRdO1xuICAgICAgICAgICA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IFwiZ2VuZXJhdGVkTGluZVwiLFxuICAgICAgICBcImdlbmVyYXRlZENvbHVtblwiLFxuICAgICAgICB1dGlsLmNvbXBhcmVCeUdlbmVyYXRlZFBvc2l0aW9uc0RlZmxhdGVkLFxuICAgICAgICB1dGlsLmdldEFyZyhhQXJncywgJ2JpYXMnLCBTb3VyY2VNYXBDb25zdW1lci5HUkVBVEVTVF9MT1dFUl9CT1VORClcbiAgICAgICk7XG5cbiAgICAgIGlmIChpbmRleCA+PSAwKSB7XG4gICAgICAgIHZhciBtYXBwaW5nID0gdGhpcy5fZ2VuZXJhdGVkTWFwcGluZ3NbaW5kZXhdO1xuXG4gICAgICAgIGlmIChtYXBwaW5nLmdlbmVyYXRlZExpbmUgPT09IG5lZWRsZS5nZW5lcmF0ZWRMaW5lKSB7XG4gICAgICAgICAgdmFyIHNvdXJjZSA9IHV0aWwuZ2V0QXJnKG1hcHBpbmcsICdzb3VyY2UnLCBudWxsKTtcbiAgICAgICAgICBpZiAoc291cmNlICE9PSBudWxsKSB7XG4gICAgICAgICAgICBzb3VyY2UgPSB0aGlzLl9zb3VyY2VzLmF0KHNvdXJjZSk7XG4gICAgICAgICAgICBpZiAodGhpcy5zb3VyY2VSb290ICE9IG51bGwpIHtcbiAgICAgICAgICAgICAgc291cmNlID0gdXRpbC5qb2luKHRoaXMuc291cmNlUm9vdCwgc291cmNlKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgICAgdmFyIG5hbWUgPSB1dGlsLmdldEFyZyhtYXBwaW5nLCAnbmFtZScsIG51bGwpO1xuICAgICAgICAgIGlmIChuYW1lICE9PSBudWxsKSB7XG4gICAgICAgICAgICBuYW1lID0gdGhpcy5fbmFtZXMuYXQobmFtZSk7XG4gICAgICAgICAgfVxuICAgICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICBzb3VyY2U6IHNvdXJjZSxcbiAgICAgICAgICAgIGxpbmU6IHV0aWwuZ2V0QXJnKG1hcHBpbmcsICdvcmlnaW5hbExpbmUnLCBudWxsKSxcbiAgICAgICAgICAgIGNvbHVtbjogdXRpbC5nZXRBcmcobWFwcGluZywgJ29yaWdpbmFsQ29sdW1uJywgbnVsbCksXG4gICAgICAgICAgICBuYW1lOiBuYW1lXG4gICAgICAgICAgfTtcbiAgICAgICAgfVxuICAgICAgfVxuXG4gICAgICByZXR1cm4ge1xuICAgICAgICBzb3VyY2U6IG51bGwsXG4gICAgICAgIGxpbmU6IG51bGwsXG4gICAgICAgIGNvbHVtbjogbnVsbCxcbiAgICAgICAgbmFtZTogbnVsbFxuICAgICAgfTtcbiAgICB9O1xuXG4gIC8qKlxuICAgKiBSZXR1cm4gdHJ1ZSBpZiB3ZSBoYXZlIHRoZSBzb3VyY2UgY29udGVudCBmb3IgZXZlcnkgc291cmNlIGluIHRoZSBzb3VyY2VcbiAgICogbWFwLCBmYWxzZSBvdGhlcndpc2UuXG4gICAqL1xuICBCYXNpY1NvdXJjZU1hcENvbnN1bWVyLnByb3RvdHlwZS5oYXNDb250ZW50c09mQWxsU291cmNlcyA9XG4gICAgZnVuY3Rpb24gQmFzaWNTb3VyY2VNYXBDb25zdW1lcl9oYXNDb250ZW50c09mQWxsU291cmNlcygpIHtcbiAgICAgIGlmICghdGhpcy5zb3VyY2VzQ29udGVudCkge1xuICAgICAgICByZXR1cm4gZmFsc2U7XG4gICAgICB9XG4gICAgICByZXR1cm4gdGhpcy5zb3VyY2VzQ29udGVudC5sZW5ndGggPj0gdGhpcy5fc291cmNlcy5zaXplKCkgJiZcbiAgICAgICAgIXRoaXMuc291cmNlc0NvbnRlbnQuc29tZShmdW5jdGlvbiAoc2MpIHsgcmV0dXJuIHNjID09IG51bGw7IH0pO1xuICAgIH07XG5cbiAgLyoqXG4gICAqIFJldHVybnMgdGhlIG9yaWdpbmFsIHNvdXJjZSBjb250ZW50LiBUaGUgb25seSBhcmd1bWVudCBpcyB0aGUgdXJsIG9mIHRoZVxuICAgKiBvcmlnaW5hbCBzb3VyY2UgZm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ICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxhc3RHZW5lcmF0ZWRDb2x1bW4pO1xuICAgICAgICAgICAgcmVtYWluaW5nTGluZXNbMF0gPSBuZXh0TGluZS5zdWJzdHIobWFwcGluZy5nZW5lcmF0ZWRDb2x1bW4gLVxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGFzdEdlbmVyYXRlZENvbHVtbik7XG4gICAgICAgICAgICBsYXN0R2VuZXJhdGVkQ29sdW1uID0gbWFwcGluZy5nZW5lcmF0ZWRDb2x1bW47XG4gICAgICAgICAgICBhZGRNYXBwaW5nV2l0aENvZGUobGFzdE1hcHBpbmcsIGNvZGUpO1xuICAgICAgICAgICAgLy8gTm8gbW9yZSByZW1haW5pbmcgY29kZSwgY29udGludWVcbiAgICAgICAgICAgIGxhc3RNYXBwaW5nID0gbWFwcGluZztcbiAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgLy8gV2UgYWRkIHRoZSBnZW5lcmF0ZWQgY29kZSB1bnRpbCB0aGUgZmlyc3QgbWFwcGluZ1xuICAgICAgICAvLyB0byB0aGUgU291cmNlTm9kZSB3aXRob3V0IGFueSBtYXBwaW5nLlxuICAgICAgICAvLyBFYWNoIGxpbmUgaXMgYWRkZWQgYXMgc2VwYXJhdGUgc3RyaW5nLlxuICAgICAgICB3aGlsZSAobGFzdEdlbmVyYXRlZExpbmUgPCBtYXBwaW5nLmdlbmVyYXRlZExpbmUpIHtcbiAgICAgICAgICBub2RlLmFkZChzaGlmdE5leHRMaW5lKCkpO1xuICAgICAgICAgIGxhc3RHZW5lcmF0ZWRMaW5lKys7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKGxhc3RHZW5lcmF0ZWRDb2x1bW4gPCBtYXBwaW5nLmdlbmVyYXRlZENvbHVtbikge1xuICAgICAgICAgIHZhciBuZXh0TGluZSA9IHJlbWFpbmluZ0xpbmVzWzBdO1xu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gIGlmIChjb250ZW50ICE9IG51bGwpIHtcbiAgICAgICAgICBpZiAoYVJlbGF0aXZlUGF0aCAhPSBudWxsKSB7XG4gICAgICAgICAgICBzb3VyY2VGaWxlID0gdXRpbC5qb2luKGFSZWxhdGl2ZVBhdGgsIHNvdXJjZUZpbGUpO1xuICAgICAgICAgIH1cbiAgICAgICAgICBub2RlLnNldFNvdXJjZUNvbnRlbnQoc291cmNlRmlsZSwgY29udGVudCk7XG4gICAgICAgIH1cbiAgICAgIH0pO1xuXG4gICAgICByZXR1cm4gbm9kZTtcblxuICAgICAgZnVuY3Rpb24gYWRkTWFwcGluZ1dpdGhDb2RlKG1hcHBpbmcsIGNvZGUpIHtcbiAgICAgICAgaWYgKG1hcHBpbmcgPT09IG51bGwgfHwgbWFwcGluZy5zb3VyY2UgPT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgIG5vZGUuYWRkKGNvZGUpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHZhciBzb3VyY2UgPSBhUmVsYXRpdmVQYXRoXG4gICAgICAgICAgICA/IHV0aWwuam9pbihhUmVsYXRpdmVQYXRoLCBtYXBwaW5nLnNvdXJjZSlcbiAgICAgICAgICAgIDogbWFwcGluZy5zb3VyY2U7XG4gICAgICAgICAgbm9kZS5hZGQobmV3IFNvdXJjZU5vZGUobWFwcGluZy5vcmlnaW5hbExpbmUsXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbWFwcGluZy5vcmlnaW5hbENvbHVtbixcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzb3VyY2UsXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29kZSxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBtYXBwaW5nLm5hbWUpKTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgIH07XG5cbiAgLyoqXG4gICAqIEFkZCBhIGNodW5rIG9mIGdlbmVyYXRlZCBKUyB0byB0aGlzIHNvdX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IGNodW5rO1xuICAgICAgaWYgKG9yaWdpbmFsLnNvdXJjZSAhPT0gbnVsbFxuICAgICAgICAgICYmIG9yaWdpbmFsLmxpbmUgIT09IG51bGxcbiAgICAgICAgICAmJiBvcmlnaW5hbC5jb2x1bW4gIT09IG51bGwpIHtcbiAgICAgICAgaWYobGFzdE9yaWdpbmFsU291cmNlICE9PSBvcmlnaW5hbC5zb3VyY2VcbiAgICAgICAgICAgfHwgbGFzdE9yaWdpbmFsTGluZSAhPT0gb3JpZ2luYWwubGluZVxuICAgICAgICAgICB8fCBsYXN0T3JpZ2luYWxDb2x1bW4gIT09IG9yaWdpbmFsLmNvbHVtblxuICAgICAgICAgICB8fCBsYXN0T3JpZ2luYWxOYW1lICE9PSBvcmlnaW5hbC5uYW1lKSB7XG4gICAgICAgICAgbWFwLmFkZE1hcHBpbmcoe1xuICAgICAgICAgICAgc291cmNlOiBvcmlnaW5hbC5zb3VyY2UsXG4gICAgICAgICAgICBvcmlnaW5hbDoge1xuICAgICAgICAgICAgICBsaW5lOiBvcmlnaW5hbC5saW5lLFxuICAgICAgICAgICAgICBjb2x1bW46IG9yaWdpbmFsLmNvbHVtblxuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIGdlbmVyYXRlZDoge1xuICAgICAgICAgICAgICBsaW5lOiBnZW5lcmF0ZWQubGluZSxcbiAgICAgICAgICAgICAgY29sdW1uOiBnZW5lcmF0ZWQuY29sdW1uXG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgbmFtZTogb3JpZ2luYWwubmFtZVxuICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgICAgIGxhc3RPcmlnaW5hbFNvdXJjZSA9IG9yaWdpbmFsLnNvdXJjZTtcbiAgICAgICAgbGFzdE9yaWdpbmFsTGluZSA9IG9yaWdpbmFsLmxpbmU7XG4gICAgICAgIGxhc3RPcmlnaW5hbENvbHVtbiA9IG9yaWdpbmFsLmNvbHVtbjtcbiAgICAgICAgbGFzdE9yaWdpbmFsT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WdpbmFsLmxpbmUsXG4gICAgICAgICAgICAgICAgY29sdW1uOiBvcmlnaW5hbC5jb2x1bW5cbiAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgZ2VuZXJhdGVkOiB7XG4gICAgICAgICAgICAgICAgbGluZTogZ2VuZXJhdGVkLmxpbmUsXG4gICAgICAgICAgICAgICAgY29sdW1uOiBnZW5lcmF0ZWQuY29sdW1uXG4gICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgIG5hbWU6IG9yaWdpbmFsLm5hbWVcbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICBnZW5lcmF0ZWQuY29sdW1uKys7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9KTtcbiAgICB0aGlzLndhbGtTb3VyY2VDb250ZW50cyhmdW5jdGlvbiAoc291cmNlRmlsZSwgc291cmNlQ29udGVudCkge1xuICAgICAgbWFwLnNldFNvdXJjZUNvbnRlbnQoc291cmNlRmlsZSwgc291cmNlQ29udGVudCk7XG4gICAgfSk7XG5cbiAgICByZXR1cm4geyBjb2RlOiBnZW5lcmF0ZWQuY29kZSwgbWFwOiBtYXAgfTtcbiAgfTtcblxuICBleHBvcnRzLlNvdXJjZU5vZGUgPSBTb3VyY2VOb2RlO1xufVxuXG5cblxuLyoqKioqKioqKioqKioqKioqXG4gKiogV0VCUEFDSyBGT09URVJcbiAqKiAuL2xpYi9zb3VyY2Utbm9kZS5qc1xuICoqIG1vZHVsZSBpZCA9IDExXG4gKiogbW9kdWxlIGNodW5rcyA9IDBcbiAqKi8iXSwic291cmNlUm9vdCI6IiJ9 \ No newline at end of file diff --git a/devtools/shared/sourcemap/tests/unit/test_array_set.js b/devtools/shared/sourcemap/tests/unit/test_array_set.js new file mode 100644 index 000000000..c12d3ba49 --- /dev/null +++ b/devtools/shared/sourcemap/tests/unit/test_array_set.js @@ -0,0 +1,683 @@ +function run_test() { + for (var k in SOURCE_MAP_TEST_MODULE) { + if (/^test/.test(k)) { + SOURCE_MAP_TEST_MODULE[k](assert); + } + } +} + + +var SOURCE_MAP_TEST_MODULE = +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; +/******/ +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.loaded = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var ArraySet = __webpack_require__(1).ArraySet; + + function makeTestSet() { + var set = new ArraySet(); + for (var i = 0; i < 100; i++) { + set.add(String(i)); + } + return set; + } + + exports['test .has() membership'] = function (assert) { + var set = makeTestSet(); + for (var i = 0; i < 100; i++) { + assert.ok(set.has(String(i))); + } + }; + + exports['test .indexOf() elements'] = function (assert) { + var set = makeTestSet(); + for (var i = 0; i < 100; i++) { + assert.strictEqual(set.indexOf(String(i)), i); + } + }; + + exports['test .at() indexing'] = function (assert) { + var set = makeTestSet(); + for (var i = 0; i < 100; i++) { + assert.strictEqual(set.at(i), String(i)); + } + }; + + exports['test creating from an array'] = function (assert) { + var set = ArraySet.fromArray(['foo', 'bar', 'baz', 'quux', 'hasOwnProperty']); + + assert.ok(set.has('foo')); + assert.ok(set.has('bar')); + assert.ok(set.has('baz')); + assert.ok(set.has('quux')); + assert.ok(set.has('hasOwnProperty')); + + assert.strictEqual(set.indexOf('foo'), 0); + assert.strictEqual(set.indexOf('bar'), 1); + assert.strictEqual(set.indexOf('baz'), 2); + assert.strictEqual(set.indexOf('quux'), 3); + + assert.strictEqual(set.at(0), 'foo'); + assert.strictEqual(set.at(1), 'bar'); + assert.strictEqual(set.at(2), 'baz'); + assert.strictEqual(set.at(3), 'quux'); + }; + + exports['test that you can add __proto__; see github issue #30'] = function (assert) { + var set = new ArraySet(); + set.add('__proto__'); + assert.ok(set.has('__proto__')); + assert.strictEqual(set.at(0), '__proto__'); + assert.strictEqual(set.indexOf('__proto__'), 0); + }; + + exports['test .fromArray() with duplicates'] = function (assert) { + var set = ArraySet.fromArray(['foo', 'foo']); + assert.ok(set.has('foo')); + assert.strictEqual(set.at(0), 'foo'); + assert.strictEqual(set.indexOf('foo'), 0); + assert.strictEqual(set.toArray().length, 1); + + set = ArraySet.fromArray(['foo', 'foo'], true); + assert.ok(set.has('foo')); + assert.strictEqual(set.at(0), 'foo'); + assert.strictEqual(set.at(1), 'foo'); + assert.strictEqual(set.indexOf('foo'), 0); + assert.strictEqual(set.toArray().length, 2); + }; + + exports['test .add() with duplicates'] = function (assert) { + var set = new ArraySet(); + set.add('foo'); + + set.add('foo'); + assert.ok(set.has('foo')); + assert.strictEqual(set.at(0), 'foo'); + assert.strictEqual(set.indexOf('foo'), 0); + assert.strictEqual(set.toArray().length, 1); + + set.add('foo', true); + assert.ok(set.has('foo')); + assert.strictEqual(set.at(0), 'foo'); + assert.strictEqual(set.at(1), 'foo'); + assert.strictEqual(set.indexOf('foo'), 0); + assert.strictEqual(set.toArray().length, 2); + }; + + exports['test .size()'] = function (assert) { + var set = new ArraySet(); + set.add('foo'); + set.add('bar'); + set.add('baz'); + assert.strictEqual(set.size(), 3); + }; + + exports['test .size() with disallowed duplicates'] = function (assert) { + var set = new ArraySet(); + + set.add('foo'); + set.add('foo'); + + set.add('bar'); + set.add('bar'); + + set.add('baz'); + set.add('baz'); + + assert.strictEqual(set.size(), 3); + }; + + exports['test .size() with allowed duplicates'] = function (assert) { + var set = new ArraySet(); + + set.add('foo'); + set.add('foo', true); + + set.add('bar'); + set.add('bar', true); + + set.add('baz'); + set.add('baz', true); + + assert.strictEqual(set.size(), 3); + }; + } + + +/***/ }, +/* 1 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var util = __webpack_require__(2); + + /** + * A data structure which is a combination of an array and a set. Adding a new + * member is O(1), testing for membership is O(1), and finding the index of an + * element is O(1). Removing elements from the set is not supported. Only + * strings are supported for membership. + */ + function ArraySet() { + this._array = []; + this._set = {}; + } + + /** + * Static method for creating ArraySet instances from an existing array. + */ + ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) { + var set = new ArraySet(); + for (var i = 0, len = aArray.length; i < len; i++) { + set.add(aArray[i], aAllowDuplicates); + } + return set; + }; + + /** + * Return how many unique items are in this ArraySet. If duplicates have been + * added, than those do not count towards the size. + * + * @returns Number + */ + ArraySet.prototype.size = function ArraySet_size() { + return Object.getOwnPropertyNames(this._set).length; + }; + + /** + * Add the given string to this set. + * + * @param String aStr + */ + ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) { + var sStr = util.toSetString(aStr); + var isDuplicate = this._set.hasOwnProperty(sStr); + var idx = this._array.length; + if (!isDuplicate || aAllowDuplicates) { + this._array.push(aStr); + } + if (!isDuplicate) { + this._set[sStr] = idx; + } + }; + + /** + * Is the given string a member of this set? + * + * @param String aStr + */ + ArraySet.prototype.has = function ArraySet_has(aStr) { + var sStr = util.toSetString(aStr); + return this._set.hasOwnProperty(sStr); + }; + + /** + * What is the index of the given string in the array? + * + * @param String aStr + */ + ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) { + var sStr = util.toSetString(aStr); + if (this._set.hasOwnProperty(sStr)) { + return this._set[sStr]; + } + throw new Error('"' + aStr + '" is not in the set.'); + }; + + /** + * What is the element at the given index? + * + * @param Number aIdx + */ + ArraySet.prototype.at = function ArraySet_at(aIdx) { + if (aIdx >= 0 && aIdx < this._array.length) { + return this._array[aIdx]; + } + throw new Error('No element indexed by ' + aIdx); + }; + + /** + * Returns the array representation of this set (which has the proper indices + * indicated by indexOf). Note that this is a copy of the internal array used + * for storing the members so that no one can mess with internal state. + */ + ArraySet.prototype.toArray = function ArraySet_toArray() { + return this._array.slice(); + }; + + exports.ArraySet = ArraySet; + } + + +/***/ }, +/* 2 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + /** + * This is a helper function for getting values from parameter/options + * objects. + * + * @param args The object we are extracting values from + * @param name The name of the property we are getting. + * @param defaultValue An optional value to return if the property is missing + * from the object. If this is not specified and the property is missing, an + * error will be thrown. + */ + function getArg(aArgs, aName, aDefaultValue) { + if (aName in aArgs) { + return aArgs[aName]; + } else if (arguments.length === 3) { + return aDefaultValue; + } else { + throw new Error('"' + aName + '" is a required argument.'); + } + } + exports.getArg = getArg; + + var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.]*)(?::(\d+))?(\S*)$/; + var dataUrlRegexp = /^data:.+\,.+$/; + + function urlParse(aUrl) { + var match = aUrl.match(urlRegexp); + if (!match) { + return null; + } + return { + scheme: match[1], + auth: match[2], + host: match[3], + port: match[4], + path: match[5] + }; + } + exports.urlParse = urlParse; + + function urlGenerate(aParsedUrl) { + var url = ''; + if (aParsedUrl.scheme) { + url += aParsedUrl.scheme + ':'; + } + url += '//'; + if (aParsedUrl.auth) { + url += aParsedUrl.auth + '@'; + } + if (aParsedUrl.host) { + url += aParsedUrl.host; + } + if (aParsedUrl.port) { + url += ":" + aParsedUrl.port + } + if (aParsedUrl.path) { + url += aParsedUrl.path; + } + return url; + } + exports.urlGenerate = urlGenerate; + + /** + * Normalizes a path, or the path portion of a URL: + * + * - Replaces consequtive slashes with one slash. + * - Removes unnecessary '.' parts. + * - Removes unnecessary '/..' parts. + * + * Based on code in the Node.js 'path' core module. + * + * @param aPath The path or url to normalize. + */ + function normalize(aPath) { + var path = aPath; + var url = urlParse(aPath); + if (url) { + if (!url.path) { + return aPath; + } + path = url.path; + } + var isAbsolute = exports.isAbsolute(path); + + var parts = path.split(/\/+/); + for (var part, up = 0, i = parts.length - 1; i >= 0; i--) { + part = parts[i]; + if (part === '.') { + parts.splice(i, 1); + } else if (part === '..') { + up++; + } else if (up > 0) { + if (part === '') { + // The first part is blank if the path is absolute. Trying to go + // above the root is a no-op. Therefore we can remove all '..' parts + // directly after the root. + parts.splice(i + 1, up); + up = 0; + } else { + parts.splice(i, 2); + up--; + } + } + } + path = parts.join('/'); + + if (path === '') { + path = isAbsolute ? '/' : '.'; + } + + if (url) { + url.path = path; + return urlGenerate(url); + } + return path; + } + exports.normalize = normalize; + + /** + * Joins two paths/URLs. + * + * @param aRoot The root path or URL. + * @param aPath The path or URL to be joined with the root. + * + * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a + * scheme-relative URL: Then the scheme of aRoot, if any, is prepended + * first. + * - Otherwise aPath is a path. If aRoot is a URL, then its path portion + * is updated with the result and aRoot is returned. Otherwise the result + * is returned. + * - If aPath is absolute, the result is aPath. + * - Otherwise the two paths are joined with a slash. + * - Joining for example 'http://' and 'www.example.com' is also supported. + */ + function join(aRoot, aPath) { + if (aRoot === "") { + aRoot = "."; + } + if (aPath === "") { + aPath = "."; + } + var aPathUrl = urlParse(aPath); + var aRootUrl = urlParse(aRoot); + if (aRootUrl) { + aRoot = aRootUrl.path || '/'; + } + + // `join(foo, '//www.example.org')` + if (aPathUrl && !aPathUrl.scheme) { + if (aRootUrl) { + aPathUrl.scheme = aRootUrl.scheme; + } + return urlGenerate(aPathUrl); + } + + if (aPathUrl || aPath.match(dataUrlRegexp)) { + return aPath; + } + + // `join('http://', 'www.example.com')` + if (aRootUrl && !aRootUrl.host && !aRootUrl.path) { + aRootUrl.host = aPath; + return urlGenerate(aRootUrl); + } + + var joined = aPath.charAt(0) === '/' + ? aPath + : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath); + + if (aRootUrl) { + aRootUrl.path = joined; + return urlGenerate(aRootUrl); + } + return joined; + } + exports.join = join; + + exports.isAbsolute = function (aPath) { + return aPath.charAt(0) === '/' || !!aPath.match(urlRegexp); + }; + + /** + * Make a path relative to a URL or another path. + * + * @param aRoot The root path or URL. + * @param aPath The path or URL to be made relative to aRoot. + */ + function relative(aRoot, aPath) { + if (aRoot === "") { + aRoot = "."; + } + + aRoot = aRoot.replace(/\/$/, ''); + + // It is possible for the path to be above the root. In this case, simply + // checking whether the root is a prefix of the path won't work. Instead, we + // need to remove components from the root one by one, until either we find + // a prefix that fits, or we run out of components to remove. + var level = 0; + while (aPath.indexOf(aRoot + '/') !== 0) { + var index = aRoot.lastIndexOf("/"); + if (index < 0) { + return aPath; + } + + // If the only part of the root that is left is the scheme (i.e. http://, + // file:///, etc.), one or more slashes (/), or simply nothing at all, we + // have exhausted all components, so the path is not relative to the root. + aRoot = aRoot.slice(0, index); + if (aRoot.match(/^([^\/]+:\/)?\/*$/)) { + return aPath; + } + + ++level; + } + + // Make sure we add a "../" for each component we removed from the root. + return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1); + } + exports.relative = relative; + + /** + * Because behavior goes wacky when you set `__proto__` on objects, we + * have to prefix all the strings in our set with an arbitrary character. + * + * See https://github.com/mozilla/source-map/pull/31 and + * https://github.com/mozilla/source-map/issues/30 + * + * @param String aStr + */ + function toSetString(aStr) { + return '$' + aStr; + } + exports.toSetString = toSetString; + + function fromSetString(aStr) { + return aStr.substr(1); + } + exports.fromSetString = fromSetString; + + /** + * Comparator between two mappings where the original positions are compared. + * + * Optionally pass in `true` as `onlyCompareGenerated` to consider two + * mappings with the same original source/line/column, but different generated + * line and column the same. Useful when searching for a mapping with a + * stubbed out mapping. + */ + function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) { + var cmp = mappingA.source - mappingB.source; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0 || onlyCompareOriginal) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + return mappingA.name - mappingB.name; + } + exports.compareByOriginalPositions = compareByOriginalPositions; + + /** + * Comparator between two mappings with deflated source and name indices where + * the generated positions are compared. + * + * Optionally pass in `true` as `onlyCompareGenerated` to consider two + * mappings with the same generated line and column, but different + * source/name/original line and column the same. Useful when searching for a + * mapping with a stubbed out mapping. + */ + function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) { + var cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0 || onlyCompareGenerated) { + return cmp; + } + + cmp = mappingA.source - mappingB.source; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0) { + return cmp; + } + + return mappingA.name - mappingB.name; + } + exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated; + + function strcmp(aStr1, aStr2) { + if (aStr1 === aStr2) { + return 0; + } + + if (aStr1 > aStr2) { + return 1; + } + + return -1; + } + + /** + * Comparator between two mappings with inflated source and name strings where + * the generated positions are compared. + */ + function compareByGeneratedPositionsInflated(mappingA, mappingB) { + var cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0) { + return cmp; + } + + cmp = strcmp(mappingA.source, mappingB.source); + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0) { + return cmp; + } + + return strcmp(mappingA.name, mappingB.name); + } + exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated; + } + + +/***/ } +/******/ ]); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly8vd2VicGFjay9ib290c3RyYXAgZjFlMTE4YWJkNTdmZDlhZDAzNTIiLCJ3ZWJwYWNrOi8vLy4vdGVzdC90ZXN0LWFycmF5LXNldC5qcyIsIndlYnBhY2s6Ly8vLi9saWIvYXJyYXktc2V0LmpzIiwid2VicGFjazovLy8uL2xpYi91dGlsLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7O0FBQUE7QUFDQTs7QUFFQTtBQUNBOztBQUVBO0FBQ0E7QUFDQTs7QUFFQTtBQUNBO0FBQ0EsdUJBQWU7QUFDZjtBQUNBO0FBQ0E7O0FBRUE7QUFDQTs7QUFFQTtBQUNBOztBQUVBO0FBQ0E7QUFDQTs7O0FBR0E7QUFDQTs7QUFFQTtBQUNBOztBQUVBO0FBQ0E7O0FBRUE7QUFDQTs7Ozs7OztBQ3RDQSxpQkFBZ0Isb0JBQW9CO0FBQ3BDO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQU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cbiAqKi8iXSwic291cmNlUm9vdCI6IiJ9 \ No newline at end of file diff --git a/devtools/shared/sourcemap/tests/unit/test_base64.js b/devtools/shared/sourcemap/tests/unit/test_base64.js new file mode 100644 index 000000000..f87a81b8f --- /dev/null +++ b/devtools/shared/sourcemap/tests/unit/test_base64.js @@ -0,0 +1,163 @@ +function run_test() { + for (var k in SOURCE_MAP_TEST_MODULE) { + if (/^test/.test(k)) { + SOURCE_MAP_TEST_MODULE[k](assert); + } + } +} + + +var SOURCE_MAP_TEST_MODULE = +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; +/******/ +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.loaded = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var base64 = __webpack_require__(1); + + exports['test out of range encoding'] = function (assert) { + assert.throws(function () { + base64.encode(-1); + }); + assert.throws(function () { + base64.encode(64); + }); + }; + + exports['test out of range decoding'] = function (assert) { + assert.equal(base64.decode('='.charCodeAt(0)), -1); + }; + + exports['test normal encoding and decoding'] = function (assert) { + for (var i = 0; i < 64; i++) { + assert.equal(base64.decode(base64.encode(i).charCodeAt(0)), i); + } + }; + } + + +/***/ }, +/* 1 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split(''); + + /** + * Encode an integer in the range of 0 to 63 to a single base 64 digit. + */ + exports.encode = function (number) { + if (0 <= number && number < intToCharMap.length) { + return intToCharMap[number]; + } + throw new TypeError("Must be between 0 and 63: " + number); + }; + + /** + * Decode a single base 64 character code digit to an integer. Returns -1 on + * failure. + */ + exports.decode = function (charCode) { + var bigA = 65; // 'A' + var bigZ = 90; // 'Z' + + var littleA = 97; // 'a' + var littleZ = 122; // 'z' + + var zero = 48; // '0' + var nine = 57; // '9' + + var plus = 43; // '+' + var slash = 47; // '/' + + var littleOffset = 26; + var numberOffset = 52; + + // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ + if (bigA <= charCode && charCode <= bigZ) { + return (charCode - bigA); + } + + // 26 - 51: abcdefghijklmnopqrstuvwxyz + if (littleA <= charCode && charCode <= littleZ) { + return (charCode - littleA + littleOffset); + } + + // 52 - 61: 0123456789 + if (zero <= charCode && charCode <= nine) { + return (charCode - zero + numberOffset); + } + + // 62: + + if (charCode == plus) { + return 62; + } + + // 63: / + if (charCode == slash) { + return 63; + } + + // Invalid base64 digit. + return -1; + }; + } + + +/***/ } +/******/ ]); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly8vd2VicGFjay9ib290c3RyYXAgMjJlMTk3NDMwNTJlZjVi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DI1OiBBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWlxuICAgIGlmIChiaWdBIDw9IGNoYXJDb2RlICYmIGNoYXJDb2RlIDw9IGJpZ1opIHtcbiAgICAgIHJldHVybiAoY2hhckNvZGUgLSBiaWdBKTtcbiAgICB9XG5cbiAgICAvLyAyNiAtIDUxOiBhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5elxuICAgIGlmIChsaXR0bGVBIDw9IGNoYXJDb2RlICYmIGNoYXJDb2RlIDw9IGxpdHRsZVopIHtcbiAgICAgIHJldHVybiAoY2hhckNvZGUgLSBsaXR0bGVBICsgbGl0dGxlT2Zmc2V0KTtcbiAgICB9XG5cbiAgICAvLyA1MiAtIDYxOiAwMTIzNDU2Nzg5XG4gICAgaWYgKHplcm8gPD0gY2hhckNvZGUgJiYgY2hhckNvZGUgPD0gbmluZSkge1xuICAgICAgcmV0dXJuIChjaGFyQ29kZSAtIHplcm8gKyBudW1iZXJPZmZzZXQpO1xuICAgIH1cblxuICAgIC8vIDYyOiArXG4gICAgaWYgKGNoYXJDb2RlID09IHBsdXMpIHtcbiAgICAgIHJldHVybiA2MjtcbiAgICB9XG5cbiAgICAvLyA2MzogL1xuICAgIGlmIChjaGFyQ29kZSA9PSBzbGFzaCkge1xuICAgICAgcmV0dXJuIDYzO1xuICAgIH1cblxuICAgIC8vIEludmFsaWQgYmFzZTY0IGRpZ2l0LlxuICAgIHJldHVybiAtMTtcbiAgfTtcbn1cblxuXG5cbi8qKioqKioqKioqKioqKioqKlxuICoqIFdFQlBBQ0sgRk9PVEVSXG4gKiogLi9saWIvYmFzZTY0LmpzXG4gKiogbW9kdWxlIGlkID0gMVxuICoqIG1vZHVsZSBjaHVua3MgPSAwXG4gKiovIl0sInNvdXJjZVJvb3QiOiIifQ== \ No newline at end of file diff --git a/devtools/shared/sourcemap/tests/unit/test_base64_vlq.js b/devtools/shared/sourcemap/tests/unit/test_base64_vlq.js new file mode 100644 index 000000000..b7b38cc88 --- /dev/null +++ b/devtools/shared/sourcemap/tests/unit/test_base64_vlq.js @@ -0,0 +1,301 @@ +function run_test() { + for (var k in SOURCE_MAP_TEST_MODULE) { + if (/^test/.test(k)) { + SOURCE_MAP_TEST_MODULE[k](assert); + } + } +} + + +var SOURCE_MAP_TEST_MODULE = +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; +/******/ +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.loaded = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var base64VLQ = __webpack_require__(1); + + exports['test normal encoding and decoding'] = function (assert) { + var result = {}; + for (var i = -255; i < 256; i++) { + var str = base64VLQ.encode(i); + base64VLQ.decode(str, 0, result); + assert.equal(result.value, i); + assert.equal(result.rest, str.length); + } + }; + } + + +/***/ }, +/* 1 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + * + * Based on the Base 64 VLQ implementation in Closure Compiler: + * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java + * + * Copyright 2011 The Closure Compiler Authors. All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + { + var base64 = __webpack_require__(2); + + // A single base 64 digit can contain 6 bits of data. For the base 64 variable + // length quantities we use in the source map spec, the first bit is the sign, + // the next four bits are the actual value, and the 6th bit is the + // continuation bit. The continuation bit tells us whether there are more + // digits in this value following this digit. + // + // Continuation + // | Sign + // | | + // V V + // 101011 + + var VLQ_BASE_SHIFT = 5; + + // binary: 100000 + var VLQ_BASE = 1 << VLQ_BASE_SHIFT; + + // binary: 011111 + var VLQ_BASE_MASK = VLQ_BASE - 1; + + // binary: 100000 + var VLQ_CONTINUATION_BIT = VLQ_BASE; + + /** + * Converts from a two-complement value to a value where the sign bit is + * placed in the least significant bit. For example, as decimals: + * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary) + * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary) + */ + function toVLQSigned(aValue) { + return aValue < 0 + ? ((-aValue) << 1) + 1 + : (aValue << 1) + 0; + } + + /** + * Converts to a two-complement value from a value where the sign bit is + * placed in the least significant bit. For example, as decimals: + * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1 + * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2 + */ + function fromVLQSigned(aValue) { + var isNegative = (aValue & 1) === 1; + var shifted = aValue >> 1; + return isNegative + ? -shifted + : shifted; + } + + /** + * Returns the base 64 VLQ encoded value. + */ + exports.encode = function base64VLQ_encode(aValue) { + var encoded = ""; + var digit; + + var vlq = toVLQSigned(aValue); + + do { + digit = vlq & VLQ_BASE_MASK; + vlq >>>= VLQ_BASE_SHIFT; + if (vlq > 0) { + // There are still more digits in this value, so we must make sure the + // continuation bit is marked. + digit |= VLQ_CONTINUATION_BIT; + } + encoded += base64.encode(digit); + } while (vlq > 0); + + return encoded; + }; + + /** + * Decodes the next base 64 VLQ value from the given string and returns the + * value and the rest of the string via the out parameter. + */ + exports.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) { + var strLen = aStr.length; + var result = 0; + var shift = 0; + var continuation, digit; + + do { + if (aIndex >= strLen) { + throw new Error("Expected more digits in base 64 VLQ value."); + } + + digit = base64.decode(aStr.charCodeAt(aIndex++)); + if (digit === -1) { + throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1)); + } + + continuation = !!(digit & VLQ_CONTINUATION_BIT); + digit &= VLQ_BASE_MASK; + result = result + (digit << shift); + shift += VLQ_BASE_SHIFT; + } while (continuation); + + aOutParam.value = fromVLQSigned(result); + aOutParam.rest = aIndex; + }; + } + + +/***/ }, +/* 2 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split(''); + + /** + * Encode an integer in the range of 0 to 63 to a single base 64 digit. + */ + exports.encode = function (number) { + if (0 <= number && number < intToCharMap.length) { + return intToCharMap[number]; + } + throw new TypeError("Must be between 0 and 63: " + number); + }; + + /** + * Decode a single base 64 character code digit to an integer. Returns -1 on + * failure. + */ + exports.decode = function (charCode) { + var bigA = 65; // 'A' + var bigZ = 90; // 'Z' + + var littleA = 97; // 'a' + var littleZ = 122; // 'z' + + var zero = 48; // '0' + var nine = 57; // '9' + + var plus = 43; // '+' + var slash = 47; // '/' + + var littleOffset = 26; + var numberOffset = 52; + + // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ + if (bigA <= charCode && charCode <= bigZ) { + return (charCode - bigA); + } + + // 26 - 51: abcdefghijklmnopqrstuvwxyz + if (littleA <= charCode && charCode <= littleZ) { + return (charCode - littleA + littleOffset); + } + + // 52 - 61: 0123456789 + if (zero <= charCode && charCode <= nine) { + return (charCode - zero + numberOffset); + } + + // 62: + + if (charCode == plus) { + return 62; + } + + // 63: / + if (charCode == slash) { + return 63; + } + + // Invalid base64 digit. + return -1; + }; + } + + +/***/ } +/******/ ]); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly8vd2VicGFjay9ib290c3RyYXAgODE2ZmNlY2MyY2FkYmFiMjRjOG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T2Zmc2V0ID0gMjY7XG4gICAgdmFyIG51bWJlck9mZnNldCA9IDUyO1xuXG4gICAgLy8gMCAtIDI1OiBBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWlxuICAgIGlmIChiaWdBIDw9IGNoYXJDb2RlICYmIGNoYXJDb2RlIDw9IGJpZ1opIHtcbiAgICAgIHJldHVybiAoY2hhckNvZGUgLSBiaWdBKTtcbiAgICB9XG5cbiAgICAvLyAyNiAtIDUxOiBhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5elxuICAgIGlmIChsaXR0bGVBIDw9IGNoYXJDb2RlICYmIGNoYXJDb2RlIDw9IGxpdHRsZVopIHtcbiAgICAgIHJldHVybiAoY2hhckNvZGUgLSBsaXR0bGVBICsgbGl0dGxlT2Zmc2V0KTtcbiAgICB9XG5cbiAgICAvLyA1MiAtIDYxOiAwMTIzNDU2Nzg5XG4gICAgaWYgKHplcm8gPD0gY2hhckNvZGUgJiYgY2hhckNvZGUgPD0gbmluZSkge1xuICAgICAgcmV0dXJuIChjaGFyQ29kZSAtIHplcm8gKyBudW1iZXJPZmZzZXQpO1xuICAgIH1cblxuICAgIC8vIDYyOiArXG4gICAgaWYgKGNoYXJDb2RlID09IHBsdXMpIHtcbiAgICAgIHJldHVybiA2MjtcbiAgICB9XG5cbiAgICAvLyA2MzogL1xuICAgIGlmIChjaGFyQ29kZSA9PSBzbGFzaCkge1xuICAgICAgcmV0dXJuIDYzO1xuICAgIH1cblxuICAgIC8vIEludmFsaWQgYmFzZTY0IGRpZ2l0LlxuICAgIHJldHVybiAtMTtcbiAgfTtcbn1cblxuXG5cbi8qKioqKioqKioqKioqKioqKlxuICoqIFdFQlBBQ0sgRk9PVEVSXG4gKiogLi9saWIvYmFzZTY0LmpzXG4gKiogbW9kdWxlIGlkID0gMlxuICoqIG1vZHVsZSBjaHVua3MgPSAwXG4gKiovIl0sInNvdXJjZVJvb3QiOiIifQ== \ No newline at end of file diff --git a/devtools/shared/sourcemap/tests/unit/test_binary_search.js b/devtools/shared/sourcemap/tests/unit/test_binary_search.js new file mode 100644 index 000000000..fcb70c520 --- /dev/null +++ b/devtools/shared/sourcemap/tests/unit/test_binary_search.js @@ -0,0 +1,276 @@ +function run_test() { + for (var k in SOURCE_MAP_TEST_MODULE) { + if (/^test/.test(k)) { + SOURCE_MAP_TEST_MODULE[k](assert); + } + } +} + + +var SOURCE_MAP_TEST_MODULE = +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; +/******/ +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.loaded = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var binarySearch = __webpack_require__(1); + + function numberCompare(a, b) { + return a - b; + } + + exports['test too high with default (glb) bias'] = function (assert) { + var needle = 30; + var haystack = [2,4,6,8,10,12,14,16,18,20]; + + assert.doesNotThrow(function () { + binarySearch.search(needle, haystack, numberCompare); + }); + + assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare)], 20); + }; + + exports['test too low with default (glb) bias'] = function (assert) { + var needle = 1; + var haystack = [2,4,6,8,10,12,14,16,18,20]; + + assert.doesNotThrow(function () { + binarySearch.search(needle, haystack, numberCompare); + }); + + assert.equal(binarySearch.search(needle, haystack, numberCompare), -1); + }; + + exports['test too high with lub bias'] = function (assert) { + var needle = 30; + var haystack = [2,4,6,8,10,12,14,16,18,20]; + + assert.doesNotThrow(function () { + binarySearch.search(needle, haystack, numberCompare); + }); + + assert.equal(binarySearch.search(needle, haystack, numberCompare, + binarySearch.LEAST_UPPER_BOUND), -1); + }; + + exports['test too low with lub bias'] = function (assert) { + var needle = 1; + var haystack = [2,4,6,8,10,12,14,16,18,20]; + + assert.doesNotThrow(function () { + binarySearch.search(needle, haystack, numberCompare); + }); + + assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare, + binarySearch.LEAST_UPPER_BOUND)], 2); + }; + + exports['test exact search'] = function (assert) { + var needle = 4; + var haystack = [2,4,6,8,10,12,14,16,18,20]; + + assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare)], 4); + }; + + exports['test fuzzy search with default (glb) bias'] = function (assert) { + var needle = 19; + var haystack = [2,4,6,8,10,12,14,16,18,20]; + + assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare)], 18); + }; + + exports['test fuzzy search with lub bias'] = function (assert) { + var needle = 19; + var haystack = [2,4,6,8,10,12,14,16,18,20]; + + assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare, + binarySearch.LEAST_UPPER_BOUND)], 20); + }; + + exports['test multiple matches'] = function (assert) { + var needle = 5; + var haystack = [1, 1, 2, 5, 5, 5, 13, 21]; + + assert.equal(binarySearch.search(needle, haystack, numberCompare, + binarySearch.LEAST_UPPER_BOUND), 3); + }; + + exports['test multiple matches at the beginning'] = function (assert) { + var needle = 1; + var haystack = [1, 1, 2, 5, 5, 5, 13, 21]; + + assert.equal(binarySearch.search(needle, haystack, numberCompare, + binarySearch.LEAST_UPPER_BOUND), 0); + }; + } + + +/***/ }, +/* 1 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + exports.GREATEST_LOWER_BOUND = 1; + exports.LEAST_UPPER_BOUND = 2; + + /** + * Recursive implementation of binary search. + * + * @param aLow Indices here and lower do not contain the needle. + * @param aHigh Indices here and higher do not contain the needle. + * @param aNeedle The element being searched for. + * @param aHaystack The non-empty array being searched. + * @param aCompare Function which takes two elements and returns -1, 0, or 1. + * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or + * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + */ + function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) { + // This function terminates when one of the following is true: + // + // 1. We find the exact element we are looking for. + // + // 2. We did not find the exact element, but we can return the index of + // the next-closest element. + // + // 3. We did not find the exact element, and there is no next-closest + // element than the one we are searching for, so we return -1. + var mid = Math.floor((aHigh - aLow) / 2) + aLow; + var cmp = aCompare(aNeedle, aHaystack[mid], true); + if (cmp === 0) { + // Found the element we are looking for. + return mid; + } + else if (cmp > 0) { + // Our needle is greater than aHaystack[mid]. + if (aHigh - mid > 1) { + // The element is in the upper half. + return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias); + } + + // The exact needle element was not found in this haystack. Determine if + // we are in termination case (3) or (2) and return the appropriate thing. + if (aBias == exports.LEAST_UPPER_BOUND) { + return aHigh < aHaystack.length ? aHigh : -1; + } else { + return mid; + } + } + else { + // Our needle is less than aHaystack[mid]. + if (mid - aLow > 1) { + // The element is in the lower half. + return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias); + } + + // we are in termination case (3) or (2) and return the appropriate thing. + if (aBias == exports.LEAST_UPPER_BOUND) { + return mid; + } else { + return aLow < 0 ? -1 : aLow; + } + } + } + + /** + * This is an implementation of binary search which will always try and return + * the index of the closest element if there is no exact hit. This is because + * mappings between original and generated line/col pairs are single points, + * and there is an implicit region between each of them, so a miss just means + * that you aren't on the very start of a region. + * + * @param aNeedle The element you are looking for. + * @param aHaystack The array that is being searched. + * @param aCompare A function which takes the needle and an element in the + * array and returns -1, 0, or 1 depending on whether the needle is less + * than, equal to, or greater than the element, respectively. + * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or + * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'. + */ + exports.search = function search(aNeedle, aHaystack, aCompare, aBias) { + if (aHaystack.length === 0) { + return -1; + } + + var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, + aCompare, aBias || exports.GREATEST_LOWER_BOUND); + if (index < 0) { + return -1; + } + + // We have found either the exact element, or the next-closest element than + // the one we are searching for. However, there may be more than one such + // element. Make sure we always return the smallest of these. + while (index - 1 >= 0) { + if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) { + break; + } + --index; + } + + return index; + }; + } + + +/***/ } +/******/ ]); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly8vd2VicGFjay9ib290c3RyYXAgYmI3MjVjOTVmZTk3YzY1OTQ3OGMiLCJ3ZWJwYWNrOi8vLy4vdGVzdC90ZXN0LWJpbmFyeS1zZWFyY2guanMiLCJ3ZWJwYWNrOi8vLy4vbGliL2JpbmFyeS1zZWFyY2guanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7QUFBQTtBQUNBOztBQUVBO0FBQ0E7O0FBRUE7QUFDQTtBQUNBOztBQUVBO0FBQ0E7QUFDQSx1QkFBZTtBQUNmO0FBQ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2ssXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGFDb21wYXJlLCBhQmlhcyB8fCBleHBvcnRzLkdSRUFURVNUX0xPV0VSX0JPVU5EKTtcbiAgICBpZiAoaW5kZXggPCAwKSB7XG4gICAgICByZXR1cm4gLTE7XG4gICAgfVxuXG4gICAgLy8gV2UgaGF2ZSBmb3VuZCBlaXRoZXIgdGhlIGV4YWN0IGVsZW1lbnQsIG9yIHRoZSBuZXh0LWNsb3Nlc3QgZWxlbWVudCB0aGFuXG4gICAgLy8gdGhlIG9uZSB3ZSBhcmUgc2VhcmNoaW5nIGZvci4gSG93ZXZlciwgdGhlcmUgbWF5IGJlIG1vcmUgdGhhbiBvbmUgc3VjaFxuICAgIC8vIGVsZW1lbnQuIE1ha2Ugc3VyZSB3ZSBhbHdheXMgcmV0dXJuIHRoZSBzbWFsbGVzdCBvZiB0aGVzZS5cbiAgICB3aGlsZSAoaW5kZXggLSAxID49IDApIHtcbiAgICAgIGlmIChhQ29tcGFyZShhSGF5c3RhY2tbaW5kZXhdLCBhSGF5c3RhY2tbaW5kZXggLSAxXSwgdHJ1ZSkgIT09IDApIHtcbiAgICAgICAgYnJlYWs7XG4gICAgICB9XG4gICAgICAtLWluZGV4O1xuICAgIH1cblxuICAgIHJldHVybiBpbmRleDtcbiAgfTtcbn1cblxuXG5cbi8qKioqKioqKioqKioqKioqKlxuICoqIFdFQlBBQ0sgRk9PVEVSXG4gKiogLi9saWIvYmluYXJ5LXNlYXJjaC5qc1xuICoqIG1vZHVsZSBpZCA9IDFcbiAqKiBtb2R1bGUgY2h1bmtzID0gMFxuICoqLyJdLCJzb3VyY2VSb290IjoiIn0= \ No newline at end of file diff --git a/devtools/shared/sourcemap/tests/unit/test_dog_fooding.js b/devtools/shared/sourcemap/tests/unit/test_dog_fooding.js new file mode 100644 index 000000000..ae94a0cd8 --- /dev/null +++ b/devtools/shared/sourcemap/tests/unit/test_dog_fooding.js @@ -0,0 +1,2985 @@ +function run_test() { + for (var k in SOURCE_MAP_TEST_MODULE) { + if (/^test/.test(k)) { + SOURCE_MAP_TEST_MODULE[k](assert); + } + } +} + + +var SOURCE_MAP_TEST_MODULE = +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; +/******/ +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.loaded = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var util = __webpack_require__(1); + var SourceMapConsumer = __webpack_require__(3).SourceMapConsumer; + var SourceMapGenerator = __webpack_require__(9).SourceMapGenerator; + + exports['test eating our own dog food'] = function (assert) { + var smg = new SourceMapGenerator({ + file: 'testing.js', + sourceRoot: '/wu/tang' + }); + + smg.addMapping({ + source: 'gza.coffee', + original: { line: 1, column: 0 }, + generated: { line: 2, column: 2 } + }); + + smg.addMapping({ + source: 'gza.coffee', + original: { line: 2, column: 0 }, + generated: { line: 3, column: 2 } + }); + + smg.addMapping({ + source: 'gza.coffee', + original: { line: 3, column: 0 }, + generated: { line: 4, column: 2 } + }); + + smg.addMapping({ + source: 'gza.coffee', + original: { line: 4, column: 0 }, + generated: { line: 5, column: 2 } + }); + + smg.addMapping({ + source: 'gza.coffee', + original: { line: 5, column: 10 }, + generated: { line: 6, column: 12 } + }); + + var smc = new SourceMapConsumer(smg.toString()); + + // Exact + util.assertMapping(2, 2, '/wu/tang/gza.coffee', 1, 0, null, null, smc, assert); + util.assertMapping(3, 2, '/wu/tang/gza.coffee', 2, 0, null, null, smc, assert); + util.assertMapping(4, 2, '/wu/tang/gza.coffee', 3, 0, null, null, smc, assert); + util.assertMapping(5, 2, '/wu/tang/gza.coffee', 4, 0, null, null, smc, assert); + util.assertMapping(6, 12, '/wu/tang/gza.coffee', 5, 10, null, null, smc, assert); + + // Fuzzy + + // Generated to original with default (glb) bias. + util.assertMapping(2, 0, null, null, null, null, null, smc, assert, true); + util.assertMapping(2, 9, '/wu/tang/gza.coffee', 1, 0, null, null, smc, assert, true); + util.assertMapping(3, 0, null, null, null, null, null, smc, assert, true); + util.assertMapping(3, 9, '/wu/tang/gza.coffee', 2, 0, null, null, smc, assert, true); + util.assertMapping(4, 0, null, null, null, null, null, smc, assert, true); + util.assertMapping(4, 9, '/wu/tang/gza.coffee', 3, 0, null, null, smc, assert, true); + util.assertMapping(5, 0, null, null, null, null, null, smc, assert, true); + util.assertMapping(5, 9, '/wu/tang/gza.coffee', 4, 0, null, null, smc, assert, true); + util.assertMapping(6, 0, null, null, null, null, null, smc, assert, true); + util.assertMapping(6, 9, null, null, null, null, null, smc, assert, true); + util.assertMapping(6, 13, '/wu/tang/gza.coffee', 5, 10, null, null, smc, assert, true); + + // Generated to original with lub bias. + util.assertMapping(2, 0, '/wu/tang/gza.coffee', 1, 0, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, true); + util.assertMapping(2, 9, null, null, null, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, true); + util.assertMapping(3, 0, '/wu/tang/gza.coffee', 2, 0, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, true); + util.assertMapping(3, 9, null, null, null, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, true); + util.assertMapping(4, 0, '/wu/tang/gza.coffee', 3, 0, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, true); + util.assertMapping(4, 9, null, null, null, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, true); + util.assertMapping(5, 0, '/wu/tang/gza.coffee', 4, 0, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, true); + util.assertMapping(5, 9, null, null, null, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, true); + util.assertMapping(6, 0, '/wu/tang/gza.coffee', 5, 10, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, true); + util.assertMapping(6, 9, '/wu/tang/gza.coffee', 5, 10, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, true); + util.assertMapping(6, 13, null, null, null, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, true); + + // Original to generated with default (glb) bias + util.assertMapping(2, 2, '/wu/tang/gza.coffee', 1, 1, null, null, smc, assert, null, true); + util.assertMapping(3, 2, '/wu/tang/gza.coffee', 2, 3, null, null, smc, assert, null, true); + util.assertMapping(4, 2, '/wu/tang/gza.coffee', 3, 6, null, null, smc, assert, null, true); + util.assertMapping(5, 2, '/wu/tang/gza.coffee', 4, 9, null, null, smc, assert, null, true); + util.assertMapping(5, 2, '/wu/tang/gza.coffee', 5, 9, null, null, smc, assert, null, true); + util.assertMapping(6, 12, '/wu/tang/gza.coffee', 6, 19, null, null, smc, assert, null, true); + + // Original to generated with lub bias. + util.assertMapping(3, 2, '/wu/tang/gza.coffee', 1, 1, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, null, true); + util.assertMapping(4, 2, '/wu/tang/gza.coffee', 2, 3, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, null, true); + util.assertMapping(5, 2, '/wu/tang/gza.coffee', 3, 6, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, null, true); + util.assertMapping(6, 12, '/wu/tang/gza.coffee', 4, 9, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, null, true); + util.assertMapping(6, 12, '/wu/tang/gza.coffee', 5, 9, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, null, true); + util.assertMapping(null, null, '/wu/tang/gza.coffee', 6, 19, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, null, true); + }; + } + + +/***/ }, +/* 1 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var util = __webpack_require__(2); + + // This is a test mapping which maps functions from two different files + // (one.js and two.js) to a minified generated source. + // + // Here is one.js: + // + // ONE.foo = function (bar) { + // return baz(bar); + // }; + // + // Here is two.js: + // + // TWO.inc = function (n) { + // return n + 1; + // }; + // + // And here is the generated code (min.js): + // + // ONE.foo=function(a){return baz(a);}; + // TWO.inc=function(a){return a+1;}; + exports.testGeneratedCode = " ONE.foo=function(a){return baz(a);};\n"+ + " TWO.inc=function(a){return a+1;};"; + exports.testMap = { + version: 3, + file: 'min.js', + names: ['bar', 'baz', 'n'], + sources: ['one.js', 'two.js'], + sourceRoot: '/the/root', + mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA' + }; + exports.testMapNoSourceRoot = { + version: 3, + file: 'min.js', + names: ['bar', 'baz', 'n'], + sources: ['one.js', 'two.js'], + mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA' + }; + exports.testMapEmptySourceRoot = { + version: 3, + file: 'min.js', + names: ['bar', 'baz', 'n'], + sources: ['one.js', 'two.js'], + sourceRoot: '', + mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA' + }; + // This mapping is identical to above, but uses the indexed format instead. + exports.indexedTestMap = { + version: 3, + file: 'min.js', + sections: [ + { + offset: { + line: 0, + column: 0 + }, + map: { + version: 3, + sources: [ + "one.js" + ], + sourcesContent: [ + ' ONE.foo = function (bar) {\n' + + ' return baz(bar);\n' + + ' };', + ], + names: [ + "bar", + "baz" + ], + mappings: "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID", + file: "min.js", + sourceRoot: "/the/root" + } + }, + { + offset: { + line: 1, + column: 0 + }, + map: { + version: 3, + sources: [ + "two.js" + ], + sourcesContent: [ + ' TWO.inc = function (n) {\n' + + ' return n + 1;\n' + + ' };' + ], + names: [ + "n" + ], + mappings: "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOA", + file: "min.js", + sourceRoot: "/the/root" + } + } + ] + }; + exports.indexedTestMapDifferentSourceRoots = { + version: 3, + file: 'min.js', + sections: [ + { + offset: { + line: 0, + column: 0 + }, + map: { + version: 3, + sources: [ + "one.js" + ], + sourcesContent: [ + ' ONE.foo = function (bar) {\n' + + ' return baz(bar);\n' + + ' };', + ], + names: [ + "bar", + "baz" + ], + mappings: "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID", + file: "min.js", + sourceRoot: "/the/root" + } + }, + { + offset: { + line: 1, + column: 0 + }, + map: { + version: 3, + sources: [ + "two.js" + ], + sourcesContent: [ + ' TWO.inc = function (n) {\n' + + ' return n + 1;\n' + + ' };' + ], + names: [ + "n" + ], + mappings: "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOA", + file: "min.js", + sourceRoot: "/different/root" + } + } + ] + }; + exports.testMapWithSourcesContent = { + version: 3, + file: 'min.js', + names: ['bar', 'baz', 'n'], + sources: ['one.js', 'two.js'], + sourcesContent: [ + ' ONE.foo = function (bar) {\n' + + ' return baz(bar);\n' + + ' };', + ' TWO.inc = function (n) {\n' + + ' return n + 1;\n' + + ' };' + ], + sourceRoot: '/the/root', + mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA' + }; + exports.testMapRelativeSources = { + version: 3, + file: 'min.js', + names: ['bar', 'baz', 'n'], + sources: ['./one.js', './two.js'], + sourcesContent: [ + ' ONE.foo = function (bar) {\n' + + ' return baz(bar);\n' + + ' };', + ' TWO.inc = function (n) {\n' + + ' return n + 1;\n' + + ' };' + ], + sourceRoot: '/the/root', + mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA' + }; + exports.emptyMap = { + version: 3, + file: 'min.js', + names: [], + sources: [], + mappings: '' + }; + + + function assertMapping(generatedLine, generatedColumn, originalSource, + originalLine, originalColumn, name, bias, map, assert, + dontTestGenerated, dontTestOriginal) { + if (!dontTestOriginal) { + var origMapping = map.originalPositionFor({ + line: generatedLine, + column: generatedColumn, + bias: bias + }); + assert.equal(origMapping.name, name, + 'Incorrect name, expected ' + JSON.stringify(name) + + ', got ' + JSON.stringify(origMapping.name)); + assert.equal(origMapping.line, originalLine, + 'Incorrect line, expected ' + JSON.stringify(originalLine) + + ', got ' + JSON.stringify(origMapping.line)); + assert.equal(origMapping.column, originalColumn, + 'Incorrect column, expected ' + JSON.stringify(originalColumn) + + ', got ' + JSON.stringify(origMapping.column)); + + var expectedSource; + + if (originalSource && map.sourceRoot && originalSource.indexOf(map.sourceRoot) === 0) { + expectedSource = originalSource; + } else if (originalSource) { + expectedSource = map.sourceRoot + ? util.join(map.sourceRoot, originalSource) + : originalSource; + } else { + expectedSource = null; + } + + assert.equal(origMapping.source, expectedSource, + 'Incorrect source, expected ' + JSON.stringify(expectedSource) + + ', got ' + JSON.stringify(origMapping.source)); + } + + if (!dontTestGenerated) { + var genMapping = map.generatedPositionFor({ + source: originalSource, + line: originalLine, + column: originalColumn, + bias: bias + }); + assert.equal(genMapping.line, generatedLine, + 'Incorrect line, expected ' + JSON.stringify(generatedLine) + + ', got ' + JSON.stringify(genMapping.line)); + assert.equal(genMapping.column, generatedColumn, + 'Incorrect column, expected ' + JSON.stringify(generatedColumn) + + ', got ' + JSON.stringify(genMapping.column)); + } + } + exports.assertMapping = assertMapping; + + function assertEqualMaps(assert, actualMap, expectedMap) { + assert.equal(actualMap.version, expectedMap.version, "version mismatch"); + assert.equal(actualMap.file, expectedMap.file, "file mismatch"); + assert.equal(actualMap.names.length, + expectedMap.names.length, + "names length mismatch: " + + actualMap.names.join(", ") + " != " + expectedMap.names.join(", ")); + for (var i = 0; i < actualMap.names.length; i++) { + assert.equal(actualMap.names[i], + expectedMap.names[i], + "names[" + i + "] mismatch: " + + actualMap.names.join(", ") + " != " + expectedMap.names.join(", ")); + } + assert.equal(actualMap.sources.length, + expectedMap.sources.length, + "sources length mismatch: " + + actualMap.sources.join(", ") + " != " + expectedMap.sources.join(", ")); + for (var i = 0; i < actualMap.sources.length; i++) { + assert.equal(actualMap.sources[i], + expectedMap.sources[i], + "sources[" + i + "] length mismatch: " + + actualMap.sources.join(", ") + " != " + expectedMap.sources.join(", ")); + } + assert.equal(actualMap.sourceRoot, + expectedMap.sourceRoot, + "sourceRoot mismatch: " + + actualMap.sourceRoot + " != " + expectedMap.sourceRoot); + assert.equal(actualMap.mappings, expectedMap.mappings, + "mappings mismatch:\nActual: " + actualMap.mappings + "\nExpected: " + expectedMap.mappings); + if (actualMap.sourcesContent) { + assert.equal(actualMap.sourcesContent.length, + expectedMap.sourcesContent.length, + "sourcesContent length mismatch"); + for (var i = 0; i < actualMap.sourcesContent.length; i++) { + assert.equal(actualMap.sourcesContent[i], + expectedMap.sourcesContent[i], + "sourcesContent[" + i + "] mismatch"); + } + } + } + exports.assertEqualMaps = assertEqualMaps; + } + + +/***/ }, +/* 2 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + /** + * This is a helper function for getting values from parameter/options + * objects. + * + * @param args The object we are extracting values from + * @param name The name of the property we are getting. + * @param defaultValue An optional value to return if the property is missing + * from the object. If this is not specified and the property is missing, an + * error will be thrown. + */ + function getArg(aArgs, aName, aDefaultValue) { + if (aName in aArgs) { + return aArgs[aName]; + } else if (arguments.length === 3) { + return aDefaultValue; + } else { + throw new Error('"' + aName + '" is a required argument.'); + } + } + exports.getArg = getArg; + + var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.]*)(?::(\d+))?(\S*)$/; + var dataUrlRegexp = /^data:.+\,.+$/; + + function urlParse(aUrl) { + var match = aUrl.match(urlRegexp); + if (!match) { + return null; + } + return { + scheme: match[1], + auth: match[2], + host: match[3], + port: match[4], + path: match[5] + }; + } + exports.urlParse = urlParse; + + function urlGenerate(aParsedUrl) { + var url = ''; + if (aParsedUrl.scheme) { + url += aParsedUrl.scheme + ':'; + } + url += '//'; + if (aParsedUrl.auth) { + url += aParsedUrl.auth + '@'; + } + if (aParsedUrl.host) { + url += aParsedUrl.host; + } + if (aParsedUrl.port) { + url += ":" + aParsedUrl.port + } + if (aParsedUrl.path) { + url += aParsedUrl.path; + } + return url; + } + exports.urlGenerate = urlGenerate; + + /** + * Normalizes a path, or the path portion of a URL: + * + * - Replaces consequtive slashes with one slash. + * - Removes unnecessary '.' parts. + * - Removes unnecessary '/..' parts. + * + * Based on code in the Node.js 'path' core module. + * + * @param aPath The path or url to normalize. + */ + function normalize(aPath) { + var path = aPath; + var url = urlParse(aPath); + if (url) { + if (!url.path) { + return aPath; + } + path = url.path; + } + var isAbsolute = exports.isAbsolute(path); + + var parts = path.split(/\/+/); + for (var part, up = 0, i = parts.length - 1; i >= 0; i--) { + part = parts[i]; + if (part === '.') { + parts.splice(i, 1); + } else if (part === '..') { + up++; + } else if (up > 0) { + if (part === '') { + // The first part is blank if the path is absolute. Trying to go + // above the root is a no-op. Therefore we can remove all '..' parts + // directly after the root. + parts.splice(i + 1, up); + up = 0; + } else { + parts.splice(i, 2); + up--; + } + } + } + path = parts.join('/'); + + if (path === '') { + path = isAbsolute ? '/' : '.'; + } + + if (url) { + url.path = path; + return urlGenerate(url); + } + return path; + } + exports.normalize = normalize; + + /** + * Joins two paths/URLs. + * + * @param aRoot The root path or URL. + * @param aPath The path or URL to be joined with the root. + * + * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a + * scheme-relative URL: Then the scheme of aRoot, if any, is prepended + * first. + * - Otherwise aPath is a path. If aRoot is a URL, then its path portion + * is updated with the result and aRoot is returned. Otherwise the result + * is returned. + * - If aPath is absolute, the result is aPath. + * - Otherwise the two paths are joined with a slash. + * - Joining for example 'http://' and 'www.example.com' is also supported. + */ + function join(aRoot, aPath) { + if (aRoot === "") { + aRoot = "."; + } + if (aPath === "") { + aPath = "."; + } + var aPathUrl = urlParse(aPath); + var aRootUrl = urlParse(aRoot); + if (aRootUrl) { + aRoot = aRootUrl.path || '/'; + } + + // `join(foo, '//www.example.org')` + if (aPathUrl && !aPathUrl.scheme) { + if (aRootUrl) { + aPathUrl.scheme = aRootUrl.scheme; + } + return urlGenerate(aPathUrl); + } + + if (aPathUrl || aPath.match(dataUrlRegexp)) { + return aPath; + } + + // `join('http://', 'www.example.com')` + if (aRootUrl && !aRootUrl.host && !aRootUrl.path) { + aRootUrl.host = aPath; + return urlGenerate(aRootUrl); + } + + var joined = aPath.charAt(0) === '/' + ? aPath + : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath); + + if (aRootUrl) { + aRootUrl.path = joined; + return urlGenerate(aRootUrl); + } + return joined; + } + exports.join = join; + + exports.isAbsolute = function (aPath) { + return aPath.charAt(0) === '/' || !!aPath.match(urlRegexp); + }; + + /** + * Make a path relative to a URL or another path. + * + * @param aRoot The root path or URL. + * @param aPath The path or URL to be made relative to aRoot. + */ + function relative(aRoot, aPath) { + if (aRoot === "") { + aRoot = "."; + } + + aRoot = aRoot.replace(/\/$/, ''); + + // It is possible for the path to be above the root. In this case, simply + // checking whether the root is a prefix of the path won't work. Instead, we + // need to remove components from the root one by one, until either we find + // a prefix that fits, or we run out of components to remove. + var level = 0; + while (aPath.indexOf(aRoot + '/') !== 0) { + var index = aRoot.lastIndexOf("/"); + if (index < 0) { + return aPath; + } + + // If the only part of the root that is left is the scheme (i.e. http://, + // file:///, etc.), one or more slashes (/), or simply nothing at all, we + // have exhausted all components, so the path is not relative to the root. + aRoot = aRoot.slice(0, index); + if (aRoot.match(/^([^\/]+:\/)?\/*$/)) { + return aPath; + } + + ++level; + } + + // Make sure we add a "../" for each component we removed from the root. + return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1); + } + exports.relative = relative; + + /** + * Because behavior goes wacky when you set `__proto__` on objects, we + * have to prefix all the strings in our set with an arbitrary character. + * + * See https://github.com/mozilla/source-map/pull/31 and + * https://github.com/mozilla/source-map/issues/30 + * + * @param String aStr + */ + function toSetString(aStr) { + return '$' + aStr; + } + exports.toSetString = toSetString; + + function fromSetString(aStr) { + return aStr.substr(1); + } + exports.fromSetString = fromSetString; + + /** + * Comparator between two mappings where the original positions are compared. + * + * Optionally pass in `true` as `onlyCompareGenerated` to consider two + * mappings with the same original source/line/column, but different generated + * line and column the same. Useful when searching for a mapping with a + * stubbed out mapping. + */ + function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) { + var cmp = mappingA.source - mappingB.source; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0 || onlyCompareOriginal) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + return mappingA.name - mappingB.name; + } + exports.compareByOriginalPositions = compareByOriginalPositions; + + /** + * Comparator between two mappings with deflated source and name indices where + * the generated positions are compared. + * + * Optionally pass in `true` as `onlyCompareGenerated` to consider two + * mappings with the same generated line and column, but different + * source/name/original line and column the same. Useful when searching for a + * mapping with a stubbed out mapping. + */ + function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) { + var cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0 || onlyCompareGenerated) { + return cmp; + } + + cmp = mappingA.source - mappingB.source; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0) { + return cmp; + } + + return mappingA.name - mappingB.name; + } + exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated; + + function strcmp(aStr1, aStr2) { + if (aStr1 === aStr2) { + return 0; + } + + if (aStr1 > aStr2) { + return 1; + } + + return -1; + } + + /** + * Comparator between two mappings with inflated source and name strings where + * the generated positions are compared. + */ + function compareByGeneratedPositionsInflated(mappingA, mappingB) { + var cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0) { + return cmp; + } + + cmp = strcmp(mappingA.source, mappingB.source); + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0) { + return cmp; + } + + return strcmp(mappingA.name, mappingB.name); + } + exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated; + } + + +/***/ }, +/* 3 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var util = __webpack_require__(2); + var binarySearch = __webpack_require__(4); + var ArraySet = __webpack_require__(5).ArraySet; + var base64VLQ = __webpack_require__(6); + var quickSort = __webpack_require__(8).quickSort; + + function SourceMapConsumer(aSourceMap) { + var sourceMap = aSourceMap; + if (typeof aSourceMap === 'string') { + sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); + } + + return sourceMap.sections != null + ? new IndexedSourceMapConsumer(sourceMap) + : new BasicSourceMapConsumer(sourceMap); + } + + SourceMapConsumer.fromSourceMap = function(aSourceMap) { + return BasicSourceMapConsumer.fromSourceMap(aSourceMap); + } + + /** + * The version of the source mapping spec that we are consuming. + */ + SourceMapConsumer.prototype._version = 3; + + // `__generatedMappings` and `__originalMappings` are arrays that hold the + // parsed mapping coordinates from the source map's "mappings" attribute. They + // are lazily instantiated, accessed via the `_generatedMappings` and + // `_originalMappings` getters respectively, and we only parse the mappings + // and create these arrays once queried for a source location. We jump through + // these hoops because there can be many thousands of mappings, and parsing + // them is expensive, so we only want to do it if we must. + // + // Each object in the arrays is of the form: + // + // { + // generatedLine: The line number in the generated code, + // generatedColumn: The column number in the generated code, + // source: The path to the original source file that generated this + // chunk of code, + // originalLine: The line number in the original source that + // corresponds to this chunk of generated code, + // originalColumn: The column number in the original source that + // corresponds to this chunk of generated code, + // name: The name of the original symbol which generated this chunk of + // code. + // } + // + // All properties except for `generatedLine` and `generatedColumn` can be + // `null`. + // + // `_generatedMappings` is ordered by the generated positions. + // + // `_originalMappings` is ordered by the original positions. + + SourceMapConsumer.prototype.__generatedMappings = null; + Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', { + get: function () { + if (!this.__generatedMappings) { + this._parseMappings(this._mappings, this.sourceRoot); + } + + return this.__generatedMappings; + } + }); + + SourceMapConsumer.prototype.__originalMappings = null; + Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', { + get: function () { + if (!this.__originalMappings) { + this._parseMappings(this._mappings, this.sourceRoot); + } + + return this.__originalMappings; + } + }); + + SourceMapConsumer.prototype._charIsMappingSeparator = + function SourceMapConsumer_charIsMappingSeparator(aStr, index) { + var c = aStr.charAt(index); + return c === ";" || c === ","; + }; + + /** + * Parse the mappings in a string in to a data structure which we can easily + * query (the ordered arrays in the `this.__generatedMappings` and + * `this.__originalMappings` properties). + */ + SourceMapConsumer.prototype._parseMappings = + function SourceMapConsumer_parseMappings(aStr, aSourceRoot) { + throw new Error("Subclasses must implement _parseMappings"); + }; + + SourceMapConsumer.GENERATED_ORDER = 1; + SourceMapConsumer.ORIGINAL_ORDER = 2; + + SourceMapConsumer.GREATEST_LOWER_BOUND = 1; + SourceMapConsumer.LEAST_UPPER_BOUND = 2; + + /** + * Iterate over each mapping between an original source/line/column and a + * generated line/column in this source map. + * + * @param Function aCallback + * The function that is called with each mapping. + * @param Object aContext + * Optional. If specified, this object will be the value of `this` every + * time that `aCallback` is called. + * @param aOrder + * Either `SourceMapConsumer.GENERATED_ORDER` or + * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to + * iterate over the mappings sorted by the generated file's line/column + * order or the original's source/line/column order, respectively. Defaults to + * `SourceMapConsumer.GENERATED_ORDER`. + */ + SourceMapConsumer.prototype.eachMapping = + function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) { + var context = aContext || null; + var order = aOrder || SourceMapConsumer.GENERATED_ORDER; + + var mappings; + switch (order) { + case SourceMapConsumer.GENERATED_ORDER: + mappings = this._generatedMappings; + break; + case SourceMapConsumer.ORIGINAL_ORDER: + mappings = this._originalMappings; + break; + default: + throw new Error("Unknown order of iteration."); + } + + var sourceRoot = this.sourceRoot; + mappings.map(function (mapping) { + var source = mapping.source === null ? null : this._sources.at(mapping.source); + if (source != null && sourceRoot != null) { + source = util.join(sourceRoot, source); + } + return { + source: source, + generatedLine: mapping.generatedLine, + generatedColumn: mapping.generatedColumn, + originalLine: mapping.originalLine, + originalColumn: mapping.originalColumn, + name: mapping.name === null ? null : this._names.at(mapping.name) + }; + }, this).forEach(aCallback, context); + }; + + /** + * Returns all generated line and column information for the original source, + * line, and column provided. If no column is provided, returns all mappings + * corresponding to a either the line we are searching for or the next + * closest line that has any mappings. Otherwise, returns all mappings + * corresponding to the given line and either the column we are searching for + * or the next closest column that has any offsets. + * + * The only argument is an object with the following properties: + * + * - source: The filename of the original source. + * - line: The line number in the original source. + * - column: Optional. the column number in the original source. + * + * and an array of objects is returned, each with the following properties: + * + * - line: The line number in the generated source, or null. + * - column: The column number in the generated source, or null. + */ + SourceMapConsumer.prototype.allGeneratedPositionsFor = + function SourceMapConsumer_allGeneratedPositionsFor(aArgs) { + var line = util.getArg(aArgs, 'line'); + + // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping + // returns the index of the closest mapping less than the needle. By + // setting needle.originalColumn to 0, we thus find the last mapping for + // the given line, provided such a mapping exists. + var needle = { + source: util.getArg(aArgs, 'source'), + originalLine: line, + originalColumn: util.getArg(aArgs, 'column', 0) + }; + + if (this.sourceRoot != null) { + needle.source = util.relative(this.sourceRoot, needle.source); + } + if (!this._sources.has(needle.source)) { + return []; + } + needle.source = this._sources.indexOf(needle.source); + + var mappings = []; + + var index = this._findMapping(needle, + this._originalMappings, + "originalLine", + "originalColumn", + util.compareByOriginalPositions, + binarySearch.LEAST_UPPER_BOUND); + if (index >= 0) { + var mapping = this._originalMappings[index]; + + if (aArgs.column === undefined) { + var originalLine = mapping.originalLine; + + // Iterate until either we run out of mappings, or we run into + // a mapping for a different line than the one we found. Since + // mappings are sorted, this is guaranteed to find all mappings for + // the line we found. + while (mapping && mapping.originalLine === originalLine) { + mappings.push({ + line: util.getArg(mapping, 'generatedLine', null), + column: util.getArg(mapping, 'generatedColumn', null), + lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) + }); + + mapping = this._originalMappings[++index]; + } + } else { + var originalColumn = mapping.originalColumn; + + // Iterate until either we run out of mappings, or we run into + // a mapping for a different line than the one we were searching for. + // Since mappings are sorted, this is guaranteed to find all mappings for + // the line we are searching for. + while (mapping && + mapping.originalLine === line && + mapping.originalColumn == originalColumn) { + mappings.push({ + line: util.getArg(mapping, 'generatedLine', null), + column: util.getArg(mapping, 'generatedColumn', null), + lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) + }); + + mapping = this._originalMappings[++index]; + } + } + } + + return mappings; + }; + + exports.SourceMapConsumer = SourceMapConsumer; + + /** + * A BasicSourceMapConsumer instance represents a parsed source map which we can + * query for information about the original file positions by giving it a file + * position in the generated source. + * + * The only parameter is the raw source map (either as a JSON string, or + * already parsed to an object). According to the spec, source maps have the + * following attributes: + * + * - version: Which version of the source map spec this map is following. + * - sources: An array of URLs to the original source files. + * - names: An array of identifiers which can be referrenced by individual mappings. + * - sourceRoot: Optional. The URL root from which all sources are relative. + * - sourcesContent: Optional. An array of contents of the original source files. + * - mappings: A string of base64 VLQs which contain the actual mappings. + * - file: Optional. The generated file this source map is associated with. + * + * Here is an example source map, taken from the source map spec[0]: + * + * { + * version : 3, + * file: "out.js", + * sourceRoot : "", + * sources: ["foo.js", "bar.js"], + * names: ["src", "maps", "are", "fun"], + * mappings: "AA,AB;;ABCDE;" + * } + * + * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1# + */ + function BasicSourceMapConsumer(aSourceMap) { + var sourceMap = aSourceMap; + if (typeof aSourceMap === 'string') { + sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); + } + + var version = util.getArg(sourceMap, 'version'); + var sources = util.getArg(sourceMap, 'sources'); + // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which + // requires the array) to play nice here. + var names = util.getArg(sourceMap, 'names', []); + var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null); + var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null); + var mappings = util.getArg(sourceMap, 'mappings'); + var file = util.getArg(sourceMap, 'file', null); + + // Once again, Sass deviates from the spec and supplies the version as a + // string rather than a number, so we use loose equality checking here. + if (version != this._version) { + throw new Error('Unsupported version: ' + version); + } + + sources = sources + // Some source maps produce relative source paths like "./foo.js" instead of + // "foo.js". Normalize these first so that future comparisons will succeed. + // See bugzil.la/1090768. + .map(util.normalize) + // Always ensure that absolute sources are internally stored relative to + // the source root, if the source root is absolute. Not doing this would + // be particularly problematic when the source root is a prefix of the + // source (valid, but why??). See github issue #199 and bugzil.la/1188982. + .map(function (source) { + return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source) + ? util.relative(sourceRoot, source) + : source; + }); + + // Pass `true` below to allow duplicate names and sources. While source maps + // are intended to be compressed and deduplicated, the TypeScript compiler + // sometimes generates source maps with duplicates in them. See Github issue + // #72 and bugzil.la/889492. + this._names = ArraySet.fromArray(names, true); + this._sources = ArraySet.fromArray(sources, true); + + this.sourceRoot = sourceRoot; + this.sourcesContent = sourcesContent; + this._mappings = mappings; + this.file = file; + } + + BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype); + BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer; + + /** + * Create a BasicSourceMapConsumer from a SourceMapGenerator. + * + * @param SourceMapGenerator aSourceMap + * The source map that will be consumed. + * @returns BasicSourceMapConsumer + */ + BasicSourceMapConsumer.fromSourceMap = + function SourceMapConsumer_fromSourceMap(aSourceMap) { + var smc = Object.create(BasicSourceMapConsumer.prototype); + + var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true); + var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true); + smc.sourceRoot = aSourceMap._sourceRoot; + smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(), + smc.sourceRoot); + smc.file = aSourceMap._file; + + // Because we are modifying the entries (by converting string sources and + // names to indices into the sources and names ArraySets), we have to make + // a copy of the entry or else bad things happen. Shared mutable state + // strikes again! See github issue #191. + + var generatedMappings = aSourceMap._mappings.toArray().slice(); + var destGeneratedMappings = smc.__generatedMappings = []; + var destOriginalMappings = smc.__originalMappings = []; + + for (var i = 0, length = generatedMappings.length; i < length; i++) { + var srcMapping = generatedMappings[i]; + var destMapping = new Mapping; + destMapping.generatedLine = srcMapping.generatedLine; + destMapping.generatedColumn = srcMapping.generatedColumn; + + if (srcMapping.source) { + destMapping.source = sources.indexOf(srcMapping.source); + destMapping.originalLine = srcMapping.originalLine; + destMapping.originalColumn = srcMapping.originalColumn; + + if (srcMapping.name) { + destMapping.name = names.indexOf(srcMapping.name); + } + + destOriginalMappings.push(destMapping); + } + + destGeneratedMappings.push(destMapping); + } + + quickSort(smc.__originalMappings, util.compareByOriginalPositions); + + return smc; + }; + + /** + * The version of the source mapping spec that we are consuming. + */ + BasicSourceMapConsumer.prototype._version = 3; + + /** + * The list of original sources. + */ + Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', { + get: function () { + return this._sources.toArray().map(function (s) { + return this.sourceRoot != null ? util.join(this.sourceRoot, s) : s; + }, this); + } + }); + + /** + * Provide the JIT with a nice shape / hidden class. + */ + function Mapping() { + this.generatedLine = 0; + this.generatedColumn = 0; + this.source = null; + this.originalLine = null; + this.originalColumn = null; + this.name = null; + } + + /** + * Parse the mappings in a string in to a data structure which we can easily + * query (the ordered arrays in the `this.__generatedMappings` and + * `this.__originalMappings` properties). + */ + BasicSourceMapConsumer.prototype._parseMappings = + function SourceMapConsumer_parseMappings(aStr, aSourceRoot) { + var generatedLine = 1; + var previousGeneratedColumn = 0; + var previousOriginalLine = 0; + var previousOriginalColumn = 0; + var previousSource = 0; + var previousName = 0; + var length = aStr.length; + var index = 0; + var cachedSegments = {}; + var temp = {}; + var originalMappings = []; + var generatedMappings = []; + var mapping, str, segment, end, value; + + while (index < length) { + if (aStr.charAt(index) === ';') { + generatedLine++; + index++; + previousGeneratedColumn = 0; + } + else if (aStr.charAt(index) === ',') { + index++; + } + else { + mapping = new Mapping(); + mapping.generatedLine = generatedLine; + + // Because each offset is encoded relative to the previous one, + // many segments often have the same encoding. We can exploit this + // fact by caching the parsed variable length fields of each segment, + // allowing us to avoid a second parse if we encounter the same + // segment again. + for (end = index; end < length; end++) { + if (this._charIsMappingSeparator(aStr, end)) { + break; + } + } + str = aStr.slice(index, end); + + segment = cachedSegments[str]; + if (segment) { + index += str.length; + } else { + segment = []; + while (index < end) { + base64VLQ.decode(aStr, index, temp); + value = temp.value; + index = temp.rest; + segment.push(value); + } + + if (segment.length === 2) { + throw new Error('Found a source, but no line and column'); + } + + if (segment.length === 3) { + throw new Error('Found a source and line, but no column'); + } + + cachedSegments[str] = segment; + } + + // Generated column. + mapping.generatedColumn = previousGeneratedColumn + segment[0]; + previousGeneratedColumn = mapping.generatedColumn; + + if (segment.length > 1) { + // Original source. + mapping.source = previousSource + segment[1]; + previousSource += segment[1]; + + // Original line. + mapping.originalLine = previousOriginalLine + segment[2]; + previousOriginalLine = mapping.originalLine; + // Lines are stored 0-based + mapping.originalLine += 1; + + // Original column. + mapping.originalColumn = previousOriginalColumn + segment[3]; + previousOriginalColumn = mapping.originalColumn; + + if (segment.length > 4) { + // Original name. + mapping.name = previousName + segment[4]; + previousName += segment[4]; + } + } + + generatedMappings.push(mapping); + if (typeof mapping.originalLine === 'number') { + originalMappings.push(mapping); + } + } + } + + quickSort(generatedMappings, util.compareByGeneratedPositionsDeflated); + this.__generatedMappings = generatedMappings; + + quickSort(originalMappings, util.compareByOriginalPositions); + this.__originalMappings = originalMappings; + }; + + /** + * Find the mapping that best matches the hypothetical "needle" mapping that + * we are searching for in the given "haystack" of mappings. + */ + BasicSourceMapConsumer.prototype._findMapping = + function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName, + aColumnName, aComparator, aBias) { + // To return the position we are searching for, we must first find the + // mapping for the given position and then return the opposite position it + // points to. Because the mappings are sorted, we can use binary search to + // find the best mapping. + + if (aNeedle[aLineName] <= 0) { + throw new TypeError('Line must be greater than or equal to 1, got ' + + aNeedle[aLineName]); + } + if (aNeedle[aColumnName] < 0) { + throw new TypeError('Column must be greater than or equal to 0, got ' + + aNeedle[aColumnName]); + } + + return binarySearch.search(aNeedle, aMappings, aComparator, aBias); + }; + + /** + * Compute the last column for each generated mapping. The last column is + * inclusive. + */ + BasicSourceMapConsumer.prototype.computeColumnSpans = + function SourceMapConsumer_computeColumnSpans() { + for (var index = 0; index < this._generatedMappings.length; ++index) { + var mapping = this._generatedMappings[index]; + + // Mappings do not contain a field for the last generated columnt. We + // can come up with an optimistic estimate, however, by assuming that + // mappings are contiguous (i.e. given two consecutive mappings, the + // first mapping ends where the second one starts). + if (index + 1 < this._generatedMappings.length) { + var nextMapping = this._generatedMappings[index + 1]; + + if (mapping.generatedLine === nextMapping.generatedLine) { + mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1; + continue; + } + } + + // The last mapping for each line spans the entire line. + mapping.lastGeneratedColumn = Infinity; + } + }; + + /** + * Returns the original source, line, and column information for the generated + * source's line and column positions provided. The only argument is an object + * with the following properties: + * + * - line: The line number in the generated source. + * - column: The column number in the generated source. + * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or + * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. + * + * and an object is returned with the following properties: + * + * - source: The original source file, or null. + * - line: The line number in the original source, or null. + * - column: The column number in the original source, or null. + * - name: The original identifier, or null. + */ + BasicSourceMapConsumer.prototype.originalPositionFor = + function SourceMapConsumer_originalPositionFor(aArgs) { + var needle = { + generatedLine: util.getArg(aArgs, 'line'), + generatedColumn: util.getArg(aArgs, 'column') + }; + + var index = this._findMapping( + needle, + this._generatedMappings, + "generatedLine", + "generatedColumn", + util.compareByGeneratedPositionsDeflated, + util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND) + ); + + if (index >= 0) { + var mapping = this._generatedMappings[index]; + + if (mapping.generatedLine === needle.generatedLine) { + var source = util.getArg(mapping, 'source', null); + if (source !== null) { + source = this._sources.at(source); + if (this.sourceRoot != null) { + source = util.join(this.sourceRoot, source); + } + } + var name = util.getArg(mapping, 'name', null); + if (name !== null) { + name = this._names.at(name); + } + return { + source: source, + line: util.getArg(mapping, 'originalLine', null), + column: util.getArg(mapping, 'originalColumn', null), + name: name + }; + } + } + + return { + source: null, + line: null, + column: null, + name: null + }; + }; + + /** + * Return true if we have the source content for every source in the source + * map, false otherwise. + */ + BasicSourceMapConsumer.prototype.hasContentsOfAllSources = + function BasicSourceMapConsumer_hasContentsOfAllSources() { + if (!this.sourcesContent) { + return false; + } + return this.sourcesContent.length >= this._sources.size() && + !this.sourcesContent.some(function (sc) { return sc == null; }); + }; + + /** + * Returns the original source content. The only argument is the url of the + * original source file. Returns null if no original source content is + * availible. + */ + BasicSourceMapConsumer.prototype.sourceContentFor = + function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) { + if (!this.sourcesContent) { + return null; + } + + if (this.sourceRoot != null) { + aSource = util.relative(this.sourceRoot, aSource); + } + + if (this._sources.has(aSource)) { + return this.sourcesContent[this._sources.indexOf(aSource)]; + } + + var url; + if (this.sourceRoot != null + && (url = util.urlParse(this.sourceRoot))) { + // XXX: file:// URIs and absolute paths lead to unexpected behavior for + // many users. We can help them out when they expect file:// URIs to + // behave like it would if they were running a local HTTP server. See + // https://bugzilla.mozilla.org/show_bug.cgi?id=885597. + var fileUriAbsPath = aSource.replace(/^file:\/\//, ""); + if (url.scheme == "file" + && this._sources.has(fileUriAbsPath)) { + return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)] + } + + if ((!url.path || url.path == "/") + && this._sources.has("/" + aSource)) { + return this.sourcesContent[this._sources.indexOf("/" + aSource)]; + } + } + + // This function is used recursively from + // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we + // don't want to throw if we can't find the source - we just want to + // return null, so we provide a flag to exit gracefully. + if (nullOnMissing) { + return null; + } + else { + throw new Error('"' + aSource + '" is not in the SourceMap.'); + } + }; + + /** + * Returns the generated line and column information for the original source, + * line, and column positions provided. The only argument is an object with + * the following properties: + * + * - source: The filename of the original source. + * - line: The line number in the original source. + * - column: The column number in the original source. + * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or + * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. + * + * and an object is returned with the following properties: + * + * - line: The line number in the generated source, or null. + * - column: The column number in the generated source, or null. + */ + BasicSourceMapConsumer.prototype.generatedPositionFor = + function SourceMapConsumer_generatedPositionFor(aArgs) { + var source = util.getArg(aArgs, 'source'); + if (this.sourceRoot != null) { + source = util.relative(this.sourceRoot, source); + } + if (!this._sources.has(source)) { + return { + line: null, + column: null, + lastColumn: null + }; + } + source = this._sources.indexOf(source); + + var needle = { + source: source, + originalLine: util.getArg(aArgs, 'line'), + originalColumn: util.getArg(aArgs, 'column') + }; + + var index = this._findMapping( + needle, + this._originalMappings, + "originalLine", + "originalColumn", + util.compareByOriginalPositions, + util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND) + ); + + if (index >= 0) { + var mapping = this._originalMappings[index]; + + if (mapping.source === needle.source) { + return { + line: util.getArg(mapping, 'generatedLine', null), + column: util.getArg(mapping, 'generatedColumn', null), + lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) + }; + } + } + + return { + line: null, + column: null, + lastColumn: null + }; + }; + + exports.BasicSourceMapConsumer = BasicSourceMapConsumer; + + /** + * An IndexedSourceMapConsumer instance represents a parsed source map which + * we can query for information. It differs from BasicSourceMapConsumer in + * that it takes "indexed" source maps (i.e. ones with a "sections" field) as + * input. + * + * The only parameter is a raw source map (either as a JSON string, or already + * parsed to an object). According to the spec for indexed source maps, they + * have the following attributes: + * + * - version: Which version of the source map spec this map is following. + * - file: Optional. The generated file this source map is associated with. + * - sections: A list of section definitions. + * + * Each value under the "sections" field has two fields: + * - offset: The offset into the original specified at which this section + * begins to apply, defined as an object with a "line" and "column" + * field. + * - map: A source map definition. This source map could also be indexed, + * but doesn't have to be. + * + * Instead of the "map" field, it's also possible to have a "url" field + * specifying a URL to retrieve a source map from, but that's currently + * unsupported. + * + * Here's an example source map, taken from the source map spec[0], but + * modified to omit a section which uses the "url" field. + * + * { + * version : 3, + * file: "app.js", + * sections: [{ + * offset: {line:100, column:10}, + * map: { + * version : 3, + * file: "section.js", + * sources: ["foo.js", "bar.js"], + * names: ["src", "maps", "are", "fun"], + * mappings: "AAAA,E;;ABCDE;" + * } + * }], + * } + * + * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt + */ + function IndexedSourceMapConsumer(aSourceMap) { + var sourceMap = aSourceMap; + if (typeof aSourceMap === 'string') { + sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); + } + + var version = util.getArg(sourceMap, 'version'); + var sections = util.getArg(sourceMap, 'sections'); + + if (version != this._version) { + throw new Error('Unsupported version: ' + version); + } + + this._sources = new ArraySet(); + this._names = new ArraySet(); + + var lastOffset = { + line: -1, + column: 0 + }; + this._sections = sections.map(function (s) { + if (s.url) { + // The url field will require support for asynchronicity. + // See https://github.com/mozilla/source-map/issues/16 + throw new Error('Support for url field in sections not implemented.'); + } + var offset = util.getArg(s, 'offset'); + var offsetLine = util.getArg(offset, 'line'); + var offsetColumn = util.getArg(offset, 'column'); + + if (offsetLine < lastOffset.line || + (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) { + throw new Error('Section offsets must be ordered and non-overlapping.'); + } + lastOffset = offset; + + return { + generatedOffset: { + // The offset fields are 0-based, but we use 1-based indices when + // encoding/decoding from VLQ. + generatedLine: offsetLine + 1, + generatedColumn: offsetColumn + 1 + }, + consumer: new SourceMapConsumer(util.getArg(s, 'map')) + } + }); + } + + IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype); + IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer; + + /** + * The version of the source mapping spec that we are consuming. + */ + IndexedSourceMapConsumer.prototype._version = 3; + + /** + * The list of original sources. + */ + Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', { + get: function () { + var sources = []; + for (var i = 0; i < this._sections.length; i++) { + for (var j = 0; j < this._sections[i].consumer.sources.length; j++) { + sources.push(this._sections[i].consumer.sources[j]); + } + } + return sources; + } + }); + + /** + * Returns the original source, line, and column information for the generated + * source's line and column positions provided. The only argument is an object + * with the following properties: + * + * - line: The line number in the generated source. + * - column: The column number in the generated source. + * + * and an object is returned with the following properties: + * + * - source: The original source file, or null. + * - line: The line number in the original source, or null. + * - column: The column number in the original source, or null. + * - name: The original identifier, or null. + */ + IndexedSourceMapConsumer.prototype.originalPositionFor = + function IndexedSourceMapConsumer_originalPositionFor(aArgs) { + var needle = { + generatedLine: util.getArg(aArgs, 'line'), + generatedColumn: util.getArg(aArgs, 'column') + }; + + // Find the section containing the generated position we're trying to map + // to an original position. + var sectionIndex = binarySearch.search(needle, this._sections, + function(needle, section) { + var cmp = needle.generatedLine - section.generatedOffset.generatedLine; + if (cmp) { + return cmp; + } + + return (needle.generatedColumn - + section.generatedOffset.generatedColumn); + }); + var section = this._sections[sectionIndex]; + + if (!section) { + return { + source: null, + line: null, + column: null, + name: null + }; + } + + return section.consumer.originalPositionFor({ + line: needle.generatedLine - + (section.generatedOffset.generatedLine - 1), + column: needle.generatedColumn - + (section.generatedOffset.generatedLine === needle.generatedLine + ? section.generatedOffset.generatedColumn - 1 + : 0), + bias: aArgs.bias + }); + }; + + /** + * Return true if we have the source content for every source in the source + * map, false otherwise. + */ + IndexedSourceMapConsumer.prototype.hasContentsOfAllSources = + function IndexedSourceMapConsumer_hasContentsOfAllSources() { + return this._sections.every(function (s) { + return s.consumer.hasContentsOfAllSources(); + }); + }; + + /** + * Returns the original source content. The only argument is the url of the + * original source file. Returns null if no original source content is + * available. + */ + IndexedSourceMapConsumer.prototype.sourceContentFor = + function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) { + for (var i = 0; i < this._sections.length; i++) { + var section = this._sections[i]; + + var content = section.consumer.sourceContentFor(aSource, true); + if (content) { + return content; + } + } + if (nullOnMissing) { + return null; + } + else { + throw new Error('"' + aSource + '" is not in the SourceMap.'); + } + }; + + /** + * Returns the generated line and column information for the original source, + * line, and column positions provided. The only argument is an object with + * the following properties: + * + * - source: The filename of the original source. + * - line: The line number in the original source. + * - column: The column number in the original source. + * + * and an object is returned with the following properties: + * + * - line: The line number in the generated source, or null. + * - column: The column number in the generated source, or null. + */ + IndexedSourceMapConsumer.prototype.generatedPositionFor = + function IndexedSourceMapConsumer_generatedPositionFor(aArgs) { + for (var i = 0; i < this._sections.length; i++) { + var section = this._sections[i]; + + // Only consider this section if the requested source is in the list of + // sources of the consumer. + if (section.consumer.sources.indexOf(util.getArg(aArgs, 'source')) === -1) { + continue; + } + var generatedPosition = section.consumer.generatedPositionFor(aArgs); + if (generatedPosition) { + var ret = { + line: generatedPosition.line + + (section.generatedOffset.generatedLine - 1), + column: generatedPosition.column + + (section.generatedOffset.generatedLine === generatedPosition.line + ? section.generatedOffset.generatedColumn - 1 + : 0) + }; + return ret; + } + } + + return { + line: null, + column: null + }; + }; + + /** + * Parse the mappings in a string in to a data structure which we can easily + * query (the ordered arrays in the `this.__generatedMappings` and + * `this.__originalMappings` properties). + */ + IndexedSourceMapConsumer.prototype._parseMappings = + function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) { + this.__generatedMappings = []; + this.__originalMappings = []; + for (var i = 0; i < this._sections.length; i++) { + var section = this._sections[i]; + var sectionMappings = section.consumer._generatedMappings; + for (var j = 0; j < sectionMappings.length; j++) { + var mapping = sectionMappings[i]; + + var source = section.consumer._sources.at(mapping.source); + if (section.consumer.sourceRoot !== null) { + source = util.join(section.consumer.sourceRoot, source); + } + this._sources.add(source); + source = this._sources.indexOf(source); + + var name = section.consumer._names.at(mapping.name); + this._names.add(name); + name = this._names.indexOf(name); + + // The mappings coming from the consumer for the section have + // generated positions relative to the start of the section, so we + // need to offset them to be relative to the start of the concatenated + // generated file. + var adjustedMapping = { + source: source, + generatedLine: mapping.generatedLine + + (section.generatedOffset.generatedLine - 1), + generatedColumn: mapping.column + + (section.generatedOffset.generatedLine === mapping.generatedLine) + ? section.generatedOffset.generatedColumn - 1 + : 0, + originalLine: mapping.originalLine, + originalColumn: mapping.originalColumn, + name: name + }; + + this.__generatedMappings.push(adjustedMapping); + if (typeof adjustedMapping.originalLine === 'number') { + this.__originalMappings.push(adjustedMapping); + } + } + } + + quickSort(this.__generatedMappings, util.compareByGeneratedPositionsDeflated); + quickSort(this.__originalMappings, util.compareByOriginalPositions); + }; + + exports.IndexedSourceMapConsumer = IndexedSourceMapConsumer; + } + + +/***/ }, +/* 4 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + exports.GREATEST_LOWER_BOUND = 1; + exports.LEAST_UPPER_BOUND = 2; + + /** + * Recursive implementation of binary search. + * + * @param aLow Indices here and lower do not contain the needle. + * @param aHigh Indices here and higher do not contain the needle. + * @param aNeedle The element being searched for. + * @param aHaystack The non-empty array being searched. + * @param aCompare Function which takes two elements and returns -1, 0, or 1. + * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or + * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + */ + function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) { + // This function terminates when one of the following is true: + // + // 1. We find the exact element we are looking for. + // + // 2. We did not find the exact element, but we can return the index of + // the next-closest element. + // + // 3. We did not find the exact element, and there is no next-closest + // element than the one we are searching for, so we return -1. + var mid = Math.floor((aHigh - aLow) / 2) + aLow; + var cmp = aCompare(aNeedle, aHaystack[mid], true); + if (cmp === 0) { + // Found the element we are looking for. + return mid; + } + else if (cmp > 0) { + // Our needle is greater than aHaystack[mid]. + if (aHigh - mid > 1) { + // The element is in the upper half. + return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias); + } + + // The exact needle element was not found in this haystack. Determine if + // we are in termination case (3) or (2) and return the appropriate thing. + if (aBias == exports.LEAST_UPPER_BOUND) { + return aHigh < aHaystack.length ? aHigh : -1; + } else { + return mid; + } + } + else { + // Our needle is less than aHaystack[mid]. + if (mid - aLow > 1) { + // The element is in the lower half. + return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias); + } + + // we are in termination case (3) or (2) and return the appropriate thing. + if (aBias == exports.LEAST_UPPER_BOUND) { + return mid; + } else { + return aLow < 0 ? -1 : aLow; + } + } + } + + /** + * This is an implementation of binary search which will always try and return + * the index of the closest element if there is no exact hit. This is because + * mappings between original and generated line/col pairs are single points, + * and there is an implicit region between each of them, so a miss just means + * that you aren't on the very start of a region. + * + * @param aNeedle The element you are looking for. + * @param aHaystack The array that is being searched. + * @param aCompare A function which takes the needle and an element in the + * array and returns -1, 0, or 1 depending on whether the needle is less + * than, equal to, or greater than the element, respectively. + * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or + * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'. + */ + exports.search = function search(aNeedle, aHaystack, aCompare, aBias) { + if (aHaystack.length === 0) { + return -1; + } + + var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, + aCompare, aBias || exports.GREATEST_LOWER_BOUND); + if (index < 0) { + return -1; + } + + // We have found either the exact element, or the next-closest element than + // the one we are searching for. However, there may be more than one such + // element. Make sure we always return the smallest of these. + while (index - 1 >= 0) { + if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) { + break; + } + --index; + } + + return index; + }; + } + + +/***/ }, +/* 5 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var util = __webpack_require__(2); + + /** + * A data structure which is a combination of an array and a set. Adding a new + * member is O(1), testing for membership is O(1), and finding the index of an + * element is O(1). Removing elements from the set is not supported. Only + * strings are supported for membership. + */ + function ArraySet() { + this._array = []; + this._set = {}; + } + + /** + * Static method for creating ArraySet instances from an existing array. + */ + ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) { + var set = new ArraySet(); + for (var i = 0, len = aArray.length; i < len; i++) { + set.add(aArray[i], aAllowDuplicates); + } + return set; + }; + + /** + * Return how many unique items are in this ArraySet. If duplicates have been + * added, than those do not count towards the size. + * + * @returns Number + */ + ArraySet.prototype.size = function ArraySet_size() { + return Object.getOwnPropertyNames(this._set).length; + }; + + /** + * Add the given string to this set. + * + * @param String aStr + */ + ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) { + var sStr = util.toSetString(aStr); + var isDuplicate = this._set.hasOwnProperty(sStr); + var idx = this._array.length; + if (!isDuplicate || aAllowDuplicates) { + this._array.push(aStr); + } + if (!isDuplicate) { + this._set[sStr] = idx; + } + }; + + /** + * Is the given string a member of this set? + * + * @param String aStr + */ + ArraySet.prototype.has = function ArraySet_has(aStr) { + var sStr = util.toSetString(aStr); + return this._set.hasOwnProperty(sStr); + }; + + /** + * What is the index of the given string in the array? + * + * @param String aStr + */ + ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) { + var sStr = util.toSetString(aStr); + if (this._set.hasOwnProperty(sStr)) { + return this._set[sStr]; + } + throw new Error('"' + aStr + '" is not in the set.'); + }; + + /** + * What is the element at the given index? + * + * @param Number aIdx + */ + ArraySet.prototype.at = function ArraySet_at(aIdx) { + if (aIdx >= 0 && aIdx < this._array.length) { + return this._array[aIdx]; + } + throw new Error('No element indexed by ' + aIdx); + }; + + /** + * Returns the array representation of this set (which has the proper indices + * indicated by indexOf). Note that this is a copy of the internal array used + * for storing the members so that no one can mess with internal state. + */ + ArraySet.prototype.toArray = function ArraySet_toArray() { + return this._array.slice(); + }; + + exports.ArraySet = ArraySet; + } + + +/***/ }, +/* 6 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + * + * Based on the Base 64 VLQ implementation in Closure Compiler: + * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java + * + * Copyright 2011 The Closure Compiler Authors. All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + { + var base64 = __webpack_require__(7); + + // A single base 64 digit can contain 6 bits of data. For the base 64 variable + // length quantities we use in the source map spec, the first bit is the sign, + // the next four bits are the actual value, and the 6th bit is the + // continuation bit. The continuation bit tells us whether there are more + // digits in this value following this digit. + // + // Continuation + // | Sign + // | | + // V V + // 101011 + + var VLQ_BASE_SHIFT = 5; + + // binary: 100000 + var VLQ_BASE = 1 << VLQ_BASE_SHIFT; + + // binary: 011111 + var VLQ_BASE_MASK = VLQ_BASE - 1; + + // binary: 100000 + var VLQ_CONTINUATION_BIT = VLQ_BASE; + + /** + * Converts from a two-complement value to a value where the sign bit is + * placed in the least significant bit. For example, as decimals: + * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary) + * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary) + */ + function toVLQSigned(aValue) { + return aValue < 0 + ? ((-aValue) << 1) + 1 + : (aValue << 1) + 0; + } + + /** + * Converts to a two-complement value from a value where the sign bit is + * placed in the least significant bit. For example, as decimals: + * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1 + * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2 + */ + function fromVLQSigned(aValue) { + var isNegative = (aValue & 1) === 1; + var shifted = aValue >> 1; + return isNegative + ? -shifted + : shifted; + } + + /** + * Returns the base 64 VLQ encoded value. + */ + exports.encode = function base64VLQ_encode(aValue) { + var encoded = ""; + var digit; + + var vlq = toVLQSigned(aValue); + + do { + digit = vlq & VLQ_BASE_MASK; + vlq >>>= VLQ_BASE_SHIFT; + if (vlq > 0) { + // There are still more digits in this value, so we must make sure the + // continuation bit is marked. + digit |= VLQ_CONTINUATION_BIT; + } + encoded += base64.encode(digit); + } while (vlq > 0); + + return encoded; + }; + + /** + * Decodes the next base 64 VLQ value from the given string and returns the + * value and the rest of the string via the out parameter. + */ + exports.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) { + var strLen = aStr.length; + var result = 0; + var shift = 0; + var continuation, digit; + + do { + if (aIndex >= strLen) { + throw new Error("Expected more digits in base 64 VLQ value."); + } + + digit = base64.decode(aStr.charCodeAt(aIndex++)); + if (digit === -1) { + throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1)); + } + + continuation = !!(digit & VLQ_CONTINUATION_BIT); + digit &= VLQ_BASE_MASK; + result = result + (digit << shift); + shift += VLQ_BASE_SHIFT; + } while (continuation); + + aOutParam.value = fromVLQSigned(result); + aOutParam.rest = aIndex; + }; + } + + +/***/ }, +/* 7 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split(''); + + /** + * Encode an integer in the range of 0 to 63 to a single base 64 digit. + */ + exports.encode = function (number) { + if (0 <= number && number < intToCharMap.length) { + return intToCharMap[number]; + } + throw new TypeError("Must be between 0 and 63: " + number); + }; + + /** + * Decode a single base 64 character code digit to an integer. Returns -1 on + * failure. + */ + exports.decode = function (charCode) { + var bigA = 65; // 'A' + var bigZ = 90; // 'Z' + + var littleA = 97; // 'a' + var littleZ = 122; // 'z' + + var zero = 48; // '0' + var nine = 57; // '9' + + var plus = 43; // '+' + var slash = 47; // '/' + + var littleOffset = 26; + var numberOffset = 52; + + // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ + if (bigA <= charCode && charCode <= bigZ) { + return (charCode - bigA); + } + + // 26 - 51: abcdefghijklmnopqrstuvwxyz + if (littleA <= charCode && charCode <= littleZ) { + return (charCode - littleA + littleOffset); + } + + // 52 - 61: 0123456789 + if (zero <= charCode && charCode <= nine) { + return (charCode - zero + numberOffset); + } + + // 62: + + if (charCode == plus) { + return 62; + } + + // 63: / + if (charCode == slash) { + return 63; + } + + // Invalid base64 digit. + return -1; + }; + } + + +/***/ }, +/* 8 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + // It turns out that some (most?) JavaScript engines don't self-host + // `Array.prototype.sort`. This makes sense because C++ will likely remain + // faster than JS when doing raw CPU-intensive sorting. However, when using a + // custom comparator function, calling back and forth between the VM's C++ and + // JIT'd JS is rather slow *and* loses JIT type information, resulting in + // worse generated code for the comparator function than would be optimal. In + // fact, when sorting with a comparator, these costs outweigh the benefits of + // sorting in C++. By using our own JS-implemented Quick Sort (below), we get + // a ~3500ms mean speed-up in `bench/bench.html`. + + /** + * Swap the elements indexed by `x` and `y` in the array `ary`. + * + * @param {Array} ary + * The array. + * @param {Number} x + * The index of the first item. + * @param {Number} y + * The index of the second item. + */ + function swap(ary, x, y) { + var temp = ary[x]; + ary[x] = ary[y]; + ary[y] = temp; + } + + /** + * Returns a random integer within the range `low .. high` inclusive. + * + * @param {Number} low + * The lower bound on the range. + * @param {Number} high + * The upper bound on the range. + */ + function randomIntInRange(low, high) { + return Math.round(low + (Math.random() * (high - low))); + } + + /** + * The Quick Sort algorithm. + * + * @param {Array} ary + * An array to sort. + * @param {function} comparator + * Function to use to compare two items. + * @param {Number} p + * Start index of the array + * @param {Number} r + * End index of the array + */ + function doQuickSort(ary, comparator, p, r) { + // If our lower bound is less than our upper bound, we (1) partition the + // array into two pieces and (2) recurse on each half. If it is not, this is + // the empty array and our base case. + + if (p < r) { + // (1) Partitioning. + // + // The partitioning chooses a pivot between `p` and `r` and moves all + // elements that are less than or equal to the pivot to the before it, and + // all the elements that are greater than it after it. The effect is that + // once partition is done, the pivot is in the exact place it will be when + // the array is put in sorted order, and it will not need to be moved + // again. This runs in O(n) time. + + // Always choose a random pivot so that an input array which is reverse + // sorted does not cause O(n^2) running time. + var pivotIndex = randomIntInRange(p, r); + var i = p - 1; + + swap(ary, pivotIndex, r); + var pivot = ary[r]; + + // Immediately after `j` is incremented in this loop, the following hold + // true: + // + // * Every element in `ary[p .. i]` is less than or equal to the pivot. + // + // * Every element in `ary[i+1 .. j-1]` is greater than the pivot. + for (var j = p; j < r; j++) { + if (comparator(ary[j], pivot) <= 0) { + i += 1; + swap(ary, i, j); + } + } + + swap(ary, i + 1, j); + var q = i + 1; + + // (2) Recurse on each half. + + doQuickSort(ary, comparator, p, q - 1); + doQuickSort(ary, comparator, q + 1, r); + } + } + + /** + * Sort the given array in-place with the given comparator function. + * + * @param {Array} ary + * An array to sort. + * @param {function} comparator + * Function to use to compare two items. + */ + exports.quickSort = function (ary, comparator) { + doQuickSort(ary, comparator, 0, ary.length - 1); + }; + } + + +/***/ }, +/* 9 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var base64VLQ = __webpack_require__(6); + var util = __webpack_require__(2); + var ArraySet = __webpack_require__(5).ArraySet; + var MappingList = __webpack_require__(10).MappingList; + + /** + * An instance of the SourceMapGenerator represents a source map which is + * being built incrementally. You may pass an object with the following + * properties: + * + * - file: The filename of the generated source. + * - sourceRoot: A root for all relative URLs in this source map. + */ + function SourceMapGenerator(aArgs) { + if (!aArgs) { + aArgs = {}; + } + this._file = util.getArg(aArgs, 'file', null); + this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null); + this._skipValidation = util.getArg(aArgs, 'skipValidation', false); + this._sources = new ArraySet(); + this._names = new ArraySet(); + this._mappings = new MappingList(); + this._sourcesContents = null; + } + + SourceMapGenerator.prototype._version = 3; + + /** + * Creates a new SourceMapGenerator based on a SourceMapConsumer + * + * @param aSourceMapConsumer The SourceMap. + */ + SourceMapGenerator.fromSourceMap = + function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) { + var sourceRoot = aSourceMapConsumer.sourceRoot; + var generator = new SourceMapGenerator({ + file: aSourceMapConsumer.file, + sourceRoot: sourceRoot + }); + aSourceMapConsumer.eachMapping(function (mapping) { + var newMapping = { + generated: { + line: mapping.generatedLine, + column: mapping.generatedColumn + } + }; + + if (mapping.source != null) { + newMapping.source = mapping.source; + if (sourceRoot != null) { + newMapping.source = util.relative(sourceRoot, newMapping.source); + } + + newMapping.original = { + line: mapping.originalLine, + column: mapping.originalColumn + }; + + if (mapping.name != null) { + newMapping.name = mapping.name; + } + } + + generator.addMapping(newMapping); + }); + aSourceMapConsumer.sources.forEach(function (sourceFile) { + var content = aSourceMapConsumer.sourceContentFor(sourceFile); + if (content != null) { + generator.setSourceContent(sourceFile, content); + } + }); + return generator; + }; + + /** + * Add a single mapping from original source line and column to the generated + * source's line and column for this source map being created. The mapping + * object should have the following properties: + * + * - generated: An object with the generated line and column positions. + * - original: An object with the original line and column positions. + * - source: The original source file (relative to the sourceRoot). + * - name: An optional original token name for this mapping. + */ + SourceMapGenerator.prototype.addMapping = + function SourceMapGenerator_addMapping(aArgs) { + var generated = util.getArg(aArgs, 'generated'); + var original = util.getArg(aArgs, 'original', null); + var source = util.getArg(aArgs, 'source', null); + var name = util.getArg(aArgs, 'name', null); + + if (!this._skipValidation) { + this._validateMapping(generated, original, source, name); + } + + if (source != null && !this._sources.has(source)) { + this._sources.add(source); + } + + if (name != null && !this._names.has(name)) { + this._names.add(name); + } + + this._mappings.add({ + generatedLine: generated.line, + generatedColumn: generated.column, + originalLine: original != null && original.line, + originalColumn: original != null && original.column, + source: source, + name: name + }); + }; + + /** + * Set the source content for a source file. + */ + SourceMapGenerator.prototype.setSourceContent = + function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) { + var source = aSourceFile; + if (this._sourceRoot != null) { + source = util.relative(this._sourceRoot, source); + } + + if (aSourceContent != null) { + // Add the source content to the _sourcesContents map. + // Create a new _sourcesContents map if the property is null. + if (!this._sourcesContents) { + this._sourcesContents = {}; + } + this._sourcesContents[util.toSetString(source)] = aSourceContent; + } else if (this._sourcesContents) { + // Remove the source file from the _sourcesContents map. + // If the _sourcesContents map is empty, set the property to null. + delete this._sourcesContents[util.toSetString(source)]; + if (Object.keys(this._sourcesContents).length === 0) { + this._sourcesContents = null; + } + } + }; + + /** + * Applies the mappings of a sub-source-map for a specific source file to the + * source map being generated. Each mapping to the supplied source file is + * rewritten using the supplied source map. Note: The resolution for the + * resulting mappings is the minimium of this map and the supplied map. + * + * @param aSourceMapConsumer The source map to be applied. + * @param aSourceFile Optional. The filename of the source file. + * If omitted, SourceMapConsumer's file property will be used. + * @param aSourceMapPath Optional. The dirname of the path to the source map + * to be applied. If relative, it is relative to the SourceMapConsumer. + * This parameter is needed when the two source maps aren't in the same + * directory, and the source map to be applied contains relative source + * paths. If so, those relative source paths need to be rewritten + * relative to the SourceMapGenerator. + */ + SourceMapGenerator.prototype.applySourceMap = + function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) { + var sourceFile = aSourceFile; + // If aSourceFile is omitted, we will use the file property of the SourceMap + if (aSourceFile == null) { + if (aSourceMapConsumer.file == null) { + throw new Error( + 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' + + 'or the source map\'s "file" property. Both were omitted.' + ); + } + sourceFile = aSourceMapConsumer.file; + } + var sourceRoot = this._sourceRoot; + // Make "sourceFile" relative if an absolute Url is passed. + if (sourceRoot != null) { + sourceFile = util.relative(sourceRoot, sourceFile); + } + // Applying the SourceMap can add and remove items from the sources and + // the names array. + var newSources = new ArraySet(); + var newNames = new ArraySet(); + + // Find mappings for the "sourceFile" + this._mappings.unsortedForEach(function (mapping) { + if (mapping.source === sourceFile && mapping.originalLine != null) { + // Check if it can be mapped by the source map, then update the mapping. + var original = aSourceMapConsumer.originalPositionFor({ + line: mapping.originalLine, + column: mapping.originalColumn + }); + if (original.source != null) { + // Copy mapping + mapping.source = original.source; + if (aSourceMapPath != null) { + mapping.source = util.join(aSourceMapPath, mapping.source) + } + if (sourceRoot != null) { + mapping.source = util.relative(sourceRoot, mapping.source); + } + mapping.originalLine = original.line; + mapping.originalColumn = original.column; + if (original.name != null) { + mapping.name = original.name; + } + } + } + + var source = mapping.source; + if (source != null && !newSources.has(source)) { + newSources.add(source); + } + + var name = mapping.name; + if (name != null && !newNames.has(name)) { + newNames.add(name); + } + + }, this); + this._sources = newSources; + this._names = newNames; + + // Copy sourcesContents of applied map. + aSourceMapConsumer.sources.forEach(function (sourceFile) { + var content = aSourceMapConsumer.sourceContentFor(sourceFile); + if (content != null) { + if (aSourceMapPath != null) { + sourceFile = util.join(aSourceMapPath, sourceFile); + } + if (sourceRoot != null) { + sourceFile = util.relative(sourceRoot, sourceFile); + } + this.setSourceContent(sourceFile, content); + } + }, this); + }; + + /** + * A mapping can have one of the three levels of data: + * + * 1. Just the generated position. + * 2. The Generated position, original position, and original source. + * 3. Generated and original position, original source, as well as a name + * token. + * + * To maintain consistency, we validate that any new mapping being added falls + * in to one of these categories. + */ + SourceMapGenerator.prototype._validateMapping = + function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource, + aName) { + if (aGenerated && 'line' in aGenerated && 'column' in aGenerated + && aGenerated.line > 0 && aGenerated.column >= 0 + && !aOriginal && !aSource && !aName) { + // Case 1. + return; + } + else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated + && aOriginal && 'line' in aOriginal && 'column' in aOriginal + && aGenerated.line > 0 && aGenerated.column >= 0 + && aOriginal.line > 0 && aOriginal.column >= 0 + && aSource) { + // Cases 2 and 3. + return; + } + else { + throw new Error('Invalid mapping: ' + JSON.stringify({ + generated: aGenerated, + source: aSource, + original: aOriginal, + name: aName + })); + } + }; + + /** + * Serialize the accumulated mappings in to the stream of base 64 VLQs + * specified by the source map format. + */ + SourceMapGenerator.prototype._serializeMappings = + function SourceMapGenerator_serializeMappings() { + var previousGeneratedColumn = 0; + var previousGeneratedLine = 1; + var previousOriginalColumn = 0; + var previousOriginalLine = 0; + var previousName = 0; + var previousSource = 0; + var result = ''; + var mapping; + var nameIdx; + var sourceIdx; + + var mappings = this._mappings.toArray(); + for (var i = 0, len = mappings.length; i < len; i++) { + mapping = mappings[i]; + + if (mapping.generatedLine !== previousGeneratedLine) { + previousGeneratedColumn = 0; + while (mapping.generatedLine !== previousGeneratedLine) { + result += ';'; + previousGeneratedLine++; + } + } + else { + if (i > 0) { + if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) { + continue; + } + result += ','; + } + } + + result += base64VLQ.encode(mapping.generatedColumn + - previousGeneratedColumn); + previousGeneratedColumn = mapping.generatedColumn; + + if (mapping.source != null) { + sourceIdx = this._sources.indexOf(mapping.source); + result += base64VLQ.encode(sourceIdx - previousSource); + previousSource = sourceIdx; + + // lines are stored 0-based in SourceMap spec version 3 + result += base64VLQ.encode(mapping.originalLine - 1 + - previousOriginalLine); + previousOriginalLine = mapping.originalLine - 1; + + result += base64VLQ.encode(mapping.originalColumn + - previousOriginalColumn); + previousOriginalColumn = mapping.originalColumn; + + if (mapping.name != null) { + nameIdx = this._names.indexOf(mapping.name); + result += base64VLQ.encode(nameIdx - previousName); + previousName = nameIdx; + } + } + } + + return result; + }; + + SourceMapGenerator.prototype._generateSourcesContent = + function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) { + return aSources.map(function (source) { + if (!this._sourcesContents) { + return null; + } + if (aSourceRoot != null) { + source = util.relative(aSourceRoot, source); + } + var key = util.toSetString(source); + return Object.prototype.hasOwnProperty.call(this._sourcesContents, + key) + ? this._sourcesContents[key] + : null; + }, this); + }; + + /** + * Externalize the source map. + */ + SourceMapGenerator.prototype.toJSON = + function SourceMapGenerator_toJSON() { + var map = { + version: this._version, + sources: this._sources.toArray(), + names: this._names.toArray(), + mappings: this._serializeMappings() + }; + if (this._file != null) { + map.file = this._file; + } + if (this._sourceRoot != null) { + map.sourceRoot = this._sourceRoot; + } + if (this._sourcesContents) { + map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot); + } + + return map; + }; + + /** + * Render the source map being generated to a string. + */ + SourceMapGenerator.prototype.toString = + function SourceMapGenerator_toString() { + return JSON.stringify(this.toJSON()); + }; + + exports.SourceMapGenerator = SourceMapGenerator; + } + + +/***/ }, +/* 10 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2014 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var util = __webpack_require__(2); + + /** + * Determine whether mappingB is after mappingA with respect to generated + * position. + */ + function generatedPositionAfter(mappingA, mappingB) { + // Optimized for most common case + var lineA = mappingA.generatedLine; + var lineB = mappingB.generatedLine; + var columnA = mappingA.generatedColumn; + var columnB = mappingB.generatedColumn; + return lineB > lineA || lineB == lineA && columnB >= columnA || + util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0; + } + + /** + * A data structure to provide a sorted view of accumulated mappings in a + * performance conscious manner. It trades a neglibable overhead in general + * case for a large speedup in case of mappings being added in order. + */ + function MappingList() { + this._array = []; + this._sorted = true; + // Serves as infimum + this._last = {generatedLine: -1, generatedColumn: 0}; + } + + /** + * Iterate through internal items. This method takes the same arguments that + * `Array.prototype.forEach` takes. + * + * NOTE: The order of the mappings is NOT guaranteed. + */ + MappingList.prototype.unsortedForEach = + function MappingList_forEach(aCallback, aThisArg) { + this._array.forEach(aCallback, aThisArg); + }; + + /** + * Add the given source mapping. + * + * @param Object aMapping + */ + MappingList.prototype.add = function MappingList_add(aMapping) { + if (generatedPositionAfter(this._last, aMapping)) { + this._last = aMapping; + this._array.push(aMapping); + } else { + this._sorted = false; + this._array.push(aMapping); + } + }; + + /** + * Returns the flat, sorted array of mappings. The mappings are sorted by + * generated position. + * + * WARNING: This method returns internal data without copying, for + * performance. The return value must NOT be mutated, and should be treated as + * an immutable borrow. If you want to take ownership, you must make your own + * copy. + */ + MappingList.prototype.toArray = function MappingList_toArray() { + if (!this._sorted) { + this._array.sort(util.compareByGeneratedPositionsInflated); + this._sorted = true; + } + return this._array; + }; + + exports.MappingList = MappingList; + } + + +/***/ } +/******/ ]); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly8vd2VicGFjay9ib290c3RyYXAgZjg0ZTU2YjRjYmQ3YWQ2NzQ5MjAiLCJ3ZWJwYWNrOi8vLy4vdGVzdC90ZXN0LWRvZy1mb29kaW5nLmpzIiwid2VicGFjazovLy8uL3Rlc3QvdXRpbC5qcyIsIndlYnBhY2s6Ly8vLi9saWIvdXRpbC5qcyIsIndlYnBhY2s6Ly8vLi9saWIvc291cmNlLW1hcC1jb25zdW1lci5qcyIsIndlYnBhY2s6Ly8vLi9saWIvYmluYXJ5LXNlYXJjaC5qcyIsIndlYnBhY2s6Ly8vLi9saWIvYXJyYXktc2V0LmpzIiwid2VicGFjazovLy8uL2xpYi9iYXNlNjQtdmxxLmpzIiwid2VicGFjazovLy8uL2xpYi9iYXNlNjQuanMiLCJ3ZWJwYWNrOi8vLy4vbGliL3F1aWNrLXNvcnQuanMiLCJ3ZWJwYWNrOi8vLy4vbGliL3NvdXJjZS1tYXAtZ2VuZXJhdG9yLmpzIiwid2VicGFjazovLy8uL2xpYi9tYXBwaW5nLWxpc3QuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7QUFBQTtBQUNBOztBQUVBO0FBQ0E7O0FBRUE7QUFDQTtBQUNBOztBQUVBO0FBQ0E7QUFDQSx1QkFBZTtBQUNmO0FBQ0E7QUFDQTs7QUFFQTtBQUNBOztBQUVBO0FBQ0E7O0FBRUE7QUFDQTtBQUNBOzs7QUFHQTtBQUNBOztB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gICAgICBtYXBwaW5nczogXCJDQUFDLElBQUksSUFBTSxTQUFVQSxHQUNsQixPQUFPQyxJQUFJRFwiLFxuICAgICAgICAgIGZpbGU6IFwibWluLmpzXCIsXG4gICAgICAgICAgc291cmNlUm9vdDogXCIvdGhlL3Jvb3RcIlxuICAgICAgICB9XG4gICAgICB9LFxuICAgICAge1xuICAgICAgICBvZmZzZXQ6IHtcbiAgICAgICAgICBsaW5lOiAxLFxuICAgICAgICAgIGNvbHVtbjogMFxuICAgICAgICB9LFxuICAgICAgICBtYXA6IHtcbiAgICAgICAgICB2ZXJzaW9uOiAzLFxuICAgICAgICAgIHNvdXJjZXM6IFtcbiAgICAgICAgICAgIFwidHdvLmpzXCJcbiAgICAgICAgICBdLFxuICAgICAgICAgIHNvdXJjZXNDb250ZW50OiBbXG4gICAgICAgICAgICAnIFRXTy5pbmMgPSBmdW5jdGlvbiAobikge1xcbicgK1xuICAgICAgICAgICAgJyAgIHJldHVybiBuICsgMTtcXG4nICtcbiAgICAgICAgICAgICcgfTsnXG4gICAgICAgICAgXSxcbiAgICAgICAgICBuYW1lczogW1xuICAgICAgICAgICAgXCJuXCJcbiAgICAgICAgICBdLFxuICAgICAgICAgIG1hcHBpbmdzOiBcIkNBQUMsSUFBSSxJQUFNLFNBQVVBLEdBQ2xCLE9BQU9BXCIsXG4gICAgICAgICAgZmlsZTogXCJtaW4uanNcIixcbiAgICAgICAgICBzb3VyY2VSb290OiBcIi90aGUvcm9vdFwiXG4gICAgICAgIH1cbiAgICAgIH1cbiAgICBdXG4gIH07XG4gIGV4cG9ydHMuaW5kZXhlZFRlc3RNYXBEaWZmZXJlbnRTb3VyY2VSb290cyA9IHtcbiAgICB2ZXJzaW9uOiAzLFxuICAgIGZpbGU6ICdtaW4uanMnLFxuICAgIHNlY3Rpb25zOiBbXG4gICAgICB7XG4gICAgICAgIG9mZnNldDoge1xuICAgICAgICAgIGxpbmU6IDAsXG4gICAgICAgICAgY29sdW1uOiAwXG4gICAgICAgIH0sXG4gICAgICAgIG1hcDoge1xuICAgICAgICAgIHZlcnNpb246IDMsXG4gICAgICAgICAgc291cmNlczogW1xuICAgICAgICAgICAgXCJvbmUuanNcIlxuICAgICAgICAgIF0sXG4gICAgICAgICAgc291cmNlc0NvbnRlbnQ6IFtcbiAgICAgICAgICAgICcgT05FLmZvbyA9IGZ1bmN0aW9uIChiYXIpIHtcXG4nICtcbiAgICAgICAgICAgICcgICByZXR1cm4gYmF6KGJhcik7XFxuJyArXG4gICAgICAgICAgICAnIH07JyxcbiAgICAgICAgICBdLFxuICAgICAgICAgIG5hbWVzOiBbXG4gICAgICAgICAgICBcImJhclwiLFxuICAgICAgICAgICAgXCJiYXpcIlxuICAgICAgICAgIF0sXG4gICAgICAgICAgbWFwcGluZ3M6IFwiQ0FBQyxJQUFJLElBQU0sU0FBVUEsR0FDbEIsT0FBT0MsSUFBSURcIixcbiAgICAgICAgICBmaWxlOiBcIm1pbi5qc1wiLFxuICAgICAgICAgIHNvdXJjZVJvb3Q6IFwiL3RoZS9yb290XCJcbiAgICAgICAgfVxuICAgICAgfSxcbiAgICAgIHtcbiAgICAgICAgb2Zmc2V0OiB7XG4gICAgICAgICAgbGluZTogMSxcbiAgICAgICAgICBjb2x1bW46IDBcbiAgICAgICAgfSxcbiAgICAgICAgbWFwOiB7XG4gICAgICAgICAgdmVyc2lvbjogMyxcbiAgICAgICAgICBzb3VyY2VzOiBbXG4gICAgICAgICAgICBcInR3by5qc1wiXG4gICAgICAgICAgXSxcbiAgICAgICAgICBzb3VyY2VzQ29udGVudDogW1xuICAgICAgICAgICAgJyBUV08uaW5jID0gZnVuY3Rpb24gKG4pIHtcXG4nICtcbiAgICAgICAgICAgICcgICByZXR1cm4gbiArIDE7XFxuJyArXG4gICAgICAgICAgICAnIH07J1xuICAgICAgICAgIF0sXG4gICAgICAgICAgbmFtZXM6IFtcbiAgICAgICAgICAgIFwiblwiXG4gICAgICAgICAgXSxcbiAgICAgICAgICBtYXBwaW5nczogXCJDQUFDLElBQUksSUFBTSxTQUFVQSxHQUNsQixPQUFPQVwiLFxuICAgICAgICAgIGZpbGU6IFwibWluLmpzXCIsXG4gICAgICAgICAgc291cmNlUm9vdDogXCIvZGlmZmVyZW50L3Jvb3RcIlxuICAgICAgICB9XG4gICAgICB9XG4gICAgXVxuICB9O1xuICBleHBvcnRzLnRlc3RNYXBXaXRoU291cmNlc0NvbnRlbnQgPSB7XG4gICAgdmVyc2lvbjogMyxcbiAgICBmaWxlOiAnbWluLmpzJyxcbiAgICBuYW1lczogWydiYXInLCAnYmF6JywgJ24nXSxcbiAgICBzb3VyY2VzOiBbJ29uZS5qcycsICd0d28uanMnXSxcbiAgICBzb3VyY2VzQ29udGVudDogW1xuICAgICAgJyBPTkUuZm9vID0gZnVuY3Rpb24gKGJhcikge1xcbicgK1xuICAgICAgJyAgIHJldHVybiBiYXooYmFyKTtcXG4nICtcbiAgICAgICcgfTsnLFxuICAgICAgJyBUV08uaW5jID0gZnVuY3Rpb24gKG4pIHtcXG4nICtcbiAgICAgICcgICByZXR1cm4gbiArIDE7XFxuJyArXG4gICAgICAnIH07J1xuICAgIF0sXG4gICAgc291cmNlUm9vdDogJy90aGUvcm9vdCcsXG4gICAgbWFwcGluZ3M6ICdDQUFDLElBQUksSUFBTSxTQUFVQSxHQUNsQixPQUFPQyxJQUFJRDtDQ0RiLElBQUksSUFBTSxTQUFVRSxHQUNsQixPQUFPQSdcbiAgfTtcbiAgZXhwb3J0cy50ZXN0TWFwUmVsYXRpdmVTb3VyY2VzID0ge1xuICAgIHZlcnNpb246IDMsXG4gICAgZmlsZTogJ21pbi5qcycsXG4gICAgbmFtZXM6IFsnYmFyJywgJ2JheicsICduJ10sXG4gICAgc291cmNlczogWycuL29uZS5qcycsICcuL3R3by5qcyddLFxuICAgIHNvdXJjZXNDb250ZW50OiBbXG4gICAgICAnIE9ORS5mb28gPSBmdW5jdGlvbiAoYmFyKSB7XFxuJyArXG4gICAgICAnICAgcmV0dXJuIGJheihiYXIpO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FyIG5lZWRsZSA9IHtcbiAgICAgICAgc291cmNlOiB1dGlsLmdldEFyZyhhQXJncywgJ3NvdXJjZScpLFxuICAgICAgICBvcmlnaW5hbExpbmU6IGxpbmUsXG4gICAgICAgIG9yaWdpbmFsQ29sdW1uOiB1dGlsLmdldEFyZyhhQXJncywgJ2NvbHVtbicsIDApXG4gICAgICB9O1xuXG4gICAgICBpZiAodGhpcy5zb3VyY2VSb290ICE9IG51bGwpIHtcbiAgICAgICAgbmVlZGxlLnNvdXJjZSA9IHV0aWwucmVsYXRpdmUodGhpcy5zb3VyY2VSb290LCBuZWVkbGUuc291cmNlKTtcbiAgICAgIH1cbiAgICAgIGlmICghdGhpcy5fc291cmNlcy5oYXMobmVlZGxlLnNvdXJjZSkpIHtcbiAgICAgICAgcmV0dXJuIFtdO1xuICAgICAgfVxuICAgICAgbmVlZGxlLnNvdXJjZSA9IHRoaXMuX3NvdXJjZXMuaW5kZXhPZihuZWVkbGUuc291cmNlKTtcblxuICAgICAgdmFyIG1hcHBpbmdzID0gW107XG5cbiAgICAgIHZhciBpbmRleCA9IHRoaXMuX2ZpbmRNYXBwaW5nKG5lZWRsZSxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX29yaWdpbmFsTWFwcGluZ3MsXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcIm9yaWdpbmFsTGluZVwiLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXCJvcmlnaW5hbENvbHVtblwiLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdXRpbC5jb21wYXJlQnlPcmlnaW5hbFBvc2l0aW9ucyxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJpbmFyeVNlYXJjaC5MRUFTVF9VUFBFUl9CT1VORCk7XG4gICAgICBpZiAoaW5kZXggPj0gMCkge1xuICAgICAgICB2YXIgbWFwcGluZyA9IHRoaXMuX29yaWdpbmFs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CBmaWVsZHMgb2YgZWFjaCBzZWdtZW50LFxuICAgICAgICAgIC8vIGFsbG93aW5nIHVzIHRvIGF2b2lkIGEgc2Vjb25kIHBhcnNlIGlmIHdlIGVuY291bnRlciB0aGUgc2FtZVxuICAgICAgICAgIC8vIHNlZ21lbnQgYWdhaW4uXG4gICAgICAgICAgZm9yIChlbmQgPSBpbmRleDsgZW5kIDwgbGVuZ3RoOyBlbmQrKykge1xuICAgICAgICAgICAgaWYgKHRoaXMuX2NoYXJJc01hcHBpbmdTZXBhcmF0b3IoYVN0ciwgZW5kKSkge1xuICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgICAgc3RyID0gYVN0ci5zbGljZShpbmRleCwgZW5kKTtcblxuICAgICAgICAgIHNlZ21lbnQgPSBjYWNoZWRTZWdtZW50c1tzdHJdO1xuICAgICAgICAgIGlmIChzZWdtZW50KSB7XG4gICAgICAgICAgICBpbmRleCArPSBzdHIubGVuZ3RoO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBzZWdtZW50ID0gW107XG4gICAgICAgICAgICB3aGlsZSAoaW5kZXggPCBlbmQpIHtcbiAgICAgICAgICAgICAgYmFzZTY0VkxRLmRlY29kZShhU3RyLCBpbmRleCwgdGVtcCk7XG4gICAgICAgICAgICAgIHZhbHVlID0gdGVtcC52YWx1ZTtcbiAgICAgICAgICAgICAgaW5kZXggPSB0ZW1wLnJlc3Q7XG4gICAgICAgICAgICAgIHNlZ21lbnQucHVzaCh2YWx1ZSk7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmIChzZWdtZW50Lmxlbmd0aCA9PT0gMikge1xuICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoJ0ZvdW5kIGEgc291cmNlLCBidXQgbm8gbGluZSBhbmQgY29sdW1uJyk7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmIChzZWdtZW50Lmxlbmd0aCA9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FwcGluZywgJ25hbWUnLCBudWxsKTtcbiAgICAgICAgICBpZiAobmFtZSAhPT0gbnVsbCkge1xuICAgICAgICAgICAgbmFtZSA9IHRoaXMuX25hbWVzLmF0KG5hbWUpO1xuICAgICAgICAgIH1cbiAgICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgc291cmNlOiBzb3VyY2UsXG4gICAgICAgICAgICBsaW5lOiB1dGlsLmdldEFyZyhtYXBwaW5nLCAnb3JpZ2luYWxMaW5lJywgbnVsbCksXG4gICAgICAgICAgICBjb2x1bW46IHV0aWwuZ2V0QXJnKG1hcHBpbmcsICdvcmlnaW5hbENvbHVtbicsIG51bGwpLFxuICAgICAgICAgICAgbmFtZTogbmFtZVxuICAgICAgICAgIH07XG4gICAgICAgIH1cbiAgICAgIH1cblxuICAgICAgcmV0dXJuIHtcbiAgICAgICAgc291cmNlOiBudWxsLFxuICAgICAgICBsaW5lOiBudWxsLFxuICAgICAgICBjb2x1bW46IG51bGwsXG4gICAgICAgIG5hbWU6IG51bGxcbiAgICAgIH07XG4gICAgfTtcblxuICAvKipcbiAgICogUmV0dXJuIHRydWUgaWYgd2UgaGF2ZSB0aGUgc291cmNlIGNvbnRlbnQgZm9yIGV2ZXJ5IHNvdXJjZSBpbiB0aGUgc291cmNlXG4gICAqIG1hcCwgZmFsc2Ugb3RoZXJ3aXNlLlxuICAgKi9cbiAgQmFzaWNTb3VyY2VNYXBDb25zdW1lci5wcm90b3R5cGUuaGFzQ29udGVudHNPZkFsbFNvdXJjZXMgPVxuICAgIGZ1bmN0aW9uIEJhc2ljU291cmNlTWFwQ29uc3VtZXJfaGFzQ29udGVudHNPZkFsbFNvdXJjZXMoKSB7XG4gICAgICBpZiAoIXRoaXMuc291cmNlc0NvbnRlbnQpIHtcbiAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgfVxuICAgICAgcmV0dXJuIHRoaXMuc291cmNlc0NvbnRlbnQubGVuZ3RoID49IHRoaXMuX3NvdXJjZXMuc2l6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W5nLnNvdXJjZSA9IHV0aWwuam9pbihhU291cmNlTWFwUGF0aCwgbWFwcGluZy5zb3VyY2UpXG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAoc291cmNlUm9vdCAhPSBudWxsKSB7XG4gICAgICAgICAgICAgIG1hcHBpbmcuc291cmNlID0gdXRpbC5yZWxhdGl2ZShzb3VyY2VSb290LCBtYXBwaW5nLnNvdXJjZSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBtYXBwaW5nLm9yaWdpbmFsTGluZSA9IG9yaWdpbmFsLmxpbmU7XG4gICAgICAgICAgICBtYXBwaW5nLm9yaWdpbmFsQ29sdW1uID0gb3JpZ2luYWwuY29sdW1uO1xuICAgICAgICAgICAgaWYgKG9yaWdpbmFsLm5hbWUgIT0gbnVsbCkge1xuICAgICAgICAgICAgICBtYXBwaW5nLm5hbWUgPSBvcmlnaW5hbC5uYW1lO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIHZhciBzb3VyY2UgPSBtYXBwaW5nLnNvdXJjZTtcbiAgICAgICAgaWYgKHNvdXJjZSAhPSBudWxsICYmICFuZXdTb3VyY2VzLmhhcyhzb3VyY2UpKSB7XG4gICAgICAgICAgbmV3U291cmNlcy5hZGQoc291cmNlKTtcbiAgICAgICAgfVxuXG4gICAgICAgIHZhciBuYW1lID0gbWFwcGluZy5uYW1lO1xuICAgICAgICBpZiAobmFtZSAhPSBudWxsICYmICFuZXdOYW1lcy5oYXMobmFtZSkpIHtcbiAgICAgICAgICBuZXdOYW1lcy5hZGQobmFtZSk7XG4gICAgICAgIH1cblxuICAgICAgfSwgdGhpcyk7XG4gICAgICB0aGlzLl9zb3VyY2VzID0gbmV3U291cmNlcztcbiAgICAgIHRoaXMuX25hbWVzID0gbmV3TmFtZXM7XG5cbiAgICAgIC8vIENvcHkgc291cmNlc0NvbnRlbnRzIG9mIGFwcGxpZWQgbWFwLlxuICAgICAgYVNvdXJjZU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Nlcy5pbmRleE9mKG1hcHBpbmcuc291cmNlKTtcbiAgICAgICAgICByZXN1bHQgKz0gYmFzZTY0VkxRLmVuY29kZShzb3VyY2VJZHggLSBwcmV2aW91c1NvdXJjZSk7XG4gICAgICAgICAgcHJldmlvdXNTb3VyY2UgPSBzb3VyY2VJZHg7XG5cbiAgICAgICAgICAvLyBsaW5lcyBhcmUgc3RvcmVkIDAtYmFzZWQgaW4gU291cmNlTWFwIHNwZWMgdmVyc2lvbiAzXG4gICAgICAgICAgcmVzdWx0ICs9IGJhc2U2NFZMUS5lbmNvZGUobWFwcGluZy5vcmlnaW5hbExpbmUgLSAxXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLSBwcmV2aW91c09yaWdpbmFsTGluZSk7XG4gICAgICAgICAgcHJldmlvdXNPcmlnaW5hbExpbmUgPSBtYXBwaW5nLm9yaWdpbmFsTGluZSAtIDE7XG5cbiAgICAgICAgICByZXN1bHQgKz0gYmFzZTY0VkxRLmVuY29kZShtYXBwaW5nLm9yaWdpbmFsQ29sdW1uXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLSBwcmV2aW91c09yaWdpbmFsQ29sdW1uKTtcbiAgICAgICAgICBwcmV2aW91c09yaWdpbmFsQ29sdW1uID0gbWFwcGluZy5vcmlnaW5hbENvbHVtbjtcblxuICAgICAgICAgIGlmIChtYXBwaW5nLm5hbWUgIT0gbnVsbCkge1xuICAgICAgICAgICAgbmFtZUlkeCA9IHRoaXMuX25hbWVzLmluZGV4T2YobWFwcGluZy5uYW1lKTtcbiAgICAgICAgICAgIHJlc3VsdCArPSBiYXNlNjRWTFEuZW5jb2RlKG5hbWVJZHggLSBwcmV2aW91c05hbWUpO1xuICAgICAgICAgICAgcHJldmlvdXNOYW1lID0gbmFtZUlkeDtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cblxuICAgICAgcmV0dXJuIHJlc3VsdDtcbiAgICB9O1xuXG4gIFNvdXJjZU1hcEdlbmVyYXRvci5wcm90b3R5cGUuX2dlbmVyYXRlU291cmNlc0NvbnRlbnQgPVxuICAgIGZ1bmN0aW9uIFNvdXJjZU1hcEdlbmVyYXRvcl9nZW5lcmF0ZVNvdXJjZXNDb250ZW50KGFTb3VyY2VzLCBhU291cmNlUm9vdCkge1xuICAgICAgcmV0dXJuIGFTb3VyY2VzLm1hcChmdW5jdGlvbiAoc291cmNlKSB7XG4gICAgICAgIGlmICghdGhpcy5fc291cmNlc0NvbnRlbnRzKSB7XG4gICAgICAgICAgcmV0dXJuIG51bGw7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKGFTb3VyY2VSb290ICE9IG51bGwpIHtcbiAgICAgICAgICBzb3VyY2UgPSB1dGlsLnJlbGF0aXZlKGFTb3VyY2VSb290LCBzb3VyY2UpO1xuICAgICAgICB9XG4gICAgICAgIHZhciBrZXkgPSB1dGlsLnRvU2V0U3RyaW5nKHNvdXJjZSk7XG4gICAgICAgIHJldHVybiBPYmplY3QucHJvdG90eXBlLmhhc093blByb3BlcnR5LmNhbGwodGhpcy5fc291cmNlc0NvbnRlbnRzLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGtleSlcbiAgICAgICAgICA/IHRoaXMuX3NvdXJjZXNDb250ZW50c1trZXldXG4gICAgICAgICAgOiBudWxsO1xuICAgICAgfSwgdGhpcyk7XG4gICAgfTtcblxuICAvKipcbiAgICogRXh0ZXJuYWxpemUgdGhlIHNvdXJjZSBtYXAuXG4gICAqL1xuICBTb3VyY2VNYXBHZW5lcmF0b3IucHJvdG90eXBlLnRvSlNPTiA9XG4gICAgZnVuY3Rpb24gU291cmNlTWFwR2VuZXJhdG9yX3RvSlNPTigpIHtcbiAgICAgIHZhciBtYXAgPSB7XG4gICAgICAgIHZlcnNpb246IHRoaXMuX3ZlcnNpb24sXG4gICAgICAgIHNvdXJjZXM6IHRoaXMuX3NvdXJjZXMudG9BcnJheSgpLFxu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5R2VuZXJhdGVkUG9zaXRpb25zSW5mbGF0ZWQpO1xuICAgICAgdGhpcy5fc29ydGVkID0gdHJ1ZTtcbiAgICB9XG4gICAgcmV0dXJuIHRoaXMuX2FycmF5O1xuICB9O1xuXG4gIGV4cG9ydHMuTWFwcGluZ0xpc3QgPSBNYXBwaW5nTGlzdDtcbn1cblxuXG5cbi8qKioqKioqKioqKioqKioqKlxuICoqIFdFQlBBQ0sgRk9PVEVSXG4gKiogLi9saWIvbWFwcGluZy1saXN0LmpzXG4gKiogbW9kdWxlIGlkID0gMTBcbiAqKiBtb2R1bGUgY2h1bmtzID0gMFxuICoqLyJdLCJzb3VyY2VSb290IjoiIn0= \ No newline at end of file diff --git a/devtools/shared/sourcemap/tests/unit/test_quick_sort.js b/devtools/shared/sourcemap/tests/unit/test_quick_sort.js new file mode 100644 index 000000000..bd2100725 --- /dev/null +++ b/devtools/shared/sourcemap/tests/unit/test_quick_sort.js @@ -0,0 +1,228 @@ +function run_test() { + for (var k in SOURCE_MAP_TEST_MODULE) { + if (/^test/.test(k)) { + SOURCE_MAP_TEST_MODULE[k](assert); + } + } +} + + +var SOURCE_MAP_TEST_MODULE = +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; +/******/ +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.loaded = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var quickSort = __webpack_require__(1).quickSort; + + function numberCompare(a, b) { + return a - b; + } + + exports['test sorting sorted array'] = function (assert) { + var ary = [0,1,2,3,4,5,6,7,8,9]; + + var quickSorted = ary.slice(); + quickSort(quickSorted, numberCompare); + + assert.equal(JSON.stringify(ary), + JSON.stringify(quickSorted)); + }; + + exports['test sorting reverse-sorted array'] = function (assert) { + var ary = [9,8,7,6,5,4,3,2,1,0]; + + var quickSorted = ary.slice(); + quickSort(quickSorted, numberCompare); + + assert.equal(JSON.stringify(ary.sort(numberCompare)), + JSON.stringify(quickSorted)); + }; + + exports['test sorting unsorted array'] = function (assert) { + var ary = []; + for (var i = 0; i < 10; i++) { + ary.push(Math.random()); + } + + var quickSorted = ary.slice(); + quickSort(quickSorted, numberCompare); + + assert.equal(JSON.stringify(ary.sort(numberCompare)), + JSON.stringify(quickSorted)); + }; + } + + +/***/ }, +/* 1 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + // It turns out that some (most?) JavaScript engines don't self-host + // `Array.prototype.sort`. This makes sense because C++ will likely remain + // faster than JS when doing raw CPU-intensive sorting. However, when using a + // custom comparator function, calling back and forth between the VM's C++ and + // JIT'd JS is rather slow *and* loses JIT type information, resulting in + // worse generated code for the comparator function than would be optimal. In + // fact, when sorting with a comparator, these costs outweigh the benefits of + // sorting in C++. By using our own JS-implemented Quick Sort (below), we get + // a ~3500ms mean speed-up in `bench/bench.html`. + + /** + * Swap the elements indexed by `x` and `y` in the array `ary`. + * + * @param {Array} ary + * The array. + * @param {Number} x + * The index of the first item. + * @param {Number} y + * The index of the second item. + */ + function swap(ary, x, y) { + var temp = ary[x]; + ary[x] = ary[y]; + ary[y] = temp; + } + + /** + * Returns a random integer within the range `low .. high` inclusive. + * + * @param {Number} low + * The lower bound on the range. + * @param {Number} high + * The upper bound on the range. + */ + function randomIntInRange(low, high) { + return Math.round(low + (Math.random() * (high - low))); + } + + /** + * The Quick Sort algorithm. + * + * @param {Array} ary + * An array to sort. + * @param {function} comparator + * Function to use to compare two items. + * @param {Number} p + * Start index of the array + * @param {Number} r + * End index of the array + */ + function doQuickSort(ary, comparator, p, r) { + // If our lower bound is less than our upper bound, we (1) partition the + // array into two pieces and (2) recurse on each half. If it is not, this is + // the empty array and our base case. + + if (p < r) { + // (1) Partitioning. + // + // The partitioning chooses a pivot between `p` and `r` and moves all + // elements that are less than or equal to the pivot to the before it, and + // all the elements that are greater than it after it. The effect is that + // once partition is done, the pivot is in the exact place it will be when + // the array is put in sorted order, and it will not need to be moved + // again. This runs in O(n) time. + + // Always choose a random pivot so that an input array which is reverse + // sorted does not cause O(n^2) running time. + var pivotIndex = randomIntInRange(p, r); + var i = p - 1; + + swap(ary, pivotIndex, r); + var pivot = ary[r]; + + // Immediately after `j` is incremented in this loop, the following hold + // true: + // + // * Every element in `ary[p .. i]` is less than or equal to the pivot. + // + // * Every element in `ary[i+1 .. j-1]` is greater than the pivot. + for (var j = p; j < r; j++) { + if (comparator(ary[j], pivot) <= 0) { + i += 1; + swap(ary, i, j); + } + } + + swap(ary, i + 1, j); + var q = i + 1; + + // (2) Recurse on each half. + + doQuickSort(ary, comparator, p, q - 1); + doQuickSort(ary, comparator, q + 1, r); + } + } + + /** + * Sort the given array in-place with the given comparator function. + * + * @param {Array} ary + * An array to sort. + * @param {function} comparator + * Function to use to compare two items. + */ + exports.quickSort = function (ary, com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d2FwKGFyeSwgaSwgaik7XG4gICAgICAgIH1cbiAgICAgIH1cblxuICAgICAgc3dhcChhcnksIGkgKyAxLCBqKTtcbiAgICAgIHZhciBxID0gaSArIDE7XG5cbiAgICAgIC8vICgyKSBSZWN1cnNlIG9uIGVhY2ggaGFsZi5cblxuICAgICAgZG9RdWlja1NvcnQoYXJ5LCBjb21wYXJhdG9yLCBwLCBxIC0gMSk7XG4gICAgICBkb1F1aWNrU29ydChhcnksIGNvbXBhcmF0b3IsIHEgKyAxLCByKTtcbiAgICB9XG4gIH1cblxuICAvKipcbiAgICogU29ydCB0aGUgZ2l2ZW4gYXJyYXkgaW4tcGxhY2Ugd2l0aCB0aGUgZ2l2ZW4gY29tcGFyYXRvciBmdW5jdGlvbi5cbiAgICpcbiAgICogQHBhcmFtIHtBcnJheX0gYXJ5XG4gICAqICAgICAgICBBbiBhcnJheSB0byBzb3J0LlxuICAgKiBAcGFyYW0ge2Z1bmN0aW9ufSBjb21wYXJhdG9yXG4gICAqICAgICAgICBGdW5jdGlvbiB0byB1c2UgdG8gY29tcGFyZSB0d28gaXRlbXMuXG4gICAqL1xuICBleHBvcnRzLnF1aWNrU29ydCA9IGZ1bmN0aW9uIChhcnksIGNvbXBhcmF0b3IpIHtcbiAgICBkb1F1aWNrU29ydChhcnksIGNvbXBhcmF0b3IsIDAsIGFyeS5sZW5ndGggLSAxKTtcbiAgfTtcbn1cblxuXG5cbi8qKioqKioqKioqKioqKioqKlxuICoqIFdFQlBBQ0sgRk9PVEVSXG4gKiogLi9saWIvcXVpY2stc29ydC5qc1xuICoqIG1vZHVsZSBpZCA9IDFcbiAqKiBtb2R1bGUgY2h1bmtzID0gMFxuICoqLyJdLCJzb3VyY2VSb290IjoiIn0= \ No newline at end of file diff --git a/devtools/shared/sourcemap/tests/unit/test_source_map_consumer.js b/devtools/shared/sourcemap/tests/unit/test_source_map_consumer.js new file mode 100644 index 000000000..77bbf06ec --- /dev/null +++ b/devtools/shared/sourcemap/tests/unit/test_source_map_consumer.js @@ -0,0 +1,4005 @@ +function run_test() { + for (var k in SOURCE_MAP_TEST_MODULE) { + if (/^test/.test(k)) { + SOURCE_MAP_TEST_MODULE[k](assert); + } + } +} + + +var SOURCE_MAP_TEST_MODULE = +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; +/******/ +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.loaded = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var util = __webpack_require__(1); + var SourceMapConsumer = __webpack_require__(3).SourceMapConsumer; + var IndexedSourceMapConsumer = __webpack_require__(3).IndexedSourceMapConsumer; + var BasicSourceMapConsumer = __webpack_require__(3).BasicSourceMapConsumer; + var SourceMapGenerator = __webpack_require__(9).SourceMapGenerator; + + exports['test that we can instantiate with a string or an object'] = function (assert) { + assert.doesNotThrow(function () { + var map = new SourceMapConsumer(util.testMap); + }); + assert.doesNotThrow(function () { + var map = new SourceMapConsumer(JSON.stringify(util.testMap)); + }); + }; + + exports['test that the object returned from new SourceMapConsumer inherits from SourceMapConsumer'] = function (assert) { + assert.ok(new SourceMapConsumer(util.testMap) instanceof SourceMapConsumer); + } + + exports['test that a BasicSourceMapConsumer is returned for sourcemaps without sections'] = function(assert) { + assert.ok(new SourceMapConsumer(util.testMap) instanceof BasicSourceMapConsumer); + }; + + exports['test that an IndexedSourceMapConsumer is returned for sourcemaps with sections'] = function(assert) { + assert.ok(new SourceMapConsumer(util.indexedTestMap) instanceof IndexedSourceMapConsumer); + }; + + exports['test that the `sources` field has the original sources'] = function (assert) { + var map; + var sources; + + map = new SourceMapConsumer(util.testMap); + sources = map.sources; + assert.equal(sources[0], '/the/root/one.js'); + assert.equal(sources[1], '/the/root/two.js'); + assert.equal(sources.length, 2); + + map = new SourceMapConsumer(util.indexedTestMap); + sources = map.sources; + assert.equal(sources[0], '/the/root/one.js'); + assert.equal(sources[1], '/the/root/two.js'); + assert.equal(sources.length, 2); + + map = new SourceMapConsumer(util.indexedTestMapDifferentSourceRoots); + sources = map.sources; + assert.equal(sources[0], '/the/root/one.js'); + assert.equal(sources[1], '/different/root/two.js'); + assert.equal(sources.length, 2); + + map = new SourceMapConsumer(util.testMapNoSourceRoot); + sources = map.sources; + assert.equal(sources[0], 'one.js'); + assert.equal(sources[1], 'two.js'); + assert.equal(sources.length, 2); + + map = new SourceMapConsumer(util.testMapEmptySourceRoot); + sources = map.sources; + assert.equal(sources[0], 'one.js'); + assert.equal(sources[1], 'two.js'); + assert.equal(sources.length, 2); + }; + + exports['test that the source root is reflected in a mapping\'s source field'] = function (assert) { + var map; + var mapping; + + map = new SourceMapConsumer(util.testMap); + + mapping = map.originalPositionFor({ + line: 2, + column: 1 + }); + assert.equal(mapping.source, '/the/root/two.js'); + + mapping = map.originalPositionFor({ + line: 1, + column: 1 + }); + assert.equal(mapping.source, '/the/root/one.js'); + + + map = new SourceMapConsumer(util.testMapNoSourceRoot); + + mapping = map.originalPositionFor({ + line: 2, + column: 1 + }); + assert.equal(mapping.source, 'two.js'); + + mapping = map.originalPositionFor({ + line: 1, + column: 1 + }); + assert.equal(mapping.source, 'one.js'); + + + map = new SourceMapConsumer(util.testMapEmptySourceRoot); + + mapping = map.originalPositionFor({ + line: 2, + column: 1 + }); + assert.equal(mapping.source, 'two.js'); + + mapping = map.originalPositionFor({ + line: 1, + column: 1 + }); + assert.equal(mapping.source, 'one.js'); + }; + + exports['test mapping tokens back exactly'] = function (assert) { + var map = new SourceMapConsumer(util.testMap); + + util.assertMapping(1, 1, '/the/root/one.js', 1, 1, null, null, map, assert); + util.assertMapping(1, 5, '/the/root/one.js', 1, 5, null, null, map, assert); + util.assertMapping(1, 9, '/the/root/one.js', 1, 11, null, null, map, assert); + util.assertMapping(1, 18, '/the/root/one.js', 1, 21, 'bar', null, map, assert); + util.assertMapping(1, 21, '/the/root/one.js', 2, 3, null, null, map, assert); + util.assertMapping(1, 28, '/the/root/one.js', 2, 10, 'baz', null, map, assert); + util.assertMapping(1, 32, '/the/root/one.js', 2, 14, 'bar', null, map, assert); + + util.assertMapping(2, 1, '/the/root/two.js', 1, 1, null, null, map, assert); + util.assertMapping(2, 5, '/the/root/two.js', 1, 5, null, null, map, assert); + util.assertMapping(2, 9, '/the/root/two.js', 1, 11, null, null, map, assert); + util.assertMapping(2, 18, '/the/root/two.js', 1, 21, 'n', null, map, assert); + util.assertMapping(2, 21, '/the/root/two.js', 2, 3, null, null, map, assert); + util.assertMapping(2, 28, '/the/root/two.js', 2, 10, 'n', null, map, assert); + }; + + exports['test mapping tokens back exactly in indexed source map'] = function (assert) { + var map = new SourceMapConsumer(util.indexedTestMap); + + util.assertMapping(1, 1, '/the/root/one.js', 1, 1, null, null, map, assert); + util.assertMapping(1, 5, '/the/root/one.js', 1, 5, null, null, map, assert); + util.assertMapping(1, 9, '/the/root/one.js', 1, 11, null, null, map, assert); + util.assertMapping(1, 18, '/the/root/one.js', 1, 21, 'bar', null, map, assert); + util.assertMapping(1, 21, '/the/root/one.js', 2, 3, null, null, map, assert); + util.assertMapping(1, 28, '/the/root/one.js', 2, 10, 'baz', null, map, assert); + util.assertMapping(1, 32, '/the/root/one.js', 2, 14, 'bar', null, map, assert); + + util.assertMapping(2, 1, '/the/root/two.js', 1, 1, null, null, map, assert); + util.assertMapping(2, 5, '/the/root/two.js', 1, 5, null, null, map, assert); + util.assertMapping(2, 9, '/the/root/two.js', 1, 11, null, null, map, assert); + util.assertMapping(2, 18, '/the/root/two.js', 1, 21, 'n', null, map, assert); + util.assertMapping(2, 21, '/the/root/two.js', 2, 3, null, null, map, assert); + util.assertMapping(2, 28, '/the/root/two.js', 2, 10, 'n', null, map, assert); + }; + + + exports['test mapping tokens back exactly'] = function (assert) { + var map = new SourceMapConsumer(util.testMap); + + util.assertMapping(1, 1, '/the/root/one.js', 1, 1, null, null, map, assert); + util.assertMapping(1, 5, '/the/root/one.js', 1, 5, null, null, map, assert); + util.assertMapping(1, 9, '/the/root/one.js', 1, 11, null, null, map, assert); + util.assertMapping(1, 18, '/the/root/one.js', 1, 21, 'bar', null, map, assert); + util.assertMapping(1, 21, '/the/root/one.js', 2, 3, null, null, map, assert); + util.assertMapping(1, 28, '/the/root/one.js', 2, 10, 'baz', null, map, assert); + util.assertMapping(1, 32, '/the/root/one.js', 2, 14, 'bar', null, map, assert); + + util.assertMapping(2, 1, '/the/root/two.js', 1, 1, null, null, map, assert); + util.assertMapping(2, 5, '/the/root/two.js', 1, 5, null, null, map, assert); + util.assertMapping(2, 9, '/the/root/two.js', 1, 11, null, null, map, assert); + util.assertMapping(2, 18, '/the/root/two.js', 1, 21, 'n', null, map, assert); + util.assertMapping(2, 21, '/the/root/two.js', 2, 3, null, null, map, assert); + util.assertMapping(2, 28, '/the/root/two.js', 2, 10, 'n', null, map, assert); + }; + + exports['test mapping tokens fuzzy'] = function (assert) { + var map = new SourceMapConsumer(util.testMap); + + // Finding original positions with default (glb) bias. + util.assertMapping(1, 20, '/the/root/one.js', 1, 21, 'bar', null, map, assert, true); + util.assertMapping(1, 30, '/the/root/one.js', 2, 10, 'baz', null, map, assert, true); + util.assertMapping(2, 12, '/the/root/two.js', 1, 11, null, null, map, assert, true); + + // Finding original positions with lub bias. + util.assertMapping(1, 16, '/the/root/one.js', 1, 21, 'bar', SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, true); + util.assertMapping(1, 26, '/the/root/one.js', 2, 10, 'baz', SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, true); + util.assertMapping(2, 6, '/the/root/two.js', 1, 11, null, SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, true); + + // Finding generated positions with default (glb) bias. + util.assertMapping(1, 18, '/the/root/one.js', 1, 22, 'bar', null, map, assert, null, true); + util.assertMapping(1, 28, '/the/root/one.js', 2, 13, 'baz', null, map, assert, null, true); + util.assertMapping(2, 9, '/the/root/two.js', 1, 16, null, null, map, assert, null, true); + + // Finding generated positions with lub bias. + util.assertMapping(1, 18, '/the/root/one.js', 1, 20, 'bar', SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, null, true); + util.assertMapping(1, 28, '/the/root/one.js', 2, 7, 'baz', SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, null, true); + util.assertMapping(2, 9, '/the/root/two.js', 1, 6, null, SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, null, true); + }; + + exports['test mapping tokens fuzzy in indexed source map'] = function (assert) { + var map = new SourceMapConsumer(util.indexedTestMap); + + // Finding original positions with default (glb) bias. + util.assertMapping(1, 20, '/the/root/one.js', 1, 21, 'bar', null, map, assert, true); + util.assertMapping(1, 30, '/the/root/one.js', 2, 10, 'baz', null, map, assert, true); + util.assertMapping(2, 12, '/the/root/two.js', 1, 11, null, null, map, assert, true); + + // Finding original positions with lub bias. + util.assertMapping(1, 16, '/the/root/one.js', 1, 21, 'bar', SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, true); + util.assertMapping(1, 26, '/the/root/one.js', 2, 10, 'baz', SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, true); + util.assertMapping(2, 6, '/the/root/two.js', 1, 11, null, SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, true); + + // Finding generated positions with default (glb) bias. + util.assertMapping(1, 18, '/the/root/one.js', 1, 22, 'bar', null, map, assert, null, true); + util.assertMapping(1, 28, '/the/root/one.js', 2, 13, 'baz', null, map, assert, null, true); + util.assertMapping(2, 9, '/the/root/two.js', 1, 16, null, null, map, assert, null, true); + + // Finding generated positions with lub bias. + util.assertMapping(1, 18, '/the/root/one.js', 1, 20, 'bar', SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, null, true); + util.assertMapping(1, 28, '/the/root/one.js', 2, 7, 'baz', SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, null, true); + util.assertMapping(2, 9, '/the/root/two.js', 1, 6, null, SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, null, true); + }; + + exports['test mappings and end of lines'] = function (assert) { + var smg = new SourceMapGenerator({ + file: 'foo.js' + }); + smg.addMapping({ + original: { line: 1, column: 1 }, + generated: { line: 1, column: 1 }, + source: 'bar.js' + }); + smg.addMapping({ + original: { line: 2, column: 2 }, + generated: { line: 2, column: 2 }, + source: 'bar.js' + }); + smg.addMapping({ + original: { line: 1, column: 1 }, + generated: { line: 1, column: 1 }, + source: 'baz.js' + }); + + var map = SourceMapConsumer.fromSourceMap(smg); + + // When finding original positions, mappings end at the end of the line. + util.assertMapping(2, 1, null, null, null, null, null, map, assert, true) + + // When finding generated positions, mappings do not end at the end of the line. + util.assertMapping(1, 1, 'bar.js', 2, 1, null, null, map, assert, null, true); + + // When finding generated positions with, mappings end at the end of the source. + util.assertMapping(null, null, 'bar.js', 3, 1, null, SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, null, true); + }; + + exports['test creating source map consumers with )]}\' prefix'] = function (assert) { + assert.doesNotThrow(function () { + var map = new SourceMapConsumer(")]}'" + JSON.stringify(util.testMap)); + }); + }; + + exports['test eachMapping'] = function (assert) { + var map; + + map = new SourceMapConsumer(util.testMap); + var previousLine = -Infinity; + var previousColumn = -Infinity; + map.eachMapping(function (mapping) { + assert.ok(mapping.generatedLine >= previousLine); + + assert.ok(mapping.source === '/the/root/one.js' || mapping.source === '/the/root/two.js'); + + if (mapping.generatedLine === previousLine) { + assert.ok(mapping.generatedColumn >= previousColumn); + previousColumn = mapping.generatedColumn; + } + else { + previousLine = mapping.generatedLine; + previousColumn = -Infinity; + } + }); + + map = new SourceMapConsumer(util.testMapNoSourceRoot); + map.eachMapping(function (mapping) { + assert.ok(mapping.source === 'one.js' || mapping.source === 'two.js'); + }); + + map = new SourceMapConsumer(util.testMapEmptySourceRoot); + map.eachMapping(function (mapping) { + assert.ok(mapping.source === 'one.js' || mapping.source === 'two.js'); + }); + }; + + exports['test eachMapping for indexed source maps'] = function(assert) { + var map = new SourceMapConsumer(util.indexedTestMap); + var previousLine = -Infinity; + var previousColumn = -Infinity; + map.eachMapping(function (mapping) { + assert.ok(mapping.generatedLine >= previousLine); + + if (mapping.source) { + assert.equal(mapping.source.indexOf(util.testMap.sourceRoot), 0); + } + + if (mapping.generatedLine === previousLine) { + assert.ok(mapping.generatedColumn >= previousColumn); + previousColumn = mapping.generatedColumn; + } + else { + previousLine = mapping.generatedLine; + previousColumn = -Infinity; + } + }); + }; + + + exports['test iterating over mappings in a different order'] = function (assert) { + var map = new SourceMapConsumer(util.testMap); + var previousLine = -Infinity; + var previousColumn = -Infinity; + var previousSource = ""; + map.eachMapping(function (mapping) { + assert.ok(mapping.source >= previousSource); + + if (mapping.source === previousSource) { + assert.ok(mapping.originalLine >= previousLine); + + if (mapping.originalLine === previousLine) { + assert.ok(mapping.originalColumn >= previousColumn); + previousColumn = mapping.originalColumn; + } + else { + previousLine = mapping.originalLine; + previousColumn = -Infinity; + } + } + else { + previousSource = mapping.source; + previousLine = -Infinity; + previousColumn = -Infinity; + } + }, null, SourceMapConsumer.ORIGINAL_ORDER); + }; + + exports['test iterating over mappings in a different order in indexed source maps'] = function (assert) { + var map = new SourceMapConsumer(util.indexedTestMap); + var previousLine = -Infinity; + var previousColumn = -Infinity; + var previousSource = ""; + map.eachMapping(function (mapping) { + assert.ok(mapping.source >= previousSource); + + if (mapping.source === previousSource) { + assert.ok(mapping.originalLine >= previousLine); + + if (mapping.originalLine === previousLine) { + assert.ok(mapping.originalColumn >= previousColumn); + previousColumn = mapping.originalColumn; + } + else { + previousLine = mapping.originalLine; + previousColumn = -Infinity; + } + } + else { + previousSource = mapping.source; + previousLine = -Infinity; + previousColumn = -Infinity; + } + }, null, SourceMapConsumer.ORIGINAL_ORDER); + }; + + exports['test that we can set the context for `this` in eachMapping'] = function (assert) { + var map = new SourceMapConsumer(util.testMap); + var context = {}; + map.eachMapping(function () { + assert.equal(this, context); + }, context); + }; + + exports['test that we can set the context for `this` in eachMapping in indexed source maps'] = function (assert) { + var map = new SourceMapConsumer(util.indexedTestMap); + var context = {}; + map.eachMapping(function () { + assert.equal(this, context); + }, context); + }; + + exports['test that the `sourcesContent` field has the original sources'] = function (assert) { + var map = new SourceMapConsumer(util.testMapWithSourcesContent); + var sourcesContent = map.sourcesContent; + + assert.equal(sourcesContent[0], ' ONE.foo = function (bar) {\n return baz(bar);\n };'); + assert.equal(sourcesContent[1], ' TWO.inc = function (n) {\n return n + 1;\n };'); + assert.equal(sourcesContent.length, 2); + }; + + exports['test that we can get the original sources for the sources'] = function (assert) { + var map = new SourceMapConsumer(util.testMapWithSourcesContent); + var sources = map.sources; + + assert.equal(map.sourceContentFor(sources[0]), ' ONE.foo = function (bar) {\n return baz(bar);\n };'); + assert.equal(map.sourceContentFor(sources[1]), ' TWO.inc = function (n) {\n return n + 1;\n };'); + assert.equal(map.sourceContentFor("one.js"), ' ONE.foo = function (bar) {\n return baz(bar);\n };'); + assert.equal(map.sourceContentFor("two.js"), ' TWO.inc = function (n) {\n return n + 1;\n };'); + assert.throws(function () { + map.sourceContentFor(""); + }, Error); + assert.throws(function () { + map.sourceContentFor("/the/root/three.js"); + }, Error); + assert.throws(function () { + map.sourceContentFor("three.js"); + }, Error); + }; + + exports['test that we can get the original source content with relative source paths'] = function (assert) { + var map = new SourceMapConsumer(util.testMapRelativeSources); + var sources = map.sources; + + assert.equal(map.sourceContentFor(sources[0]), ' ONE.foo = function (bar) {\n return baz(bar);\n };'); + assert.equal(map.sourceContentFor(sources[1]), ' TWO.inc = function (n) {\n return n + 1;\n };'); + assert.equal(map.sourceContentFor("one.js"), ' ONE.foo = function (bar) {\n return baz(bar);\n };'); + assert.equal(map.sourceContentFor("two.js"), ' TWO.inc = function (n) {\n return n + 1;\n };'); + assert.throws(function () { + map.sourceContentFor(""); + }, Error); + assert.throws(function () { + map.sourceContentFor("/the/root/three.js"); + }, Error); + assert.throws(function () { + map.sourceContentFor("three.js"); + }, Error); + }; + + exports['test that we can get the original source content for the sources on an indexed source map'] = function (assert) { + var map = new SourceMapConsumer(util.indexedTestMap); + var sources = map.sources; + + assert.equal(map.sourceContentFor(sources[0]), ' ONE.foo = function (bar) {\n return baz(bar);\n };'); + assert.equal(map.sourceContentFor(sources[1]), ' TWO.inc = function (n) {\n return n + 1;\n };'); + assert.equal(map.sourceContentFor("one.js"), ' ONE.foo = function (bar) {\n return baz(bar);\n };'); + assert.equal(map.sourceContentFor("two.js"), ' TWO.inc = function (n) {\n return n + 1;\n };'); + assert.throws(function () { + map.sourceContentFor(""); + }, Error); + assert.throws(function () { + map.sourceContentFor("/the/root/three.js"); + }, Error); + assert.throws(function () { + map.sourceContentFor("three.js"); + }, Error); + }; + + exports['test hasContentsOfAllSources, single source with contents'] = function (assert) { + // Has one source: foo.js (with contents). + var mapWithContents = new SourceMapGenerator(); + mapWithContents.addMapping({ source: 'foo.js', + original: { line: 1, column: 10 }, + generated: { line: 1, column: 10 } }); + mapWithContents.setSourceContent('foo.js', 'content of foo.js'); + var consumer = new SourceMapConsumer(mapWithContents.toJSON()); + assert.ok(consumer.hasContentsOfAllSources()); + }; + + exports['test hasContentsOfAllSources, single source without contents'] = function (assert) { + // Has one source: foo.js (without contents). + var mapWithoutContents = new SourceMapGenerator(); + mapWithoutContents.addMapping({ source: 'foo.js', + original: { line: 1, column: 10 }, + generated: { line: 1, column: 10 } }); + var consumer = new SourceMapConsumer(mapWithoutContents.toJSON()); + assert.ok(!consumer.hasContentsOfAllSources()); + }; + + exports['test hasContentsOfAllSources, two sources with contents'] = function (assert) { + // Has two sources: foo.js (with contents) and bar.js (with contents). + var mapWithBothContents = new SourceMapGenerator(); + mapWithBothContents.addMapping({ source: 'foo.js', + original: { line: 1, column: 10 }, + generated: { line: 1, column: 10 } }); + mapWithBothContents.addMapping({ source: 'bar.js', + original: { line: 1, column: 10 }, + generated: { line: 1, column: 10 } }); + mapWithBothContents.setSourceContent('foo.js', 'content of foo.js'); + mapWithBothContents.setSourceContent('bar.js', 'content of bar.js'); + var consumer = new SourceMapConsumer(mapWithBothContents.toJSON()); + assert.ok(consumer.hasContentsOfAllSources()); + }; + + exports['test hasContentsOfAllSources, two sources one with and one without contents'] = function (assert) { + // Has two sources: foo.js (with contents) and bar.js (without contents). + var mapWithoutSomeContents = new SourceMapGenerator(); + mapWithoutSomeContents.addMapping({ source: 'foo.js', + original: { line: 1, column: 10 }, + generated: { line: 1, column: 10 } }); + mapWithoutSomeContents.addMapping({ source: 'bar.js', + original: { line: 1, column: 10 }, + generated: { line: 1, column: 10 } }); + mapWithoutSomeContents.setSourceContent('foo.js', 'content of foo.js'); + var consumer = new SourceMapConsumer(mapWithoutSomeContents.toJSON()); + assert.ok(!consumer.hasContentsOfAllSources()); + }; + + exports['test sourceRoot + generatedPositionFor'] = function (assert) { + var map = new SourceMapGenerator({ + sourceRoot: 'foo/bar', + file: 'baz.js' + }); + map.addMapping({ + original: { line: 1, column: 1 }, + generated: { line: 2, column: 2 }, + source: 'bang.coffee' + }); + map.addMapping({ + original: { line: 5, column: 5 }, + generated: { line: 6, column: 6 }, + source: 'bang.coffee' + }); + map = new SourceMapConsumer(map.toString()); + + // Should handle without sourceRoot. + var pos = map.generatedPositionFor({ + line: 1, + column: 1, + source: 'bang.coffee' + }); + + assert.equal(pos.line, 2); + assert.equal(pos.column, 2); + + // Should handle with sourceRoot. + var pos = map.generatedPositionFor({ + line: 1, + column: 1, + source: 'foo/bar/bang.coffee' + }); + + assert.equal(pos.line, 2); + assert.equal(pos.column, 2); + }; + + exports['test sourceRoot + generatedPositionFor for path above the root'] = function (assert) { + var map = new SourceMapGenerator({ + sourceRoot: 'foo/bar', + file: 'baz.js' + }); + map.addMapping({ + original: { line: 1, column: 1 }, + generated: { line: 2, column: 2 }, + source: '../bang.coffee' + }); + map = new SourceMapConsumer(map.toString()); + + // Should handle with sourceRoot. + var pos = map.generatedPositionFor({ + line: 1, + column: 1, + source: 'foo/bang.coffee' + }); + + assert.equal(pos.line, 2); + assert.equal(pos.column, 2); + }; + + exports['test allGeneratedPositionsFor for line'] = function (assert) { + var map = new SourceMapGenerator({ + file: 'generated.js' + }); + map.addMapping({ + original: { line: 1, column: 1 }, + generated: { line: 2, column: 2 }, + source: 'foo.coffee' + }); + map.addMapping({ + original: { line: 1, column: 1 }, + generated: { line: 2, column: 2 }, + source: 'bar.coffee' + }); + map.addMapping({ + original: { line: 2, column: 1 }, + generated: { line: 3, column: 2 }, + source: 'bar.coffee' + }); + map.addMapping({ + original: { line: 2, column: 2 }, + generated: { line: 3, column: 3 }, + source: 'bar.coffee' + }); + map.addMapping({ + original: { line: 3, column: 1 }, + generated: { line: 4, column: 2 }, + source: 'bar.coffee' + }); + map = new SourceMapConsumer(map.toString()); + + var mappings = map.allGeneratedPositionsFor({ + line: 2, + source: 'bar.coffee' + }); + + assert.equal(mappings.length, 2); + assert.equal(mappings[0].line, 3); + assert.equal(mappings[0].column, 2); + assert.equal(mappings[1].line, 3); + assert.equal(mappings[1].column, 3); + }; + + exports['test allGeneratedPositionsFor for line fuzzy'] = function (assert) { + var map = new SourceMapGenerator({ + file: 'generated.js' + }); + map.addMapping({ + original: { line: 1, column: 1 }, + generated: { line: 2, column: 2 }, + source: 'foo.coffee' + }); + map.addMapping({ + original: { line: 1, column: 1 }, + generated: { line: 2, column: 2 }, + source: 'bar.coffee' + }); + map.addMapping({ + original: { line: 3, column: 1 }, + generated: { line: 4, column: 2 }, + source: 'bar.coffee' + }); + map = new SourceMapConsumer(map.toString()); + + var mappings = map.allGeneratedPositionsFor({ + line: 2, + source: 'bar.coffee' + }); + + assert.equal(mappings.length, 1); + assert.equal(mappings[0].line, 4); + assert.equal(mappings[0].column, 2); + }; + + exports['test allGeneratedPositionsFor for empty source map'] = function (assert) { + var map = new SourceMapGenerator({ + file: 'generated.js' + }); + map = new SourceMapConsumer(map.toString()); + + var mappings = map.allGeneratedPositionsFor({ + line: 2, + source: 'bar.coffee' + }); + + assert.equal(mappings.length, 0); + }; + + exports['test allGeneratedPositionsFor for column'] = function (assert) { + var map = new SourceMapGenerator({ + file: 'generated.js' + }); + map.addMapping({ + original: { line: 1, column: 1 }, + generated: { line: 1, column: 2 }, + source: 'foo.coffee' + }); + map.addMapping({ + original: { line: 1, column: 1 }, + generated: { line: 1, column: 3 }, + source: 'foo.coffee' + }); + map = new SourceMapConsumer(map.toString()); + + var mappings = map.allGeneratedPositionsFor({ + line: 1, + column: 1, + source: 'foo.coffee' + }); + + assert.equal(mappings.length, 2); + assert.equal(mappings[0].line, 1); + assert.equal(mappings[0].column, 2); + assert.equal(mappings[1].line, 1); + assert.equal(mappings[1].column, 3); + }; + + exports['test allGeneratedPositionsFor for column fuzzy'] = function (assert) { + var map = new SourceMapGenerator({ + file: 'generated.js' + }); + map.addMapping({ + original: { line: 1, column: 1 }, + generated: { line: 1, column: 2 }, + source: 'foo.coffee' + }); + map.addMapping({ + original: { line: 1, column: 1 }, + generated: { line: 1, column: 3 }, + source: 'foo.coffee' + }); + map = new SourceMapConsumer(map.toString()); + + var mappings = map.allGeneratedPositionsFor({ + line: 1, + column: 0, + source: 'foo.coffee' + }); + + assert.equal(mappings.length, 2); + assert.equal(mappings[0].line, 1); + assert.equal(mappings[0].column, 2); + assert.equal(mappings[1].line, 1); + assert.equal(mappings[1].column, 3); + }; + + exports['test allGeneratedPositionsFor for column on different line fuzzy'] = function (assert) { + var map = new SourceMapGenerator({ + file: 'generated.js' + }); + map.addMapping({ + original: { line: 2, column: 1 }, + generated: { line: 2, column: 2 }, + source: 'foo.coffee' + }); + map.addMapping({ + original: { line: 2, column: 1 }, + generated: { line: 2, column: 3 }, + source: 'foo.coffee' + }); + map = new SourceMapConsumer(map.toString()); + + var mappings = map.allGeneratedPositionsFor({ + line: 1, + column: 0, + source: 'foo.coffee' + }); + + assert.equal(mappings.length, 0); + }; + + exports['test computeColumnSpans'] = function (assert) { + var map = new SourceMapGenerator({ + file: 'generated.js' + }); + map.addMapping({ + original: { line: 1, column: 1 }, + generated: { line: 1, column: 1 }, + source: 'foo.coffee' + }); + map.addMapping({ + original: { line: 2, column: 1 }, + generated: { line: 2, column: 1 }, + source: 'foo.coffee' + }); + map.addMapping({ + original: { line: 2, column: 2 }, + generated: { line: 2, column: 10 }, + source: 'foo.coffee' + }); + map.addMapping({ + original: { line: 2, column: 3 }, + generated: { line: 2, column: 20 }, + source: 'foo.coffee' + }); + map.addMapping({ + original: { line: 3, column: 1 }, + generated: { line: 3, column: 1 }, + source: 'foo.coffee' + }); + map.addMapping({ + original: { line: 3, column: 2 }, + generated: { line: 3, column: 2 }, + source: 'foo.coffee' + }); + map = new SourceMapConsumer(map.toString()); + + map.computeColumnSpans(); + + var mappings = map.allGeneratedPositionsFor({ + line: 1, + source: 'foo.coffee' + }); + + assert.equal(mappings.length, 1); + assert.equal(mappings[0].lastColumn, Infinity); + + var mappings = map.allGeneratedPositionsFor({ + line: 2, + source: 'foo.coffee' + }); + + assert.equal(mappings.length, 3); + assert.equal(mappings[0].lastColumn, 9); + assert.equal(mappings[1].lastColumn, 19); + assert.equal(mappings[2].lastColumn, Infinity); + + var mappings = map.allGeneratedPositionsFor({ + line: 3, + source: 'foo.coffee' + }); + + assert.equal(mappings.length, 2); + assert.equal(mappings[0].lastColumn, 1); + assert.equal(mappings[1].lastColumn, Infinity); + }; + + exports['test sourceRoot + originalPositionFor'] = function (assert) { + var map = new SourceMapGenerator({ + sourceRoot: 'foo/bar', + file: 'baz.js' + }); + map.addMapping({ + original: { line: 1, column: 1 }, + generated: { line: 2, column: 2 }, + source: 'bang.coffee' + }); + map = new SourceMapConsumer(map.toString()); + + var pos = map.originalPositionFor({ + line: 2, + column: 2, + }); + + // Should always have the prepended source root + assert.equal(pos.source, 'foo/bar/bang.coffee'); + assert.equal(pos.line, 1); + assert.equal(pos.column, 1); + }; + + exports['test github issue #56'] = function (assert) { + var map = new SourceMapGenerator({ + sourceRoot: 'http://', + file: 'www.example.com/foo.js' + }); + map.addMapping({ + original: { line: 1, column: 1 }, + generated: { line: 2, column: 2 }, + source: 'www.example.com/original.js' + }); + map = new SourceMapConsumer(map.toString()); + + var sources = map.sources; + assert.equal(sources.length, 1); + assert.equal(sources[0], 'http://www.example.com/original.js'); + }; + + exports['test github issue #43'] = function (assert) { + var map = new SourceMapGenerator({ + sourceRoot: 'http://example.com', + file: 'foo.js' + }); + map.addMapping({ + original: { line: 1, column: 1 }, + generated: { line: 2, column: 2 }, + source: 'http://cdn.example.com/original.js' + }); + map = new SourceMapConsumer(map.toString()); + + var sources = map.sources; + assert.equal(sources.length, 1, + 'Should only be one source.'); + assert.equal(sources[0], 'http://cdn.example.com/original.js', + 'Should not be joined with the sourceRoot.'); + }; + + exports['test absolute path, but same host sources'] = function (assert) { + var map = new SourceMapGenerator({ + sourceRoot: 'http://example.com/foo/bar', + file: 'foo.js' + }); + map.addMapping({ + original: { line: 1, column: 1 }, + generated: { line: 2, column: 2 }, + source: '/original.js' + }); + map = new SourceMapConsumer(map.toString()); + + var sources = map.sources; + assert.equal(sources.length, 1, + 'Should only be one source.'); + assert.equal(sources[0], 'http://example.com/original.js', + 'Source should be relative the host of the source root.'); + }; + + exports['test indexed source map errors when sections are out of order by line'] = function(assert) { + // Make a deep copy of the indexedTestMap + var misorderedIndexedTestMap = JSON.parse(JSON.stringify(util.indexedTestMap)); + + misorderedIndexedTestMap.sections[0].offset = { + line: 2, + column: 0 + }; + + assert.throws(function() { + new SourceMapConsumer(misorderedIndexedTestMap); + }, Error); + }; + + exports['test github issue #64'] = function (assert) { + var map = new SourceMapConsumer({ + "version": 3, + "file": "foo.js", + "sourceRoot": "http://example.com/", + "sources": ["/a"], + "names": [], + "mappings": "AACA", + "sourcesContent": ["foo"] + }); + + assert.equal(map.sourceContentFor("a"), "foo"); + assert.equal(map.sourceContentFor("/a"), "foo"); + }; + + exports['test bug 885597'] = function (assert) { + var map = new SourceMapConsumer({ + "version": 3, + "file": "foo.js", + "sourceRoot": "file:///Users/AlGore/Invented/The/Internet/", + "sources": ["/a"], + "names": [], + "mappings": "AACA", + "sourcesContent": ["foo"] + }); + + var s = map.sources[0]; + assert.equal(map.sourceContentFor(s), "foo"); + }; + + exports['test github issue #72, duplicate sources'] = function (assert) { + var map = new SourceMapConsumer({ + "version": 3, + "file": "foo.js", + "sources": ["source1.js", "source1.js", "source3.js"], + "names": [], + "mappings": ";EAAC;;IAEE;;MEEE", + "sourceRoot": "http://example.com" + }); + + var pos = map.originalPositionFor({ + line: 2, + column: 2 + }); + assert.equal(pos.source, 'http://example.com/source1.js'); + assert.equal(pos.line, 1); + assert.equal(pos.column, 1); + + var pos = map.originalPositionFor({ + line: 4, + column: 4 + }); + assert.equal(pos.source, 'http://example.com/source1.js'); + assert.equal(pos.line, 3); + assert.equal(pos.column, 3); + + var pos = map.originalPositionFor({ + line: 6, + column: 6 + }); + assert.equal(pos.source, 'http://example.com/source3.js'); + assert.equal(pos.line, 5); + assert.equal(pos.column, 5); + }; + + exports['test github issue #72, duplicate names'] = function (assert) { + var map = new SourceMapConsumer({ + "version": 3, + "file": "foo.js", + "sources": ["source.js"], + "names": ["name1", "name1", "name3"], + "mappings": ";EAACA;;IAEEA;;MAEEE", + "sourceRoot": "http://example.com" + }); + + var pos = map.originalPositionFor({ + line: 2, + column: 2 + }); + assert.equal(pos.name, 'name1'); + assert.equal(pos.line, 1); + assert.equal(pos.column, 1); + + var pos = map.originalPositionFor({ + line: 4, + column: 4 + }); + assert.equal(pos.name, 'name1'); + assert.equal(pos.line, 3); + assert.equal(pos.column, 3); + + var pos = map.originalPositionFor({ + line: 6, + column: 6 + }); + assert.equal(pos.name, 'name3'); + assert.equal(pos.line, 5); + assert.equal(pos.column, 5); + }; + + exports['test SourceMapConsumer.fromSourceMap'] = function (assert) { + var smg = new SourceMapGenerator({ + sourceRoot: 'http://example.com/', + file: 'foo.js' + }); + smg.addMapping({ + original: { line: 1, column: 1 }, + generated: { line: 2, column: 2 }, + source: 'bar.js' + }); + smg.addMapping({ + original: { line: 2, column: 2 }, + generated: { line: 4, column: 4 }, + source: 'baz.js', + name: 'dirtMcGirt' + }); + smg.setSourceContent('baz.js', 'baz.js content'); + + var smc = SourceMapConsumer.fromSourceMap(smg); + assert.equal(smc.file, 'foo.js'); + assert.equal(smc.sourceRoot, 'http://example.com/'); + assert.equal(smc.sources.length, 2); + assert.equal(smc.sources[0], 'http://example.com/bar.js'); + assert.equal(smc.sources[1], 'http://example.com/baz.js'); + assert.equal(smc.sourceContentFor('baz.js'), 'baz.js content'); + + var pos = smc.originalPositionFor({ + line: 2, + column: 2 + }); + assert.equal(pos.line, 1); + assert.equal(pos.column, 1); + assert.equal(pos.source, 'http://example.com/bar.js'); + assert.equal(pos.name, null); + + pos = smc.generatedPositionFor({ + line: 1, + column: 1, + source: 'http://example.com/bar.js' + }); + assert.equal(pos.line, 2); + assert.equal(pos.column, 2); + + pos = smc.originalPositionFor({ + line: 4, + column: 4 + }); + assert.equal(pos.line, 2); + assert.equal(pos.column, 2); + assert.equal(pos.source, 'http://example.com/baz.js'); + assert.equal(pos.name, 'dirtMcGirt'); + + pos = smc.generatedPositionFor({ + line: 2, + column: 2, + source: 'http://example.com/baz.js' + }); + assert.equal(pos.line, 4); + assert.equal(pos.column, 4); + }; + + exports['test issue #191'] = function (assert) { + var generator = new SourceMapGenerator({ file: 'a.css' }); + generator.addMapping({ + source: 'b.css', + original: { + line: 1, + column: 0 + }, + generated: { + line: 1, + column: 0 + } + }); + + // Create a SourceMapConsumer from the SourceMapGenerator, ... + var consumer = SourceMapConsumer.fromSourceMap(generator); + // ... and then try and use the SourceMapGenerator again. This should not + // throw. + generator.toJSON(); + + assert.ok(true, "Using a SourceMapGenerator again after creating a " + + "SourceMapConsumer from it should not throw"); + }; + + exports['test sources where their prefix is the source root: issue #199'] = function (assert) { + var testSourceMap = { + "version": 3, + "sources": ["/source/app/app/app.js"], + "names": ["System"], + "mappings": "AAAAA", + "file": "app/app.js", + "sourcesContent": ["'use strict';"], + "sourceRoot":"/source/" + }; + + var consumer = new SourceMapConsumer(testSourceMap); + + function consumerHasSource(s) { + assert.ok(consumer.sourceContentFor(s)); + } + + consumer.sources.forEach(consumerHasSource); + testSourceMap.sources.forEach(consumerHasSource); + }; + + exports['test sources where their prefix is the source root and the source root is a url: issue #199'] = function (assert) { + var testSourceMap = { + "version": 3, + "sources": ["http://example.com/source/app/app/app.js"], + "names": ["System"], + "mappings": "AAAAA", + "sourcesContent": ["'use strict';"], + "sourceRoot":"http://example.com/source/" + }; + + var consumer = new SourceMapConsumer(testSourceMap); + + function consumerHasSource(s) { + assert.ok(consumer.sourceContentFor(s)); + } + + consumer.sources.forEach(consumerHasSource); + testSourceMap.sources.forEach(consumerHasSource); + }; + } + + +/***/ }, +/* 1 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var util = __webpack_require__(2); + + // This is a test mapping which maps functions from two different files + // (one.js and two.js) to a minified generated source. + // + // Here is one.js: + // + // ONE.foo = function (bar) { + // return baz(bar); + // }; + // + // Here is two.js: + // + // TWO.inc = function (n) { + // return n + 1; + // }; + // + // And here is the generated code (min.js): + // + // ONE.foo=function(a){return baz(a);}; + // TWO.inc=function(a){return a+1;}; + exports.testGeneratedCode = " ONE.foo=function(a){return baz(a);};\n"+ + " TWO.inc=function(a){return a+1;};"; + exports.testMap = { + version: 3, + file: 'min.js', + names: ['bar', 'baz', 'n'], + sources: ['one.js', 'two.js'], + sourceRoot: '/the/root', + mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA' + }; + exports.testMapNoSourceRoot = { + version: 3, + file: 'min.js', + names: ['bar', 'baz', 'n'], + sources: ['one.js', 'two.js'], + mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA' + }; + exports.testMapEmptySourceRoot = { + version: 3, + file: 'min.js', + names: ['bar', 'baz', 'n'], + sources: ['one.js', 'two.js'], + sourceRoot: '', + mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA' + }; + // This mapping is identical to above, but uses the indexed format instead. + exports.indexedTestMap = { + version: 3, + file: 'min.js', + sections: [ + { + offset: { + line: 0, + column: 0 + }, + map: { + version: 3, + sources: [ + "one.js" + ], + sourcesContent: [ + ' ONE.foo = function (bar) {\n' + + ' return baz(bar);\n' + + ' };', + ], + names: [ + "bar", + "baz" + ], + mappings: "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID", + file: "min.js", + sourceRoot: "/the/root" + } + }, + { + offset: { + line: 1, + column: 0 + }, + map: { + version: 3, + sources: [ + "two.js" + ], + sourcesContent: [ + ' TWO.inc = function (n) {\n' + + ' return n + 1;\n' + + ' };' + ], + names: [ + "n" + ], + mappings: "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOA", + file: "min.js", + sourceRoot: "/the/root" + } + } + ] + }; + exports.indexedTestMapDifferentSourceRoots = { + version: 3, + file: 'min.js', + sections: [ + { + offset: { + line: 0, + column: 0 + }, + map: { + version: 3, + sources: [ + "one.js" + ], + sourcesContent: [ + ' ONE.foo = function (bar) {\n' + + ' return baz(bar);\n' + + ' };', + ], + names: [ + "bar", + "baz" + ], + mappings: "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID", + file: "min.js", + sourceRoot: "/the/root" + } + }, + { + offset: { + line: 1, + column: 0 + }, + map: { + version: 3, + sources: [ + "two.js" + ], + sourcesContent: [ + ' TWO.inc = function (n) {\n' + + ' return n + 1;\n' + + ' };' + ], + names: [ + "n" + ], + mappings: "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOA", + file: "min.js", + sourceRoot: "/different/root" + } + } + ] + }; + exports.testMapWithSourcesContent = { + version: 3, + file: 'min.js', + names: ['bar', 'baz', 'n'], + sources: ['one.js', 'two.js'], + sourcesContent: [ + ' ONE.foo = function (bar) {\n' + + ' return baz(bar);\n' + + ' };', + ' TWO.inc = function (n) {\n' + + ' return n + 1;\n' + + ' };' + ], + sourceRoot: '/the/root', + mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA' + }; + exports.testMapRelativeSources = { + version: 3, + file: 'min.js', + names: ['bar', 'baz', 'n'], + sources: ['./one.js', './two.js'], + sourcesContent: [ + ' ONE.foo = function (bar) {\n' + + ' return baz(bar);\n' + + ' };', + ' TWO.inc = function (n) {\n' + + ' return n + 1;\n' + + ' };' + ], + sourceRoot: '/the/root', + mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA' + }; + exports.emptyMap = { + version: 3, + file: 'min.js', + names: [], + sources: [], + mappings: '' + }; + + + function assertMapping(generatedLine, generatedColumn, originalSource, + originalLine, originalColumn, name, bias, map, assert, + dontTestGenerated, dontTestOriginal) { + if (!dontTestOriginal) { + var origMapping = map.originalPositionFor({ + line: generatedLine, + column: generatedColumn, + bias: bias + }); + assert.equal(origMapping.name, name, + 'Incorrect name, expected ' + JSON.stringify(name) + + ', got ' + JSON.stringify(origMapping.name)); + assert.equal(origMapping.line, originalLine, + 'Incorrect line, expected ' + JSON.stringify(originalLine) + + ', got ' + JSON.stringify(origMapping.line)); + assert.equal(origMapping.column, originalColumn, + 'Incorrect column, expected ' + JSON.stringify(originalColumn) + + ', got ' + JSON.stringify(origMapping.column)); + + var expectedSource; + + if (originalSource && map.sourceRoot && originalSource.indexOf(map.sourceRoot) === 0) { + expectedSource = originalSource; + } else if (originalSource) { + expectedSource = map.sourceRoot + ? util.join(map.sourceRoot, originalSource) + : originalSource; + } else { + expectedSource = null; + } + + assert.equal(origMapping.source, expectedSource, + 'Incorrect source, expected ' + JSON.stringify(expectedSource) + + ', got ' + JSON.stringify(origMapping.source)); + } + + if (!dontTestGenerated) { + var genMapping = map.generatedPositionFor({ + source: originalSource, + line: originalLine, + column: originalColumn, + bias: bias + }); + assert.equal(genMapping.line, generatedLine, + 'Incorrect line, expected ' + JSON.stringify(generatedLine) + + ', got ' + JSON.stringify(genMapping.line)); + assert.equal(genMapping.column, generatedColumn, + 'Incorrect column, expected ' + JSON.stringify(generatedColumn) + + ', got ' + JSON.stringify(genMapping.column)); + } + } + exports.assertMapping = assertMapping; + + function assertEqualMaps(assert, actualMap, expectedMap) { + assert.equal(actualMap.version, expectedMap.version, "version mismatch"); + assert.equal(actualMap.file, expectedMap.file, "file mismatch"); + assert.equal(actualMap.names.length, + expectedMap.names.length, + "names length mismatch: " + + actualMap.names.join(", ") + " != " + expectedMap.names.join(", ")); + for (var i = 0; i < actualMap.names.length; i++) { + assert.equal(actualMap.names[i], + expectedMap.names[i], + "names[" + i + "] mismatch: " + + actualMap.names.join(", ") + " != " + expectedMap.names.join(", ")); + } + assert.equal(actualMap.sources.length, + expectedMap.sources.length, + "sources length mismatch: " + + actualMap.sources.join(", ") + " != " + expectedMap.sources.join(", ")); + for (var i = 0; i < actualMap.sources.length; i++) { + assert.equal(actualMap.sources[i], + expectedMap.sources[i], + "sources[" + i + "] length mismatch: " + + actualMap.sources.join(", ") + " != " + expectedMap.sources.join(", ")); + } + assert.equal(actualMap.sourceRoot, + expectedMap.sourceRoot, + "sourceRoot mismatch: " + + actualMap.sourceRoot + " != " + expectedMap.sourceRoot); + assert.equal(actualMap.mappings, expectedMap.mappings, + "mappings mismatch:\nActual: " + actualMap.mappings + "\nExpected: " + expectedMap.mappings); + if (actualMap.sourcesContent) { + assert.equal(actualMap.sourcesContent.length, + expectedMap.sourcesContent.length, + "sourcesContent length mismatch"); + for (var i = 0; i < actualMap.sourcesContent.length; i++) { + assert.equal(actualMap.sourcesContent[i], + expectedMap.sourcesContent[i], + "sourcesContent[" + i + "] mismatch"); + } + } + } + exports.assertEqualMaps = assertEqualMaps; + } + + +/***/ }, +/* 2 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + /** + * This is a helper function for getting values from parameter/options + * objects. + * + * @param args The object we are extracting values from + * @param name The name of the property we are getting. + * @param defaultValue An optional value to return if the property is missing + * from the object. If this is not specified and the property is missing, an + * error will be thrown. + */ + function getArg(aArgs, aName, aDefaultValue) { + if (aName in aArgs) { + return aArgs[aName]; + } else if (arguments.length === 3) { + return aDefaultValue; + } else { + throw new Error('"' + aName + '" is a required argument.'); + } + } + exports.getArg = getArg; + + var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.]*)(?::(\d+))?(\S*)$/; + var dataUrlRegexp = /^data:.+\,.+$/; + + function urlParse(aUrl) { + var match = aUrl.match(urlRegexp); + if (!match) { + return null; + } + return { + scheme: match[1], + auth: match[2], + host: match[3], + port: match[4], + path: match[5] + }; + } + exports.urlParse = urlParse; + + function urlGenerate(aParsedUrl) { + var url = ''; + if (aParsedUrl.scheme) { + url += aParsedUrl.scheme + ':'; + } + url += '//'; + if (aParsedUrl.auth) { + url += aParsedUrl.auth + '@'; + } + if (aParsedUrl.host) { + url += aParsedUrl.host; + } + if (aParsedUrl.port) { + url += ":" + aParsedUrl.port + } + if (aParsedUrl.path) { + url += aParsedUrl.path; + } + return url; + } + exports.urlGenerate = urlGenerate; + + /** + * Normalizes a path, or the path portion of a URL: + * + * - Replaces consequtive slashes with one slash. + * - Removes unnecessary '.' parts. + * - Removes unnecessary '/..' parts. + * + * Based on code in the Node.js 'path' core module. + * + * @param aPath The path or url to normalize. + */ + function normalize(aPath) { + var path = aPath; + var url = urlParse(aPath); + if (url) { + if (!url.path) { + return aPath; + } + path = url.path; + } + var isAbsolute = exports.isAbsolute(path); + + var parts = path.split(/\/+/); + for (var part, up = 0, i = parts.length - 1; i >= 0; i--) { + part = parts[i]; + if (part === '.') { + parts.splice(i, 1); + } else if (part === '..') { + up++; + } else if (up > 0) { + if (part === '') { + // The first part is blank if the path is absolute. Trying to go + // above the root is a no-op. Therefore we can remove all '..' parts + // directly after the root. + parts.splice(i + 1, up); + up = 0; + } else { + parts.splice(i, 2); + up--; + } + } + } + path = parts.join('/'); + + if (path === '') { + path = isAbsolute ? '/' : '.'; + } + + if (url) { + url.path = path; + return urlGenerate(url); + } + return path; + } + exports.normalize = normalize; + + /** + * Joins two paths/URLs. + * + * @param aRoot The root path or URL. + * @param aPath The path or URL to be joined with the root. + * + * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a + * scheme-relative URL: Then the scheme of aRoot, if any, is prepended + * first. + * - Otherwise aPath is a path. If aRoot is a URL, then its path portion + * is updated with the result and aRoot is returned. Otherwise the result + * is returned. + * - If aPath is absolute, the result is aPath. + * - Otherwise the two paths are joined with a slash. + * - Joining for example 'http://' and 'www.example.com' is also supported. + */ + function join(aRoot, aPath) { + if (aRoot === "") { + aRoot = "."; + } + if (aPath === "") { + aPath = "."; + } + var aPathUrl = urlParse(aPath); + var aRootUrl = urlParse(aRoot); + if (aRootUrl) { + aRoot = aRootUrl.path || '/'; + } + + // `join(foo, '//www.example.org')` + if (aPathUrl && !aPathUrl.scheme) { + if (aRootUrl) { + aPathUrl.scheme = aRootUrl.scheme; + } + return urlGenerate(aPathUrl); + } + + if (aPathUrl || aPath.match(dataUrlRegexp)) { + return aPath; + } + + // `join('http://', 'www.example.com')` + if (aRootUrl && !aRootUrl.host && !aRootUrl.path) { + aRootUrl.host = aPath; + return urlGenerate(aRootUrl); + } + + var joined = aPath.charAt(0) === '/' + ? aPath + : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath); + + if (aRootUrl) { + aRootUrl.path = joined; + return urlGenerate(aRootUrl); + } + return joined; + } + exports.join = join; + + exports.isAbsolute = function (aPath) { + return aPath.charAt(0) === '/' || !!aPath.match(urlRegexp); + }; + + /** + * Make a path relative to a URL or another path. + * + * @param aRoot The root path or URL. + * @param aPath The path or URL to be made relative to aRoot. + */ + function relative(aRoot, aPath) { + if (aRoot === "") { + aRoot = "."; + } + + aRoot = aRoot.replace(/\/$/, ''); + + // It is possible for the path to be above the root. In this case, simply + // checking whether the root is a prefix of the path won't work. Instead, we + // need to remove components from the root one by one, until either we find + // a prefix that fits, or we run out of components to remove. + var level = 0; + while (aPath.indexOf(aRoot + '/') !== 0) { + var index = aRoot.lastIndexOf("/"); + if (index < 0) { + return aPath; + } + + // If the only part of the root that is left is the scheme (i.e. http://, + // file:///, etc.), one or more slashes (/), or simply nothing at all, we + // have exhausted all components, so the path is not relative to the root. + aRoot = aRoot.slice(0, index); + if (aRoot.match(/^([^\/]+:\/)?\/*$/)) { + return aPath; + } + + ++level; + } + + // Make sure we add a "../" for each component we removed from the root. + return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1); + } + exports.relative = relative; + + /** + * Because behavior goes wacky when you set `__proto__` on objects, we + * have to prefix all the strings in our set with an arbitrary character. + * + * See https://github.com/mozilla/source-map/pull/31 and + * https://github.com/mozilla/source-map/issues/30 + * + * @param String aStr + */ + function toSetString(aStr) { + return '$' + aStr; + } + exports.toSetString = toSetString; + + function fromSetString(aStr) { + return aStr.substr(1); + } + exports.fromSetString = fromSetString; + + /** + * Comparator between two mappings where the original positions are compared. + * + * Optionally pass in `true` as `onlyCompareGenerated` to consider two + * mappings with the same original source/line/column, but different generated + * line and column the same. Useful when searching for a mapping with a + * stubbed out mapping. + */ + function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) { + var cmp = mappingA.source - mappingB.source; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0 || onlyCompareOriginal) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + return mappingA.name - mappingB.name; + } + exports.compareByOriginalPositions = compareByOriginalPositions; + + /** + * Comparator between two mappings with deflated source and name indices where + * the generated positions are compared. + * + * Optionally pass in `true` as `onlyCompareGenerated` to consider two + * mappings with the same generated line and column, but different + * source/name/original line and column the same. Useful when searching for a + * mapping with a stubbed out mapping. + */ + function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) { + var cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0 || onlyCompareGenerated) { + return cmp; + } + + cmp = mappingA.source - mappingB.source; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0) { + return cmp; + } + + return mappingA.name - mappingB.name; + } + exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated; + + function strcmp(aStr1, aStr2) { + if (aStr1 === aStr2) { + return 0; + } + + if (aStr1 > aStr2) { + return 1; + } + + return -1; + } + + /** + * Comparator between two mappings with inflated source and name strings where + * the generated positions are compared. + */ + function compareByGeneratedPositionsInflated(mappingA, mappingB) { + var cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0) { + return cmp; + } + + cmp = strcmp(mappingA.source, mappingB.source); + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0) { + return cmp; + } + + return strcmp(mappingA.name, mappingB.name); + } + exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated; + } + + +/***/ }, +/* 3 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var util = __webpack_require__(2); + var binarySearch = __webpack_require__(4); + var ArraySet = __webpack_require__(5).ArraySet; + var base64VLQ = __webpack_require__(6); + var quickSort = __webpack_require__(8).quickSort; + + function SourceMapConsumer(aSourceMap) { + var sourceMap = aSourceMap; + if (typeof aSourceMap === 'string') { + sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); + } + + return sourceMap.sections != null + ? new IndexedSourceMapConsumer(sourceMap) + : new BasicSourceMapConsumer(sourceMap); + } + + SourceMapConsumer.fromSourceMap = function(aSourceMap) { + return BasicSourceMapConsumer.fromSourceMap(aSourceMap); + } + + /** + * The version of the source mapping spec that we are consuming. + */ + SourceMapConsumer.prototype._version = 3; + + // `__generatedMappings` and `__originalMappings` are arrays that hold the + // parsed mapping coordinates from the source map's "mappings" attribute. They + // are lazily instantiated, accessed via the `_generatedMappings` and + // `_originalMappings` getters respectively, and we only parse the mappings + // and create these arrays once queried for a source location. We jump through + // these hoops because there can be many thousands of mappings, and parsing + // them is expensive, so we only want to do it if we must. + // + // Each object in the arrays is of the form: + // + // { + // generatedLine: The line number in the generated code, + // generatedColumn: The column number in the generated code, + // source: The path to the original source file that generated this + // chunk of code, + // originalLine: The line number in the original source that + // corresponds to this chunk of generated code, + // originalColumn: The column number in the original source that + // corresponds to this chunk of generated code, + // name: The name of the original symbol which generated this chunk of + // code. + // } + // + // All properties except for `generatedLine` and `generatedColumn` can be + // `null`. + // + // `_generatedMappings` is ordered by the generated positions. + // + // `_originalMappings` is ordered by the original positions. + + SourceMapConsumer.prototype.__generatedMappings = null; + Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', { + get: function () { + if (!this.__generatedMappings) { + this._parseMappings(this._mappings, this.sourceRoot); + } + + return this.__generatedMappings; + } + }); + + SourceMapConsumer.prototype.__originalMappings = null; + Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', { + get: function () { + if (!this.__originalMappings) { + this._parseMappings(this._mappings, this.sourceRoot); + } + + return this.__originalMappings; + } + }); + + SourceMapConsumer.prototype._charIsMappingSeparator = + function SourceMapConsumer_charIsMappingSeparator(aStr, index) { + var c = aStr.charAt(index); + return c === ";" || c === ","; + }; + + /** + * Parse the mappings in a string in to a data structure which we can easily + * query (the ordered arrays in the `this.__generatedMappings` and + * `this.__originalMappings` properties). + */ + SourceMapConsumer.prototype._parseMappings = + function SourceMapConsumer_parseMappings(aStr, aSourceRoot) { + throw new Error("Subclasses must implement _parseMappings"); + }; + + SourceMapConsumer.GENERATED_ORDER = 1; + SourceMapConsumer.ORIGINAL_ORDER = 2; + + SourceMapConsumer.GREATEST_LOWER_BOUND = 1; + SourceMapConsumer.LEAST_UPPER_BOUND = 2; + + /** + * Iterate over each mapping between an original source/line/column and a + * generated line/column in this source map. + * + * @param Function aCallback + * The function that is called with each mapping. + * @param Object aContext + * Optional. If specified, this object will be the value of `this` every + * time that `aCallback` is called. + * @param aOrder + * Either `SourceMapConsumer.GENERATED_ORDER` or + * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to + * iterate over the mappings sorted by the generated file's line/column + * order or the original's source/line/column order, respectively. Defaults to + * `SourceMapConsumer.GENERATED_ORDER`. + */ + SourceMapConsumer.prototype.eachMapping = + function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) { + var context = aContext || null; + var order = aOrder || SourceMapConsumer.GENERATED_ORDER; + + var mappings; + switch (order) { + case SourceMapConsumer.GENERATED_ORDER: + mappings = this._generatedMappings; + break; + case SourceMapConsumer.ORIGINAL_ORDER: + mappings = this._originalMappings; + break; + default: + throw new Error("Unknown order of iteration."); + } + + var sourceRoot = this.sourceRoot; + mappings.map(function (mapping) { + var source = mapping.source === null ? null : this._sources.at(mapping.source); + if (source != null && sourceRoot != null) { + source = util.join(sourceRoot, source); + } + return { + source: source, + generatedLine: mapping.generatedLine, + generatedColumn: mapping.generatedColumn, + originalLine: mapping.originalLine, + originalColumn: mapping.originalColumn, + name: mapping.name === null ? null : this._names.at(mapping.name) + }; + }, this).forEach(aCallback, context); + }; + + /** + * Returns all generated line and column information for the original source, + * line, and column provided. If no column is provided, returns all mappings + * corresponding to a either the line we are searching for or the next + * closest line that has any mappings. Otherwise, returns all mappings + * corresponding to the given line and either the column we are searching for + * or the next closest column that has any offsets. + * + * The only argument is an object with the following properties: + * + * - source: The filename of the original source. + * - line: The line number in the original source. + * - column: Optional. the column number in the original source. + * + * and an array of objects is returned, each with the following properties: + * + * - line: The line number in the generated source, or null. + * - column: The column number in the generated source, or null. + */ + SourceMapConsumer.prototype.allGeneratedPositionsFor = + function SourceMapConsumer_allGeneratedPositionsFor(aArgs) { + var line = util.getArg(aArgs, 'line'); + + // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping + // returns the index of the closest mapping less than the needle. By + // setting needle.originalColumn to 0, we thus find the last mapping for + // the given line, provided such a mapping exists. + var needle = { + source: util.getArg(aArgs, 'source'), + originalLine: line, + originalColumn: util.getArg(aArgs, 'column', 0) + }; + + if (this.sourceRoot != null) { + needle.source = util.relative(this.sourceRoot, needle.source); + } + if (!this._sources.has(needle.source)) { + return []; + } + needle.source = this._sources.indexOf(needle.source); + + var mappings = []; + + var index = this._findMapping(needle, + this._originalMappings, + "originalLine", + "originalColumn", + util.compareByOriginalPositions, + binarySearch.LEAST_UPPER_BOUND); + if (index >= 0) { + var mapping = this._originalMappings[index]; + + if (aArgs.column === undefined) { + var originalLine = mapping.originalLine; + + // Iterate until either we run out of mappings, or we run into + // a mapping for a different line than the one we found. Since + // mappings are sorted, this is guaranteed to find all mappings for + // the line we found. + while (mapping && mapping.originalLine === originalLine) { + mappings.push({ + line: util.getArg(mapping, 'generatedLine', null), + column: util.getArg(mapping, 'generatedColumn', null), + lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) + }); + + mapping = this._originalMappings[++index]; + } + } else { + var originalColumn = mapping.originalColumn; + + // Iterate until either we run out of mappings, or we run into + // a mapping for a different line than the one we were searching for. + // Since mappings are sorted, this is guaranteed to find all mappings for + // the line we are searching for. + while (mapping && + mapping.originalLine === line && + mapping.originalColumn == originalColumn) { + mappings.push({ + line: util.getArg(mapping, 'generatedLine', null), + column: util.getArg(mapping, 'generatedColumn', null), + lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) + }); + + mapping = this._originalMappings[++index]; + } + } + } + + return mappings; + }; + + exports.SourceMapConsumer = SourceMapConsumer; + + /** + * A BasicSourceMapConsumer instance represents a parsed source map which we can + * query for information about the original file positions by giving it a file + * position in the generated source. + * + * The only parameter is the raw source map (either as a JSON string, or + * already parsed to an object). According to the spec, source maps have the + * following attributes: + * + * - version: Which version of the source map spec this map is following. + * - sources: An array of URLs to the original source files. + * - names: An array of identifiers which can be referrenced by individual mappings. + * - sourceRoot: Optional. The URL root from which all sources are relative. + * - sourcesContent: Optional. An array of contents of the original source files. + * - mappings: A string of base64 VLQs which contain the actual mappings. + * - file: Optional. The generated file this source map is associated with. + * + * Here is an example source map, taken from the source map spec[0]: + * + * { + * version : 3, + * file: "out.js", + * sourceRoot : "", + * sources: ["foo.js", "bar.js"], + * names: ["src", "maps", "are", "fun"], + * mappings: "AA,AB;;ABCDE;" + * } + * + * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1# + */ + function BasicSourceMapConsumer(aSourceMap) { + var sourceMap = aSourceMap; + if (typeof aSourceMap === 'string') { + sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); + } + + var version = util.getArg(sourceMap, 'version'); + var sources = util.getArg(sourceMap, 'sources'); + // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which + // requires the array) to play nice here. + var names = util.getArg(sourceMap, 'names', []); + var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null); + var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null); + var mappings = util.getArg(sourceMap, 'mappings'); + var file = util.getArg(sourceMap, 'file', null); + + // Once again, Sass deviates from the spec and supplies the version as a + // string rather than a number, so we use loose equality checking here. + if (version != this._version) { + throw new Error('Unsupported version: ' + version); + } + + sources = sources + // Some source maps produce relative source paths like "./foo.js" instead of + // "foo.js". Normalize these first so that future comparisons will succeed. + // See bugzil.la/1090768. + .map(util.normalize) + // Always ensure that absolute sources are internally stored relative to + // the source root, if the source root is absolute. Not doing this would + // be particularly problematic when the source root is a prefix of the + // source (valid, but why??). See github issue #199 and bugzil.la/1188982. + .map(function (source) { + return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source) + ? util.relative(sourceRoot, source) + : source; + }); + + // Pass `true` below to allow duplicate names and sources. While source maps + // are intended to be compressed and deduplicated, the TypeScript compiler + // sometimes generates source maps with duplicates in them. See Github issue + // #72 and bugzil.la/889492. + this._names = ArraySet.fromArray(names, true); + this._sources = ArraySet.fromArray(sources, true); + + this.sourceRoot = sourceRoot; + this.sourcesContent = sourcesContent; + this._mappings = mappings; + this.file = file; + } + + BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype); + BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer; + + /** + * Create a BasicSourceMapConsumer from a SourceMapGenerator. + * + * @param SourceMapGenerator aSourceMap + * The source map that will be consumed. + * @returns BasicSourceMapConsumer + */ + BasicSourceMapConsumer.fromSourceMap = + function SourceMapConsumer_fromSourceMap(aSourceMap) { + var smc = Object.create(BasicSourceMapConsumer.prototype); + + var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true); + var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true); + smc.sourceRoot = aSourceMap._sourceRoot; + smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(), + smc.sourceRoot); + smc.file = aSourceMap._file; + + // Because we are modifying the entries (by converting string sources and + // names to indices into the sources and names ArraySets), we have to make + // a copy of the entry or else bad things happen. Shared mutable state + // strikes again! See github issue #191. + + var generatedMappings = aSourceMap._mappings.toArray().slice(); + var destGeneratedMappings = smc.__generatedMappings = []; + var destOriginalMappings = smc.__originalMappings = []; + + for (var i = 0, length = generatedMappings.length; i < length; i++) { + var srcMapping = generatedMappings[i]; + var destMapping = new Mapping; + destMapping.generatedLine = srcMapping.generatedLine; + destMapping.generatedColumn = srcMapping.generatedColumn; + + if (srcMapping.source) { + destMapping.source = sources.indexOf(srcMapping.source); + destMapping.originalLine = srcMapping.originalLine; + destMapping.originalColumn = srcMapping.originalColumn; + + if (srcMapping.name) { + destMapping.name = names.indexOf(srcMapping.name); + } + + destOriginalMappings.push(destMapping); + } + + destGeneratedMappings.push(destMapping); + } + + quickSort(smc.__originalMappings, util.compareByOriginalPositions); + + return smc; + }; + + /** + * The version of the source mapping spec that we are consuming. + */ + BasicSourceMapConsumer.prototype._version = 3; + + /** + * The list of original sources. + */ + Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', { + get: function () { + return this._sources.toArray().map(function (s) { + return this.sourceRoot != null ? util.join(this.sourceRoot, s) : s; + }, this); + } + }); + + /** + * Provide the JIT with a nice shape / hidden class. + */ + function Mapping() { + this.generatedLine = 0; + this.generatedColumn = 0; + this.source = null; + this.originalLine = null; + this.originalColumn = null; + this.name = null; + } + + /** + * Parse the mappings in a string in to a data structure which we can easily + * query (the ordered arrays in the `this.__generatedMappings` and + * `this.__originalMappings` properties). + */ + BasicSourceMapConsumer.prototype._parseMappings = + function SourceMapConsumer_parseMappings(aStr, aSourceRoot) { + var generatedLine = 1; + var previousGeneratedColumn = 0; + var previousOriginalLine = 0; + var previousOriginalColumn = 0; + var previousSource = 0; + var previousName = 0; + var length = aStr.length; + var index = 0; + var cachedSegments = {}; + var temp = {}; + var originalMappings = []; + var generatedMappings = []; + var mapping, str, segment, end, value; + + while (index < length) { + if (aStr.charAt(index) === ';') { + generatedLine++; + index++; + previousGeneratedColumn = 0; + } + else if (aStr.charAt(index) === ',') { + index++; + } + else { + mapping = new Mapping(); + mapping.generatedLine = generatedLine; + + // Because each offset is encoded relative to the previous one, + // many segments often have the same encoding. We can exploit this + // fact by caching the parsed variable length fields of each segment, + // allowing us to avoid a second parse if we encounter the same + // segment again. + for (end = index; end < length; end++) { + if (this._charIsMappingSeparator(aStr, end)) { + break; + } + } + str = aStr.slice(index, end); + + segment = cachedSegments[str]; + if (segment) { + index += str.length; + } else { + segment = []; + while (index < end) { + base64VLQ.decode(aStr, index, temp); + value = temp.value; + index = temp.rest; + segment.push(value); + } + + if (segment.length === 2) { + throw new Error('Found a source, but no line and column'); + } + + if (segment.length === 3) { + throw new Error('Found a source and line, but no column'); + } + + cachedSegments[str] = segment; + } + + // Generated column. + mapping.generatedColumn = previousGeneratedColumn + segment[0]; + previousGeneratedColumn = mapping.generatedColumn; + + if (segment.length > 1) { + // Original source. + mapping.source = previousSource + segment[1]; + previousSource += segment[1]; + + // Original line. + mapping.originalLine = previousOriginalLine + segment[2]; + previousOriginalLine = mapping.originalLine; + // Lines are stored 0-based + mapping.originalLine += 1; + + // Original column. + mapping.originalColumn = previousOriginalColumn + segment[3]; + previousOriginalColumn = mapping.originalColumn; + + if (segment.length > 4) { + // Original name. + mapping.name = previousName + segment[4]; + previousName += segment[4]; + } + } + + generatedMappings.push(mapping); + if (typeof mapping.originalLine === 'number') { + originalMappings.push(mapping); + } + } + } + + quickSort(generatedMappings, util.compareByGeneratedPositionsDeflated); + this.__generatedMappings = generatedMappings; + + quickSort(originalMappings, util.compareByOriginalPositions); + this.__originalMappings = originalMappings; + }; + + /** + * Find the mapping that best matches the hypothetical "needle" mapping that + * we are searching for in the given "haystack" of mappings. + */ + BasicSourceMapConsumer.prototype._findMapping = + function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName, + aColumnName, aComparator, aBias) { + // To return the position we are searching for, we must first find the + // mapping for the given position and then return the opposite position it + // points to. Because the mappings are sorted, we can use binary search to + // find the best mapping. + + if (aNeedle[aLineName] <= 0) { + throw new TypeError('Line must be greater than or equal to 1, got ' + + aNeedle[aLineName]); + } + if (aNeedle[aColumnName] < 0) { + throw new TypeError('Column must be greater than or equal to 0, got ' + + aNeedle[aColumnName]); + } + + return binarySearch.search(aNeedle, aMappings, aComparator, aBias); + }; + + /** + * Compute the last column for each generated mapping. The last column is + * inclusive. + */ + BasicSourceMapConsumer.prototype.computeColumnSpans = + function SourceMapConsumer_computeColumnSpans() { + for (var index = 0; index < this._generatedMappings.length; ++index) { + var mapping = this._generatedMappings[index]; + + // Mappings do not contain a field for the last generated columnt. We + // can come up with an optimistic estimate, however, by assuming that + // mappings are contiguous (i.e. given two consecutive mappings, the + // first mapping ends where the second one starts). + if (index + 1 < this._generatedMappings.length) { + var nextMapping = this._generatedMappings[index + 1]; + + if (mapping.generatedLine === nextMapping.generatedLine) { + mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1; + continue; + } + } + + // The last mapping for each line spans the entire line. + mapping.lastGeneratedColumn = Infinity; + } + }; + + /** + * Returns the original source, line, and column information for the generated + * source's line and column positions provided. The only argument is an object + * with the following properties: + * + * - line: The line number in the generated source. + * - column: The column number in the generated source. + * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or + * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. + * + * and an object is returned with the following properties: + * + * - source: The original source file, or null. + * - line: The line number in the original source, or null. + * - column: The column number in the original source, or null. + * - name: The original identifier, or null. + */ + BasicSourceMapConsumer.prototype.originalPositionFor = + function SourceMapConsumer_originalPositionFor(aArgs) { + var needle = { + generatedLine: util.getArg(aArgs, 'line'), + generatedColumn: util.getArg(aArgs, 'column') + }; + + var index = this._findMapping( + needle, + this._generatedMappings, + "generatedLine", + "generatedColumn", + util.compareByGeneratedPositionsDeflated, + util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND) + ); + + if (index >= 0) { + var mapping = this._generatedMappings[index]; + + if (mapping.generatedLine === needle.generatedLine) { + var source = util.getArg(mapping, 'source', null); + if (source !== null) { + source = this._sources.at(source); + if (this.sourceRoot != null) { + source = util.join(this.sourceRoot, source); + } + } + var name = util.getArg(mapping, 'name', null); + if (name !== null) { + name = this._names.at(name); + } + return { + source: source, + line: util.getArg(mapping, 'originalLine', null), + column: util.getArg(mapping, 'originalColumn', null), + name: name + }; + } + } + + return { + source: null, + line: null, + column: null, + name: null + }; + }; + + /** + * Return true if we have the source content for every source in the source + * map, false otherwise. + */ + BasicSourceMapConsumer.prototype.hasContentsOfAllSources = + function BasicSourceMapConsumer_hasContentsOfAllSources() { + if (!this.sourcesContent) { + return false; + } + return this.sourcesContent.length >= this._sources.size() && + !this.sourcesContent.some(function (sc) { return sc == null; }); + }; + + /** + * Returns the original source content. The only argument is the url of the + * original source file. Returns null if no original source content is + * availible. + */ + BasicSourceMapConsumer.prototype.sourceContentFor = + function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) { + if (!this.sourcesContent) { + return null; + } + + if (this.sourceRoot != null) { + aSource = util.relative(this.sourceRoot, aSource); + } + + if (this._sources.has(aSource)) { + return this.sourcesContent[this._sources.indexOf(aSource)]; + } + + var url; + if (this.sourceRoot != null + && (url = util.urlParse(this.sourceRoot))) { + // XXX: file:// URIs and absolute paths lead to unexpected behavior for + // many users. We can help them out when they expect file:// URIs to + // behave like it would if they were running a local HTTP server. See + // https://bugzilla.mozilla.org/show_bug.cgi?id=885597. + var fileUriAbsPath = aSource.replace(/^file:\/\//, ""); + if (url.scheme == "file" + && this._sources.has(fileUriAbsPath)) { + return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)] + } + + if ((!url.path || url.path == "/") + && this._sources.has("/" + aSource)) { + return this.sourcesContent[this._sources.indexOf("/" + aSource)]; + } + } + + // This function is used recursively from + // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we + // don't want to throw if we can't find the source - we just want to + // return null, so we provide a flag to exit gracefully. + if (nullOnMissing) { + return null; + } + else { + throw new Error('"' + aSource + '" is not in the SourceMap.'); + } + }; + + /** + * Returns the generated line and column information for the original source, + * line, and column positions provided. The only argument is an object with + * the following properties: + * + * - source: The filename of the original source. + * - line: The line number in the original source. + * - column: The column number in the original source. + * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or + * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. + * + * and an object is returned with the following properties: + * + * - line: The line number in the generated source, or null. + * - column: The column number in the generated source, or null. + */ + BasicSourceMapConsumer.prototype.generatedPositionFor = + function SourceMapConsumer_generatedPositionFor(aArgs) { + var source = util.getArg(aArgs, 'source'); + if (this.sourceRoot != null) { + source = util.relative(this.sourceRoot, source); + } + if (!this._sources.has(source)) { + return { + line: null, + column: null, + lastColumn: null + }; + } + source = this._sources.indexOf(source); + + var needle = { + source: source, + originalLine: util.getArg(aArgs, 'line'), + originalColumn: util.getArg(aArgs, 'column') + }; + + var index = this._findMapping( + needle, + this._originalMappings, + "originalLine", + "originalColumn", + util.compareByOriginalPositions, + util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND) + ); + + if (index >= 0) { + var mapping = this._originalMappings[index]; + + if (mapping.source === needle.source) { + return { + line: util.getArg(mapping, 'generatedLine', null), + column: util.getArg(mapping, 'generatedColumn', null), + lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) + }; + } + } + + return { + line: null, + column: null, + lastColumn: null + }; + }; + + exports.BasicSourceMapConsumer = BasicSourceMapConsumer; + + /** + * An IndexedSourceMapConsumer instance represents a parsed source map which + * we can query for information. It differs from BasicSourceMapConsumer in + * that it takes "indexed" source maps (i.e. ones with a "sections" field) as + * input. + * + * The only parameter is a raw source map (either as a JSON string, or already + * parsed to an object). According to the spec for indexed source maps, they + * have the following attributes: + * + * - version: Which version of the source map spec this map is following. + * - file: Optional. The generated file this source map is associated with. + * - sections: A list of section definitions. + * + * Each value under the "sections" field has two fields: + * - offset: The offset into the original specified at which this section + * begins to apply, defined as an object with a "line" and "column" + * field. + * - map: A source map definition. This source map could also be indexed, + * but doesn't have to be. + * + * Instead of the "map" field, it's also possible to have a "url" field + * specifying a URL to retrieve a source map from, but that's currently + * unsupported. + * + * Here's an example source map, taken from the source map spec[0], but + * modified to omit a section which uses the "url" field. + * + * { + * version : 3, + * file: "app.js", + * sections: [{ + * offset: {line:100, column:10}, + * map: { + * version : 3, + * file: "section.js", + * sources: ["foo.js", "bar.js"], + * names: ["src", "maps", "are", "fun"], + * mappings: "AAAA,E;;ABCDE;" + * } + * }], + * } + * + * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt + */ + function IndexedSourceMapConsumer(aSourceMap) { + var sourceMap = aSourceMap; + if (typeof aSourceMap === 'string') { + sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); + } + + var version = util.getArg(sourceMap, 'version'); + var sections = util.getArg(sourceMap, 'sections'); + + if (version != this._version) { + throw new Error('Unsupported version: ' + version); + } + + this._sources = new ArraySet(); + this._names = new ArraySet(); + + var lastOffset = { + line: -1, + column: 0 + }; + this._sections = sections.map(function (s) { + if (s.url) { + // The url field will require support for asynchronicity. + // See https://github.com/mozilla/source-map/issues/16 + throw new Error('Support for url field in sections not implemented.'); + } + var offset = util.getArg(s, 'offset'); + var offsetLine = util.getArg(offset, 'line'); + var offsetColumn = util.getArg(offset, 'column'); + + if (offsetLine < lastOffset.line || + (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) { + throw new Error('Section offsets must be ordered and non-overlapping.'); + } + lastOffset = offset; + + return { + generatedOffset: { + // The offset fields are 0-based, but we use 1-based indices when + // encoding/decoding from VLQ. + generatedLine: offsetLine + 1, + generatedColumn: offsetColumn + 1 + }, + consumer: new SourceMapConsumer(util.getArg(s, 'map')) + } + }); + } + + IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype); + IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer; + + /** + * The version of the source mapping spec that we are consuming. + */ + IndexedSourceMapConsumer.prototype._version = 3; + + /** + * The list of original sources. + */ + Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', { + get: function () { + var sources = []; + for (var i = 0; i < this._sections.length; i++) { + for (var j = 0; j < this._sections[i].consumer.sources.length; j++) { + sources.push(this._sections[i].consumer.sources[j]); + } + } + return sources; + } + }); + + /** + * Returns the original source, line, and column information for the generated + * source's line and column positions provided. The only argument is an object + * with the following properties: + * + * - line: The line number in the generated source. + * - column: The column number in the generated source. + * + * and an object is returned with the following properties: + * + * - source: The original source file, or null. + * - line: The line number in the original source, or null. + * - column: The column number in the original source, or null. + * - name: The original identifier, or null. + */ + IndexedSourceMapConsumer.prototype.originalPositionFor = + function IndexedSourceMapConsumer_originalPositionFor(aArgs) { + var needle = { + generatedLine: util.getArg(aArgs, 'line'), + generatedColumn: util.getArg(aArgs, 'column') + }; + + // Find the section containing the generated position we're trying to map + // to an original position. + var sectionIndex = binarySearch.search(needle, this._sections, + function(needle, section) { + var cmp = needle.generatedLine - section.generatedOffset.generatedLine; + if (cmp) { + return cmp; + } + + return (needle.generatedColumn - + section.generatedOffset.generatedColumn); + }); + var section = this._sections[sectionIndex]; + + if (!section) { + return { + source: null, + line: null, + column: null, + name: null + }; + } + + return section.consumer.originalPositionFor({ + line: needle.generatedLine - + (section.generatedOffset.generatedLine - 1), + column: needle.generatedColumn - + (section.generatedOffset.generatedLine === needle.generatedLine + ? section.generatedOffset.generatedColumn - 1 + : 0), + bias: aArgs.bias + }); + }; + + /** + * Return true if we have the source content for every source in the source + * map, false otherwise. + */ + IndexedSourceMapConsumer.prototype.hasContentsOfAllSources = + function IndexedSourceMapConsumer_hasContentsOfAllSources() { + return this._sections.every(function (s) { + return s.consumer.hasContentsOfAllSources(); + }); + }; + + /** + * Returns the original source content. The only argument is the url of the + * original source file. Returns null if no original source content is + * available. + */ + IndexedSourceMapConsumer.prototype.sourceContentFor = + function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) { + for (var i = 0; i < this._sections.length; i++) { + var section = this._sections[i]; + + var content = section.consumer.sourceContentFor(aSource, true); + if (content) { + return content; + } + } + if (nullOnMissing) { + return null; + } + else { + throw new Error('"' + aSource + '" is not in the SourceMap.'); + } + }; + + /** + * Returns the generated line and column information for the original source, + * line, and column positions provided. The only argument is an object with + * the following properties: + * + * - source: The filename of the original source. + * - line: The line number in the original source. + * - column: The column number in the original source. + * + * and an object is returned with the following properties: + * + * - line: The line number in the generated source, or null. + * - column: The column number in the generated source, or null. + */ + IndexedSourceMapConsumer.prototype.generatedPositionFor = + function IndexedSourceMapConsumer_generatedPositionFor(aArgs) { + for (var i = 0; i < this._sections.length; i++) { + var section = this._sections[i]; + + // Only consider this section if the requested source is in the list of + // sources of the consumer. + if (section.consumer.sources.indexOf(util.getArg(aArgs, 'source')) === -1) { + continue; + } + var generatedPosition = section.consumer.generatedPositionFor(aArgs); + if (generatedPosition) { + var ret = { + line: generatedPosition.line + + (section.generatedOffset.generatedLine - 1), + column: generatedPosition.column + + (section.generatedOffset.generatedLine === generatedPosition.line + ? section.generatedOffset.generatedColumn - 1 + : 0) + }; + return ret; + } + } + + return { + line: null, + column: null + }; + }; + + /** + * Parse the mappings in a string in to a data structure which we can easily + * query (the ordered arrays in the `this.__generatedMappings` and + * `this.__originalMappings` properties). + */ + IndexedSourceMapConsumer.prototype._parseMappings = + function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) { + this.__generatedMappings = []; + this.__originalMappings = []; + for (var i = 0; i < this._sections.length; i++) { + var section = this._sections[i]; + var sectionMappings = section.consumer._generatedMappings; + for (var j = 0; j < sectionMappings.length; j++) { + var mapping = sectionMappings[i]; + + var source = section.consumer._sources.at(mapping.source); + if (section.consumer.sourceRoot !== null) { + source = util.join(section.consumer.sourceRoot, source); + } + this._sources.add(source); + source = this._sources.indexOf(source); + + var name = section.consumer._names.at(mapping.name); + this._names.add(name); + name = this._names.indexOf(name); + + // The mappings coming from the consumer for the section have + // generated positions relative to the start of the section, so we + // need to offset them to be relative to the start of the concatenated + // generated file. + var adjustedMapping = { + source: source, + generatedLine: mapping.generatedLine + + (section.generatedOffset.generatedLine - 1), + generatedColumn: mapping.column + + (section.generatedOffset.generatedLine === mapping.generatedLine) + ? section.generatedOffset.generatedColumn - 1 + : 0, + originalLine: mapping.originalLine, + originalColumn: mapping.originalColumn, + name: name + }; + + this.__generatedMappings.push(adjustedMapping); + if (typeof adjustedMapping.originalLine === 'number') { + this.__originalMappings.push(adjustedMapping); + } + } + } + + quickSort(this.__generatedMappings, util.compareByGeneratedPositionsDeflated); + quickSort(this.__originalMappings, util.compareByOriginalPositions); + }; + + exports.IndexedSourceMapConsumer = IndexedSourceMapConsumer; + } + + +/***/ }, +/* 4 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + exports.GREATEST_LOWER_BOUND = 1; + exports.LEAST_UPPER_BOUND = 2; + + /** + * Recursive implementation of binary search. + * + * @param aLow Indices here and lower do not contain the needle. + * @param aHigh Indices here and higher do not contain the needle. + * @param aNeedle The element being searched for. + * @param aHaystack The non-empty array being searched. + * @param aCompare Function which takes two elements and returns -1, 0, or 1. + * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or + * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + */ + function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) { + // This function terminates when one of the following is true: + // + // 1. We find the exact element we are looking for. + // + // 2. We did not find the exact element, but we can return the index of + // the next-closest element. + // + // 3. We did not find the exact element, and there is no next-closest + // element than the one we are searching for, so we return -1. + var mid = Math.floor((aHigh - aLow) / 2) + aLow; + var cmp = aCompare(aNeedle, aHaystack[mid], true); + if (cmp === 0) { + // Found the element we are looking for. + return mid; + } + else if (cmp > 0) { + // Our needle is greater than aHaystack[mid]. + if (aHigh - mid > 1) { + // The element is in the upper half. + return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias); + } + + // The exact needle element was not found in this haystack. Determine if + // we are in termination case (3) or (2) and return the appropriate thing. + if (aBias == exports.LEAST_UPPER_BOUND) { + return aHigh < aHaystack.length ? aHigh : -1; + } else { + return mid; + } + } + else { + // Our needle is less than aHaystack[mid]. + if (mid - aLow > 1) { + // The element is in the lower half. + return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias); + } + + // we are in termination case (3) or (2) and return the appropriate thing. + if (aBias == exports.LEAST_UPPER_BOUND) { + return mid; + } else { + return aLow < 0 ? -1 : aLow; + } + } + } + + /** + * This is an implementation of binary search which will always try and return + * the index of the closest element if there is no exact hit. This is because + * mappings between original and generated line/col pairs are single points, + * and there is an implicit region between each of them, so a miss just means + * that you aren't on the very start of a region. + * + * @param aNeedle The element you are looking for. + * @param aHaystack The array that is being searched. + * @param aCompare A function which takes the needle and an element in the + * array and returns -1, 0, or 1 depending on whether the needle is less + * than, equal to, or greater than the element, respectively. + * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or + * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'. + */ + exports.search = function search(aNeedle, aHaystack, aCompare, aBias) { + if (aHaystack.length === 0) { + return -1; + } + + var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, + aCompare, aBias || exports.GREATEST_LOWER_BOUND); + if (index < 0) { + return -1; + } + + // We have found either the exact element, or the next-closest element than + // the one we are searching for. However, there may be more than one such + // element. Make sure we always return the smallest of these. + while (index - 1 >= 0) { + if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) { + break; + } + --index; + } + + return index; + }; + } + + +/***/ }, +/* 5 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var util = __webpack_require__(2); + + /** + * A data structure which is a combination of an array and a set. Adding a new + * member is O(1), testing for membership is O(1), and finding the index of an + * element is O(1). Removing elements from the set is not supported. Only + * strings are supported for membership. + */ + function ArraySet() { + this._array = []; + this._set = {}; + } + + /** + * Static method for creating ArraySet instances from an existing array. + */ + ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) { + var set = new ArraySet(); + for (var i = 0, len = aArray.length; i < len; i++) { + set.add(aArray[i], aAllowDuplicates); + } + return set; + }; + + /** + * Return how many unique items are in this ArraySet. If duplicates have been + * added, than those do not count towards the size. + * + * @returns Number + */ + ArraySet.prototype.size = function ArraySet_size() { + return Object.getOwnPropertyNames(this._set).length; + }; + + /** + * Add the given string to this set. + * + * @param String aStr + */ + ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) { + var sStr = util.toSetString(aStr); + var isDuplicate = this._set.hasOwnProperty(sStr); + var idx = this._array.length; + if (!isDuplicate || aAllowDuplicates) { + this._array.push(aStr); + } + if (!isDuplicate) { + this._set[sStr] = idx; + } + }; + + /** + * Is the given string a member of this set? + * + * @param String aStr + */ + ArraySet.prototype.has = function ArraySet_has(aStr) { + var sStr = util.toSetString(aStr); + return this._set.hasOwnProperty(sStr); + }; + + /** + * What is the index of the given string in the array? + * + * @param String aStr + */ + ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) { + var sStr = util.toSetString(aStr); + if (this._set.hasOwnProperty(sStr)) { + return this._set[sStr]; + } + throw new Error('"' + aStr + '" is not in the set.'); + }; + + /** + * What is the element at the given index? + * + * @param Number aIdx + */ + ArraySet.prototype.at = function ArraySet_at(aIdx) { + if (aIdx >= 0 && aIdx < this._array.length) { + return this._array[aIdx]; + } + throw new Error('No element indexed by ' + aIdx); + }; + + /** + * Returns the array representation of this set (which has the proper indices + * indicated by indexOf). Note that this is a copy of the internal array used + * for storing the members so that no one can mess with internal state. + */ + ArraySet.prototype.toArray = function ArraySet_toArray() { + return this._array.slice(); + }; + + exports.ArraySet = ArraySet; + } + + +/***/ }, +/* 6 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + * + * Based on the Base 64 VLQ implementation in Closure Compiler: + * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java + * + * Copyright 2011 The Closure Compiler Authors. All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + { + var base64 = __webpack_require__(7); + + // A single base 64 digit can contain 6 bits of data. For the base 64 variable + // length quantities we use in the source map spec, the first bit is the sign, + // the next four bits are the actual value, and the 6th bit is the + // continuation bit. The continuation bit tells us whether there are more + // digits in this value following this digit. + // + // Continuation + // | Sign + // | | + // V V + // 101011 + + var VLQ_BASE_SHIFT = 5; + + // binary: 100000 + var VLQ_BASE = 1 << VLQ_BASE_SHIFT; + + // binary: 011111 + var VLQ_BASE_MASK = VLQ_BASE - 1; + + // binary: 100000 + var VLQ_CONTINUATION_BIT = VLQ_BASE; + + /** + * Converts from a two-complement value to a value where the sign bit is + * placed in the least significant bit. For example, as decimals: + * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary) + * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary) + */ + function toVLQSigned(aValue) { + return aValue < 0 + ? ((-aValue) << 1) + 1 + : (aValue << 1) + 0; + } + + /** + * Converts to a two-complement value from a value where the sign bit is + * placed in the least significant bit. For example, as decimals: + * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1 + * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2 + */ + function fromVLQSigned(aValue) { + var isNegative = (aValue & 1) === 1; + var shifted = aValue >> 1; + return isNegative + ? -shifted + : shifted; + } + + /** + * Returns the base 64 VLQ encoded value. + */ + exports.encode = function base64VLQ_encode(aValue) { + var encoded = ""; + var digit; + + var vlq = toVLQSigned(aValue); + + do { + digit = vlq & VLQ_BASE_MASK; + vlq >>>= VLQ_BASE_SHIFT; + if (vlq > 0) { + // There are still more digits in this value, so we must make sure the + // continuation bit is marked. + digit |= VLQ_CONTINUATION_BIT; + } + encoded += base64.encode(digit); + } while (vlq > 0); + + return encoded; + }; + + /** + * Decodes the next base 64 VLQ value from the given string and returns the + * value and the rest of the string via the out parameter. + */ + exports.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) { + var strLen = aStr.length; + var result = 0; + var shift = 0; + var continuation, digit; + + do { + if (aIndex >= strLen) { + throw new Error("Expected more digits in base 64 VLQ value."); + } + + digit = base64.decode(aStr.charCodeAt(aIndex++)); + if (digit === -1) { + throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1)); + } + + continuation = !!(digit & VLQ_CONTINUATION_BIT); + digit &= VLQ_BASE_MASK; + result = result + (digit << shift); + shift += VLQ_BASE_SHIFT; + } while (continuation); + + aOutParam.value = fromVLQSigned(result); + aOutParam.rest = aIndex; + }; + } + + +/***/ }, +/* 7 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split(''); + + /** + * Encode an integer in the range of 0 to 63 to a single base 64 digit. + */ + exports.encode = function (number) { + if (0 <= number && number < intToCharMap.length) { + return intToCharMap[number]; + } + throw new TypeError("Must be between 0 and 63: " + number); + }; + + /** + * Decode a single base 64 character code digit to an integer. Returns -1 on + * failure. + */ + exports.decode = function (charCode) { + var bigA = 65; // 'A' + var bigZ = 90; // 'Z' + + var littleA = 97; // 'a' + var littleZ = 122; // 'z' + + var zero = 48; // '0' + var nine = 57; // '9' + + var plus = 43; // '+' + var slash = 47; // '/' + + var littleOffset = 26; + var numberOffset = 52; + + // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ + if (bigA <= charCode && charCode <= bigZ) { + return (charCode - bigA); + } + + // 26 - 51: abcdefghijklmnopqrstuvwxyz + if (littleA <= charCode && charCode <= littleZ) { + return (charCode - littleA + littleOffset); + } + + // 52 - 61: 0123456789 + if (zero <= charCode && charCode <= nine) { + return (charCode - zero + numberOffset); + } + + // 62: + + if (charCode == plus) { + return 62; + } + + // 63: / + if (charCode == slash) { + return 63; + } + + // Invalid base64 digit. + return -1; + }; + } + + +/***/ }, +/* 8 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + // It turns out that some (most?) JavaScript engines don't self-host + // `Array.prototype.sort`. This makes sense because C++ will likely remain + // faster than JS when doing raw CPU-intensive sorting. However, when using a + // custom comparator function, calling back and forth between the VM's C++ and + // JIT'd JS is rather slow *and* loses JIT type information, resulting in + // worse generated code for the comparator function than would be optimal. In + // fact, when sorting with a comparator, these costs outweigh the benefits of + // sorting in C++. By using our own JS-implemented Quick Sort (below), we get + // a ~3500ms mean speed-up in `bench/bench.html`. + + /** + * Swap the elements indexed by `x` and `y` in the array `ary`. + * + * @param {Array} ary + * The array. + * @param {Number} x + * The index of the first item. + * @param {Number} y + * The index of the second item. + */ + function swap(ary, x, y) { + var temp = ary[x]; + ary[x] = ary[y]; + ary[y] = temp; + } + + /** + * Returns a random integer within the range `low .. high` inclusive. + * + * @param {Number} low + * The lower bound on the range. + * @param {Number} high + * The upper bound on the range. + */ + function randomIntInRange(low, high) { + return Math.round(low + (Math.random() * (high - low))); + } + + /** + * The Quick Sort algorithm. + * + * @param {Array} ary + * An array to sort. + * @param {function} comparator + * Function to use to compare two items. + * @param {Number} p + * Start index of the array + * @param {Number} r + * End index of the array + */ + function doQuickSort(ary, comparator, p, r) { + // If our lower bound is less than our upper bound, we (1) partition the + // array into two pieces and (2) recurse on each half. If it is not, this is + // the empty array and our base case. + + if (p < r) { + // (1) Partitioning. + // + // The partitioning chooses a pivot between `p` and `r` and moves all + // elements that are less than or equal to the pivot to the before it, and + // all the elements that are greater than it after it. The effect is that + // once partition is done, the pivot is in the exact place it will be when + // the array is put in sorted order, and it will not need to be moved + // again. This runs in O(n) time. + + // Always choose a random pivot so that an input array which is reverse + // sorted does not cause O(n^2) running time. + var pivotIndex = randomIntInRange(p, r); + var i = p - 1; + + swap(ary, pivotIndex, r); + var pivot = ary[r]; + + // Immediately after `j` is incremented in this loop, the following hold + // true: + // + // * Every element in `ary[p .. i]` is less than or equal to the pivot. + // + // * Every element in `ary[i+1 .. j-1]` is greater than the pivot. + for (var j = p; j < r; j++) { + if (comparator(ary[j], pivot) <= 0) { + i += 1; + swap(ary, i, j); + } + } + + swap(ary, i + 1, j); + var q = i + 1; + + // (2) Recurse on each half. + + doQuickSort(ary, comparator, p, q - 1); + doQuickSort(ary, comparator, q + 1, r); + } + } + + /** + * Sort the given array in-place with the given comparator function. + * + * @param {Array} ary + * An array to sort. + * @param {function} comparator + * Function to use to compare two items. + */ + exports.quickSort = function (ary, comparator) { + doQuickSort(ary, comparator, 0, ary.length - 1); + }; + } + + +/***/ }, +/* 9 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var base64VLQ = __webpack_require__(6); + var util = __webpack_require__(2); + var ArraySet = __webpack_require__(5).ArraySet; + var MappingList = __webpack_require__(10).MappingList; + + /** + * An instance of the SourceMapGenerator represents a source map which is + * being built incrementally. You may pass an object with the following + * properties: + * + * - file: The filename of the generated source. + * - sourceRoot: A root for all relative URLs in this source map. + */ + function SourceMapGenerator(aArgs) { + if (!aArgs) { + aArgs = {}; + } + this._file = util.getArg(aArgs, 'file', null); + this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null); + this._skipValidation = util.getArg(aArgs, 'skipValidation', false); + this._sources = new ArraySet(); + this._names = new ArraySet(); + this._mappings = new MappingList(); + this._sourcesContents = null; + } + + SourceMapGenerator.prototype._version = 3; + + /** + * Creates a new SourceMapGenerator based on a SourceMapConsumer + * + * @param aSourceMapConsumer The SourceMap. + */ + SourceMapGenerator.fromSourceMap = + function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) { + var sourceRoot = aSourceMapConsumer.sourceRoot; + var generator = new SourceMapGenerator({ + file: aSourceMapConsumer.file, + sourceRoot: sourceRoot + }); + aSourceMapConsumer.eachMapping(function (mapping) { + var newMapping = { + generated: { + line: mapping.generatedLine, + column: mapping.generatedColumn + } + }; + + if (mapping.source != null) { + newMapping.source = mapping.source; + if (sourceRoot != null) { + newMapping.source = util.relative(sourceRoot, newMapping.source); + } + + newMapping.original = { + line: mapping.originalLine, + column: mapping.originalColumn + }; + + if (mapping.name != null) { + newMapping.name = mapping.name; + } + } + + generator.addMapping(newMapping); + }); + aSourceMapConsumer.sources.forEach(function (sourceFile) { + var content = aSourceMapConsumer.sourceContentFor(sourceFile); + if (content != null) { + generator.setSourceContent(sourceFile, content); + } + }); + return generator; + }; + + /** + * Add a single mapping from original source line and column to the generated + * source's line and column for this source map being created. The mapping + * object should have the following properties: + * + * - generated: An object with the generated line and column positions. + * - original: An object with the original line and column positions. + * - source: The original source file (relative to the sourceRoot). + * - name: An optional original token name for this mapping. + */ + SourceMapGenerator.prototype.addMapping = + function SourceMapGenerator_addMapping(aArgs) { + var generated = util.getArg(aArgs, 'generated'); + var original = util.getArg(aArgs, 'original', null); + var source = util.getArg(aArgs, 'source', null); + var name = util.getArg(aArgs, 'name', null); + + if (!this._skipValidation) { + this._validateMapping(generated, original, source, name); + } + + if (source != null && !this._sources.has(source)) { + this._sources.add(source); + } + + if (name != null && !this._names.has(name)) { + this._names.add(name); + } + + this._mappings.add({ + generatedLine: generated.line, + generatedColumn: generated.column, + originalLine: original != null && original.line, + originalColumn: original != null && original.column, + source: source, + name: name + }); + }; + + /** + * Set the source content for a source file. + */ + SourceMapGenerator.prototype.setSourceContent = + function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) { + var source = aSourceFile; + if (this._sourceRoot != null) { + source = util.relative(this._sourceRoot, source); + } + + if (aSourceContent != null) { + // Add the source content to the _sourcesContents map. + // Create a new _sourcesContents map if the property is null. + if (!this._sourcesContents) { + this._sourcesContents = {}; + } + this._sourcesContents[util.toSetString(source)] = aSourceContent; + } else if (this._sourcesContents) { + // Remove the source file from the _sourcesContents map. + // If the _sourcesContents map is empty, set the property to null. + delete this._sourcesContents[util.toSetString(source)]; + if (Object.keys(this._sourcesContents).length === 0) { + this._sourcesContents = null; + } + } + }; + + /** + * Applies the mappings of a sub-source-map for a specific source file to the + * source map being generated. Each mapping to the supplied source file is + * rewritten using the supplied source map. Note: The resolution for the + * resulting mappings is the minimium of this map and the supplied map. + * + * @param aSourceMapConsumer The source map to be applied. + * @param aSourceFile Optional. The filename of the source file. + * If omitted, SourceMapConsumer's file property will be used. + * @param aSourceMapPath Optional. The dirname of the path to the source map + * to be applied. If relative, it is relative to the SourceMapConsumer. + * This parameter is needed when the two source maps aren't in the same + * directory, and the source map to be applied contains relative source + * paths. If so, those relative source paths need to be rewritten + * relative to the SourceMapGenerator. + */ + SourceMapGenerator.prototype.applySourceMap = + function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) { + var sourceFile = aSourceFile; + // If aSourceFile is omitted, we will use the file property of the SourceMap + if (aSourceFile == null) { + if (aSourceMapConsumer.file == null) { + throw new Error( + 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' + + 'or the source map\'s "file" property. Both were omitted.' + ); + } + sourceFile = aSourceMapConsumer.file; + } + var sourceRoot = this._sourceRoot; + // Make "sourceFile" relative if an absolute Url is passed. + if (sourceRoot != null) { + sourceFile = util.relative(sourceRoot, sourceFile); + } + // Applying the SourceMap can add and remove items from the sources and + // the names array. + var newSources = new ArraySet(); + var newNames = new ArraySet(); + + // Find mappings for the "sourceFile" + this._mappings.unsortedForEach(function (mapping) { + if (mapping.source === sourceFile && mapping.originalLine != null) { + // Check if it can be mapped by the source map, then update the mapping. + var original = aSourceMapConsumer.originalPositionFor({ + line: mapping.originalLine, + column: mapping.originalColumn + }); + if (original.source != null) { + // Copy mapping + mapping.source = original.source; + if (aSourceMapPath != null) { + mapping.source = util.join(aSourceMapPath, mapping.source) + } + if (sourceRoot != null) { + mapping.source = util.relative(sourceRoot, mapping.source); + } + mapping.originalLine = original.line; + mapping.originalColumn = original.column; + if (original.name != null) { + mapping.name = original.name; + } + } + } + + var source = mapping.source; + if (source != null && !newSources.has(source)) { + newSources.add(source); + } + + var name = mapping.name; + if (name != null && !newNames.has(name)) { + newNames.add(name); + } + + }, this); + this._sources = newSources; + this._names = newNames; + + // Copy sourcesContents of applied map. + aSourceMapConsumer.sources.forEach(function (sourceFile) { + var content = aSourceMapConsumer.sourceContentFor(sourceFile); + if (content != null) { + if (aSourceMapPath != null) { + sourceFile = util.join(aSourceMapPath, sourceFile); + } + if (sourceRoot != null) { + sourceFile = util.relative(sourceRoot, sourceFile); + } + this.setSourceContent(sourceFile, content); + } + }, this); + }; + + /** + * A mapping can have one of the three levels of data: + * + * 1. Just the generated position. + * 2. The Generated position, original position, and original source. + * 3. Generated and original position, original source, as well as a name + * token. + * + * To maintain consistency, we validate that any new mapping being added falls + * in to one of these categories. + */ + SourceMapGenerator.prototype._validateMapping = + function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource, + aName) { + if (aGenerated && 'line' in aGenerated && 'column' in aGenerated + && aGenerated.line > 0 && aGenerated.column >= 0 + && !aOriginal && !aSource && !aName) { + // Case 1. + return; + } + else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated + && aOriginal && 'line' in aOriginal && 'column' in aOriginal + && aGenerated.line > 0 && aGenerated.column >= 0 + && aOriginal.line > 0 && aOriginal.column >= 0 + && aSource) { + // Cases 2 and 3. + return; + } + else { + throw new Error('Invalid mapping: ' + JSON.stringify({ + generated: aGenerated, + source: aSource, + original: aOriginal, + name: aName + })); + } + }; + + /** + * Serialize the accumulated mappings in to the stream of base 64 VLQs + * specified by the source map format. + */ + SourceMapGenerator.prototype._serializeMappings = + function SourceMapGenerator_serializeMappings() { + var previousGeneratedColumn = 0; + var previousGeneratedLine = 1; + var previousOriginalColumn = 0; + var previousOriginalLine = 0; + var previousName = 0; + var previousSource = 0; + var result = ''; + var mapping; + var nameIdx; + var sourceIdx; + + var mappings = this._mappings.toArray(); + for (var i = 0, len = mappings.length; i < len; i++) { + mapping = mappings[i]; + + if (mapping.generatedLine !== previousGeneratedLine) { + previousGeneratedColumn = 0; + while (mapping.generatedLine !== previousGeneratedLine) { + result += ';'; + previousGeneratedLine++; + } + } + else { + if (i > 0) { + if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) { + continue; + } + result += ','; + } + } + + result += base64VLQ.encode(mapping.generatedColumn + - previousGeneratedColumn); + previousGeneratedColumn = mapping.generatedColumn; + + if (mapping.source != null) { + sourceIdx = this._sources.indexOf(mapping.source); + result += base64VLQ.encode(sourceIdx - previousSource); + previousSource = sourceIdx; + + // lines are stored 0-based in SourceMap spec version 3 + result += base64VLQ.encode(mapping.originalLine - 1 + - previousOriginalLine); + previousOriginalLine = mapping.originalLine - 1; + + result += base64VLQ.encode(mapping.originalColumn + - previousOriginalColumn); + previousOriginalColumn = mapping.originalColumn; + + if (mapping.name != null) { + nameIdx = this._names.indexOf(mapping.name); + result += base64VLQ.encode(nameIdx - previousName); + previousName = nameIdx; + } + } + } + + return result; + }; + + SourceMapGenerator.prototype._generateSourcesContent = + function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) { + return aSources.map(function (source) { + if (!this._sourcesContents) { + return null; + } + if (aSourceRoot != null) { + source = util.relative(aSourceRoot, source); + } + var key = util.toSetString(source); + return Object.prototype.hasOwnProperty.call(this._sourcesContents, + key) + ? this._sourcesContents[key] + : null; + }, this); + }; + + /** + * Externalize the source map. + */ + SourceMapGenerator.prototype.toJSON = + function SourceMapGenerator_toJSON() { + var map = { + version: this._version, + sources: this._sources.toArray(), + names: this._names.toArray(), + mappings: this._serializeMappings() + }; + if (this._file != null) { + map.file = this._file; + } + if (this._sourceRoot != null) { + map.sourceRoot = this._sourceRoot; + } + if (this._sourcesContents) { + map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot); + } + + return map; + }; + + /** + * Render the source map being generated to a string. + */ + SourceMapGenerator.prototype.toString = + function SourceMapGenerator_toString() { + return JSON.stringify(this.toJSON()); + }; + + exports.SourceMapGenerator = SourceMapGenerator; + } + + +/***/ }, +/* 10 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2014 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var util = __webpack_require__(2); + + /** + * Determine whether mappingB is after mappingA with respect to generated + * position. + */ + function generatedPositionAfter(mappingA, mappingB) { + // Optimized for most common case + var lineA = mappingA.generatedLine; + var lineB = mappingB.generatedLine; + var columnA = mappingA.generatedColumn; + var columnB = mappingB.generatedColumn; + return lineB > lineA || lineB == lineA && columnB >= columnA || + util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0; + } + + /** + * A data structure to provide a sorted view of accumulated mappings in a + * performance conscious manner. It trades a neglibable overhead in general + * case for a large speedup in case of mappings being added in order. + */ + function MappingList() { + this._array = []; + this._sorted = true; + // Serves as infimum + this._last = {generatedLine: -1, generatedColumn: 0}; + } + + /** + * Iterate through internal items. This method takes the same arguments that + * `Array.prototype.forEach` takes. + * + * NOTE: The order of the mappings is NOT guaranteed. + */ + MappingList.prototype.unsortedForEach = + function MappingList_forEach(aCallback, aThisArg) { + this._array.forEach(aCallback, aThisArg); + }; + + /** + * Add the given source mapping. + * + * @param Object aMapping + */ + MappingList.prototype.add = function MappingList_add(aMapping) { + if (generatedPositionAfter(this._last, aMapping)) { + this._last = aMapping; + this._array.push(aMapping); + } else { + this._sorted = false; + this._array.push(aMapping); + } + }; + + /** + * Returns the flat, sorted array of mappings. The mappings are sorted by + * generated position. + * + * WARNING: This method returns internal data without copying, for + * performance. The return value must NOT be mutated, and should be treated as + * an immutable borrow. If you want to take ownership, you must make your own + * copy. + */ + MappingList.prototype.toArray = function MappingList_toArray() { + if (!this._sorted) { + this._array.sort(util.compareByGeneratedPositionsInflated); + this._sorted = true; + } + return this._array; + }; + + exports.MappingList = MappingList; + } + + +/***/ } +/******/ ]); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly8vd2VicGFjay9ib290c3RyYXAgZGExYmM2OWM5ZmUyOGIwN2RiNzIiLCJ3ZWJwYWNrOi8vLy4vdGVzdC90ZXN0LXNvdXJjZS1tYXAtY29uc3VtZXIuanMiLCJ3ZWJwYWNrOi8vLy4vdGVzdC91dGlsLmpzIiwid2VicGFjazovLy8uL2xpYi91dGlsLmpzIiwid2VicGFjazovLy8uL2xpYi9zb3VyY2UtbWFwLWNvbnN1bWVyLmpzIiwid2VicGFjazovLy8uL2xpYi9iaW5hcnktc2VhcmNoLmpzIiwid2VicGFjazovLy8uL2xpYi9hcnJ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dW5jdGlvbiAoYXNzZXJ0KSB7XG4gICAgLy8gSGFzIHR3byBzb3VyY2VzOiBmb28uanMgKHdpdGggY29udGVudHMpIGFuZCBiYXIuanMgKHdpdGggY29udGVudHMpLlxuICAgIHZhciBtYXBXaXRoQm90aENvbnRlbnRzID0gbmV3IFNvdXJjZU1hcEdlbmVyYXRvcigpO1xuICAgIG1hcFdpdGhCb3RoQ29udGVudHMuYWRkTWFwcGluZyh7IHNvdXJjZTogJ2Zvby5qcycsXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3JpZ2luYWw6IHsgbGluZTogMSwgY29sdW1uOiAxMCB9LFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGdlbmVyYXRlZDogeyBsaW5lOiAxLCBjb2x1bW46IDEwIH0gfSk7XG4gICAgbWFwV2l0aEJvdGhDb250ZW50cy5hZGRNYXBwaW5nKHsgc291cmNlOiAnYmFyLmpzJyxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvcmlnaW5hbDogeyBsaW5lOiAxLCBjb2x1bW46IDEwIH0sXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZ2VuZXJhdGVkOiB7IGxpbmU6IDEsIGNvbHVtbjogMTAgfSB9KTtcbiAgICBtYXBXaXRoQm90aENvbnRlbnRzLnNldFNvdXJjZUNvbnRlbnQoJ2Zvby5qcycsICdjb250ZW50IG9mIGZvby5qcycpO1xuICAgIG1hcFdpdGhCb3RoQ29udGVudHMuc2V0U291cmNlQ29udGVudCgnYmFyLmpzJywgJ2NvbnRlbnQgb2YgYmFyLmpzJyk7XG4gICAgdmFyIGNvbnN1bWVyID0gbmV3IFNvdXJjZU1hcENvbnN1bWVyKG1hcFdpdGhCb3RoQ29udGVudHMudG9KU09OKCkpO1xuICAgIGFzc2VydC5vayhjb25zdW1lci5oYXNDb250ZW50c09mQWxsU291cmNlcygpKTtcbiAgfTtcblxuICBleHBvcnRzWyd0ZXN0IGhhc0NvbnRlbnRzT2ZBbGxTb3VyY2VzLCB0d28gc291cmNlcyBvbmUgd2l0aCBhbmQgb25lIHdpdGhvdXQgY29udGVudHMnXSA9IGZ1bmN0aW9uIChhc3NlcnQpIHtcbiAgICAvLyBIYXMgdHdvIHNvdXJjZXM6IGZvby5qcyAod2l0aCBjb250ZW50cykgYW5kIGJhci5qcyAod2l0aG91dCBjb250ZW50cykuXG4gICAgdmFyIG1hcFdpdGhvdXRTb21lQ29udGVudHMgPSBuZXcgU291cmNlTWFwR2VuZXJhdG9yKCk7XG4gICAgbWFwV2l0aG91dFNvbWVDb250ZW50cy5hZGRNYXBwaW5nKHsgc291cmNlOiAnZm9vLmpzJyxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvcmlnaW5hbDogeyBsaW5lOiAxLCBjb2x1bW46IDEwIH0sXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZ2VuZXJhdGVkOiB7IGxpbmU6IDEsIGNvbHVtbjogMTAgfSB9KTtcbiAgICBtYXBXaXRob3V0U29tZUNvbnRlbnRzLmFkZE1hcHBpbmcoeyBzb3VyY2U6ICdiYXIuanMnLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9yaWdpbmFsOiB7IGxpbmU6IDEsIGNvbHVtbjogMTAgfSxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBnZW5lcmF0ZWQ6IHsgbGluZTogMSwgY29sdW1uOiAxMCB9IH0pO1xuICAgIG1hcFdpdGhvdXRTb21lQ29udGVudHMuc2V0U291cmNlQ29udGVudCgnZm9vLmpzJywgJ2NvbnRlbnQgb2YgZm9vLmpzJyk7XG4gICAgdmFyIGNvbnN1bWVyID0gbmV3IFNvdXJjZU1hcENvbnN1bWVyKG1hcFdpdGhvdXRTb21lQ29udGVudHMudG9KU09OKCkpO1xuICAgIGFzc2VydC5vayghY29uc3VtZXIuaGFzQ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JQUFNLFNBQVVBLEdBQ2xCLE9BQU9DLElBQUlEO0NDRGIsSUFBSSxJQUFNLFNBQVVFLEdBQ2xCLE9BQU9BJ1xuICB9O1xuICAvLyBUaGlzIG1hcHBpbmcgaXMgaWRlbnRpY2FsIHRvIGFib3ZlLCBidXQgdXNlcyB0aGUgaW5kZXhlZCBmb3JtYXQgaW5zdGVhZC5cbiAgZXhwb3J0cy5pbmRleGVkVGVzdE1hcCA9IHtcbiAgICB2ZXJzaW9uOiAzLFxuICAgIGZpbGU6ICdtaW4uanMnLFxuICAgIHNlY3Rpb25zOiBbXG4gICAgICB7XG4gICAgICAgIG9mZnNldDoge1xuICAgICAgICAgIGxpbmU6IDAsXG4gICAgICAgICAgY29sdW1uOiAwXG4gICAgICAgIH0sXG4gICAgICAgIG1hcDoge1xuICAgICAgICAgIHZlcnNpb246IDMsXG4gICAgICAgICAgc291cmNlczogW1xuICAgICAgICAgICAgXCJvbmUuanNcIlxuICAgICAgICAgIF0sXG4gICAgICAgICAgc291cmNlc0NvbnRlbnQ6IFtcbiAgICAgICAgICAgICcgT05FLmZvbyA9IGZ1bmN0aW9uIChiYXIpIHtcXG4nICtcbiAgICAgICAgICAgICcgICByZXR1cm4gYmF6KGJhcik7XFxuJyArXG4gICAgICAgICAgICAnIH07JyxcbiAgICAgICAgICBdLFxuICAgICAgICAgIG5hbWVzOiBbXG4gICAgICAgICAgICBcImJhclwiLFxuICAgICAgICAgICAgXCJiYXpcIlxuICAgICAgICAgIF0sXG4gICAgICAgICAgbWFwcGluZ3M6IFwiQ0FBQyxJQUFJLElBQU0sU0FBVUEsR0FDbEIsT0FBT0MsSUFBSURcIixcbiAgICAgICAgICBmaWxlOiBcIm1pbi5qc1wiLFxuICAgICAgICAgIHNvdXJjZVJvb3Q6IFwiL3RoZS9yb290XCJcbiAgICAgICAgfVxuICAgICAgfSxcbiAgICAgIHtcbiAgICAgICAgb2Zmc2V0OiB7XG4gICAgICAgICAgbGluZTogMSxcbiAgICAgICAgICBjb2x1bW46IDBcbiAgICAgICAgfSxcbiAgICAgICAgbWFwOiB7XG4gICAgICAgICAgdmVyc2lvbjogMyxcbiAgICAgICAgICBzb3VyY2VzOiBbXG4gICAgICAgICAgICBcInR3by5qc1wiXG4gICAgICAgICAgXSxcbiAgICAgICAgICBzb3VyY2VzQ29udGVudDogW1xuICAgICAgICAgICAgJyBUV08uaW5jID0gZnVuY3Rpb24gKG4pIHtcXG4nICtcbiAgICAgICAgICAgICcgICByZXR1cm4gbiArIDE7XFxuJyArXG4gICAgICAgICAgICAnIH07J1xuICAgICAgICAgIF0sXG4gICAgICAgICAgbmFtZXM6IFtcbiAgICAgICAgICAgIFwiblwiXG4gICAgICAgICAgXSxcbiAgICAgICAgICBtYXBwaW5nczogXCJDQUFDLElBQUksSUFBTSxTQUFVQSxHQUNsQixPQUFPQVwiLFxuICAgICAgICAgIGZpbGU6IFwibWluLmpzXCIsXG4gICAgICAgICAgc291cmNlUm9vdDogXCIvdGhlL3Jvb3RcIlxuICAgICAgICB9XG4gICAgICB9XG4gICAgXVxuICB9O1xuICBleHBvcnRzLmluZGV4ZWRUZXN0TWFwRGlmZmVyZW50U291cmNlUm9vdHMgPSB7XG4gICAgdmVyc2lvbjogMyxcbiAgICBmaWxlOiAnbWluLmpzJyxcbiAgICBzZWN0aW9uczogW1xuICAgICAge1xuICAgICAgICBvZmZzZXQ6IHtcbiAgICAgICAgICBsaW5lOiAwLFxuICAgICAgICAgIGNvbHVtbjogMFxuICAgICAgICB9LFxuICAgICAgICBtYXA6IHtcbiAgICAgICAgICB2ZXJzaW9uOiAzLFxuICAgICAgICAgIHNvdXJjZXM6IFtcbiAgICAgICAgICAgIFwib25lLmpzXCJcbiAgICAgICAgICBdLFxuICAgICAgICAgIHNvdXJjZXNDb250ZW50OiBbXG4gICAgICAgICAgICAnIE9ORS5mb28gPSBmdW5jdGlvbiAoYmFyKSB7XFxuJyArXG4gICAgICAgICAgICAnICAgcmV0dXJuIGJheihiYXIpO1xcbicgK1xuICAgICAgICAgICAgJyB9OycsXG4gICAgICAgICAgXSxcbiAgICAgICAgICBuYW1lczogW1xuICAgICAgICAgICAgXCJiYXJcIixcbiAgICAgICAgICAgIFwiYmF6XCJcbiAgICAgICAgICBdLFxuICAgICAgICAgIG1hcHBpbmdzOiBcIkNBQUMsSUFBSSxJQUFNLFNBQVVBLEdBQ2xCLE9BQU9DLElBQUlEXCIsXG4gICAgICAgICAgZmlsZTogXCJtaW4uanNcIixcbiAgICAgICAgICBzb3VyY2VSb290OiBcIi90aGUvcm9vdFwiXG4gICAgICAgIH1cbiAgICAgIH0sXG4gICAgICB7XG4gICAgICAgIG9mZnNldDoge1xuICAgICAgICAgIGxpbmU6IDEsXG4gICAgICAgICAgY29sdW1uOiAwXG4gICAgICAgIH0sXG4gICAgICAgIG1hcDoge1xuICAgICAgICAgIHZlcnNpb246IDMsXG4gICAgICAgICAgc291cmNlczogW1xuICAgICAgICAgICAgXCJ0d28uanNcIlxuICAgICAgICAgIF0sXG4gICAgICAgICAgc291cmNlc0NvbnRlbnQ6IFtcbiAgICAgICAgICAgICcgVFdPLmluYyA9IGZ1bmN0aW9uIChuKSB7XFxuJyArXG4gICAgICAgICAgICAnICAgcmV0dXJuIG4gKyAxO1xcbicgK1xuICAgICAgICAgICAgJyB9OydcbiAgICAgICAgICBdLFxuICAgICAgICAgIG5hbWVzOiBbXG4gICAgICAgICAgICBcIm5cIlxuICAgICAgICAgIF0sXG4gICAgICAgICAgbWFwcGluZ3M6IFwiQ0FBQyxJQUFJLElBQU0sU0FBVUEsR0FDbEIsT0FBT0FcIixcbiAgICAgICAgICBmaWxlOiBcIm1pbi5qc1wiLFxuICAgICAgICAgIHNvdXJjZVJvb3Q6IFwiL2RpZmZlcmVudC9yb290XCJcbiAgICAgICAgfVxuICAgICAgfVxuICAgIF1cbiAgfTtcbiAgZXhwb3J0cy50ZXN0TWFwV2l0aFNvdXJjZXNDb250ZW50ID0ge1xuICAgIHZlcnNpb246IDMsXG4gICAgZm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XZlKHRoaXMuc291cmNlUm9vdCwgbmVlZGxlLnNvdXJjZSk7XG4gICAgICB9XG4gICAgICBpZiAoIXRoaXMuX3NvdXJjZXMuaGFzKG5lZWRsZS5zb3VyY2UpKSB7XG4gICAgICAgIHJldHVybiBbXTtcbiAgICAgIH1cbiAgICAgIG5lZWRsZS5zb3VyY2UgPSB0aGlzLl9zb3VyY2VzLmluZGV4T2YobmVlZGxlLnNvdXJjZSk7XG5cbiAgICAgIHZhciBtYXBwaW5ncyA9IFtdO1xuXG4gICAgICB2YXIgaW5kZXggPSB0aGlzLl9maW5kTWFwcGluZyhuZWVkbGUsXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9vcmlnaW5hbE1hcHBpbmdzLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXCJvcmlnaW5hbExpbmVcIixcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwib3JpZ2luYWxDb2x1bW5cIixcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHV0aWwuY29tcGFyZUJ5T3JpZ2luYWxQb3NpdGlvbnMsXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBiaW5hcnlTZWFyY2guTEVBU1RfVVBQRVJfQk9VTkQpO1xuICAgICAgaWYgKGluZGV4ID49IDApIHtcbiAgICAgICAgdmFyIG1hcHBpbmcgPSB0aGlzLl9vcmlnaW5hbE1hcHBpbmdzW2luZGV4XTtcblxuICAgICAgICBpZiAoYUFyZ3MuY29sdW1uID09PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICB2YXIgb3JpZ2luYWxMaW5lID0gbWFwcGluZy5vcmlnaW5hbExpbmU7XG5cbiAgICAgICAgICAvLyBJdGVyYXRlIHVudGlsIGVpdGhlciB3ZSBydW4gb3V0IG9mIG1hcHBpbmdzLCBvciB3ZSBydW4gaW50b1xuICAgICAgICAgIC8vIGEgbWFwcGluZyBmb3IgYSBka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wYXJhdG9yKGFTdHIsIGVuZCkpIHtcbiAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIHN0ciA9IGFTdHIuc2xpY2UoaW5kZXgsIGVuZCk7XG5cbiAgICAgICAgICBzZWdtZW50ID0gY2FjaGVkU2VnbWVudHNbc3RyXTtcbiAgICAgICAgICBpZiAoc2VnbWVudCkge1xuICAgICAgICAgICAgaW5kZXggKz0gc3RyLmxlbmd0aDtcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgc2VnbWVudCA9IFtdO1xuICAgICAgICAgICAgd2hpbGUgKGluZGV4IDwgZW5kKSB7XG4gICAgICAgICAgICAgIGJhc2U2NFZMUS5kZWNvZGUoYVN0ciwgaW5kZXgsIHRlbXApO1xuICAgICAgICAgICAgICB2YWx1ZSA9IHRlbXAudmFsdWU7XG4gICAgICAgICAgICAgIGluZGV4ID0gdGVtcC5yZXN0O1xuICAgICAgICAgICAgICBzZWdtZW50LnB1c2godmFsdWUpO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAoc2VnbWVudC5sZW5ndGggPT09IDIpIHtcbiAgICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCdGb3VuZCBhIHNvdXJjZSwgYnV0IG5vIGxpbmUgYW5kIGNvbHVtbicpO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAoc2VnbWVudC5sZW5ndGggPT09IDMpIHtcbiAgICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCdGb3VuZCBhIHNvdXJjZSBhbmQgbGluZSwgYnV0IG5vIGNvbHVtbicpO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBjYWNoZWRTZWdtZW50c1tzdHJdID0gc2VnbWVudDtcbiAgICAgICAgICB9XG5cbiAgICAgICAgICAvLyBHZW5lcmF0ZWQgY29sdW1uLlxuICAgICAgICAgIG1hcHBpbmcuZ2VuZXJhdGVkQ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FyZ3MsICdsaW5lJyksXG4gICAgICAgIG9yaWdpbmFsQ29sdW1uOiB1dGlsLmdldEFyZyhhQXJncywgJ2NvbHVtbicpXG4gICAgICB9O1xuXG4gICAgICB2YXIgaW5kZXggPSB0aGlzLl9maW5kTWFwcGluZyhcbiAgICAgICAgbmVlZGxlLFxuICAgICAgICB0aGlzLl9vcmlnaW5hbE1hcHBpbmdzLFxuICAgICAgICBcIm9yaWdpbmFsTGluZVwiLFxuICAgICAgICBcIm9yaWdpbmFsQ29sdW1uXCIsXG4gICAgICAgIHV0aWwuY29tcGFyZUJ5T3JpZ2luYWxQb3NpdGlvbnMsXG4gICAgICAgIHV0aWwuZ2V0QXJnKGFBcmdzLCAnYmlhcycsIFNvdXJjZU1hcENvbnN1bWVyLkdSRUFURVNUX0xPV0VSX0JPVU5EKVxuICAgICAgKTtcblxuICAgICAgaWYgKGluZGV4ID49IDApIHtcbiAgICAgICAgdmFyIG1hcHBpbmcgPSB0aGlzLl9vcmlnaW5hbE1hcHBpbmdzW2luZGV4XTtcblxuICAgICAgICBpZiAobWFwcGluZy5zb3VyY2UgPT09IG5lZWRsZS5zb3VyY2UpIHtcbiAgICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgbGluZTogdXRpbC5nZXRBcmcobWFwcGluZywgJ2dlbmVyYXRlZExpbmUnLCBudWxsKSxcbiAgICAgICAgICAgIGNvbHVtbjogdXRpbC5nZXRBcmcobWFwcGluZywgJ2dlbmVyYXRlZENvbHVtbicsIG51bGwpLFxuICAgICAgICAgICAgbGFzdENvbHVtbjogdXRpbC5nZXRBcmcobWFwcGluZywgJ2xhc3RHZW5lcmF0ZWRDb2x1bW4nLCBudWxsKVxuICAgICAgICAgIH07XG4gICAgICAgIH1cbiAgICAgIH1cblxuICAgICAgcmV0dXJuIHtcbiAgICAgICAgbGluZTogbnVsbCxcbiAgICAgICAgY29sdW1uOiBudWxsLFxuICAgICAgICBsYXN0Q29sdW1uOiBudWxsXG4gICAgICB9O1xuICA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ICAgdmFyIHNvdXJjZVJvb3QgPSBhU291cmNlTWFwQ29uc3VtZXIuc291cmNlUm9vdDtcbiAgICAgIHZhciBnZW5lcmF0b3IgPSBuZXcgU291cmNlTWFwR2VuZXJhdG9yKHtcbiAgICAgICAgZmlsZTogYVNvdXJjZU1hcENvbnN1bWVyLmZpbGUsXG4gICAgICAgIHNvdXJjZVJvb3Q6IHNvdXJjZVJvb3RcbiAgICAgIH0pO1xuICAgICAgYVNvdXJjZU1hcENvbnN1bWVyLmVhY2hNYXBwaW5nKGZ1bmN0aW9uIChtYXBwaW5nKSB7XG4gICAgICAgIHZhciBuZXdNYXBwaW5nID0ge1xuICAgICAgICAgIGdlbmVyYXRlZDoge1xuICAgICAgICAgICAgbGluZTogbWFwcGluZy5nZW5lcmF0ZWRMaW5lLFxuICAgICAgICAgICAgY29sdW1uOiBtYXBwaW5nLmdlbmVyYXRlZENvbHVtblxuICAgICAgICAgIH1cbiAgICAgICAgfTtcblxuICAgICAgICBpZiAobWFwcGluZy5zb3VyY2UgIT0gbnVsbCkge1xuICAgICAgICAgIG5ld01hcHBpbmcuc291cmNlID0gbWFwcGluZy5zb3VyY2U7XG4gICAgICAgICAgaWYgKHNvdXJjZVJvb3QgIT0gbnVsbCkge1xuICAgICAgICAgICAgbmV3TWFwcGluZy5zb3VyY2UgPSB1dGlsLnJlbGF0aXZlKHNvdXJjZVJvb3QsIG5ld01hcHBpbmcuc291cmNlKTtcbiAgICAgICAgICB9XG5cbiAgICAgICAgICBuZXdNYXBwaW5nLm9yaWdpbmFsID0ge1xuICAgICAgICAgICAgbGluZTogbWFwcGluZy5vcmlnaW5hbExpbmUsXG4gICAgICAgICAgICBjb2x1bW46IG1hcHBpbmcub3JpZ2luYWxDb2x1bW5cbiAgICAgICAgICB9O1xuXG4gICAgICAgICAgaWYgKG1hcHBpbmcubmFtZSAhPSBudWxsKSB7XG4gICAgICAgICAgICBuZXdNYXBwaW5nLm5hbWUgPSBtYXBwaW5nLm5hbWU7XG4g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VyYXRlZExpbmUgIT09IHByZXZpb3VzR2VuZXJhdGVkTGluZSkge1xuICAgICAgICAgICAgcmVzdWx0ICs9ICc7JztcbiAgICAgICAgICAgIHByZXZpb3VzR2VuZXJhdGVkTGluZSsrO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBlbHNlIHtcbiAgICAgICAgICBpZiAoaSA+IDApIHtcbiAgICAgICAgICAgIGlmICghdXRpbC5jb21wYXJlQnlHZW5lcmF0ZWRQb3NpdGlvbnNJbmZsYXRlZChtYXBwaW5nLCBtYXBwaW5nc1tpIC0gMV0pKSB7XG4gICAgICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmVzdWx0ICs9ICcsJztcbiAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICByZXN1bHQgKz0gYmFzZTY0VkxRLmVuY29kZShtYXBwaW5nLmdlbmVyYXRlZENvbHVtblxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAtIHByZXZpb3VzR2VuZXJhdGVkQ29sdW1uKTtcbiAgICAgICAgcHJldmlvdXNHZW5lcmF0ZWRDb2x1bW4gPSBtYXBwaW5nLmdlbmVyYXRlZENvbHVtbjtcblxuICAgICAgICBpZiAobWFwcGluZy5zb3VyY2UgIT0gbnVsbCkge1xuICAgICAgICAgIHNvdXJjZUlkeCA9IHRoaXMuX3NvdXJjZXMuaW5kZXhPZihtYXBwaW5nLnNvdXJjZSk7XG4gICAgICAgICAgcmVzdWx0ICs9IGJhc2U2NFZMUS5lbmNvZGUoc291cmNlSWR4IC0gcHJldmlvdXNTb3VyY2UpO1xuICAgICAgICAgIHByZXZpb3VzU291cmNlID0gc291cmNlSWR4O1xuXG4gICAgICAgICAgLy8gbGluZXMgYXJlIHN0b3JlZCAwLWJhc2VkIGluIFNvdXJjZU1hcCBzcGVjIHZlcnNpb24gM1xuICAgICAgICAgIHJlc3VsdCArPSBiYXNlNjRWTFEuZW5jb2RlKG1hcHBpbmcub3JpZ2luYWxMaW5lIC0gMVxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC0gcHJldmlvdXNPcmlnaW5hbExpbmUpO1xuICAgICAgICAgIHByZXZpb3VzT3JpZ2luYWxMaW5lID0gbWFwcGluZy5vcmlnaW5hbExpbmUgLSAxO1xuXG4gICAgICAgICAgcmVzdWx0ICs9IGJhc2U2NFZMUS5lbmNvZGUobWFwcGluZy5vcmlnaW5hbENvbHVtblxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC0gcHJldmlvdXNPcmlnaW5hbENvbHVtbik7XG4gICAgICAgICAgcHJldmlvdXNPcmlnaW5hbENvbHVtbiA9IG1hcHBpbmcub3JpZ2luYWxDb2x1bW47XG5cbiAgICAgICAgICBpZiAobWFwcGluZy5uYW1lICE9IG51bGwpIHtcbiAgICAgICAgICAgIG5hbWVJZHggPSB0aGlzLl9uYW1lcy5pbmRleE9mKG1hcHBpbmcubmFtZSk7XG4gICAgICAgICAgICByZXN1bHQgKz0gYmFzZTY0VkxRLmVuY29kZShuYW1lSWR4IC0gcHJldmlvdXNOYW1lKTtcbiAgICAgICAgICAgIHByZXZpb3VzTmFtZSA9IG5hbWVJZHg7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG5cbiAgICAgIHJldHVybiByZXN1bHQ7XG4gICAgfTtcblxuICBTb3VyY2VNYXBHZW5lcmF0b3IucHJvdG90eXBlLl9nZW5lcmF0ZVNvdXJjZXNDb250ZW50ID1cbiAgICBmdW5jdGlvbiBTb3VyY2VNYXBHZW5lcmF0b3JfZ2VuZXJhdGVTb3VyY2VzQ29udGVudChhU291cmNlcywgYVNvdXJjZVJvb3QpIHtcbiAgICAgIHJldHVybiBhU291cmNlcy5tYXAoZnVuY3Rpb24gKHNvdXJjZSkge1xuICAgICAgICBpZiAoIXRoaXMuX3NvdXJjZXNDb250ZW50cykge1xuICAgICAgICAgIHJldHVybiBudWxsO1xuICAgICAgICB9XG4gICAgICAgIGlmIChhU291cmNlUm9vdCAhPSBudWxsKSB7XG4gICAgICAgICAgc291cmNlID0gdXRpbC5yZWxhdGl2ZShhU291cmNlUm9vdCwgc291cmNlKTtcbiAgICAgICAgfVxuICAgICAgICB2YXIga2V5ID0gdXRpbC50b1NldFN0cmluZyhzb3VyY2UpO1xuICAgICAgICByZXR1cm4gT2JqZWN0LnByb3RvdHlwZS5oYXNPd25Qcm9wZXJ0eS5jYWxsKHRoaXMuX3NvdXJjZXNDb250ZW50cyxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBrZXkpXG4gICAgICAgICAgPyB0aGlzLl9zb3VyY2VzQ29udGVudHNba2V5XVxuICAgICAgICAgIDogbnVsbDtcbiAgICAgIH0sIHRoaXMpO1xuICAgIH07XG5cbiAgLyoqXG4gICAqIEV4dGVybmFsaXplIHRoZSBzb3VyY2UgbWFwLlxuICAgKi9cbiAgU291cmNlTWFwR2VuZXJhdG9yLnByb3RvdHlwZS50b0pTT04gPVxuICAgIGZ1bmN0aW9uIFNvdXJjZU1hcEdlbmVyYXRvcl90b0pTT04oKSB7XG4gICAgICB2YXIgbWFwID0ge1xuICAgICAgICB2ZXJzaW9uOiB0aGlzLl92ZXJzaW9uLFxuICAgICAgICBzb3VyY2VzOiB0aGlzLl9zb3VyY2VzLnRvQXJyYXkoKSxcbiAgICAgICAgbmFtZXM6IHRoaXMuX25hbWVzLnRvQXJyYXkoKSxcbiAgICAgICAgbWFwcGluZ3M6IHRoaXMuX3NlcmlhbGl6ZU1hcHBpbmdzKClcbiAgICAgIH07XG4gICAgICBpZiAodGhpcy5fZmlsZSAhPSBudWxsKSB7XG4gICAgICAgIG1hcC5maWxlID0gdGhpcy5fZmlsZTtcbiAgICAgIH1cbiAgICAgIGlmICh0aGlzLl9zb3VyY2VSb290ICE9IG51bGwpIHtcbiAgICAgICAgbWFwLnNvdXJjZVJvb3QgPSB0aGlzLl9zb3VyY2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IDBcbiAqKi8iXSwic291cmNlUm9vdCI6IiJ9 \ No newline at end of file diff --git a/devtools/shared/sourcemap/tests/unit/test_source_map_generator.js b/devtools/shared/sourcemap/tests/unit/test_source_map_generator.js new file mode 100644 index 000000000..4b5fd4976 --- /dev/null +++ b/devtools/shared/sourcemap/tests/unit/test_source_map_generator.js @@ -0,0 +1,4039 @@ +function run_test() { + for (var k in SOURCE_MAP_TEST_MODULE) { + if (/^test/.test(k)) { + SOURCE_MAP_TEST_MODULE[k](assert); + } + } +} + + +var SOURCE_MAP_TEST_MODULE = +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; +/******/ +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.loaded = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var SourceMapGenerator = __webpack_require__(1).SourceMapGenerator; + var SourceMapConsumer = __webpack_require__(7).SourceMapConsumer; + var SourceNode = __webpack_require__(10).SourceNode; + var util = __webpack_require__(11); + + exports['test some simple stuff'] = function (assert) { + var map = new SourceMapGenerator({ + file: 'foo.js', + sourceRoot: '.' + }); + assert.ok(true); + + var map = new SourceMapGenerator().toJSON(); + assert.ok(!('file' in map)); + assert.ok(!('sourceRoot' in map)); + }; + + exports['test JSON serialization'] = function (assert) { + var map = new SourceMapGenerator({ + file: 'foo.js', + sourceRoot: '.' + }); + assert.equal(map.toString(), JSON.stringify(map)); + }; + + exports['test adding mappings (case 1)'] = function (assert) { + var map = new SourceMapGenerator({ + file: 'generated-foo.js', + sourceRoot: '.' + }); + + assert.doesNotThrow(function () { + map.addMapping({ + generated: { line: 1, column: 1 } + }); + }); + }; + + exports['test adding mappings (case 2)'] = function (assert) { + var map = new SourceMapGenerator({ + file: 'generated-foo.js', + sourceRoot: '.' + }); + + assert.doesNotThrow(function () { + map.addMapping({ + generated: { line: 1, column: 1 }, + source: 'bar.js', + original: { line: 1, column: 1 } + }); + }); + }; + + exports['test adding mappings (case 3)'] = function (assert) { + var map = new SourceMapGenerator({ + file: 'generated-foo.js', + sourceRoot: '.' + }); + + assert.doesNotThrow(function () { + map.addMapping({ + generated: { line: 1, column: 1 }, + source: 'bar.js', + original: { line: 1, column: 1 }, + name: 'someToken' + }); + }); + }; + + exports['test adding mappings (invalid)'] = function (assert) { + var map = new SourceMapGenerator({ + file: 'generated-foo.js', + sourceRoot: '.' + }); + + // Not enough info. + assert.throws(function () { + map.addMapping({}); + }); + + // Original file position, but no source. + assert.throws(function () { + map.addMapping({ + generated: { line: 1, column: 1 }, + original: { line: 1, column: 1 } + }); + }); + }; + + exports['test adding mappings with skipValidation'] = function (assert) { + var map = new SourceMapGenerator({ + file: 'generated-foo.js', + sourceRoot: '.', + skipValidation: true + }); + + // Not enough info, caught by `util.getArgs` + assert.throws(function () { + map.addMapping({}); + }); + + // Original file position, but no source. Not checked. + assert.doesNotThrow(function () { + map.addMapping({ + generated: { line: 1, column: 1 }, + original: { line: 1, column: 1 } + }); + }); + }; + + exports['test that the correct mappings are being generated'] = function (assert) { + var map = new SourceMapGenerator({ + file: 'min.js', + sourceRoot: '/the/root' + }); + + map.addMapping({ + generated: { line: 1, column: 1 }, + original: { line: 1, column: 1 }, + source: 'one.js' + }); + map.addMapping({ + generated: { line: 1, column: 5 }, + original: { line: 1, column: 5 }, + source: 'one.js' + }); + map.addMapping({ + generated: { line: 1, column: 9 }, + original: { line: 1, column: 11 }, + source: 'one.js' + }); + map.addMapping({ + generated: { line: 1, column: 18 }, + original: { line: 1, column: 21 }, + source: 'one.js', + name: 'bar' + }); + map.addMapping({ + generated: { line: 1, column: 21 }, + original: { line: 2, column: 3 }, + source: 'one.js' + }); + map.addMapping({ + generated: { line: 1, column: 28 }, + original: { line: 2, column: 10 }, + source: 'one.js', + name: 'baz' + }); + map.addMapping({ + generated: { line: 1, column: 32 }, + original: { line: 2, column: 14 }, + source: 'one.js', + name: 'bar' + }); + + map.addMapping({ + generated: { line: 2, column: 1 }, + original: { line: 1, column: 1 }, + source: 'two.js' + }); + map.addMapping({ + generated: { line: 2, column: 5 }, + original: { line: 1, column: 5 }, + source: 'two.js' + }); + map.addMapping({ + generated: { line: 2, column: 9 }, + original: { line: 1, column: 11 }, + source: 'two.js' + }); + map.addMapping({ + generated: { line: 2, column: 18 }, + original: { line: 1, column: 21 }, + source: 'two.js', + name: 'n' + }); + map.addMapping({ + generated: { line: 2, column: 21 }, + original: { line: 2, column: 3 }, + source: 'two.js' + }); + map.addMapping({ + generated: { line: 2, column: 28 }, + original: { line: 2, column: 10 }, + source: 'two.js', + name: 'n' + }); + + map = JSON.parse(map.toString()); + + util.assertEqualMaps(assert, map, util.testMap); + }; + + exports['test that adding a mapping with an empty string name does not break generation'] = function (assert) { + var map = new SourceMapGenerator({ + file: 'generated-foo.js', + sourceRoot: '.' + }); + + map.addMapping({ + generated: { line: 1, column: 1 }, + source: 'bar.js', + original: { line: 1, column: 1 }, + name: '' + }); + + assert.doesNotThrow(function () { + JSON.parse(map.toString()); + }); + }; + + exports['test that source content can be set'] = function (assert) { + var map = new SourceMapGenerator({ + file: 'min.js', + sourceRoot: '/the/root' + }); + map.addMapping({ + generated: { line: 1, column: 1 }, + original: { line: 1, column: 1 }, + source: 'one.js' + }); + map.addMapping({ + generated: { line: 2, column: 1 }, + original: { line: 1, column: 1 }, + source: 'two.js' + }); + map.setSourceContent('one.js', 'one file content'); + + map = JSON.parse(map.toString()); + assert.equal(map.sources[0], 'one.js'); + assert.equal(map.sources[1], 'two.js'); + assert.equal(map.sourcesContent[0], 'one file content'); + assert.equal(map.sourcesContent[1], null); + }; + + exports['test .fromSourceMap'] = function (assert) { + var map = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(util.testMap)); + util.assertEqualMaps(assert, map.toJSON(), util.testMap); + }; + + exports['test .fromSourceMap with sourcesContent'] = function (assert) { + var map = SourceMapGenerator.fromSourceMap( + new SourceMapConsumer(util.testMapWithSourcesContent)); + util.assertEqualMaps(assert, map.toJSON(), util.testMapWithSourcesContent); + }; + + exports['test applySourceMap'] = function (assert) { + var node = new SourceNode(null, null, null, [ + new SourceNode(2, 0, 'fileX', 'lineX2\n'), + 'genA1\n', + new SourceNode(2, 0, 'fileY', 'lineY2\n'), + 'genA2\n', + new SourceNode(1, 0, 'fileX', 'lineX1\n'), + 'genA3\n', + new SourceNode(1, 0, 'fileY', 'lineY1\n') + ]); + var mapStep1 = node.toStringWithSourceMap({ + file: 'fileA' + }).map; + mapStep1.setSourceContent('fileX', 'lineX1\nlineX2\n'); + mapStep1 = mapStep1.toJSON(); + + node = new SourceNode(null, null, null, [ + 'gen1\n', + new SourceNode(1, 0, 'fileA', 'lineA1\n'), + new SourceNode(2, 0, 'fileA', 'lineA2\n'), + new SourceNode(3, 0, 'fileA', 'lineA3\n'), + new SourceNode(4, 0, 'fileA', 'lineA4\n'), + new SourceNode(1, 0, 'fileB', 'lineB1\n'), + new SourceNode(2, 0, 'fileB', 'lineB2\n'), + 'gen2\n' + ]); + var mapStep2 = node.toStringWithSourceMap({ + file: 'fileGen' + }).map; + mapStep2.setSourceContent('fileB', 'lineB1\nlineB2\n'); + mapStep2 = mapStep2.toJSON(); + + node = new SourceNode(null, null, null, [ + 'gen1\n', + new SourceNode(2, 0, 'fileX', 'lineA1\n'), + new SourceNode(2, 0, 'fileA', 'lineA2\n'), + new SourceNode(2, 0, 'fileY', 'lineA3\n'), + new SourceNode(4, 0, 'fileA', 'lineA4\n'), + new SourceNode(1, 0, 'fileB', 'lineB1\n'), + new SourceNode(2, 0, 'fileB', 'lineB2\n'), + 'gen2\n' + ]); + var expectedMap = node.toStringWithSourceMap({ + file: 'fileGen' + }).map; + expectedMap.setSourceContent('fileX', 'lineX1\nlineX2\n'); + expectedMap.setSourceContent('fileB', 'lineB1\nlineB2\n'); + expectedMap = expectedMap.toJSON(); + + // apply source map "mapStep1" to "mapStep2" + var generator = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(mapStep2)); + generator.applySourceMap(new SourceMapConsumer(mapStep1)); + var actualMap = generator.toJSON(); + + util.assertEqualMaps(assert, actualMap, expectedMap); + }; + + exports['test applySourceMap throws when file is missing'] = function (assert) { + var map = new SourceMapGenerator({ + file: 'test.js' + }); + var map2 = new SourceMapGenerator(); + assert.throws(function() { + map.applySourceMap(new SourceMapConsumer(map2.toJSON())); + }); + }; + + exports['test the two additional parameters of applySourceMap'] = function (assert) { + // Assume the following directory structure: + // + // http://foo.org/ + // bar.coffee + // app/ + // coffee/ + // foo.coffee + // temp/ + // bundle.js + // temp_maps/ + // bundle.js.map + // public/ + // bundle.min.js + // bundle.min.js.map + // + // http://www.example.com/ + // baz.coffee + + var bundleMap = new SourceMapGenerator({ + file: 'bundle.js' + }); + bundleMap.addMapping({ + generated: { line: 3, column: 3 }, + original: { line: 2, column: 2 }, + source: '../../coffee/foo.coffee' + }); + bundleMap.setSourceContent('../../coffee/foo.coffee', 'foo coffee'); + bundleMap.addMapping({ + generated: { line: 13, column: 13 }, + original: { line: 12, column: 12 }, + source: '/bar.coffee' + }); + bundleMap.setSourceContent('/bar.coffee', 'bar coffee'); + bundleMap.addMapping({ + generated: { line: 23, column: 23 }, + original: { line: 22, column: 22 }, + source: 'http://www.example.com/baz.coffee' + }); + bundleMap.setSourceContent( + 'http://www.example.com/baz.coffee', + 'baz coffee' + ); + bundleMap = new SourceMapConsumer(bundleMap.toJSON()); + + var minifiedMap = new SourceMapGenerator({ + file: 'bundle.min.js', + sourceRoot: '..' + }); + minifiedMap.addMapping({ + generated: { line: 1, column: 1 }, + original: { line: 3, column: 3 }, + source: 'temp/bundle.js' + }); + minifiedMap.addMapping({ + generated: { line: 11, column: 11 }, + original: { line: 13, column: 13 }, + source: 'temp/bundle.js' + }); + minifiedMap.addMapping({ + generated: { line: 21, column: 21 }, + original: { line: 23, column: 23 }, + source: 'temp/bundle.js' + }); + minifiedMap = new SourceMapConsumer(minifiedMap.toJSON()); + + var expectedMap = function (sources) { + var map = new SourceMapGenerator({ + file: 'bundle.min.js', + sourceRoot: '..' + }); + map.addMapping({ + generated: { line: 1, column: 1 }, + original: { line: 2, column: 2 }, + source: sources[0] + }); + map.setSourceContent(sources[0], 'foo coffee'); + map.addMapping({ + generated: { line: 11, column: 11 }, + original: { line: 12, column: 12 }, + source: sources[1] + }); + map.setSourceContent(sources[1], 'bar coffee'); + map.addMapping({ + generated: { line: 21, column: 21 }, + original: { line: 22, column: 22 }, + source: sources[2] + }); + map.setSourceContent(sources[2], 'baz coffee'); + return map.toJSON(); + } + + var actualMap = function (aSourceMapPath) { + var map = SourceMapGenerator.fromSourceMap(minifiedMap); + // Note that relying on `bundleMap.file` (which is simply 'bundle.js') + // instead of supplying the second parameter wouldn't work here. + map.applySourceMap(bundleMap, '../temp/bundle.js', aSourceMapPath); + return map.toJSON(); + } + + util.assertEqualMaps(assert, actualMap('../temp/temp_maps'), expectedMap([ + 'coffee/foo.coffee', + '/bar.coffee', + 'http://www.example.com/baz.coffee' + ])); + + util.assertEqualMaps(assert, actualMap('/app/temp/temp_maps'), expectedMap([ + '/app/coffee/foo.coffee', + '/bar.coffee', + 'http://www.example.com/baz.coffee' + ])); + + util.assertEqualMaps(assert, actualMap('http://foo.org/app/temp/temp_maps'), expectedMap([ + 'http://foo.org/app/coffee/foo.coffee', + 'http://foo.org/bar.coffee', + 'http://www.example.com/baz.coffee' + ])); + + // If the third parameter is omitted or set to the current working + // directory we get incorrect source paths: + + util.assertEqualMaps(assert, actualMap(), expectedMap([ + '../coffee/foo.coffee', + '/bar.coffee', + 'http://www.example.com/baz.coffee' + ])); + + util.assertEqualMaps(assert, actualMap(''), expectedMap([ + '../coffee/foo.coffee', + '/bar.coffee', + 'http://www.example.com/baz.coffee' + ])); + + util.assertEqualMaps(assert, actualMap('.'), expectedMap([ + '../coffee/foo.coffee', + '/bar.coffee', + 'http://www.example.com/baz.coffee' + ])); + + util.assertEqualMaps(assert, actualMap('./'), expectedMap([ + '../coffee/foo.coffee', + '/bar.coffee', + 'http://www.example.com/baz.coffee' + ])); + }; + + exports['test applySourceMap name handling'] = function (assert) { + // Imagine some CoffeeScript code being compiled into JavaScript and then + // minified. + + var assertName = function(coffeeName, jsName, expectedName) { + var minifiedMap = new SourceMapGenerator({ + file: 'test.js.min' + }); + minifiedMap.addMapping({ + generated: { line: 1, column: 4 }, + original: { line: 1, column: 4 }, + source: 'test.js', + name: jsName + }); + + var coffeeMap = new SourceMapGenerator({ + file: 'test.js' + }); + coffeeMap.addMapping({ + generated: { line: 1, column: 4 }, + original: { line: 1, column: 0 }, + source: 'test.coffee', + name: coffeeName + }); + + minifiedMap.applySourceMap(new SourceMapConsumer(coffeeMap.toJSON())); + + new SourceMapConsumer(minifiedMap.toJSON()).eachMapping(function(mapping) { + assert.equal(mapping.name, expectedName); + }); + }; + + // `foo = 1` -> `var foo = 1;` -> `var a=1` + // CoffeeScript doesn’t rename variables, so there’s no need for it to + // provide names in its source maps. Minifiers do rename variables and + // therefore do provide names in their source maps. So that name should be + // retained if the original map lacks names. + assertName(null, 'foo', 'foo'); + + // `foo = 1` -> `var coffee$foo = 1;` -> `var a=1` + // Imagine that CoffeeScript prefixed all variables with `coffee$`. Even + // though the minifier then also provides a name, the original name is + // what corresponds to the source. + assertName('foo', 'coffee$foo', 'foo'); + + // `foo = 1` -> `var coffee$foo = 1;` -> `var coffee$foo=1` + // Minifiers can turn off variable mangling. Then there’s no need to + // provide names in the source map, but the names from the original map are + // still needed. + assertName('foo', null, 'foo'); + + // `foo = 1` -> `var foo = 1;` -> `var foo=1` + // No renaming at all. + assertName(null, null, null); + }; + + exports['test sorting with duplicate generated mappings'] = function (assert) { + var map = new SourceMapGenerator({ + file: 'test.js' + }); + map.addMapping({ + generated: { line: 3, column: 0 }, + original: { line: 2, column: 0 }, + source: 'a.js' + }); + map.addMapping({ + generated: { line: 2, column: 0 } + }); + map.addMapping({ + generated: { line: 2, column: 0 } + }); + map.addMapping({ + generated: { line: 1, column: 0 }, + original: { line: 1, column: 0 }, + source: 'a.js' + }); + + util.assertEqualMaps(assert, map.toJSON(), { + version: 3, + file: 'test.js', + sources: ['a.js'], + names: [], + mappings: 'AAAA;A;AACA' + }); + }; + + exports['test ignore duplicate mappings.'] = function (assert) { + var init = { file: 'min.js', sourceRoot: '/the/root' }; + var map1, map2; + + // null original source location + var nullMapping1 = { + generated: { line: 1, column: 0 } + }; + var nullMapping2 = { + generated: { line: 2, column: 2 } + }; + + map1 = new SourceMapGenerator(init); + map2 = new SourceMapGenerator(init); + + map1.addMapping(nullMapping1); + map1.addMapping(nullMapping1); + + map2.addMapping(nullMapping1); + + util.assertEqualMaps(assert, map1.toJSON(), map2.toJSON()); + + map1.addMapping(nullMapping2); + map1.addMapping(nullMapping1); + + map2.addMapping(nullMapping2); + + util.assertEqualMaps(assert, map1.toJSON(), map2.toJSON()); + + // original source location + var srcMapping1 = { + generated: { line: 1, column: 0 }, + original: { line: 11, column: 0 }, + source: 'srcMapping1.js' + }; + var srcMapping2 = { + generated: { line: 2, column: 2 }, + original: { line: 11, column: 0 }, + source: 'srcMapping2.js' + }; + + map1 = new SourceMapGenerator(init); + map2 = new SourceMapGenerator(init); + + map1.addMapping(srcMapping1); + map1.addMapping(srcMapping1); + + map2.addMapping(srcMapping1); + + util.assertEqualMaps(assert, map1.toJSON(), map2.toJSON()); + + map1.addMapping(srcMapping2); + map1.addMapping(srcMapping1); + + map2.addMapping(srcMapping2); + + util.assertEqualMaps(assert, map1.toJSON(), map2.toJSON()); + + // full original source and name information + var fullMapping1 = { + generated: { line: 1, column: 0 }, + original: { line: 11, column: 0 }, + source: 'fullMapping1.js', + name: 'fullMapping1' + }; + var fullMapping2 = { + generated: { line: 2, column: 2 }, + original: { line: 11, column: 0 }, + source: 'fullMapping2.js', + name: 'fullMapping2' + }; + + map1 = new SourceMapGenerator(init); + map2 = new SourceMapGenerator(init); + + map1.addMapping(fullMapping1); + map1.addMapping(fullMapping1); + + map2.addMapping(fullMapping1); + + util.assertEqualMaps(assert, map1.toJSON(), map2.toJSON()); + + map1.addMapping(fullMapping2); + map1.addMapping(fullMapping1); + + map2.addMapping(fullMapping2); + + util.assertEqualMaps(assert, map1.toJSON(), map2.toJSON()); + }; + + exports['test github issue #72, check for duplicate names or sources'] = function (assert) { + var map = new SourceMapGenerator({ + file: 'test.js' + }); + map.addMapping({ + generated: { line: 1, column: 1 }, + original: { line: 2, column: 2 }, + source: 'a.js', + name: 'foo' + }); + map.addMapping({ + generated: { line: 3, column: 3 }, + original: { line: 4, column: 4 }, + source: 'a.js', + name: 'foo' + }); + util.assertEqualMaps(assert, map.toJSON(), { + version: 3, + file: 'test.js', + sources: ['a.js'], + names: ['foo'], + mappings: 'CACEA;;GAEEA' + }); + }; + + exports['test setting sourcesContent to null when already null'] = function (assert) { + var smg = new SourceMapGenerator({ file: "foo.js" }); + assert.doesNotThrow(function() { + smg.setSourceContent("bar.js", null); + }); + }; + + exports['test applySourceMap with unexact match'] = function (assert) { + var map1 = new SourceMapGenerator({ + file: 'bundled-source' + }); + map1.addMapping({ + generated: { line: 1, column: 4 }, + original: { line: 1, column: 4 }, + source: 'transformed-source' + }); + map1.addMapping({ + generated: { line: 2, column: 4 }, + original: { line: 2, column: 4 }, + source: 'transformed-source' + }); + + var map2 = new SourceMapGenerator({ + file: 'transformed-source' + }); + map2.addMapping({ + generated: { line: 2, column: 0 }, + original: { line: 1, column: 0 }, + source: 'original-source' + }); + + var expectedMap = new SourceMapGenerator({ + file: 'bundled-source' + }); + expectedMap.addMapping({ + generated: { line: 1, column: 4 }, + original: { line: 1, column: 4 }, + source: 'transformed-source' + }); + expectedMap.addMapping({ + generated: { line: 2, column: 4 }, + original: { line: 1, column: 0 }, + source: 'original-source' + }); + + map1.applySourceMap(new SourceMapConsumer(map2.toJSON())); + + util.assertEqualMaps(assert, map1.toJSON(), expectedMap.toJSON()); + }; + + exports['test issue #192'] = function (assert) { + var generator = new SourceMapGenerator(); + generator.addMapping({ + source: 'a.js', + generated: { line: 1, column: 10 }, + original: { line: 1, column: 10 }, + }); + generator.addMapping({ + source: 'b.js', + generated: { line: 1, column: 10 }, + original: { line: 2, column: 20 }, + }); + + var consumer = new SourceMapConsumer(generator.toJSON()); + + var n = 0; + consumer.eachMapping(function () { n++ }); + + assert.equal(n, 2, + "Should not de-duplicate mappings that have the same " + + "generated positions, but different original positions."); + }; + } + + +/***/ }, +/* 1 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var base64VLQ = __webpack_require__(2); + var util = __webpack_require__(4); + var ArraySet = __webpack_require__(5).ArraySet; + var MappingList = __webpack_require__(6).MappingList; + + /** + * An instance of the SourceMapGenerator represents a source map which is + * being built incrementally. You may pass an object with the following + * properties: + * + * - file: The filename of the generated source. + * - sourceRoot: A root for all relative URLs in this source map. + */ + function SourceMapGenerator(aArgs) { + if (!aArgs) { + aArgs = {}; + } + this._file = util.getArg(aArgs, 'file', null); + this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null); + this._skipValidation = util.getArg(aArgs, 'skipValidation', false); + this._sources = new ArraySet(); + this._names = new ArraySet(); + this._mappings = new MappingList(); + this._sourcesContents = null; + } + + SourceMapGenerator.prototype._version = 3; + + /** + * Creates a new SourceMapGenerator based on a SourceMapConsumer + * + * @param aSourceMapConsumer The SourceMap. + */ + SourceMapGenerator.fromSourceMap = + function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) { + var sourceRoot = aSourceMapConsumer.sourceRoot; + var generator = new SourceMapGenerator({ + file: aSourceMapConsumer.file, + sourceRoot: sourceRoot + }); + aSourceMapConsumer.eachMapping(function (mapping) { + var newMapping = { + generated: { + line: mapping.generatedLine, + column: mapping.generatedColumn + } + }; + + if (mapping.source != null) { + newMapping.source = mapping.source; + if (sourceRoot != null) { + newMapping.source = util.relative(sourceRoot, newMapping.source); + } + + newMapping.original = { + line: mapping.originalLine, + column: mapping.originalColumn + }; + + if (mapping.name != null) { + newMapping.name = mapping.name; + } + } + + generator.addMapping(newMapping); + }); + aSourceMapConsumer.sources.forEach(function (sourceFile) { + var content = aSourceMapConsumer.sourceContentFor(sourceFile); + if (content != null) { + generator.setSourceContent(sourceFile, content); + } + }); + return generator; + }; + + /** + * Add a single mapping from original source line and column to the generated + * source's line and column for this source map being created. The mapping + * object should have the following properties: + * + * - generated: An object with the generated line and column positions. + * - original: An object with the original line and column positions. + * - source: The original source file (relative to the sourceRoot). + * - name: An optional original token name for this mapping. + */ + SourceMapGenerator.prototype.addMapping = + function SourceMapGenerator_addMapping(aArgs) { + var generated = util.getArg(aArgs, 'generated'); + var original = util.getArg(aArgs, 'original', null); + var source = util.getArg(aArgs, 'source', null); + var name = util.getArg(aArgs, 'name', null); + + if (!this._skipValidation) { + this._validateMapping(generated, original, source, name); + } + + if (source != null && !this._sources.has(source)) { + this._sources.add(source); + } + + if (name != null && !this._names.has(name)) { + this._names.add(name); + } + + this._mappings.add({ + generatedLine: generated.line, + generatedColumn: generated.column, + originalLine: original != null && original.line, + originalColumn: original != null && original.column, + source: source, + name: name + }); + }; + + /** + * Set the source content for a source file. + */ + SourceMapGenerator.prototype.setSourceContent = + function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) { + var source = aSourceFile; + if (this._sourceRoot != null) { + source = util.relative(this._sourceRoot, source); + } + + if (aSourceContent != null) { + // Add the source content to the _sourcesContents map. + // Create a new _sourcesContents map if the property is null. + if (!this._sourcesContents) { + this._sourcesContents = {}; + } + this._sourcesContents[util.toSetString(source)] = aSourceContent; + } else if (this._sourcesContents) { + // Remove the source file from the _sourcesContents map. + // If the _sourcesContents map is empty, set the property to null. + delete this._sourcesContents[util.toSetString(source)]; + if (Object.keys(this._sourcesContents).length === 0) { + this._sourcesContents = null; + } + } + }; + + /** + * Applies the mappings of a sub-source-map for a specific source file to the + * source map being generated. Each mapping to the supplied source file is + * rewritten using the supplied source map. Note: The resolution for the + * resulting mappings is the minimium of this map and the supplied map. + * + * @param aSourceMapConsumer The source map to be applied. + * @param aSourceFile Optional. The filename of the source file. + * If omitted, SourceMapConsumer's file property will be used. + * @param aSourceMapPath Optional. The dirname of the path to the source map + * to be applied. If relative, it is relative to the SourceMapConsumer. + * This parameter is needed when the two source maps aren't in the same + * directory, and the source map to be applied contains relative source + * paths. If so, those relative source paths need to be rewritten + * relative to the SourceMapGenerator. + */ + SourceMapGenerator.prototype.applySourceMap = + function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) { + var sourceFile = aSourceFile; + // If aSourceFile is omitted, we will use the file property of the SourceMap + if (aSourceFile == null) { + if (aSourceMapConsumer.file == null) { + throw new Error( + 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' + + 'or the source map\'s "file" property. Both were omitted.' + ); + } + sourceFile = aSourceMapConsumer.file; + } + var sourceRoot = this._sourceRoot; + // Make "sourceFile" relative if an absolute Url is passed. + if (sourceRoot != null) { + sourceFile = util.relative(sourceRoot, sourceFile); + } + // Applying the SourceMap can add and remove items from the sources and + // the names array. + var newSources = new ArraySet(); + var newNames = new ArraySet(); + + // Find mappings for the "sourceFile" + this._mappings.unsortedForEach(function (mapping) { + if (mapping.source === sourceFile && mapping.originalLine != null) { + // Check if it can be mapped by the source map, then update the mapping. + var original = aSourceMapConsumer.originalPositionFor({ + line: mapping.originalLine, + column: mapping.originalColumn + }); + if (original.source != null) { + // Copy mapping + mapping.source = original.source; + if (aSourceMapPath != null) { + mapping.source = util.join(aSourceMapPath, mapping.source) + } + if (sourceRoot != null) { + mapping.source = util.relative(sourceRoot, mapping.source); + } + mapping.originalLine = original.line; + mapping.originalColumn = original.column; + if (original.name != null) { + mapping.name = original.name; + } + } + } + + var source = mapping.source; + if (source != null && !newSources.has(source)) { + newSources.add(source); + } + + var name = mapping.name; + if (name != null && !newNames.has(name)) { + newNames.add(name); + } + + }, this); + this._sources = newSources; + this._names = newNames; + + // Copy sourcesContents of applied map. + aSourceMapConsumer.sources.forEach(function (sourceFile) { + var content = aSourceMapConsumer.sourceContentFor(sourceFile); + if (content != null) { + if (aSourceMapPath != null) { + sourceFile = util.join(aSourceMapPath, sourceFile); + } + if (sourceRoot != null) { + sourceFile = util.relative(sourceRoot, sourceFile); + } + this.setSourceContent(sourceFile, content); + } + }, this); + }; + + /** + * A mapping can have one of the three levels of data: + * + * 1. Just the generated position. + * 2. The Generated position, original position, and original source. + * 3. Generated and original position, original source, as well as a name + * token. + * + * To maintain consistency, we validate that any new mapping being added falls + * in to one of these categories. + */ + SourceMapGenerator.prototype._validateMapping = + function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource, + aName) { + if (aGenerated && 'line' in aGenerated && 'column' in aGenerated + && aGenerated.line > 0 && aGenerated.column >= 0 + && !aOriginal && !aSource && !aName) { + // Case 1. + return; + } + else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated + && aOriginal && 'line' in aOriginal && 'column' in aOriginal + && aGenerated.line > 0 && aGenerated.column >= 0 + && aOriginal.line > 0 && aOriginal.column >= 0 + && aSource) { + // Cases 2 and 3. + return; + } + else { + throw new Error('Invalid mapping: ' + JSON.stringify({ + generated: aGenerated, + source: aSource, + original: aOriginal, + name: aName + })); + } + }; + + /** + * Serialize the accumulated mappings in to the stream of base 64 VLQs + * specified by the source map format. + */ + SourceMapGenerator.prototype._serializeMappings = + function SourceMapGenerator_serializeMappings() { + var previousGeneratedColumn = 0; + var previousGeneratedLine = 1; + var previousOriginalColumn = 0; + var previousOriginalLine = 0; + var previousName = 0; + var previousSource = 0; + var result = ''; + var mapping; + var nameIdx; + var sourceIdx; + + var mappings = this._mappings.toArray(); + for (var i = 0, len = mappings.length; i < len; i++) { + mapping = mappings[i]; + + if (mapping.generatedLine !== previousGeneratedLine) { + previousGeneratedColumn = 0; + while (mapping.generatedLine !== previousGeneratedLine) { + result += ';'; + previousGeneratedLine++; + } + } + else { + if (i > 0) { + if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) { + continue; + } + result += ','; + } + } + + result += base64VLQ.encode(mapping.generatedColumn + - previousGeneratedColumn); + previousGeneratedColumn = mapping.generatedColumn; + + if (mapping.source != null) { + sourceIdx = this._sources.indexOf(mapping.source); + result += base64VLQ.encode(sourceIdx - previousSource); + previousSource = sourceIdx; + + // lines are stored 0-based in SourceMap spec version 3 + result += base64VLQ.encode(mapping.originalLine - 1 + - previousOriginalLine); + previousOriginalLine = mapping.originalLine - 1; + + result += base64VLQ.encode(mapping.originalColumn + - previousOriginalColumn); + previousOriginalColumn = mapping.originalColumn; + + if (mapping.name != null) { + nameIdx = this._names.indexOf(mapping.name); + result += base64VLQ.encode(nameIdx - previousName); + previousName = nameIdx; + } + } + } + + return result; + }; + + SourceMapGenerator.prototype._generateSourcesContent = + function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) { + return aSources.map(function (source) { + if (!this._sourcesContents) { + return null; + } + if (aSourceRoot != null) { + source = util.relative(aSourceRoot, source); + } + var key = util.toSetString(source); + return Object.prototype.hasOwnProperty.call(this._sourcesContents, + key) + ? this._sourcesContents[key] + : null; + }, this); + }; + + /** + * Externalize the source map. + */ + SourceMapGenerator.prototype.toJSON = + function SourceMapGenerator_toJSON() { + var map = { + version: this._version, + sources: this._sources.toArray(), + names: this._names.toArray(), + mappings: this._serializeMappings() + }; + if (this._file != null) { + map.file = this._file; + } + if (this._sourceRoot != null) { + map.sourceRoot = this._sourceRoot; + } + if (this._sourcesContents) { + map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot); + } + + return map; + }; + + /** + * Render the source map being generated to a string. + */ + SourceMapGenerator.prototype.toString = + function SourceMapGenerator_toString() { + return JSON.stringify(this.toJSON()); + }; + + exports.SourceMapGenerator = SourceMapGenerator; + } + + +/***/ }, +/* 2 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + * + * Based on the Base 64 VLQ implementation in Closure Compiler: + * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java + * + * Copyright 2011 The Closure Compiler Authors. All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + { + var base64 = __webpack_require__(3); + + // A single base 64 digit can contain 6 bits of data. For the base 64 variable + // length quantities we use in the source map spec, the first bit is the sign, + // the next four bits are the actual value, and the 6th bit is the + // continuation bit. The continuation bit tells us whether there are more + // digits in this value following this digit. + // + // Continuation + // | Sign + // | | + // V V + // 101011 + + var VLQ_BASE_SHIFT = 5; + + // binary: 100000 + var VLQ_BASE = 1 << VLQ_BASE_SHIFT; + + // binary: 011111 + var VLQ_BASE_MASK = VLQ_BASE - 1; + + // binary: 100000 + var VLQ_CONTINUATION_BIT = VLQ_BASE; + + /** + * Converts from a two-complement value to a value where the sign bit is + * placed in the least significant bit. For example, as decimals: + * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary) + * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary) + */ + function toVLQSigned(aValue) { + return aValue < 0 + ? ((-aValue) << 1) + 1 + : (aValue << 1) + 0; + } + + /** + * Converts to a two-complement value from a value where the sign bit is + * placed in the least significant bit. For example, as decimals: + * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1 + * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2 + */ + function fromVLQSigned(aValue) { + var isNegative = (aValue & 1) === 1; + var shifted = aValue >> 1; + return isNegative + ? -shifted + : shifted; + } + + /** + * Returns the base 64 VLQ encoded value. + */ + exports.encode = function base64VLQ_encode(aValue) { + var encoded = ""; + var digit; + + var vlq = toVLQSigned(aValue); + + do { + digit = vlq & VLQ_BASE_MASK; + vlq >>>= VLQ_BASE_SHIFT; + if (vlq > 0) { + // There are still more digits in this value, so we must make sure the + // continuation bit is marked. + digit |= VLQ_CONTINUATION_BIT; + } + encoded += base64.encode(digit); + } while (vlq > 0); + + return encoded; + }; + + /** + * Decodes the next base 64 VLQ value from the given string and returns the + * value and the rest of the string via the out parameter. + */ + exports.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) { + var strLen = aStr.length; + var result = 0; + var shift = 0; + var continuation, digit; + + do { + if (aIndex >= strLen) { + throw new Error("Expected more digits in base 64 VLQ value."); + } + + digit = base64.decode(aStr.charCodeAt(aIndex++)); + if (digit === -1) { + throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1)); + } + + continuation = !!(digit & VLQ_CONTINUATION_BIT); + digit &= VLQ_BASE_MASK; + result = result + (digit << shift); + shift += VLQ_BASE_SHIFT; + } while (continuation); + + aOutParam.value = fromVLQSigned(result); + aOutParam.rest = aIndex; + }; + } + + +/***/ }, +/* 3 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split(''); + + /** + * Encode an integer in the range of 0 to 63 to a single base 64 digit. + */ + exports.encode = function (number) { + if (0 <= number && number < intToCharMap.length) { + return intToCharMap[number]; + } + throw new TypeError("Must be between 0 and 63: " + number); + }; + + /** + * Decode a single base 64 character code digit to an integer. Returns -1 on + * failure. + */ + exports.decode = function (charCode) { + var bigA = 65; // 'A' + var bigZ = 90; // 'Z' + + var littleA = 97; // 'a' + var littleZ = 122; // 'z' + + var zero = 48; // '0' + var nine = 57; // '9' + + var plus = 43; // '+' + var slash = 47; // '/' + + var littleOffset = 26; + var numberOffset = 52; + + // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ + if (bigA <= charCode && charCode <= bigZ) { + return (charCode - bigA); + } + + // 26 - 51: abcdefghijklmnopqrstuvwxyz + if (littleA <= charCode && charCode <= littleZ) { + return (charCode - littleA + littleOffset); + } + + // 52 - 61: 0123456789 + if (zero <= charCode && charCode <= nine) { + return (charCode - zero + numberOffset); + } + + // 62: + + if (charCode == plus) { + return 62; + } + + // 63: / + if (charCode == slash) { + return 63; + } + + // Invalid base64 digit. + return -1; + }; + } + + +/***/ }, +/* 4 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + /** + * This is a helper function for getting values from parameter/options + * objects. + * + * @param args The object we are extracting values from + * @param name The name of the property we are getting. + * @param defaultValue An optional value to return if the property is missing + * from the object. If this is not specified and the property is missing, an + * error will be thrown. + */ + function getArg(aArgs, aName, aDefaultValue) { + if (aName in aArgs) { + return aArgs[aName]; + } else if (arguments.length === 3) { + return aDefaultValue; + } else { + throw new Error('"' + aName + '" is a required argument.'); + } + } + exports.getArg = getArg; + + var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.]*)(?::(\d+))?(\S*)$/; + var dataUrlRegexp = /^data:.+\,.+$/; + + function urlParse(aUrl) { + var match = aUrl.match(urlRegexp); + if (!match) { + return null; + } + return { + scheme: match[1], + auth: match[2], + host: match[3], + port: match[4], + path: match[5] + }; + } + exports.urlParse = urlParse; + + function urlGenerate(aParsedUrl) { + var url = ''; + if (aParsedUrl.scheme) { + url += aParsedUrl.scheme + ':'; + } + url += '//'; + if (aParsedUrl.auth) { + url += aParsedUrl.auth + '@'; + } + if (aParsedUrl.host) { + url += aParsedUrl.host; + } + if (aParsedUrl.port) { + url += ":" + aParsedUrl.port + } + if (aParsedUrl.path) { + url += aParsedUrl.path; + } + return url; + } + exports.urlGenerate = urlGenerate; + + /** + * Normalizes a path, or the path portion of a URL: + * + * - Replaces consequtive slashes with one slash. + * - Removes unnecessary '.' parts. + * - Removes unnecessary '/..' parts. + * + * Based on code in the Node.js 'path' core module. + * + * @param aPath The path or url to normalize. + */ + function normalize(aPath) { + var path = aPath; + var url = urlParse(aPath); + if (url) { + if (!url.path) { + return aPath; + } + path = url.path; + } + var isAbsolute = exports.isAbsolute(path); + + var parts = path.split(/\/+/); + for (var part, up = 0, i = parts.length - 1; i >= 0; i--) { + part = parts[i]; + if (part === '.') { + parts.splice(i, 1); + } else if (part === '..') { + up++; + } else if (up > 0) { + if (part === '') { + // The first part is blank if the path is absolute. Trying to go + // above the root is a no-op. Therefore we can remove all '..' parts + // directly after the root. + parts.splice(i + 1, up); + up = 0; + } else { + parts.splice(i, 2); + up--; + } + } + } + path = parts.join('/'); + + if (path === '') { + path = isAbsolute ? '/' : '.'; + } + + if (url) { + url.path = path; + return urlGenerate(url); + } + return path; + } + exports.normalize = normalize; + + /** + * Joins two paths/URLs. + * + * @param aRoot The root path or URL. + * @param aPath The path or URL to be joined with the root. + * + * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a + * scheme-relative URL: Then the scheme of aRoot, if any, is prepended + * first. + * - Otherwise aPath is a path. If aRoot is a URL, then its path portion + * is updated with the result and aRoot is returned. Otherwise the result + * is returned. + * - If aPath is absolute, the result is aPath. + * - Otherwise the two paths are joined with a slash. + * - Joining for example 'http://' and 'www.example.com' is also supported. + */ + function join(aRoot, aPath) { + if (aRoot === "") { + aRoot = "."; + } + if (aPath === "") { + aPath = "."; + } + var aPathUrl = urlParse(aPath); + var aRootUrl = urlParse(aRoot); + if (aRootUrl) { + aRoot = aRootUrl.path || '/'; + } + + // `join(foo, '//www.example.org')` + if (aPathUrl && !aPathUrl.scheme) { + if (aRootUrl) { + aPathUrl.scheme = aRootUrl.scheme; + } + return urlGenerate(aPathUrl); + } + + if (aPathUrl || aPath.match(dataUrlRegexp)) { + return aPath; + } + + // `join('http://', 'www.example.com')` + if (aRootUrl && !aRootUrl.host && !aRootUrl.path) { + aRootUrl.host = aPath; + return urlGenerate(aRootUrl); + } + + var joined = aPath.charAt(0) === '/' + ? aPath + : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath); + + if (aRootUrl) { + aRootUrl.path = joined; + return urlGenerate(aRootUrl); + } + return joined; + } + exports.join = join; + + exports.isAbsolute = function (aPath) { + return aPath.charAt(0) === '/' || !!aPath.match(urlRegexp); + }; + + /** + * Make a path relative to a URL or another path. + * + * @param aRoot The root path or URL. + * @param aPath The path or URL to be made relative to aRoot. + */ + function relative(aRoot, aPath) { + if (aRoot === "") { + aRoot = "."; + } + + aRoot = aRoot.replace(/\/$/, ''); + + // It is possible for the path to be above the root. In this case, simply + // checking whether the root is a prefix of the path won't work. Instead, we + // need to remove components from the root one by one, until either we find + // a prefix that fits, or we run out of components to remove. + var level = 0; + while (aPath.indexOf(aRoot + '/') !== 0) { + var index = aRoot.lastIndexOf("/"); + if (index < 0) { + return aPath; + } + + // If the only part of the root that is left is the scheme (i.e. http://, + // file:///, etc.), one or more slashes (/), or simply nothing at all, we + // have exhausted all components, so the path is not relative to the root. + aRoot = aRoot.slice(0, index); + if (aRoot.match(/^([^\/]+:\/)?\/*$/)) { + return aPath; + } + + ++level; + } + + // Make sure we add a "../" for each component we removed from the root. + return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1); + } + exports.relative = relative; + + /** + * Because behavior goes wacky when you set `__proto__` on objects, we + * have to prefix all the strings in our set with an arbitrary character. + * + * See https://github.com/mozilla/source-map/pull/31 and + * https://github.com/mozilla/source-map/issues/30 + * + * @param String aStr + */ + function toSetString(aStr) { + return '$' + aStr; + } + exports.toSetString = toSetString; + + function fromSetString(aStr) { + return aStr.substr(1); + } + exports.fromSetString = fromSetString; + + /** + * Comparator between two mappings where the original positions are compared. + * + * Optionally pass in `true` as `onlyCompareGenerated` to consider two + * mappings with the same original source/line/column, but different generated + * line and column the same. Useful when searching for a mapping with a + * stubbed out mapping. + */ + function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) { + var cmp = mappingA.source - mappingB.source; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0 || onlyCompareOriginal) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + return mappingA.name - mappingB.name; + } + exports.compareByOriginalPositions = compareByOriginalPositions; + + /** + * Comparator between two mappings with deflated source and name indices where + * the generated positions are compared. + * + * Optionally pass in `true` as `onlyCompareGenerated` to consider two + * mappings with the same generated line and column, but different + * source/name/original line and column the same. Useful when searching for a + * mapping with a stubbed out mapping. + */ + function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) { + var cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0 || onlyCompareGenerated) { + return cmp; + } + + cmp = mappingA.source - mappingB.source; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0) { + return cmp; + } + + return mappingA.name - mappingB.name; + } + exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated; + + function strcmp(aStr1, aStr2) { + if (aStr1 === aStr2) { + return 0; + } + + if (aStr1 > aStr2) { + return 1; + } + + return -1; + } + + /** + * Comparator between two mappings with inflated source and name strings where + * the generated positions are compared. + */ + function compareByGeneratedPositionsInflated(mappingA, mappingB) { + var cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0) { + return cmp; + } + + cmp = strcmp(mappingA.source, mappingB.source); + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0) { + return cmp; + } + + return strcmp(mappingA.name, mappingB.name); + } + exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated; + } + + +/***/ }, +/* 5 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var util = __webpack_require__(4); + + /** + * A data structure which is a combination of an array and a set. Adding a new + * member is O(1), testing for membership is O(1), and finding the index of an + * element is O(1). Removing elements from the set is not supported. Only + * strings are supported for membership. + */ + function ArraySet() { + this._array = []; + this._set = {}; + } + + /** + * Static method for creating ArraySet instances from an existing array. + */ + ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) { + var set = new ArraySet(); + for (var i = 0, len = aArray.length; i < len; i++) { + set.add(aArray[i], aAllowDuplicates); + } + return set; + }; + + /** + * Return how many unique items are in this ArraySet. If duplicates have been + * added, than those do not count towards the size. + * + * @returns Number + */ + ArraySet.prototype.size = function ArraySet_size() { + return Object.getOwnPropertyNames(this._set).length; + }; + + /** + * Add the given string to this set. + * + * @param String aStr + */ + ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) { + var sStr = util.toSetString(aStr); + var isDuplicate = this._set.hasOwnProperty(sStr); + var idx = this._array.length; + if (!isDuplicate || aAllowDuplicates) { + this._array.push(aStr); + } + if (!isDuplicate) { + this._set[sStr] = idx; + } + }; + + /** + * Is the given string a member of this set? + * + * @param String aStr + */ + ArraySet.prototype.has = function ArraySet_has(aStr) { + var sStr = util.toSetString(aStr); + return this._set.hasOwnProperty(sStr); + }; + + /** + * What is the index of the given string in the array? + * + * @param String aStr + */ + ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) { + var sStr = util.toSetString(aStr); + if (this._set.hasOwnProperty(sStr)) { + return this._set[sStr]; + } + throw new Error('"' + aStr + '" is not in the set.'); + }; + + /** + * What is the element at the given index? + * + * @param Number aIdx + */ + ArraySet.prototype.at = function ArraySet_at(aIdx) { + if (aIdx >= 0 && aIdx < this._array.length) { + return this._array[aIdx]; + } + throw new Error('No element indexed by ' + aIdx); + }; + + /** + * Returns the array representation of this set (which has the proper indices + * indicated by indexOf). Note that this is a copy of the internal array used + * for storing the members so that no one can mess with internal state. + */ + ArraySet.prototype.toArray = function ArraySet_toArray() { + return this._array.slice(); + }; + + exports.ArraySet = ArraySet; + } + + +/***/ }, +/* 6 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2014 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var util = __webpack_require__(4); + + /** + * Determine whether mappingB is after mappingA with respect to generated + * position. + */ + function generatedPositionAfter(mappingA, mappingB) { + // Optimized for most common case + var lineA = mappingA.generatedLine; + var lineB = mappingB.generatedLine; + var columnA = mappingA.generatedColumn; + var columnB = mappingB.generatedColumn; + return lineB > lineA || lineB == lineA && columnB >= columnA || + util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0; + } + + /** + * A data structure to provide a sorted view of accumulated mappings in a + * performance conscious manner. It trades a neglibable overhead in general + * case for a large speedup in case of mappings being added in order. + */ + function MappingList() { + this._array = []; + this._sorted = true; + // Serves as infimum + this._last = {generatedLine: -1, generatedColumn: 0}; + } + + /** + * Iterate through internal items. This method takes the same arguments that + * `Array.prototype.forEach` takes. + * + * NOTE: The order of the mappings is NOT guaranteed. + */ + MappingList.prototype.unsortedForEach = + function MappingList_forEach(aCallback, aThisArg) { + this._array.forEach(aCallback, aThisArg); + }; + + /** + * Add the given source mapping. + * + * @param Object aMapping + */ + MappingList.prototype.add = function MappingList_add(aMapping) { + if (generatedPositionAfter(this._last, aMapping)) { + this._last = aMapping; + this._array.push(aMapping); + } else { + this._sorted = false; + this._array.push(aMapping); + } + }; + + /** + * Returns the flat, sorted array of mappings. The mappings are sorted by + * generated position. + * + * WARNING: This method returns internal data without copying, for + * performance. The return value must NOT be mutated, and should be treated as + * an immutable borrow. If you want to take ownership, you must make your own + * copy. + */ + MappingList.prototype.toArray = function MappingList_toArray() { + if (!this._sorted) { + this._array.sort(util.compareByGeneratedPositionsInflated); + this._sorted = true; + } + return this._array; + }; + + exports.MappingList = MappingList; + } + + +/***/ }, +/* 7 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var util = __webpack_require__(4); + var binarySearch = __webpack_require__(8); + var ArraySet = __webpack_require__(5).ArraySet; + var base64VLQ = __webpack_require__(2); + var quickSort = __webpack_require__(9).quickSort; + + function SourceMapConsumer(aSourceMap) { + var sourceMap = aSourceMap; + if (typeof aSourceMap === 'string') { + sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); + } + + return sourceMap.sections != null + ? new IndexedSourceMapConsumer(sourceMap) + : new BasicSourceMapConsumer(sourceMap); + } + + SourceMapConsumer.fromSourceMap = function(aSourceMap) { + return BasicSourceMapConsumer.fromSourceMap(aSourceMap); + } + + /** + * The version of the source mapping spec that we are consuming. + */ + SourceMapConsumer.prototype._version = 3; + + // `__generatedMappings` and `__originalMappings` are arrays that hold the + // parsed mapping coordinates from the source map's "mappings" attribute. They + // are lazily instantiated, accessed via the `_generatedMappings` and + // `_originalMappings` getters respectively, and we only parse the mappings + // and create these arrays once queried for a source location. We jump through + // these hoops because there can be many thousands of mappings, and parsing + // them is expensive, so we only want to do it if we must. + // + // Each object in the arrays is of the form: + // + // { + // generatedLine: The line number in the generated code, + // generatedColumn: The column number in the generated code, + // source: The path to the original source file that generated this + // chunk of code, + // originalLine: The line number in the original source that + // corresponds to this chunk of generated code, + // originalColumn: The column number in the original source that + // corresponds to this chunk of generated code, + // name: The name of the original symbol which generated this chunk of + // code. + // } + // + // All properties except for `generatedLine` and `generatedColumn` can be + // `null`. + // + // `_generatedMappings` is ordered by the generated positions. + // + // `_originalMappings` is ordered by the original positions. + + SourceMapConsumer.prototype.__generatedMappings = null; + Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', { + get: function () { + if (!this.__generatedMappings) { + this._parseMappings(this._mappings, this.sourceRoot); + } + + return this.__generatedMappings; + } + }); + + SourceMapConsumer.prototype.__originalMappings = null; + Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', { + get: function () { + if (!this.__originalMappings) { + this._parseMappings(this._mappings, this.sourceRoot); + } + + return this.__originalMappings; + } + }); + + SourceMapConsumer.prototype._charIsMappingSeparator = + function SourceMapConsumer_charIsMappingSeparator(aStr, index) { + var c = aStr.charAt(index); + return c === ";" || c === ","; + }; + + /** + * Parse the mappings in a string in to a data structure which we can easily + * query (the ordered arrays in the `this.__generatedMappings` and + * `this.__originalMappings` properties). + */ + SourceMapConsumer.prototype._parseMappings = + function SourceMapConsumer_parseMappings(aStr, aSourceRoot) { + throw new Error("Subclasses must implement _parseMappings"); + }; + + SourceMapConsumer.GENERATED_ORDER = 1; + SourceMapConsumer.ORIGINAL_ORDER = 2; + + SourceMapConsumer.GREATEST_LOWER_BOUND = 1; + SourceMapConsumer.LEAST_UPPER_BOUND = 2; + + /** + * Iterate over each mapping between an original source/line/column and a + * generated line/column in this source map. + * + * @param Function aCallback + * The function that is called with each mapping. + * @param Object aContext + * Optional. If specified, this object will be the value of `this` every + * time that `aCallback` is called. + * @param aOrder + * Either `SourceMapConsumer.GENERATED_ORDER` or + * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to + * iterate over the mappings sorted by the generated file's line/column + * order or the original's source/line/column order, respectively. Defaults to + * `SourceMapConsumer.GENERATED_ORDER`. + */ + SourceMapConsumer.prototype.eachMapping = + function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) { + var context = aContext || null; + var order = aOrder || SourceMapConsumer.GENERATED_ORDER; + + var mappings; + switch (order) { + case SourceMapConsumer.GENERATED_ORDER: + mappings = this._generatedMappings; + break; + case SourceMapConsumer.ORIGINAL_ORDER: + mappings = this._originalMappings; + break; + default: + throw new Error("Unknown order of iteration."); + } + + var sourceRoot = this.sourceRoot; + mappings.map(function (mapping) { + var source = mapping.source === null ? null : this._sources.at(mapping.source); + if (source != null && sourceRoot != null) { + source = util.join(sourceRoot, source); + } + return { + source: source, + generatedLine: mapping.generatedLine, + generatedColumn: mapping.generatedColumn, + originalLine: mapping.originalLine, + originalColumn: mapping.originalColumn, + name: mapping.name === null ? null : this._names.at(mapping.name) + }; + }, this).forEach(aCallback, context); + }; + + /** + * Returns all generated line and column information for the original source, + * line, and column provided. If no column is provided, returns all mappings + * corresponding to a either the line we are searching for or the next + * closest line that has any mappings. Otherwise, returns all mappings + * corresponding to the given line and either the column we are searching for + * or the next closest column that has any offsets. + * + * The only argument is an object with the following properties: + * + * - source: The filename of the original source. + * - line: The line number in the original source. + * - column: Optional. the column number in the original source. + * + * and an array of objects is returned, each with the following properties: + * + * - line: The line number in the generated source, or null. + * - column: The column number in the generated source, or null. + */ + SourceMapConsumer.prototype.allGeneratedPositionsFor = + function SourceMapConsumer_allGeneratedPositionsFor(aArgs) { + var line = util.getArg(aArgs, 'line'); + + // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping + // returns the index of the closest mapping less than the needle. By + // setting needle.originalColumn to 0, we thus find the last mapping for + // the given line, provided such a mapping exists. + var needle = { + source: util.getArg(aArgs, 'source'), + originalLine: line, + originalColumn: util.getArg(aArgs, 'column', 0) + }; + + if (this.sourceRoot != null) { + needle.source = util.relative(this.sourceRoot, needle.source); + } + if (!this._sources.has(needle.source)) { + return []; + } + needle.source = this._sources.indexOf(needle.source); + + var mappings = []; + + var index = this._findMapping(needle, + this._originalMappings, + "originalLine", + "originalColumn", + util.compareByOriginalPositions, + binarySearch.LEAST_UPPER_BOUND); + if (index >= 0) { + var mapping = this._originalMappings[index]; + + if (aArgs.column === undefined) { + var originalLine = mapping.originalLine; + + // Iterate until either we run out of mappings, or we run into + // a mapping for a different line than the one we found. Since + // mappings are sorted, this is guaranteed to find all mappings for + // the line we found. + while (mapping && mapping.originalLine === originalLine) { + mappings.push({ + line: util.getArg(mapping, 'generatedLine', null), + column: util.getArg(mapping, 'generatedColumn', null), + lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) + }); + + mapping = this._originalMappings[++index]; + } + } else { + var originalColumn = mapping.originalColumn; + + // Iterate until either we run out of mappings, or we run into + // a mapping for a different line than the one we were searching for. + // Since mappings are sorted, this is guaranteed to find all mappings for + // the line we are searching for. + while (mapping && + mapping.originalLine === line && + mapping.originalColumn == originalColumn) { + mappings.push({ + line: util.getArg(mapping, 'generatedLine', null), + column: util.getArg(mapping, 'generatedColumn', null), + lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) + }); + + mapping = this._originalMappings[++index]; + } + } + } + + return mappings; + }; + + exports.SourceMapConsumer = SourceMapConsumer; + + /** + * A BasicSourceMapConsumer instance represents a parsed source map which we can + * query for information about the original file positions by giving it a file + * position in the generated source. + * + * The only parameter is the raw source map (either as a JSON string, or + * already parsed to an object). According to the spec, source maps have the + * following attributes: + * + * - version: Which version of the source map spec this map is following. + * - sources: An array of URLs to the original source files. + * - names: An array of identifiers which can be referrenced by individual mappings. + * - sourceRoot: Optional. The URL root from which all sources are relative. + * - sourcesContent: Optional. An array of contents of the original source files. + * - mappings: A string of base64 VLQs which contain the actual mappings. + * - file: Optional. The generated file this source map is associated with. + * + * Here is an example source map, taken from the source map spec[0]: + * + * { + * version : 3, + * file: "out.js", + * sourceRoot : "", + * sources: ["foo.js", "bar.js"], + * names: ["src", "maps", "are", "fun"], + * mappings: "AA,AB;;ABCDE;" + * } + * + * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1# + */ + function BasicSourceMapConsumer(aSourceMap) { + var sourceMap = aSourceMap; + if (typeof aSourceMap === 'string') { + sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); + } + + var version = util.getArg(sourceMap, 'version'); + var sources = util.getArg(sourceMap, 'sources'); + // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which + // requires the array) to play nice here. + var names = util.getArg(sourceMap, 'names', []); + var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null); + var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null); + var mappings = util.getArg(sourceMap, 'mappings'); + var file = util.getArg(sourceMap, 'file', null); + + // Once again, Sass deviates from the spec and supplies the version as a + // string rather than a number, so we use loose equality checking here. + if (version != this._version) { + throw new Error('Unsupported version: ' + version); + } + + sources = sources + // Some source maps produce relative source paths like "./foo.js" instead of + // "foo.js". Normalize these first so that future comparisons will succeed. + // See bugzil.la/1090768. + .map(util.normalize) + // Always ensure that absolute sources are internally stored relative to + // the source root, if the source root is absolute. Not doing this would + // be particularly problematic when the source root is a prefix of the + // source (valid, but why??). See github issue #199 and bugzil.la/1188982. + .map(function (source) { + return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source) + ? util.relative(sourceRoot, source) + : source; + }); + + // Pass `true` below to allow duplicate names and sources. While source maps + // are intended to be compressed and deduplicated, the TypeScript compiler + // sometimes generates source maps with duplicates in them. See Github issue + // #72 and bugzil.la/889492. + this._names = ArraySet.fromArray(names, true); + this._sources = ArraySet.fromArray(sources, true); + + this.sourceRoot = sourceRoot; + this.sourcesContent = sourcesContent; + this._mappings = mappings; + this.file = file; + } + + BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype); + BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer; + + /** + * Create a BasicSourceMapConsumer from a SourceMapGenerator. + * + * @param SourceMapGenerator aSourceMap + * The source map that will be consumed. + * @returns BasicSourceMapConsumer + */ + BasicSourceMapConsumer.fromSourceMap = + function SourceMapConsumer_fromSourceMap(aSourceMap) { + var smc = Object.create(BasicSourceMapConsumer.prototype); + + var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true); + var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true); + smc.sourceRoot = aSourceMap._sourceRoot; + smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(), + smc.sourceRoot); + smc.file = aSourceMap._file; + + // Because we are modifying the entries (by converting string sources and + // names to indices into the sources and names ArraySets), we have to make + // a copy of the entry or else bad things happen. Shared mutable state + // strikes again! See github issue #191. + + var generatedMappings = aSourceMap._mappings.toArray().slice(); + var destGeneratedMappings = smc.__generatedMappings = []; + var destOriginalMappings = smc.__originalMappings = []; + + for (var i = 0, length = generatedMappings.length; i < length; i++) { + var srcMapping = generatedMappings[i]; + var destMapping = new Mapping; + destMapping.generatedLine = srcMapping.generatedLine; + destMapping.generatedColumn = srcMapping.generatedColumn; + + if (srcMapping.source) { + destMapping.source = sources.indexOf(srcMapping.source); + destMapping.originalLine = srcMapping.originalLine; + destMapping.originalColumn = srcMapping.originalColumn; + + if (srcMapping.name) { + destMapping.name = names.indexOf(srcMapping.name); + } + + destOriginalMappings.push(destMapping); + } + + destGeneratedMappings.push(destMapping); + } + + quickSort(smc.__originalMappings, util.compareByOriginalPositions); + + return smc; + }; + + /** + * The version of the source mapping spec that we are consuming. + */ + BasicSourceMapConsumer.prototype._version = 3; + + /** + * The list of original sources. + */ + Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', { + get: function () { + return this._sources.toArray().map(function (s) { + return this.sourceRoot != null ? util.join(this.sourceRoot, s) : s; + }, this); + } + }); + + /** + * Provide the JIT with a nice shape / hidden class. + */ + function Mapping() { + this.generatedLine = 0; + this.generatedColumn = 0; + this.source = null; + this.originalLine = null; + this.originalColumn = null; + this.name = null; + } + + /** + * Parse the mappings in a string in to a data structure which we can easily + * query (the ordered arrays in the `this.__generatedMappings` and + * `this.__originalMappings` properties). + */ + BasicSourceMapConsumer.prototype._parseMappings = + function SourceMapConsumer_parseMappings(aStr, aSourceRoot) { + var generatedLine = 1; + var previousGeneratedColumn = 0; + var previousOriginalLine = 0; + var previousOriginalColumn = 0; + var previousSource = 0; + var previousName = 0; + var length = aStr.length; + var index = 0; + var cachedSegments = {}; + var temp = {}; + var originalMappings = []; + var generatedMappings = []; + var mapping, str, segment, end, value; + + while (index < length) { + if (aStr.charAt(index) === ';') { + generatedLine++; + index++; + previousGeneratedColumn = 0; + } + else if (aStr.charAt(index) === ',') { + index++; + } + else { + mapping = new Mapping(); + mapping.generatedLine = generatedLine; + + // Because each offset is encoded relative to the previous one, + // many segments often have the same encoding. We can exploit this + // fact by caching the parsed variable length fields of each segment, + // allowing us to avoid a second parse if we encounter the same + // segment again. + for (end = index; end < length; end++) { + if (this._charIsMappingSeparator(aStr, end)) { + break; + } + } + str = aStr.slice(index, end); + + segment = cachedSegments[str]; + if (segment) { + index += str.length; + } else { + segment = []; + while (index < end) { + base64VLQ.decode(aStr, index, temp); + value = temp.value; + index = temp.rest; + segment.push(value); + } + + if (segment.length === 2) { + throw new Error('Found a source, but no line and column'); + } + + if (segment.length === 3) { + throw new Error('Found a source and line, but no column'); + } + + cachedSegments[str] = segment; + } + + // Generated column. + mapping.generatedColumn = previousGeneratedColumn + segment[0]; + previousGeneratedColumn = mapping.generatedColumn; + + if (segment.length > 1) { + // Original source. + mapping.source = previousSource + segment[1]; + previousSource += segment[1]; + + // Original line. + mapping.originalLine = previousOriginalLine + segment[2]; + previousOriginalLine = mapping.originalLine; + // Lines are stored 0-based + mapping.originalLine += 1; + + // Original column. + mapping.originalColumn = previousOriginalColumn + segment[3]; + previousOriginalColumn = mapping.originalColumn; + + if (segment.length > 4) { + // Original name. + mapping.name = previousName + segment[4]; + previousName += segment[4]; + } + } + + generatedMappings.push(mapping); + if (typeof mapping.originalLine === 'number') { + originalMappings.push(mapping); + } + } + } + + quickSort(generatedMappings, util.compareByGeneratedPositionsDeflated); + this.__generatedMappings = generatedMappings; + + quickSort(originalMappings, util.compareByOriginalPositions); + this.__originalMappings = originalMappings; + }; + + /** + * Find the mapping that best matches the hypothetical "needle" mapping that + * we are searching for in the given "haystack" of mappings. + */ + BasicSourceMapConsumer.prototype._findMapping = + function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName, + aColumnName, aComparator, aBias) { + // To return the position we are searching for, we must first find the + // mapping for the given position and then return the opposite position it + // points to. Because the mappings are sorted, we can use binary search to + // find the best mapping. + + if (aNeedle[aLineName] <= 0) { + throw new TypeError('Line must be greater than or equal to 1, got ' + + aNeedle[aLineName]); + } + if (aNeedle[aColumnName] < 0) { + throw new TypeError('Column must be greater than or equal to 0, got ' + + aNeedle[aColumnName]); + } + + return binarySearch.search(aNeedle, aMappings, aComparator, aBias); + }; + + /** + * Compute the last column for each generated mapping. The last column is + * inclusive. + */ + BasicSourceMapConsumer.prototype.computeColumnSpans = + function SourceMapConsumer_computeColumnSpans() { + for (var index = 0; index < this._generatedMappings.length; ++index) { + var mapping = this._generatedMappings[index]; + + // Mappings do not contain a field for the last generated columnt. We + // can come up with an optimistic estimate, however, by assuming that + // mappings are contiguous (i.e. given two consecutive mappings, the + // first mapping ends where the second one starts). + if (index + 1 < this._generatedMappings.length) { + var nextMapping = this._generatedMappings[index + 1]; + + if (mapping.generatedLine === nextMapping.generatedLine) { + mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1; + continue; + } + } + + // The last mapping for each line spans the entire line. + mapping.lastGeneratedColumn = Infinity; + } + }; + + /** + * Returns the original source, line, and column information for the generated + * source's line and column positions provided. The only argument is an object + * with the following properties: + * + * - line: The line number in the generated source. + * - column: The column number in the generated source. + * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or + * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. + * + * and an object is returned with the following properties: + * + * - source: The original source file, or null. + * - line: The line number in the original source, or null. + * - column: The column number in the original source, or null. + * - name: The original identifier, or null. + */ + BasicSourceMapConsumer.prototype.originalPositionFor = + function SourceMapConsumer_originalPositionFor(aArgs) { + var needle = { + generatedLine: util.getArg(aArgs, 'line'), + generatedColumn: util.getArg(aArgs, 'column') + }; + + var index = this._findMapping( + needle, + this._generatedMappings, + "generatedLine", + "generatedColumn", + util.compareByGeneratedPositionsDeflated, + util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND) + ); + + if (index >= 0) { + var mapping = this._generatedMappings[index]; + + if (mapping.generatedLine === needle.generatedLine) { + var source = util.getArg(mapping, 'source', null); + if (source !== null) { + source = this._sources.at(source); + if (this.sourceRoot != null) { + source = util.join(this.sourceRoot, source); + } + } + var name = util.getArg(mapping, 'name', null); + if (name !== null) { + name = this._names.at(name); + } + return { + source: source, + line: util.getArg(mapping, 'originalLine', null), + column: util.getArg(mapping, 'originalColumn', null), + name: name + }; + } + } + + return { + source: null, + line: null, + column: null, + name: null + }; + }; + + /** + * Return true if we have the source content for every source in the source + * map, false otherwise. + */ + BasicSourceMapConsumer.prototype.hasContentsOfAllSources = + function BasicSourceMapConsumer_hasContentsOfAllSources() { + if (!this.sourcesContent) { + return false; + } + return this.sourcesContent.length >= this._sources.size() && + !this.sourcesContent.some(function (sc) { return sc == null; }); + }; + + /** + * Returns the original source content. The only argument is the url of the + * original source file. Returns null if no original source content is + * availible. + */ + BasicSourceMapConsumer.prototype.sourceContentFor = + function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) { + if (!this.sourcesContent) { + return null; + } + + if (this.sourceRoot != null) { + aSource = util.relative(this.sourceRoot, aSource); + } + + if (this._sources.has(aSource)) { + return this.sourcesContent[this._sources.indexOf(aSource)]; + } + + var url; + if (this.sourceRoot != null + && (url = util.urlParse(this.sourceRoot))) { + // XXX: file:// URIs and absolute paths lead to unexpected behavior for + // many users. We can help them out when they expect file:// URIs to + // behave like it would if they were running a local HTTP server. See + // https://bugzilla.mozilla.org/show_bug.cgi?id=885597. + var fileUriAbsPath = aSource.replace(/^file:\/\//, ""); + if (url.scheme == "file" + && this._sources.has(fileUriAbsPath)) { + return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)] + } + + if ((!url.path || url.path == "/") + && this._sources.has("/" + aSource)) { + return this.sourcesContent[this._sources.indexOf("/" + aSource)]; + } + } + + // This function is used recursively from + // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we + // don't want to throw if we can't find the source - we just want to + // return null, so we provide a flag to exit gracefully. + if (nullOnMissing) { + return null; + } + else { + throw new Error('"' + aSource + '" is not in the SourceMap.'); + } + }; + + /** + * Returns the generated line and column information for the original source, + * line, and column positions provided. The only argument is an object with + * the following properties: + * + * - source: The filename of the original source. + * - line: The line number in the original source. + * - column: The column number in the original source. + * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or + * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. + * + * and an object is returned with the following properties: + * + * - line: The line number in the generated source, or null. + * - column: The column number in the generated source, or null. + */ + BasicSourceMapConsumer.prototype.generatedPositionFor = + function SourceMapConsumer_generatedPositionFor(aArgs) { + var source = util.getArg(aArgs, 'source'); + if (this.sourceRoot != null) { + source = util.relative(this.sourceRoot, source); + } + if (!this._sources.has(source)) { + return { + line: null, + column: null, + lastColumn: null + }; + } + source = this._sources.indexOf(source); + + var needle = { + source: source, + originalLine: util.getArg(aArgs, 'line'), + originalColumn: util.getArg(aArgs, 'column') + }; + + var index = this._findMapping( + needle, + this._originalMappings, + "originalLine", + "originalColumn", + util.compareByOriginalPositions, + util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND) + ); + + if (index >= 0) { + var mapping = this._originalMappings[index]; + + if (mapping.source === needle.source) { + return { + line: util.getArg(mapping, 'generatedLine', null), + column: util.getArg(mapping, 'generatedColumn', null), + lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) + }; + } + } + + return { + line: null, + column: null, + lastColumn: null + }; + }; + + exports.BasicSourceMapConsumer = BasicSourceMapConsumer; + + /** + * An IndexedSourceMapConsumer instance represents a parsed source map which + * we can query for information. It differs from BasicSourceMapConsumer in + * that it takes "indexed" source maps (i.e. ones with a "sections" field) as + * input. + * + * The only parameter is a raw source map (either as a JSON string, or already + * parsed to an object). According to the spec for indexed source maps, they + * have the following attributes: + * + * - version: Which version of the source map spec this map is following. + * - file: Optional. The generated file this source map is associated with. + * - sections: A list of section definitions. + * + * Each value under the "sections" field has two fields: + * - offset: The offset into the original specified at which this section + * begins to apply, defined as an object with a "line" and "column" + * field. + * - map: A source map definition. This source map could also be indexed, + * but doesn't have to be. + * + * Instead of the "map" field, it's also possible to have a "url" field + * specifying a URL to retrieve a source map from, but that's currently + * unsupported. + * + * Here's an example source map, taken from the source map spec[0], but + * modified to omit a section which uses the "url" field. + * + * { + * version : 3, + * file: "app.js", + * sections: [{ + * offset: {line:100, column:10}, + * map: { + * version : 3, + * file: "section.js", + * sources: ["foo.js", "bar.js"], + * names: ["src", "maps", "are", "fun"], + * mappings: "AAAA,E;;ABCDE;" + * } + * }], + * } + * + * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt + */ + function IndexedSourceMapConsumer(aSourceMap) { + var sourceMap = aSourceMap; + if (typeof aSourceMap === 'string') { + sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); + } + + var version = util.getArg(sourceMap, 'version'); + var sections = util.getArg(sourceMap, 'sections'); + + if (version != this._version) { + throw new Error('Unsupported version: ' + version); + } + + this._sources = new ArraySet(); + this._names = new ArraySet(); + + var lastOffset = { + line: -1, + column: 0 + }; + this._sections = sections.map(function (s) { + if (s.url) { + // The url field will require support for asynchronicity. + // See https://github.com/mozilla/source-map/issues/16 + throw new Error('Support for url field in sections not implemented.'); + } + var offset = util.getArg(s, 'offset'); + var offsetLine = util.getArg(offset, 'line'); + var offsetColumn = util.getArg(offset, 'column'); + + if (offsetLine < lastOffset.line || + (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) { + throw new Error('Section offsets must be ordered and non-overlapping.'); + } + lastOffset = offset; + + return { + generatedOffset: { + // The offset fields are 0-based, but we use 1-based indices when + // encoding/decoding from VLQ. + generatedLine: offsetLine + 1, + generatedColumn: offsetColumn + 1 + }, + consumer: new SourceMapConsumer(util.getArg(s, 'map')) + } + }); + } + + IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype); + IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer; + + /** + * The version of the source mapping spec that we are consuming. + */ + IndexedSourceMapConsumer.prototype._version = 3; + + /** + * The list of original sources. + */ + Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', { + get: function () { + var sources = []; + for (var i = 0; i < this._sections.length; i++) { + for (var j = 0; j < this._sections[i].consumer.sources.length; j++) { + sources.push(this._sections[i].consumer.sources[j]); + } + } + return sources; + } + }); + + /** + * Returns the original source, line, and column information for the generated + * source's line and column positions provided. The only argument is an object + * with the following properties: + * + * - line: The line number in the generated source. + * - column: The column number in the generated source. + * + * and an object is returned with the following properties: + * + * - source: The original source file, or null. + * - line: The line number in the original source, or null. + * - column: The column number in the original source, or null. + * - name: The original identifier, or null. + */ + IndexedSourceMapConsumer.prototype.originalPositionFor = + function IndexedSourceMapConsumer_originalPositionFor(aArgs) { + var needle = { + generatedLine: util.getArg(aArgs, 'line'), + generatedColumn: util.getArg(aArgs, 'column') + }; + + // Find the section containing the generated position we're trying to map + // to an original position. + var sectionIndex = binarySearch.search(needle, this._sections, + function(needle, section) { + var cmp = needle.generatedLine - section.generatedOffset.generatedLine; + if (cmp) { + return cmp; + } + + return (needle.generatedColumn - + section.generatedOffset.generatedColumn); + }); + var section = this._sections[sectionIndex]; + + if (!section) { + return { + source: null, + line: null, + column: null, + name: null + }; + } + + return section.consumer.originalPositionFor({ + line: needle.generatedLine - + (section.generatedOffset.generatedLine - 1), + column: needle.generatedColumn - + (section.generatedOffset.generatedLine === needle.generatedLine + ? section.generatedOffset.generatedColumn - 1 + : 0), + bias: aArgs.bias + }); + }; + + /** + * Return true if we have the source content for every source in the source + * map, false otherwise. + */ + IndexedSourceMapConsumer.prototype.hasContentsOfAllSources = + function IndexedSourceMapConsumer_hasContentsOfAllSources() { + return this._sections.every(function (s) { + return s.consumer.hasContentsOfAllSources(); + }); + }; + + /** + * Returns the original source content. The only argument is the url of the + * original source file. Returns null if no original source content is + * available. + */ + IndexedSourceMapConsumer.prototype.sourceContentFor = + function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) { + for (var i = 0; i < this._sections.length; i++) { + var section = this._sections[i]; + + var content = section.consumer.sourceContentFor(aSource, true); + if (content) { + return content; + } + } + if (nullOnMissing) { + return null; + } + else { + throw new Error('"' + aSource + '" is not in the SourceMap.'); + } + }; + + /** + * Returns the generated line and column information for the original source, + * line, and column positions provided. The only argument is an object with + * the following properties: + * + * - source: The filename of the original source. + * - line: The line number in the original source. + * - column: The column number in the original source. + * + * and an object is returned with the following properties: + * + * - line: The line number in the generated source, or null. + * - column: The column number in the generated source, or null. + */ + IndexedSourceMapConsumer.prototype.generatedPositionFor = + function IndexedSourceMapConsumer_generatedPositionFor(aArgs) { + for (var i = 0; i < this._sections.length; i++) { + var section = this._sections[i]; + + // Only consider this section if the requested source is in the list of + // sources of the consumer. + if (section.consumer.sources.indexOf(util.getArg(aArgs, 'source')) === -1) { + continue; + } + var generatedPosition = section.consumer.generatedPositionFor(aArgs); + if (generatedPosition) { + var ret = { + line: generatedPosition.line + + (section.generatedOffset.generatedLine - 1), + column: generatedPosition.column + + (section.generatedOffset.generatedLine === generatedPosition.line + ? section.generatedOffset.generatedColumn - 1 + : 0) + }; + return ret; + } + } + + return { + line: null, + column: null + }; + }; + + /** + * Parse the mappings in a string in to a data structure which we can easily + * query (the ordered arrays in the `this.__generatedMappings` and + * `this.__originalMappings` properties). + */ + IndexedSourceMapConsumer.prototype._parseMappings = + function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) { + this.__generatedMappings = []; + this.__originalMappings = []; + for (var i = 0; i < this._sections.length; i++) { + var section = this._sections[i]; + var sectionMappings = section.consumer._generatedMappings; + for (var j = 0; j < sectionMappings.length; j++) { + var mapping = sectionMappings[i]; + + var source = section.consumer._sources.at(mapping.source); + if (section.consumer.sourceRoot !== null) { + source = util.join(section.consumer.sourceRoot, source); + } + this._sources.add(source); + source = this._sources.indexOf(source); + + var name = section.consumer._names.at(mapping.name); + this._names.add(name); + name = this._names.indexOf(name); + + // The mappings coming from the consumer for the section have + // generated positions relative to the start of the section, so we + // need to offset them to be relative to the start of the concatenated + // generated file. + var adjustedMapping = { + source: source, + generatedLine: mapping.generatedLine + + (section.generatedOffset.generatedLine - 1), + generatedColumn: mapping.column + + (section.generatedOffset.generatedLine === mapping.generatedLine) + ? section.generatedOffset.generatedColumn - 1 + : 0, + originalLine: mapping.originalLine, + originalColumn: mapping.originalColumn, + name: name + }; + + this.__generatedMappings.push(adjustedMapping); + if (typeof adjustedMapping.originalLine === 'number') { + this.__originalMappings.push(adjustedMapping); + } + } + } + + quickSort(this.__generatedMappings, util.compareByGeneratedPositionsDeflated); + quickSort(this.__originalMappings, util.compareByOriginalPositions); + }; + + exports.IndexedSourceMapConsumer = IndexedSourceMapConsumer; + } + + +/***/ }, +/* 8 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + exports.GREATEST_LOWER_BOUND = 1; + exports.LEAST_UPPER_BOUND = 2; + + /** + * Recursive implementation of binary search. + * + * @param aLow Indices here and lower do not contain the needle. + * @param aHigh Indices here and higher do not contain the needle. + * @param aNeedle The element being searched for. + * @param aHaystack The non-empty array being searched. + * @param aCompare Function which takes two elements and returns -1, 0, or 1. + * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or + * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + */ + function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) { + // This function terminates when one of the following is true: + // + // 1. We find the exact element we are looking for. + // + // 2. We did not find the exact element, but we can return the index of + // the next-closest element. + // + // 3. We did not find the exact element, and there is no next-closest + // element than the one we are searching for, so we return -1. + var mid = Math.floor((aHigh - aLow) / 2) + aLow; + var cmp = aCompare(aNeedle, aHaystack[mid], true); + if (cmp === 0) { + // Found the element we are looking for. + return mid; + } + else if (cmp > 0) { + // Our needle is greater than aHaystack[mid]. + if (aHigh - mid > 1) { + // The element is in the upper half. + return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias); + } + + // The exact needle element was not found in this haystack. Determine if + // we are in termination case (3) or (2) and return the appropriate thing. + if (aBias == exports.LEAST_UPPER_BOUND) { + return aHigh < aHaystack.length ? aHigh : -1; + } else { + return mid; + } + } + else { + // Our needle is less than aHaystack[mid]. + if (mid - aLow > 1) { + // The element is in the lower half. + return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias); + } + + // we are in termination case (3) or (2) and return the appropriate thing. + if (aBias == exports.LEAST_UPPER_BOUND) { + return mid; + } else { + return aLow < 0 ? -1 : aLow; + } + } + } + + /** + * This is an implementation of binary search which will always try and return + * the index of the closest element if there is no exact hit. This is because + * mappings between original and generated line/col pairs are single points, + * and there is an implicit region between each of them, so a miss just means + * that you aren't on the very start of a region. + * + * @param aNeedle The element you are looking for. + * @param aHaystack The array that is being searched. + * @param aCompare A function which takes the needle and an element in the + * array and returns -1, 0, or 1 depending on whether the needle is less + * than, equal to, or greater than the element, respectively. + * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or + * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'. + */ + exports.search = function search(aNeedle, aHaystack, aCompare, aBias) { + if (aHaystack.length === 0) { + return -1; + } + + var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, + aCompare, aBias || exports.GREATEST_LOWER_BOUND); + if (index < 0) { + return -1; + } + + // We have found either the exact element, or the next-closest element than + // the one we are searching for. However, there may be more than one such + // element. Make sure we always return the smallest of these. + while (index - 1 >= 0) { + if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) { + break; + } + --index; + } + + return index; + }; + } + + +/***/ }, +/* 9 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + // It turns out that some (most?) JavaScript engines don't self-host + // `Array.prototype.sort`. This makes sense because C++ will likely remain + // faster than JS when doing raw CPU-intensive sorting. However, when using a + // custom comparator function, calling back and forth between the VM's C++ and + // JIT'd JS is rather slow *and* loses JIT type information, resulting in + // worse generated code for the comparator function than would be optimal. In + // fact, when sorting with a comparator, these costs outweigh the benefits of + // sorting in C++. By using our own JS-implemented Quick Sort (below), we get + // a ~3500ms mean speed-up in `bench/bench.html`. + + /** + * Swap the elements indexed by `x` and `y` in the array `ary`. + * + * @param {Array} ary + * The array. + * @param {Number} x + * The index of the first item. + * @param {Number} y + * The index of the second item. + */ + function swap(ary, x, y) { + var temp = ary[x]; + ary[x] = ary[y]; + ary[y] = temp; + } + + /** + * Returns a random integer within the range `low .. high` inclusive. + * + * @param {Number} low + * The lower bound on the range. + * @param {Number} high + * The upper bound on the range. + */ + function randomIntInRange(low, high) { + return Math.round(low + (Math.random() * (high - low))); + } + + /** + * The Quick Sort algorithm. + * + * @param {Array} ary + * An array to sort. + * @param {function} comparator + * Function to use to compare two items. + * @param {Number} p + * Start index of the array + * @param {Number} r + * End index of the array + */ + function doQuickSort(ary, comparator, p, r) { + // If our lower bound is less than our upper bound, we (1) partition the + // array into two pieces and (2) recurse on each half. If it is not, this is + // the empty array and our base case. + + if (p < r) { + // (1) Partitioning. + // + // The partitioning chooses a pivot between `p` and `r` and moves all + // elements that are less than or equal to the pivot to the before it, and + // all the elements that are greater than it after it. The effect is that + // once partition is done, the pivot is in the exact place it will be when + // the array is put in sorted order, and it will not need to be moved + // again. This runs in O(n) time. + + // Always choose a random pivot so that an input array which is reverse + // sorted does not cause O(n^2) running time. + var pivotIndex = randomIntInRange(p, r); + var i = p - 1; + + swap(ary, pivotIndex, r); + var pivot = ary[r]; + + // Immediately after `j` is incremented in this loop, the following hold + // true: + // + // * Every element in `ary[p .. i]` is less than or equal to the pivot. + // + // * Every element in `ary[i+1 .. j-1]` is greater than the pivot. + for (var j = p; j < r; j++) { + if (comparator(ary[j], pivot) <= 0) { + i += 1; + swap(ary, i, j); + } + } + + swap(ary, i + 1, j); + var q = i + 1; + + // (2) Recurse on each half. + + doQuickSort(ary, comparator, p, q - 1); + doQuickSort(ary, comparator, q + 1, r); + } + } + + /** + * Sort the given array in-place with the given comparator function. + * + * @param {Array} ary + * An array to sort. + * @param {function} comparator + * Function to use to compare two items. + */ + exports.quickSort = function (ary, comparator) { + doQuickSort(ary, comparator, 0, ary.length - 1); + }; + } + + +/***/ }, +/* 10 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var SourceMapGenerator = __webpack_require__(1).SourceMapGenerator; + var util = __webpack_require__(4); + + // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other + // operating systems these days (capturing the result). + var REGEX_NEWLINE = /(\r?\n)/; + + // Newline character code for charCodeAt() comparisons + var NEWLINE_CODE = 10; + + // Private symbol for identifying `SourceNode`s when multiple versions of + // the source-map library are loaded. This MUST NOT CHANGE across + // versions! + var isSourceNode = "$$$isSourceNode$$$"; + + /** + * SourceNodes provide a way to abstract over interpolating/concatenating + * snippets of generated JavaScript source code while maintaining the line and + * column information associated with the original source code. + * + * @param aLine The original line number. + * @param aColumn The original column number. + * @param aSource The original source's filename. + * @param aChunks Optional. An array of strings which are snippets of + * generated JS, or other SourceNodes. + * @param aName The original identifier. + */ + function SourceNode(aLine, aColumn, aSource, aChunks, aName) { + this.children = []; + this.sourceContents = {}; + this.line = aLine == null ? null : aLine; + this.column = aColumn == null ? null : aColumn; + this.source = aSource == null ? null : aSource; + this.name = aName == null ? null : aName; + this[isSourceNode] = true; + if (aChunks != null) this.add(aChunks); + } + + /** + * Creates a SourceNode from generated code and a SourceMapConsumer. + * + * @param aGeneratedCode The generated code + * @param aSourceMapConsumer The SourceMap for the generated code + * @param aRelativePath Optional. The path that relative sources in the + * SourceMapConsumer should be relative to. + */ + SourceNode.fromStringWithSourceMap = + function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) { + // The SourceNode we want to fill with the generated code + // and the SourceMap + var node = new SourceNode(); + + // All even indices of this array are one line of the generated code, + // while all odd indices are the newlines between two adjacent lines + // (since `REGEX_NEWLINE` captures its match). + // Processed fragments are removed from this array, by calling `shiftNextLine`. + var remainingLines = aGeneratedCode.split(REGEX_NEWLINE); + var shiftNextLine = function() { + var lineContents = remainingLines.shift(); + // The last line of a file might not have a newline. + var newLine = remainingLines.shift() || ""; + return lineContents + newLine; + }; + + // We need to remember the position of "remainingLines" + var lastGeneratedLine = 1, lastGeneratedColumn = 0; + + // The generate SourceNodes we need a code range. + // To extract it current and last mapping is used. + // Here we store the last mapping. + var lastMapping = null; + + aSourceMapConsumer.eachMapping(function (mapping) { + if (lastMapping !== null) { + // We add the code from "lastMapping" to "mapping": + // First check if there is a new line in between. + if (lastGeneratedLine < mapping.generatedLine) { + var code = ""; + // Associate first line with "lastMapping" + addMappingWithCode(lastMapping, shiftNextLine()); + lastGeneratedLine++; + lastGeneratedColumn = 0; + // The remaining code is added without mapping + } else { + // There is no new line in between. + // Associate the code between "lastGeneratedColumn" and + // "mapping.generatedColumn" with "lastMapping" + var nextLine = remainingLines[0]; + var code = nextLine.substr(0, mapping.generatedColumn - + lastGeneratedColumn); + remainingLines[0] = nextLine.substr(mapping.generatedColumn - + lastGeneratedColumn); + lastGeneratedColumn = mapping.generatedColumn; + addMappingWithCode(lastMapping, code); + // No more remaining code, continue + lastMapping = mapping; + return; + } + } + // We add the generated code until the first mapping + // to the SourceNode without any mapping. + // Each line is added as separate string. + while (lastGeneratedLine < mapping.generatedLine) { + node.add(shiftNextLine()); + lastGeneratedLine++; + } + if (lastGeneratedColumn < mapping.generatedColumn) { + var nextLine = remainingLines[0]; + node.add(nextLine.substr(0, mapping.generatedColumn)); + remainingLines[0] = nextLine.substr(mapping.generatedColumn); + lastGeneratedColumn = mapping.generatedColumn; + } + lastMapping = mapping; + }, this); + // We have processed all mappings. + if (remainingLines.length > 0) { + if (lastMapping) { + // Associate the remaining code in the current line with "lastMapping" + addMappingWithCode(lastMapping, shiftNextLine()); + } + // and add the remaining lines without any mapping + node.add(remainingLines.join("")); + } + + // Copy sourcesContent into SourceNode + aSourceMapConsumer.sources.forEach(function (sourceFile) { + var content = aSourceMapConsumer.sourceContentFor(sourceFile); + if (content != null) { + if (aRelativePath != null) { + sourceFile = util.join(aRelativePath, sourceFile); + } + node.setSourceContent(sourceFile, content); + } + }); + + return node; + + function addMappingWithCode(mapping, code) { + if (mapping === null || mapping.source === undefined) { + node.add(code); + } else { + var source = aRelativePath + ? util.join(aRelativePath, mapping.source) + : mapping.source; + node.add(new SourceNode(mapping.originalLine, + mapping.originalColumn, + source, + code, + mapping.name)); + } + } + }; + + /** + * Add a chunk of generated JS to this source node. + * + * @param aChunk A string snippet of generated JS code, another instance of + * SourceNode, or an array where each member is one of those things. + */ + SourceNode.prototype.add = function SourceNode_add(aChunk) { + if (Array.isArray(aChunk)) { + aChunk.forEach(function (chunk) { + this.add(chunk); + }, this); + } + else if (aChunk[isSourceNode] || typeof aChunk === "string") { + if (aChunk) { + this.children.push(aChunk); + } + } + else { + throw new TypeError( + "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk + ); + } + return this; + }; + + /** + * Add a chunk of generated JS to the beginning of this source node. + * + * @param aChunk A string snippet of generated JS code, another instance of + * SourceNode, or an array where each member is one of those things. + */ + SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) { + if (Array.isArray(aChunk)) { + for (var i = aChunk.length-1; i >= 0; i--) { + this.prepend(aChunk[i]); + } + } + else if (aChunk[isSourceNode] || typeof aChunk === "string") { + this.children.unshift(aChunk); + } + else { + throw new TypeError( + "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk + ); + } + return this; + }; + + /** + * Walk over the tree of JS snippets in this node and its children. The + * walking function is called once for each snippet of JS and is passed that + * snippet and the its original associated source's line/column location. + * + * @param aFn The traversal function. + */ + SourceNode.prototype.walk = function SourceNode_walk(aFn) { + var chunk; + for (var i = 0, len = this.children.length; i < len; i++) { + chunk = this.children[i]; + if (chunk[isSourceNode]) { + chunk.walk(aFn); + } + else { + if (chunk !== '') { + aFn(chunk, { source: this.source, + line: this.line, + column: this.column, + name: this.name }); + } + } + } + }; + + /** + * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between + * each of `this.children`. + * + * @param aSep The separator. + */ + SourceNode.prototype.join = function SourceNode_join(aSep) { + var newChildren; + var i; + var len = this.children.length; + if (len > 0) { + newChildren = []; + for (i = 0; i < len-1; i++) { + newChildren.push(this.children[i]); + newChildren.push(aSep); + } + newChildren.push(this.children[i]); + this.children = newChildren; + } + return this; + }; + + /** + * Call String.prototype.replace on the very right-most source snippet. Useful + * for trimming whitespace from the end of a source node, etc. + * + * @param aPattern The pattern to replace. + * @param aReplacement The thing to replace the pattern with. + */ + SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) { + var lastChild = this.children[this.children.length - 1]; + if (lastChild[isSourceNode]) { + lastChild.replaceRight(aPattern, aReplacement); + } + else if (typeof lastChild === 'string') { + this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement); + } + else { + this.children.push(''.replace(aPattern, aReplacement)); + } + return this; + }; + + /** + * Set the source content for a source file. This will be added to the SourceMapGenerator + * in the sourcesContent field. + * + * @param aSourceFile The filename of the source file + * @param aSourceContent The content of the source file + */ + SourceNode.prototype.setSourceContent = + function SourceNode_setSourceContent(aSourceFile, aSourceContent) { + this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent; + }; + + /** + * Walk over the tree of SourceNodes. The walking function is called for each + * source file content and is passed the filename and source content. + * + * @param aFn The traversal function. + */ + SourceNode.prototype.walkSourceContents = + function SourceNode_walkSourceContents(aFn) { + for (var i = 0, len = this.children.length; i < len; i++) { + if (this.children[i][isSourceNode]) { + this.children[i].walkSourceContents(aFn); + } + } + + var sources = Object.keys(this.sourceContents); + for (var i = 0, len = sources.length; i < len; i++) { + aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]); + } + }; + + /** + * Return the string representation of this source node. Walks over the tree + * and concatenates all the various snippets together to one string. + */ + SourceNode.prototype.toString = function SourceNode_toString() { + var str = ""; + this.walk(function (chunk) { + str += chunk; + }); + return str; + }; + + /** + * Returns the string representation of this source node along with a source + * map. + */ + SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) { + var generated = { + code: "", + line: 1, + column: 0 + }; + var map = new SourceMapGenerator(aArgs); + var sourceMappingActive = false; + var lastOriginalSource = null; + var lastOriginalLine = null; + var lastOriginalColumn = null; + var lastOriginalName = null; + this.walk(function (chunk, original) { + generated.code += chunk; + if (original.source !== null + && original.line !== null + && original.column !== null) { + if(lastOriginalSource !== original.source + || lastOriginalLine !== original.line + || lastOriginalColumn !== original.column + || lastOriginalName !== original.name) { + map.addMapping({ + source: original.source, + original: { + line: original.line, + column: original.column + }, + generated: { + line: generated.line, + column: generated.column + }, + name: original.name + }); + } + lastOriginalSource = original.source; + lastOriginalLine = original.line; + lastOriginalColumn = original.column; + lastOriginalName = original.name; + sourceMappingActive = true; + } else if (sourceMappingActive) { + map.addMapping({ + generated: { + line: generated.line, + column: generated.column + } + }); + lastOriginalSource = null; + sourceMappingActive = false; + } + for (var idx = 0, length = chunk.length; idx < length; idx++) { + if (chunk.charCodeAt(idx) === NEWLINE_CODE) { + generated.line++; + generated.column = 0; + // Mappings end at eol + if (idx + 1 === length) { + lastOriginalSource = null; + sourceMappingActive = false; + } else if (sourceMappingActive) { + map.addMapping({ + source: original.source, + original: { + line: original.line, + column: original.column + }, + generated: { + line: generated.line, + column: generated.column + }, + name: original.name + }); + } + } else { + generated.column++; + } + } + }); + this.walkSourceContents(function (sourceFile, sourceContent) { + map.setSourceContent(sourceFile, sourceContent); + }); + + return { code: generated.code, map: map }; + }; + + exports.SourceNode = SourceNode; + } + + +/***/ }, +/* 11 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var util = __webpack_require__(4); + + // This is a test mapping which maps functions from two different files + // (one.js and two.js) to a minified generated source. + // + // Here is one.js: + // + // ONE.foo = function (bar) { + // return baz(bar); + // }; + // + // Here is two.js: + // + // TWO.inc = function (n) { + // return n + 1; + // }; + // + // And here is the generated code (min.js): + // + // ONE.foo=function(a){return baz(a);}; + // TWO.inc=function(a){return a+1;}; + exports.testGeneratedCode = " ONE.foo=function(a){return baz(a);};\n"+ + " TWO.inc=function(a){return a+1;};"; + exports.testMap = { + version: 3, + file: 'min.js', + names: ['bar', 'baz', 'n'], + sources: ['one.js', 'two.js'], + sourceRoot: '/the/root', + mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA' + }; + exports.testMapNoSourceRoot = { + version: 3, + file: 'min.js', + names: ['bar', 'baz', 'n'], + sources: ['one.js', 'two.js'], + mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA' + }; + exports.testMapEmptySourceRoot = { + version: 3, + file: 'min.js', + names: ['bar', 'baz', 'n'], + sources: ['one.js', 'two.js'], + sourceRoot: '', + mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA' + }; + // This mapping is identical to above, but uses the indexed format instead. + exports.indexedTestMap = { + version: 3, + file: 'min.js', + sections: [ + { + offset: { + line: 0, + column: 0 + }, + map: { + version: 3, + sources: [ + "one.js" + ], + sourcesContent: [ + ' ONE.foo = function (bar) {\n' + + ' return baz(bar);\n' + + ' };', + ], + names: [ + "bar", + "baz" + ], + mappings: "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID", + file: "min.js", + sourceRoot: "/the/root" + } + }, + { + offset: { + line: 1, + column: 0 + }, + map: { + version: 3, + sources: [ + "two.js" + ], + sourcesContent: [ + ' TWO.inc = function (n) {\n' + + ' return n + 1;\n' + + ' };' + ], + names: [ + "n" + ], + mappings: "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOA", + file: "min.js", + sourceRoot: "/the/root" + } + } + ] + }; + exports.indexedTestMapDifferentSourceRoots = { + version: 3, + file: 'min.js', + sections: [ + { + offset: { + line: 0, + column: 0 + }, + map: { + version: 3, + sources: [ + "one.js" + ], + sourcesContent: [ + ' ONE.foo = function (bar) {\n' + + ' return baz(bar);\n' + + ' };', + ], + names: [ + "bar", + "baz" + ], + mappings: "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID", + file: "min.js", + sourceRoot: "/the/root" + } + }, + { + offset: { + line: 1, + column: 0 + }, + map: { + version: 3, + sources: [ + "two.js" + ], + sourcesContent: [ + ' TWO.inc = function (n) {\n' + + ' return n + 1;\n' + + ' };' + ], + names: [ + "n" + ], + mappings: "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOA", + file: "min.js", + sourceRoot: "/different/root" + } + } + ] + }; + exports.testMapWithSourcesContent = { + version: 3, + file: 'min.js', + names: ['bar', 'baz', 'n'], + sources: ['one.js', 'two.js'], + sourcesContent: [ + ' ONE.foo = function (bar) {\n' + + ' return baz(bar);\n' + + ' };', + ' TWO.inc = function (n) {\n' + + ' return n + 1;\n' + + ' };' + ], + sourceRoot: '/the/root', + mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA' + }; + exports.testMapRelativeSources = { + version: 3, + file: 'min.js', + names: ['bar', 'baz', 'n'], + sources: ['./one.js', './two.js'], + sourcesContent: [ + ' ONE.foo = function (bar) {\n' + + ' return baz(bar);\n' + + ' };', + ' TWO.inc = function (n) {\n' + + ' return n + 1;\n' + + ' };' + ], + sourceRoot: '/the/root', + mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA' + }; + exports.emptyMap = { + version: 3, + file: 'min.js', + names: [], + sources: [], + mappings: '' + }; + + + function assertMapping(generatedLine, generatedColumn, originalSource, + originalLine, originalColumn, name, bias, map, assert, + dontTestGenerated, dontTestOriginal) { + if (!dontTestOriginal) { + var origMapping = map.originalPositionFor({ + line: generatedLine, + column: generatedColumn, + bias: bias + }); + assert.equal(origMapping.name, name, + 'Incorrect name, expected ' + JSON.stringify(name) + + ', got ' + JSON.stringify(origMapping.name)); + assert.equal(origMapping.line, originalLine, + 'Incorrect line, expected ' + JSON.stringify(originalLine) + + ', got ' + JSON.stringify(origMapping.line)); + assert.equal(origMapping.column, originalColumn, + 'Incorrect column, expected ' + JSON.stringify(originalColumn) + + ', got ' + JSON.stringify(origMapping.column)); + + var expectedSource; + + if (originalSource && map.sourceRoot && originalSource.indexOf(map.sourceRoot) === 0) { + expectedSource = originalSource; + } else if (originalSource) { + expectedSource = map.sourceRoot + ? util.join(map.sourceRoot, originalSource) + : originalSource; + } else { + expectedSource = null; + } + + assert.equal(origMapping.source, expectedSource, + 'Incorrect source, expected ' + JSON.stringify(expectedSource) + + ', got ' + JSON.stringify(origMapping.source)); + } + + if (!dontTestGenerated) { + var genMapping = map.generatedPositionFor({ + source: originalSource, + line: originalLine, + column: originalColumn, + bias: bias + }); + assert.equal(genMapping.line, generatedLine, + 'Incorrect line, expected ' + JSON.stringify(generatedLine) + + ', got ' + JSON.stringify(genMapping.line)); + assert.equal(genMapping.column, generatedColumn, + 'Incorrect column, expected ' + JSON.stringify(generatedColumn) + + ', got ' + JSON.stringify(genMapping.column)); + } + } + exports.assertMapping = assertMapping; + + function assertEqualMaps(assert, actualMap, expectedMap) { + assert.equal(actualMap.version, expectedMap.version, "version mismatch"); + assert.equal(actualMap.file, expectedMap.file, "file mismatch"); + assert.equal(actualMap.names.length, + expectedMap.names.length, + "names length mismatch: " + + actualMap.names.join(", ") + " != " + expectedMap.names.join(", ")); + for (var i = 0; i < actualMap.names.length; i++) { + assert.equal(actualMap.names[i], + expectedMap.names[i], + "names[" + i + "] mismatch: " + + actualMap.names.join(", ") + " != " + expectedMap.names.join(", ")); + } + assert.equal(actualMap.sources.length, + expectedMap.sources.length, + "sources length mismatch: " + + actualMap.sources.join(", ") + " != " + expectedMap.sources.join(", ")); + for (var i = 0; i < actualMap.sources.length; i++) { + assert.equal(actualMap.sources[i], + expectedMap.sources[i], + "sources[" + i + "] length mismatch: " + + actualMap.sources.join(", ") + " != " + expectedMap.sources.join(", ")); + } + assert.equal(actualMap.sourceRoot, + expectedMap.sourceRoot, + "sourceRoot mismatch: " + + actualMap.sourceRoot + " != " + expectedMap.sourceRoot); + assert.equal(actualMap.mappings, expectedMap.mappings, + "mappings mismatch:\nActual: " + actualMap.mappings + "\nExpected: " + expectedMap.mappings); + if (actualMap.sourcesContent) { + assert.equal(actualMap.sourcesContent.length, + expectedMap.sourcesContent.length, + "sourcesContent length mismatch"); + for (var i = 0; i < actualMap.sourcesContent.length; i++) { + assert.equal(actualMap.sourcesContent[i], + expectedMap.sourcesContent[i], + "sourcesContent[" + i + "] mismatch"); + } + } + } + exports.assertEqualMaps = assertEqualMaps; + } + + +/***/ } +/******/ ]); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly8vd2VicGFjay9ib290c3RyYXAgYWYzMzMzY2Y1YzNkNDVlOWZjMGYiLCJ3ZWJwYWNrOi8vLy4vdGVzdC90ZXN0LXNvdXJjZS1tYXAtZ2VuZXJhdG9yLmpzIiwid2VicGFjazovLy8uL2xpYi9zb3VyY2UtbWFwLWdlbmVyYXRvci5qcyIsIndlYnBhY2s6Ly8vLi9saWIvYmFzZTY0LXZscS5qcyIsIndlYnBhY2s6Ly8vLi9saWIvYmFzZTY0LmpzIiwid2VicGFjazovLy8uL2xpYi91dGlsLmpzIiwid2VicGFjazovLy8uL2xpYi9hcnJheS1zZXQuanMiLCJ3ZWJwYWNrOi8vLy4vbGliL21hcHBpbmctbGlzdC5qcyIsIndlYnBhY2s6Ly8vLi9saWIvc291cmNlLW1hcC1jb25zdW1lci5qcyIsIndlYnBhY2s6Ly8vLi9saWIvYmluYXJ5LXNlYXJjaC5qcyIsIndlYnBhY2s6Ly8vLi9saWIvcXVpY2stc29ydC5qcyIsIndlYnBhY2s6Ly8vLi9saWIvc291cmNlLW5vZGUuanMiLCJ3ZWJwYWNrOi8vLy4vdGVzdC91dGlsLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Oz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Sb290XG4gICAgICB9KTtcbiAgICAgIGFTb3VyY2VNYXBDb25zdW1lci5lYWNoTWFwcGluZyhmdW5jdGlvbiAobWFwcGluZykge1xuICAgICAgICB2YXIgbmV3TWFwcGluZyA9IHtcbiAgICAgICAgICBnZW5lcmF0ZWQ6IHtcbiAgICAgICAgICAgIGxpbmU6IG1hcHBpbmcuZ2VuZXJhdGVkTGluZSxcbiAgICAgICAgICAgIGNvbHVtbjogbWFwcGluZy5nZW5lcmF0ZWRDb2x1bW5cbiAgICAgICAgICB9XG4gICAgICAgIH07XG5cbiAgICAgICAgaWYgKG1hcHBpbmcuc291cmNlICE9IG51bGwpIHtcbiAgICAgICAgICBuZXdNYXBwaW5nLnNvdXJjZSA9IG1hcHBpbmcuc291cmNlO1xuICAgICAgICAgIGlmIChzb3VyY2VSb290ICE9IG51bGwpIHtcbiAgICAgICAgICAgIG5ld01hcHBpbmcuc291cmNlID0gdXRpbC5yZWxhdGl2ZShzb3VyY2VSb290LCBuZXdNYXBwaW5nLnNvdXJjZSk7XG4gICAgICAgICAgfVxuXG4gICAgICAgICAgbmV3TWFwcGluZy5vcmlnaW5hbCA9IHtcbiAgICAgICAgICAgIGxpbmU6IG1hcHBpbmcub3JpZ2luYWxMaW5lLFxuICAgICAgICAgICAgY29sdW1uOiBtYXBwaW5nLm9yaWdpbmFsQ29sdW1uXG4gICAgICAgICAgfTtcblxuICAgICAgICAgIGlmIChtYXBwaW5nLm5hbWUgIT0gbnVsbCkge1xuICAgICAgICAgICAgbmV3TWFwcGluZy5uYW1lID0gbWFwcGluZy5uYW1lO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIGdlbmVyYXRvci5hZGRNYXBwaW5nKG5ld01hcHBpbmcpO1xuICAgICAgfSk7XG4gICAgICBhU291cmNlTWFwQ29uc3VtZXIuc291cmNlcy5mb3JFYWNoKGZ1bmN0aW9uIChzb3VyY2VGaWxlKSB7XG4gICAgICAgIHZhciBjb250ZW50ID0gYVNvdX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W4gYmUgbWFwcGVkIGJ5IHRoZSBzb3VyY2UgbWFwLCB0aGVuIHVwZGF0ZSB0aGUgbWFwcGluZy5cbiAgICAgICAgICB2YXIgb3JpZ2luYWwgPSBhU291cmNlTWFwQ29uc3VtZXIub3JpZ2luYWxQb3NpdGlvbkZvcih7XG4gICAgICAgICAgICBsaW5lOiBtYXBwaW5nLm9yaWdpbmFsTGluZSxcbiAgICAgICAgICAgIGNvbHVtbjogbWFwcGluZy5vcmlnaW5hbENvbHVtblxuICAgICAgICAgIH0pO1xuICAgICAgICAgIGlmIChvcmlnaW5hbC5zb3VyY2UgIT0gbnVsbCkge1xuICAgICAgICAgICAgLy8gQ29weSBtYXBwaW5nXG4gICAgICAgICAgICBtYXBwaW5nLnNvdXJjZSA9IG9yaWdpbmFsLnNvdXJjZTtcbiAgICAgICAgICAgIGlmIChhU291cmNlTWFwUGF0aCAhPSBudWxsKSB7XG4gICAgICAgICAgICAgIG1hcHBpbmcuc291cmNlID0gdXRpbC5qb2luKGFTb3VyY2VNYXBQYXRoLCBtYXBwaW5nLnNvdXJjZSlcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmIChzb3VyY2VSb290ICE9IG51bGwpIHtcbiAgICAgICAgICAgICAgbWFwcGluZy5zb3VyY2UgPSB1dGlsLnJlbGF0aXZlKHNvdXJjZVJvb3QsIG1hcHBpbmcuc291cmNlKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIG1hcHBpbmcub3JpZ2luYWxMaW5lID0gb3JpZ2luYWwubGluZTtcbiAgICAgICAgICAgIG1hcHBpbmcub3JpZ2luYWxDb2x1bW4gPSBvcmlnaW5hbC5jb2x1bW47XG4gICAgICAgICAgICBpZiAob3JpZ2luYWwubmFtZSAhPSBudWxsKSB7XG4gICAgICAgICAgICAgIG1hcHBpbmcubmFtZSA9IG9yaWdpbmFsLm5hbWU7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgdmFyIHNvdXJjZSA9IG1hcHBpbmcuc291cmNlO1xuICAgICAgICBpZiAoc291cmNlICE9IG51bGwgJiYgIW5ld1NvdXJjZXMuaGFzKHNvdXJjZSkpIHtcbiAgICAgICAgICBuZXdTb3VyY2VzLmFkZChzb3VyY2UpO1xuICAgICAgICB9XG5cbiAgICAgICAgdmFyIG5hbWUgPSBtYXBwaW5nLm5hbWU7XG4gICAgICAgIGlmIChuYW1lICE9IG51bGwgJiYgIW5ld05hbWVzLmhhcyhuYW1lKSkge1xuICAgICAgICAgIG5ld05hbWVzLmFkZChuYW1lKTtcbiAgICAgICAgfVxuXG4gICAgICB9LCB0aGlzKTtcbiAgICAgIHRoaXMuX3NvdXJjZXMgPSBuZXdTb3VyY2VzO1xuICAgICAgdGhpcy5fbmFtZXMgPSBuZXdOYW1lcztcblxuICAgICAgLy8gQ29weSBzb3VyY2VzQ29udGVudHMgb2YgYXBwbGllZCBtYXAuXG4gICAgICBhU291cmNlTWFwQ29uc3VtZXIuc291cmNlcy5mb3JFYWNoKGZ1bmN0aW9uIChzb3VyY2VGaWxlKSB7XG4gICAgICAgIHZhciBjb250ZW50ID0gYVNvdXJjZU1hcENvbnN1bWVyLnNvdXJjZUNvbnRlbnRGb3Ioc291cmNlRmlsZSk7XG4gICAgICAgIGlmIChjb250ZW50ICE9IG51bGwpIHtcbiAgICAgICAgICBpZiAoYVNvdXJjZU1hcFBhdGggIT0gbnVsbCkge1xuICAgICAgICAgICAgc291cmNlRmlsZSA9IHV0aWwuam9pbihhU291cmNlTWFwUGF0aCwgc291cmNlRmlsZSk7XG4gICAgICAgICAgfVxuICAgICAgICAgIGlmIChzb3VyY2VSb290ICE9IG51bGwpIHtcbiAgICAgICAgICAgIHNvdXJjZUZpbGUgPSB1dGlsLnJlbGF0aXZlKHNvdXJjZVJvb3QsIHNvdXJjZUZpbGUpO1xuICAgICAgICAgIH1cbiAgICAgICAgICB0aGlzLnNldFNvdXJjZUNvbnRlbnQoc291cmNlRmlsZSwgY29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yZUJ5R2VuZXJhdGVkUG9zaXRpb25zSW5mbGF0ZWQobWFwcGluZywgbWFwcGluZ3NbaSAtIDFdKSkge1xuICAgICAgICAgICAgICBjb250aW51ZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHJlc3VsdCArPSAnLCc7XG4gICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgcmVzdWx0ICs9IGJhc2U2NFZMUS5lbmNvZGUobWFwcGluZy5nZW5lcmF0ZWRDb2x1bW5cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLSBwcmV2aW91c0dlbmVyYXRlZENvbHVtbik7XG4gICAgICAgIHByZXZpb3VzR2VuZXJhdGVkQ29sdW1uID0gbWFwcGluZy5nZW5lcmF0ZWRDb2x1bW47XG5cbiAgICAgICAgaWYgKG1hcHBpbmcuc291cmNlICE9IG51bGwpIHtcbiAgICAgICAgICBzb3VyY2VJZHggPSB0aGlzLl9zb3VyY2VzLmluZGV4T2YobWFwcGluZy5zb3VyY2UpO1xuICAgICAgICAgIHJlc3VsdCArPSBiYXNlNjRWTFEuZW5jb2RlKHNvdXJjZUlkeCAtIHByZXZpb3VzU291cmNlKTtcbiAgICAgICAgICBwcmV2aW91c1NvdXJjZSA9IHNvdXJjZUlkeDtcblxuICAgICAgICAgIC8vIGxpbmVzIGFyZSBzdG9yZWQgMC1iYXNlZCBpbiBTb3VyY2VNYXAgc3BlYyB2ZXJzaW9uIDNcbiAgICAgICAgICByZXN1bHQgKz0gYmFzZTY0VkxRLmVuY29kZShtYXBwaW5nLm9yaWdpbmFsTGluZSAtIDFcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAtIHByZXZpb3VzT3JpZ2luYWxMaW5lKTtcbiAgICAgICAgICBwcmV2aW91c09yaWdpbmFsTGluZSA9IG1hcHBpbmcub3JpZ2luYWxMaW5lIC0gMTtcblxuICAgICAgICAgIHJlc3VsdCArPSBiYXNlNjRWTFEuZW5jb2RlKG1hcHB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jdC5wcm90b3R5cGUuaGFzT3duUHJvcGVydHkuY2FsbCh0aGlzLl9zb3VyY2VzQ29udGVudHMsXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAga2V5KVxuICAgICAgICAgID8gdGhpcy5fc291cmNlc0NvbnRlbnRzW2tleV1cbiAgICAgICAgICA6IG51bGw7XG4gICAgICB9LCB0aGlzKTtcbiAgICB9O1xuXG4gIC8qKlxuICAgKiBFeHRlcm5hbGl6ZSB0aGUgc291cmNlIG1hcC5cbiAgICovXG4gIFNvdXJjZU1hcEdlbmVyYXRvci5wcm90b3R5cGUudG9KU09OID1cbiAgICBmdW5jdGlvbiBTb3VyY2VNYXBHZW5lcmF0b3JfdG9KU09OKCkge1xuICAgICAgdmFyIG1hcCA9IHtcbiAgICAgICAgdmVyc2lvbjogdGhpcy5fdmVyc2lvbixcbiAgICAgICAgc291cmNlczogdGhpcy5fc291cmNlcy50b0FycmF5KCksXG4gICAgICAgIG5hbWVzOiB0aGlzLl9uYW1lcy50b0FycmF5KCksXG4gICAgICAgIG1hcHBpbmdzOiB0aGlzLl9zZXJpYWxpemVNYXBwaW5ncygpXG4gICAgICB9O1xuICAgICAgaWYgKHRoaXMuX2ZpbGUgIT0gbnVsbCkge1xuICAgICAgICBtYXAuZmlsZSA9IHRoaXMuX2ZpbGU7XG4gICAgICB9XG4gICAgICBpZiAodGhpcy5fc291cmNlUm9vdCAhPSBudWxsKSB7XG4gICAgICAgIG1hcC5zb3VyY2VSb290ID0gdGhpcy5fc291cmNlUm9vdDtcbiAgICAgIH1cbiAgICAgIGlmICh0aGlzLl9zb3VyY2VzQ29udGVudHMpIHtcbiAgICAgICAgbWFwLnNvdXJjZXNDb250ZW50ID0gdGhpcy5fZ2VuZXJhdGVTb3VyY2VzQ29udGVudChtYXAuc291cmNlcywgbWFwLnNvdXJjZVJvb3QpO1xuICAgICAgfVxuXG4gICAgICByZXR1cm4gbWFwO1xuICAgIH07XG5cbiA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VwiLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXCJvcmlnaW5hbENvbHVtblwiLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdXRpbC5jb21wYXJlQnlPcmlnaW5hbFBvc2l0aW9ucyxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJpbmFyeVNlYXJjaC5MRUFTVF9VUFBFUl9CT1VORCk7XG4gICAgICBpZiAoaW5kZXggPj0gMCkge1xuICAgICAgICB2YXIgbWFwcGluZyA9IHRoaXMuX29yaWdpbmFsTWFwcGluZ3NbaW5kZXhdO1xuXG4gICAgICAgIGlmIChhQXJncy5jb2x1bW4gPT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgIHZhciBvcmlnaW5hbExpbmUgPSBtYXBwaW5nLm9yaWdpbmFsTGluZTtcblxuICAgICAgICAgIC8vIEl0ZXJhdGUgdW50aWwgZWl0aGVyIHdlIHJ1biBvdXQgb2YgbWFwcGluZ3MsIG9yIHdlIHJ1biBpbnRvXG4gICAgICAgICAgLy8gYSBtYXBwaW5nIGZvciBhIGRpZmZlcmVudCBsaW5lIHRoYW4gdGhlIG9uZSB3ZSBmb3VuZC4gU2luY2VcbiAgICAgICAgICAvLyBtYXBwaW5ncyBhcmUgc29ydGVkLCB0aGlzIGlzIGd1YXJhbnRlZWQgdG8gZmluZCBhbGwgbWFwcGluZ3MgZm9yXG4gICAgICAgICAgLy8gdGhlIGxpbmUgd2UgZm91bmQuXG4gICAgICAgICAgd2hpbGUgKG1hcHBpbmcgJiYgbWFwcGluZy5vcmlnaW5hbExpbmUgPT09IG9yaWdpbmFsTGluZSkge1xuICAgICAgICAgICAgbWFwcGluZ3MucHVzaCh7XG4gICAgICAgICAgICAgIGxpbmU6IHV0aWwuZ2V0QXJnKG1hcHBpbmcsICdnZW5lcmF0ZWRMaW5lJywgbnVsbCksXG4gICAgICAgICAgICAgIGNvbHVtbjogdXRpbC5nZXRBcmcobWFwcGlu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biAgICAgICAgICAgICAgaW5kZXggPSB0ZW1wLnJlc3Q7XG4gICAgICAgICAgICAgIHNlZ21lbnQucHVzaCh2YWx1ZSk7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmIChzZWdtZW50Lmxlbmd0aCA9PT0gMikge1xuICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoJ0ZvdW5kIGEgc291cmNlLCBidXQgbm8gbGluZSBhbmQgY29sdW1uJyk7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmIChzZWdtZW50Lmxlbmd0aCA9PT0gMykge1xuICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoJ0ZvdW5kIGEgc291cmNlIGFuZCBsaW5lLCBidXQgbm8gY29sdW1uJyk7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGNhY2hlZFNlZ21lbnRzW3N0cl0gPSBzZWdtZW50O1xuICAgICAgICAgIH1cblxuICAgICAgICAgIC8vIEdlbmVyYXRlZCBjb2x1bW4uXG4gICAgICAgICAgbWFwcGluZy5nZW5lcmF0ZWRDb2x1bW4gPSBwcmV2aW91c0dlbmVyYXRlZENvbHVtbiArIHNlZ21lbnRbMF07XG4gICAgICAgICAgcHJldmlvdXNHZW5lcmF0ZWRDb2x1bW4gPSBtYXBwaW5nLmdlbmVyYXRlZENvbHVtbjtcblxuICAgICAgICAgIGlmIChzZWdtZW50Lmxlbmd0aCA+IDEpIHtcbiAgICAgICAgICAgIC8vIE9yaWdpbmFsIHNvdXJjZS5cbiAgICAgICAgICAgIG1hcHBpbmcuc291cmNlID0gcHJldmlvdXNTb3VyY2UgKyBzZWdtZW50WzFdO1xuICAgICAgICAgICAgcHJldmlvdXNTb3VyY2UgKz0gc2VnbWVudFsxXTtcblxuICAgICAgICAgICAgLy8gT3JpZ2luYWwgbGluZS5cbiAgICAgICAgICAgIG1hcHBpbmcub3JpZ2luYWxMaW5lID0gcHJldmlvdXNPcmlnaW5hbExpbmUgKyB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gbnVsbCk7XG4gICAgICAgICAgaWYgKHNvdXJjZSAhPT0gbnVsbCkge1xuICAgICAgICAgICAgc291cmNlID0gdGhpcy5fc291cmNlcy5hdChzb3VyY2UpO1xuICAgICAgICAgICAgaWYgKHRoaXMuc291cmNlUm9vdCAhPSBudWxsKSB7XG4gICAgICAgICAgICAgIHNvdXJjZSA9IHV0aWwuam9pbih0aGlzLnNvdXJjZVJvb3QsIHNvdXJjZSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIHZhciBuYW1lID0gdXRpbC5nZXRBcmcobWFwcGluZywgJ25hbWUnLCBudWxsKTtcbiAgICAgICAgICBpZiAobmFtZSAhPT0gbnVsbCkge1xuICAgICAgICAgICAgbmFtZSA9IHRoaXMuX25hbWVzLmF0KG5hbWUpO1xuICAgICAgICAgIH1cbiAgICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgc291cmNlOiBzb3VyY2UsXG4gICAgICAgICAgICBsaW5lOiB1dGlsLmdldEFyZyhtYXBwaW5nLCAnb3JpZ2luYWxMaW5lJywgbnVsbCksXG4gICAgICAgICAgICBjb2x1bW46IHV0aWwuZ2V0QXJnKG1hcHBpbmcsICdvcmlnaW5hbENvbHVtbicsIG51bGwpLFxuICAgICAgICAgICAgbmFtZTogbmFtZVxuICAgICAgICAgIH07XG4gICAgICAgIH1cbiAgICAgIH1cblxuICAgICAgcmV0dXJuIHtcbiAgICAgICAgc291cmNlOiBudWxsLFxuICAgICAgICBsaW5lOiBudWxsLFxuICAgICAgICBjb2x1bW46IG51bGwsXG4gICAgICAgIG5hbWU6IG51bGxcbiAgICAgIH07XG4gICAgfTtcblxuICAvKipcbiAgICogUmV0dXJuIHRydWUgaWYgd2UgaGF2ZSB0aGUgc291cmNlIGNvbnRlbnQgZm9yIGV2ZXJ5IHNvdXJjZSBpbiB0aGUgc291cmNlXG4gICAqIG1hcCwgZmFsc2Ugb3RoZXJ3aXNlLlxuICAgKi9cbiAgQmFzaWNTb3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dXaXRoQ29kZShsYXN0TWFwcGluZywgc2hpZnROZXh0TGluZSgpKTtcbiAgICAgICAgICAgIGxhc3RHZW5lcmF0ZWRMaW5lKys7XG4gICAgICAgICAgICBsYXN0R2VuZXJhdGVkQ29sdW1uID0gMDtcbiAgICAgICAgICAgIC8vIFRoZSByZW1haW5pbmcgY29kZSBpcyBhZGRlZCB3aXRob3V0IG1hcHBpbmdcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgLy8gVGhlcmUgaXMgbm8gbmV3IGxpbmUgaW4gYmV0d2Vlbi5cbiAgICAgICAgICAgIC8vIEFzc29jaWF0ZSB0aGUgY29kZSBiZXR3ZWVuIFwibGFzdEdlbmVyYXRlZENvbHVtblwiIGFuZFxuICAgICAgICAgICAgLy8gXCJtYXBwaW5nLmdlbmVyYXRlZENvbHVtblwiIHdpdGggXCJsYXN0TWFwcGluZ1wiXG4gICAgICAgICAgICB2YXIgbmV4dExpbmUgPSByZW1haW5pbmdMaW5lc1swXTtcbiAgICAgICAgICAgIHZhciBjb2RlID0gbmV4dExpbmUuc3Vic3RyKDAsIG1hcHBpbmcuZ2VuZXJhdGVkQ29sdW1uIC1cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxhc3RHZW5lcmF0ZWRDb2x1bW4pO1xuICAgICAgICAgICAgcmVtYWluaW5nTGluZXNbMF0gPSBuZXh0TGluZS5zdWJzdHIobWFwcGluZy5nZW5lcmF0ZWRDb2x1bW4gLVxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGFzdEdlbmVyYXRlZENvbHVtbik7XG4gICAgICAgICAgICBsYXN0R2VuZXJhdGVkQ29sdW1uID0gbWFwcGluZy5nZW5lcmF0ZWRDb2x1bW47XG4gICAgICAgICAgICBhZGRNYXBwaW5nV2l0aENvZGUobGFzdE1hcHBpbmcsIGNvZGUpO1xuICAgICAgICAgICAgLy8gTm8gbW9yZSByZW1haW5pbm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cGluZy5zb3VyY2UgPT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgIG5vZGUuYWRkKGNvZGUpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHZhciBzb3VyY2UgPSBhUmVsYXRpdmVQYXRoXG4gICAgICAgICAgICA/IHV0aWwuam9pbihhUmVsYXRpdmVQYXRoLCBtYXBwaW5nLnNvdXJjZSlcbiAgICAgICAgICAgIDogbWFwcGluZy5zb3VyY2U7XG4gICAgICAgICAgbm9kZS5hZGQobmV3IFNvdXJjZU5vZGUobWFwcGluZy5vcmlnaW5hbExpbmUsXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbWFwcGluZy5vcmlnaW5hbENvbHVtbixcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzb3VyY2UsXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29kZSxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBtYXBwaW5nLm5hbWUpKTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgIH07XG5cbiAgLyoqXG4gICAqIEFkZCBhIGNodW5rIG9mIGdlbmVyYXRlZCBKUyB0byB0aGlzIHNvdXJjZSBub2RlLlxuICAgKlxuICAgKiBAcGFyYW0gYUNodW5rIEEgc3RyaW5nIHNuaXBwZXQgb2YgZ2VuZXJhdGVkIEpTIGNvZGUsIGFub3RoZXIgaW5zdGFuY2Ugb2ZcbiAgICogICAgICAgIFNvdXJjZU5vZGUsIG9yIGFuIGFycmF5IHdoZXJlIGVhY2ggbWVtYmVyIGlzIG9uZSBvZiB0aG9zZSB0aGluZ3MuXG4gICAqL1xuICBTb3VyY2VOb2RlLnByb3RvdHlwZS5hZGQgPSBmdW5jdGlvbiBTb3VyY2VOb2RlX2FkZChhQ2h1bmspIHtcbiAgICBpZiAoQXJyYXkuaXNBcnJheShhQ2h1bmspKSB7XG4gICAgICBhQ2h1bmsuZm9yRWFjaChmdW5jdGlvbiAoY2h1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7XG4gICAgICAgICAgbWFwLmFkZE1hcHBpbmcoe1xuICAgICAgICAgICAgc291cmNlOiBvcmlnaW5hbC5zb3VyY2UsXG4gICAgICAgICAgICBvcmlnaW5hbDoge1xuICAgICAgICAgICAgICBsaW5lOiBvcmlnaW5hbC5saW5lLFxuICAgICAgICAgICAgICBjb2x1bW46IG9yaWdpbmFsLmNvbHVtblxuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIGdlbmVyYXRlZDoge1xuICAgICAgICAgICAgICBsaW5lOiBnZW5lcmF0ZWQubGluZSxcbiAgICAgICAgICAgICAgY29sdW1uOiBnZW5lcmF0ZWQuY29sdW1uXG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgbmFtZTogb3JpZ2luYWwubmFtZVxuICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgICAgIGxhc3RPcmlnaW5hbFNvdXJjZSA9IG9yaWdpbmFsLnNvdXJjZTtcbiAgICAgICAgbGFzdE9yaWdpbmFsTGluZSA9IG9yaWdpbmFsLmxpbmU7XG4gICAgICAgIGxhc3RPcmlnaW5hbENvbHVtbiA9IG9yaWdpbmFsLmNvbHVtbjtcbiAgICAgICAgbGFzdE9yaWdpbmFsTmFtZSA9IG9yaWdpbmFsLm5hbWU7XG4gICAgICAgIHNvdXJjZU1hcHBpbmdBY3RpdmUgPSB0cnVlO1xuICAgICAgfSBlbHNlIGlmIChzb3VyY2VNYXBwaW5nQWN0aXZlKSB7XG4gICAgICAgIG1hcC5hZGRNYXBwaW5nKHtcbiAgICAgICAgICBnZW5lcmF0ZWQ6IHtcbiAgICAgICAgICAgIGxpbmU6IGdlbmVyYXRlZC5saW5lLFxuICAgICAgICAgICAgY29sdW1uOiBnZW5lcmF0ZWQuY29sdW1uXG4gICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICAgICAgbGFzdE9yaWdpbmFsU291cmNlID0gbnVsbDtcbiAgICAgICAgc291cmNlTWFwcGluZ0FjdGl2ZSA9IGZhbHNlO1xuICAgICAgfVxuICAgICAgZm9yICh2YXIgaWR4ID0gMCwgbGVuZ3RoID0gY2h1bmsubGVuZ3RoOyBpZHggPCBsZW5ndGg7IGlkeCsrKSB7XG4gICAgICAgIGlmIChjaHVuay5jaGFyQ29kZUF0KGlkeCkgPT09IE5FV0xJTkVfQ09ERSkge1xuICAgICAgICAgIGdlbmVyYXRlZC5saW5lKys7XG4gICAgICAgICAgZ2VuZXJhdGVkLmNvbHVtbiA9IDA7XG4gICAgICAgICAgLy8gTWFwcGluZ3MgZW5kIGF0IGVvbFxuICAgICAgICAgIGlmIChpZHggKyAxID09PSBsZW5ndGgpIHtcbiAgICAgICAgICAgIGxhc3RPcmlnaW5hbFNvdXJjZSA9IG51bGw7XG4gICAgICAgICAgICBzb3VyY2VNYXBwaW5nQWN0aXZlID0gZmFsc2U7XG4gICAgICAgICAgfSBlbHNlIGlmIChzb3VyY2VNYXBwaW5nQWN0aXZlKSB7XG4gICAgICAgICAgICBtYXAuYWRkTWFwcGluZyh7XG4gICAgICAgICAgICAgIHNvdXJjZTogb3JpZ2luYWwuc291cmNlLFxuICAgICAgICAgICAgICBvcmlnaW5hbDoge1xuICAgICAgICAgICAgICAgIGxpbmU6IG9yaWdpbmFsLmxpbmUsXG4gICAgICAgICAgICAgICAgY29sdW1uOiBvcmlnaW5hbC5jb2x1bW5cbiAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgZ2VuZXJhdGVkOiB7XG4gICAgICAgICAgICAgICAgbGluZTogZ2VuZXJhdGVkLmxpbmUsXG4gICAgICAgICAgICAgICAgY29sdW1uOiBnZW5lcmF0ZWQuY29sdW1uXG4gICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgIG5hbWU6IG9yaWdpbmFsLm5hbWVcbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICBnZW5lcmF0ZWQuY29sdW1uKys7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9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ICBdLFxuICAgICAgICAgIG5hbWVzOiBbXG4gICAgICAgICAgICBcImJhclwiLFxuICAgICAgICAgICAgXCJiYXpcIlxuICAgICAgICAgIF0sXG4gICAgICAgICAgbWFwcGluZ3M6IFwiQ0FBQyxJQUFJLElBQU0sU0FBVUEsR0FDbEIsT0FBT0MsSUFBSURcIixcbiAgICAgICAgICBmaWxlOiBcIm1pbi5qc1wiLFxuICAgICAgICAgIHNvdXJjZVJvb3Q6IFwiL3RoZS9yb290XCJcbiAgICAgICAgfVxuICAgICAgfSxcbiAgICAgIHtcbiAgICAgICAgb2Zmc2V0OiB7XG4gICAgICAgICAgbGluZTogMSxcbiAgICAgICAgICBjb2x1bW46IDBcbiAgICAgICAgfSxcbiAgICAgICAgbWFwOiB7XG4gICAgICAgICAgdmVyc2lvbjogMyxcbiAgICAgICAgICBzb3VyY2VzOiBbXG4gICAgICAgICAgICBcInR3by5qc1wiXG4gICAgICAgICAgXSxcbiAgICAgICAgICBzb3VyY2VzQ29udGVudDogW1xuICAgICAgICAgICAgJyBUV08uaW5jID0gZnVuY3Rpb24gKG4pIHtcXG4nICtcbiAgICAgICAgICAgICcgICByZXR1cm4gbiArIDE7XFxuJyArXG4gICAgICAgICAgICAnIH07J1xuICAgICAgICAgIF0sXG4gICAgICAgICAgbmFtZXM6IFtcbiAgICAgICAgICAgIFwiblwiXG4gICAgICAgICAgXSxcbiAgICAgICAgICBtYXBwaW5nczogXCJDQUFDLElBQUksSUFBTSxTQUFVQSxHQUNsQixPQUFPQVwiLFxuICAgICAgICAgIGZpbGU6IFwibWluLmpzXCIsXG4gICAgICAgICAgc291cmNlUm9vdDogXCIvdGhlL3Jvb3RcIlxuICAgICAgICB9XG4gICAgICB9XG4gICAgXVxuICB9O1xuICBleHBvcnRzLmluZGV4ZWRUZXN0TWFwRGlmZmVyZW50U291cmNlUm9vdHMgPSB7XG4gICAgdmVyc2lvbjogMyxcbiAgICBmaWxlOiAnbWluLmpzJyxcbiAgICBzZWN0aW9uczogW1xuICAgICAge1xuICAgICAgICBvZmZzZXQ6IHtcbiAgICAgICAgICBsaW5lOiAwLFxuICAgICAgICAgIGNvbHVtbjogMFxuICAgICAgICB9LFxuICAgICAgICBtYXA6IHtcbiAgICAgICAgICB2ZXJzaW9uOiAzLFxuICAgICAgICAgIHNvdXJjZXM6IFtcbiAgICAgICAgICAgIFwib25lLmpzXCJcbiAgICAgICAgICBdLFxuICAgICAgICAgIHNvdXJjZXNDb250ZW50OiBbXG4gICAgICAgICAgICAnIE9ORS5mb28gPSBmdW5jdGlvbiAoYmFyKSB7XFxuJyArXG4gICAgICAgICAgICAnICAgcmV0dXJuIGJheihiYXIpO1xcbicgK1xuICAgICAgICAgICAgJyB9OycsXG4gICAgICAgICAgXSxcbiAgICAgICAgICBuYW1lczogW1xuICAgICAgICAgICAgXCJiYXJcIixcbiAgICAgICAgICAgIFwiYmF6XCJcbiAgICAgICAgICBdLFxuICAgICAgICAgIG1hcHBpbmdzOiBcIkNBQUMsSUFBSSxJQUFNLFNBQVVBLEdBQ2xCLE9BQU9DLElBQUlEXCIsXG4gICAgICAgICAgZmlsZTogXCJtaW4uanNcIixcbiAgICAgICAgICBzb3VyY2VSb290OiBcIi90aGUvcm9vdFwiXG4gICAgICAgIH1cbiAgICAgIH0sXG4gICAgICB7XG4gICAgICAgIG9mZnNldDoge1xuICAgICAgICAgIGxpbmU6IDEsXG4gICAgICAgICAgY29sdW1uOiAwXG4gICAgICAgIH0sXG4gICAgICAgIG1hcDoge1xuICAgICAgICAgIHZlcnNpb246IDMsXG4gICAgICAgICAgc291cmNlczogW1xuICAgICAgICAgICAgXCJ0d28uanNcIlxuICAgICAgICAgIF0sXG4gICAgICAgICAgc291cmNlc0NvbnRlbnQ6IFtcbiAgICAgICAgICAgICcgVFdPLmluYyA9IGZ1bmN0aW9uIChuKSB7XFxuJyArXG4gICAgICAgICAgICAnICAgcmV0dXJuIG4gKyAxO1xcbicgK1xuICAgICAgICAgICAgJyB9OydcbiAgICAgICAgIC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AgICAgYmlhczogYmlhc1xuICAgICAgfSk7XG4gICAgICBhc3NlcnQuZXF1YWwob3JpZ01hcHBpbmcubmFtZSwgbmFtZSxcbiAgICAgICAgICAgICAgICAgICAnSW5jb3JyZWN0IG5hbWUsIGV4cGVjdGVkICcgKyBKU09OLnN0cmluZ2lmeShuYW1lKVxuICAgICAgICAgICAgICAgICAgICsgJywgZ290ICcgKyBKU09OLnN0cmluZ2lmeShvcmlnTWFwcGluZy5uYW1lKSk7XG4gICAgICBhc3NlcnQuZXF1YWwob3JpZ01hcHBpbmcubGluZSwgb3JpZ2luYWxMaW5lLFxuICAgICAgICAgICAgICAgICAgICdJbmNvcnJlY3QgbGluZSwgZXhwZWN0ZWQgJyArIEpTT04uc3RyaW5naWZ5KG9yaWdpbmFsTGluZSlcbiAgICAgICAgICAgICAgICAgICArICcsIGdvdCAnICsgSlNPTi5zdHJpbmdpZnkob3JpZ01hcHBpbmcubGluZSkpO1xuICAgICAgYXNzZXJ0LmVxdWFsKG9yaWdNYXBwaW5nLmNvbHVtbiwgb3JpZ2luYWxDb2x1bW4sXG4gICAgICAgICAgICAgICAgICAgJ0luY29ycmVjdCBjb2x1bW4sIGV4cGVjdGVkICcgKyBKU09OLnN0cmluZ2lmeShvcmlnaW5hbENvbHVtbilcbiAgICAgICAgICAgICAgICAgICArICcsIGdvdCAnICsgSlNPTi5zdHJpbmdpZnkob3JpZ01hcHBpbmcuY29sdW1uKSk7XG5cbiAgICAgIHZhciBleHBlY3RlZFNvdXJjZTtcblxuICAgICAgaWYgKG9yaWdpbmFsU291cmNlICYmIG1hcC5zb3VyY2VSb290ICYmIG9yaWdpbmFsU291cmNlLmluZGV4T2YobWFwLnNvdXJjZVJvb3QpID09PSAwKSB7XG4gICAgICAgIGV4cGVjdGVkU291cmNlID0gb3JpZ2luYWxTb3VyY2U7XG4gICAgICB9IGVsc2UgaWYgKG9yaWdpbmFsU291cmNlKSB7XG4gICAgICAgIGV4cGVjdGVkU291cmNlID0gbWFwLn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ogbW9kdWxlIGNodW5rcyA9IDBcbiAqKi8iXSwic291cmNlUm9vdCI6IiJ9 \ No newline at end of file diff --git a/devtools/shared/sourcemap/tests/unit/test_source_node.js b/devtools/shared/sourcemap/tests/unit/test_source_node.js new file mode 100644 index 000000000..f41b2d80d --- /dev/null +++ b/devtools/shared/sourcemap/tests/unit/test_source_node.js @@ -0,0 +1,3908 @@ +function run_test() { + for (var k in SOURCE_MAP_TEST_MODULE) { + if (/^test/.test(k)) { + SOURCE_MAP_TEST_MODULE[k](assert); + } + } +} + + +var SOURCE_MAP_TEST_MODULE = +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; +/******/ +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.loaded = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var util = __webpack_require__(1); + var SourceMapGenerator = __webpack_require__(3).SourceMapGenerator; + var SourceMapConsumer = __webpack_require__(8).SourceMapConsumer; + var SourceNode = __webpack_require__(11).SourceNode; + + function forEachNewline(fn) { + return function (assert) { + ['\n', '\r\n'].forEach(fn.bind(null, assert)); + } + } + + exports['test .add()'] = function (assert) { + var node = new SourceNode(null, null, null); + + // Adding a string works. + node.add('function noop() {}'); + + // Adding another source node works. + node.add(new SourceNode(null, null, null)); + + // Adding an array works. + node.add(['function foo() {', + new SourceNode(null, null, null, + 'return 10;'), + '}']); + + // Adding other stuff doesn't. + assert.throws(function () { + node.add({}); + }); + assert.throws(function () { + node.add(function () {}); + }); + }; + + exports['test .prepend()'] = function (assert) { + var node = new SourceNode(null, null, null); + + // Prepending a string works. + node.prepend('function noop() {}'); + assert.equal(node.children[0], 'function noop() {}'); + assert.equal(node.children.length, 1); + + // Prepending another source node works. + node.prepend(new SourceNode(null, null, null)); + assert.equal(node.children[0], ''); + assert.equal(node.children[1], 'function noop() {}'); + assert.equal(node.children.length, 2); + + // Prepending an array works. + node.prepend(['function foo() {', + new SourceNode(null, null, null, + 'return 10;'), + '}']); + assert.equal(node.children[0], 'function foo() {'); + assert.equal(node.children[1], 'return 10;'); + assert.equal(node.children[2], '}'); + assert.equal(node.children[3], ''); + assert.equal(node.children[4], 'function noop() {}'); + assert.equal(node.children.length, 5); + + // Prepending other stuff doesn't. + assert.throws(function () { + node.prepend({}); + }); + assert.throws(function () { + node.prepend(function () {}); + }); + }; + + exports['test .toString()'] = function (assert) { + assert.equal((new SourceNode(null, null, null, + ['function foo() {', + new SourceNode(null, null, null, 'return 10;'), + '}'])).toString(), + 'function foo() {return 10;}'); + }; + + exports['test .join()'] = function (assert) { + assert.equal((new SourceNode(null, null, null, + ['a', 'b', 'c', 'd'])).join(', ').toString(), + 'a, b, c, d'); + }; + + exports['test .walk()'] = function (assert) { + var node = new SourceNode(null, null, null, + ['(function () {\n', + ' ', new SourceNode(1, 0, 'a.js', ['someCall()']), ';\n', + ' ', new SourceNode(2, 0, 'b.js', ['if (foo) bar()']), ';\n', + '}());']); + var expected = [ + { str: '(function () {\n', source: null, line: null, column: null }, + { str: ' ', source: null, line: null, column: null }, + { str: 'someCall()', source: 'a.js', line: 1, column: 0 }, + { str: ';\n', source: null, line: null, column: null }, + { str: ' ', source: null, line: null, column: null }, + { str: 'if (foo) bar()', source: 'b.js', line: 2, column: 0 }, + { str: ';\n', source: null, line: null, column: null }, + { str: '}());', source: null, line: null, column: null }, + ]; + var i = 0; + node.walk(function (chunk, loc) { + assert.equal(expected[i].str, chunk); + assert.equal(expected[i].source, loc.source); + assert.equal(expected[i].line, loc.line); + assert.equal(expected[i].column, loc.column); + i++; + }); + }; + + exports['test .replaceRight'] = function (assert) { + var node; + + // Not nested + node = new SourceNode(null, null, null, 'hello world'); + node.replaceRight(/world/, 'universe'); + assert.equal(node.toString(), 'hello universe'); + + // Nested + node = new SourceNode(null, null, null, + [new SourceNode(null, null, null, 'hey sexy mama, '), + new SourceNode(null, null, null, 'want to kill all humans?')]); + node.replaceRight(/kill all humans/, 'watch Futurama'); + assert.equal(node.toString(), 'hey sexy mama, want to watch Futurama?'); + }; + + exports['test .toStringWithSourceMap()'] = forEachNewline(function (assert, nl) { + var node = new SourceNode(null, null, null, + ['(function () {' + nl, + ' ', + new SourceNode(1, 0, 'a.js', 'someCall', 'originalCall'), + new SourceNode(1, 8, 'a.js', '()'), + ';' + nl, + ' ', new SourceNode(2, 0, 'b.js', ['if (foo) bar()']), ';' + nl, + '}());']); + var result = node.toStringWithSourceMap({ + file: 'foo.js' + }); + + assert.equal(result.code, [ + '(function () {', + ' someCall();', + ' if (foo) bar();', + '}());' + ].join(nl)); + + var map = result.map; + var mapWithoutOptions = node.toStringWithSourceMap().map; + + assert.ok(map instanceof SourceMapGenerator, 'map instanceof SourceMapGenerator'); + assert.ok(mapWithoutOptions instanceof SourceMapGenerator, 'mapWithoutOptions instanceof SourceMapGenerator'); + assert.ok(!('file' in mapWithoutOptions)); + mapWithoutOptions._file = 'foo.js'; + util.assertEqualMaps(assert, map.toJSON(), mapWithoutOptions.toJSON()); + + map = new SourceMapConsumer(map.toString()); + + var actual; + + actual = map.originalPositionFor({ + line: 1, + column: 4 + }); + assert.equal(actual.source, null); + assert.equal(actual.line, null); + assert.equal(actual.column, null); + + actual = map.originalPositionFor({ + line: 2, + column: 2 + }); + assert.equal(actual.source, 'a.js'); + assert.equal(actual.line, 1); + assert.equal(actual.column, 0); + assert.equal(actual.name, 'originalCall'); + + actual = map.originalPositionFor({ + line: 3, + column: 2 + }); + assert.equal(actual.source, 'b.js'); + assert.equal(actual.line, 2); + assert.equal(actual.column, 0); + + actual = map.originalPositionFor({ + line: 3, + column: 16 + }); + assert.equal(actual.source, null); + assert.equal(actual.line, null); + assert.equal(actual.column, null); + + actual = map.originalPositionFor({ + line: 4, + column: 2 + }); + assert.equal(actual.source, null); + assert.equal(actual.line, null); + assert.equal(actual.column, null); + }); + + exports['test .fromStringWithSourceMap()'] = forEachNewline(function (assert, nl) { + var testCode = util.testGeneratedCode.replace(/\n/g, nl); + var node = SourceNode.fromStringWithSourceMap( + testCode, + new SourceMapConsumer(util.testMap)); + + var result = node.toStringWithSourceMap({ + file: 'min.js' + }); + var map = result.map; + var code = result.code; + + assert.equal(code, testCode); + assert.ok(map instanceof SourceMapGenerator, 'map instanceof SourceMapGenerator'); + map = map.toJSON(); + assert.equal(map.version, util.testMap.version); + assert.equal(map.file, util.testMap.file); + assert.equal(map.mappings, util.testMap.mappings); + }); + + exports['test .fromStringWithSourceMap() empty map'] = forEachNewline(function (assert, nl) { + var node = SourceNode.fromStringWithSourceMap( + util.testGeneratedCode.replace(/\n/g, nl), + new SourceMapConsumer(util.emptyMap)); + var result = node.toStringWithSourceMap({ + file: 'min.js' + }); + var map = result.map; + var code = result.code; + + assert.equal(code, util.testGeneratedCode.replace(/\n/g, nl)); + assert.ok(map instanceof SourceMapGenerator, 'map instanceof SourceMapGenerator'); + map = map.toJSON(); + assert.equal(map.version, util.emptyMap.version); + assert.equal(map.file, util.emptyMap.file); + assert.equal(map.mappings.length, util.emptyMap.mappings.length); + assert.equal(map.mappings, util.emptyMap.mappings); + }); + + exports['test .fromStringWithSourceMap() complex version'] = forEachNewline(function (assert, nl) { + var input = new SourceNode(null, null, null, [ + "(function() {" + nl, + " var Test = {};" + nl, + " ", new SourceNode(1, 0, "a.js", "Test.A = { value: 1234 };" + nl), + " ", new SourceNode(2, 0, "a.js", "Test.A.x = 'xyz';"), nl, + "}());" + nl, + "/* Generated Source */"]); + input = input.toStringWithSourceMap({ + file: 'foo.js' + }); + + var node = SourceNode.fromStringWithSourceMap( + input.code, + new SourceMapConsumer(input.map.toString())); + + var result = node.toStringWithSourceMap({ + file: 'foo.js' + }); + var map = result.map; + var code = result.code; + + assert.equal(code, input.code); + assert.ok(map instanceof SourceMapGenerator, 'map instanceof SourceMapGenerator'); + map = map.toJSON(); + var inputMap = input.map.toJSON(); + util.assertEqualMaps(assert, map, inputMap); + }); + + exports['test .fromStringWithSourceMap() third argument'] = function (assert) { + // Assume the following directory structure: + // + // http://foo.org/ + // bar.coffee + // app/ + // coffee/ + // foo.coffee + // coffeeBundle.js # Made from {foo,bar,baz}.coffee + // maps/ + // coffeeBundle.js.map + // js/ + // foo.js + // public/ + // app.js # Made from {foo,coffeeBundle}.js + // app.js.map + // + // http://www.example.com/ + // baz.coffee + + var coffeeBundle = new SourceNode(1, 0, 'foo.coffee', 'foo(coffee);\n'); + coffeeBundle.setSourceContent('foo.coffee', 'foo coffee'); + coffeeBundle.add(new SourceNode(2, 0, '/bar.coffee', 'bar(coffee);\n')); + coffeeBundle.add(new SourceNode(3, 0, 'http://www.example.com/baz.coffee', 'baz(coffee);')); + coffeeBundle = coffeeBundle.toStringWithSourceMap({ + file: 'foo.js', + sourceRoot: '..' + }); + + var foo = new SourceNode(1, 0, 'foo.js', 'foo(js);'); + + var test = function(relativePath, expectedSources) { + var app = new SourceNode(); + app.add(SourceNode.fromStringWithSourceMap( + coffeeBundle.code, + new SourceMapConsumer(coffeeBundle.map.toString()), + relativePath)); + app.add(foo); + var i = 0; + app.walk(function (chunk, loc) { + assert.equal(loc.source, expectedSources[i]); + i++; + }); + app.walkSourceContents(function (sourceFile, sourceContent) { + assert.equal(sourceFile, expectedSources[0]); + assert.equal(sourceContent, 'foo coffee'); + }) + }; + + test('../coffee/maps', [ + '../coffee/foo.coffee', + '/bar.coffee', + 'http://www.example.com/baz.coffee', + 'foo.js' + ]); + + // If the third parameter is omitted or set to the current working + // directory we get incorrect source paths: + + test(undefined, [ + '../foo.coffee', + '/bar.coffee', + 'http://www.example.com/baz.coffee', + 'foo.js' + ]); + + test('', [ + '../foo.coffee', + '/bar.coffee', + 'http://www.example.com/baz.coffee', + 'foo.js' + ]); + + test('.', [ + '../foo.coffee', + '/bar.coffee', + 'http://www.example.com/baz.coffee', + 'foo.js' + ]); + + test('./', [ + '../foo.coffee', + '/bar.coffee', + 'http://www.example.com/baz.coffee', + 'foo.js' + ]); + }; + + exports['test .toStringWithSourceMap() merging duplicate mappings'] = forEachNewline(function (assert, nl) { + var input = new SourceNode(null, null, null, [ + new SourceNode(1, 0, "a.js", "(function"), + new SourceNode(1, 0, "a.js", "() {" + nl), + " ", + new SourceNode(1, 0, "a.js", "var Test = "), + new SourceNode(1, 0, "b.js", "{};" + nl), + new SourceNode(2, 0, "b.js", "Test"), + new SourceNode(2, 0, "b.js", ".A", "A"), + new SourceNode(2, 20, "b.js", " = { value: ", "A"), + "1234", + new SourceNode(2, 40, "b.js", " };" + nl, "A"), + "}());" + nl, + "/* Generated Source */" + ]); + input = input.toStringWithSourceMap({ + file: 'foo.js' + }); + + assert.equal(input.code, [ + "(function() {", + " var Test = {};", + "Test.A = { value: 1234 };", + "}());", + "/* Generated Source */" + ].join(nl)) + + var correctMap = new SourceMapGenerator({ + file: 'foo.js' + }); + correctMap.addMapping({ + generated: { line: 1, column: 0 }, + source: 'a.js', + original: { line: 1, column: 0 } + }); + // Here is no need for a empty mapping, + // because mappings ends at eol + correctMap.addMapping({ + generated: { line: 2, column: 2 }, + source: 'a.js', + original: { line: 1, column: 0 } + }); + correctMap.addMapping({ + generated: { line: 2, column: 13 }, + source: 'b.js', + original: { line: 1, column: 0 } + }); + correctMap.addMapping({ + generated: { line: 3, column: 0 }, + source: 'b.js', + original: { line: 2, column: 0 } + }); + correctMap.addMapping({ + generated: { line: 3, column: 4 }, + source: 'b.js', + name: 'A', + original: { line: 2, column: 0 } + }); + correctMap.addMapping({ + generated: { line: 3, column: 6 }, + source: 'b.js', + name: 'A', + original: { line: 2, column: 20 } + }); + // This empty mapping is required, + // because there is a hole in the middle of the line + correctMap.addMapping({ + generated: { line: 3, column: 18 } + }); + correctMap.addMapping({ + generated: { line: 3, column: 22 }, + source: 'b.js', + name: 'A', + original: { line: 2, column: 40 } + }); + // Here is no need for a empty mapping, + // because mappings ends at eol + + var inputMap = input.map.toJSON(); + correctMap = correctMap.toJSON(); + util.assertEqualMaps(assert, inputMap, correctMap); + }); + + exports['test .toStringWithSourceMap() multi-line SourceNodes'] = forEachNewline(function (assert, nl) { + var input = new SourceNode(null, null, null, [ + new SourceNode(1, 0, "a.js", "(function() {" + nl + "var nextLine = 1;" + nl + "anotherLine();" + nl), + new SourceNode(2, 2, "b.js", "Test.call(this, 123);" + nl), + new SourceNode(2, 2, "b.js", "this['stuff'] = 'v';" + nl), + new SourceNode(2, 2, "b.js", "anotherLine();" + nl), + "/*" + nl + "Generated" + nl + "Source" + nl + "*/" + nl, + new SourceNode(3, 4, "c.js", "anotherLine();" + nl), + "/*" + nl + "Generated" + nl + "Source" + nl + "*/" + ]); + input = input.toStringWithSourceMap({ + file: 'foo.js' + }); + + assert.equal(input.code, [ + "(function() {", + "var nextLine = 1;", + "anotherLine();", + "Test.call(this, 123);", + "this['stuff'] = 'v';", + "anotherLine();", + "/*", + "Generated", + "Source", + "*/", + "anotherLine();", + "/*", + "Generated", + "Source", + "*/" + ].join(nl)); + + var correctMap = new SourceMapGenerator({ + file: 'foo.js' + }); + correctMap.addMapping({ + generated: { line: 1, column: 0 }, + source: 'a.js', + original: { line: 1, column: 0 } + }); + correctMap.addMapping({ + generated: { line: 2, column: 0 }, + source: 'a.js', + original: { line: 1, column: 0 } + }); + correctMap.addMapping({ + generated: { line: 3, column: 0 }, + source: 'a.js', + original: { line: 1, column: 0 } + }); + correctMap.addMapping({ + generated: { line: 4, column: 0 }, + source: 'b.js', + original: { line: 2, column: 2 } + }); + correctMap.addMapping({ + generated: { line: 5, column: 0 }, + source: 'b.js', + original: { line: 2, column: 2 } + }); + correctMap.addMapping({ + generated: { line: 6, column: 0 }, + source: 'b.js', + original: { line: 2, column: 2 } + }); + correctMap.addMapping({ + generated: { line: 11, column: 0 }, + source: 'c.js', + original: { line: 3, column: 4 } + }); + + var inputMap = input.map.toJSON(); + correctMap = correctMap.toJSON(); + util.assertEqualMaps(assert, inputMap, correctMap); + }); + + exports['test .toStringWithSourceMap() with empty string'] = function (assert) { + var node = new SourceNode(1, 0, 'empty.js', ''); + var result = node.toStringWithSourceMap(); + assert.equal(result.code, ''); + }; + + exports['test .toStringWithSourceMap() with consecutive newlines'] = forEachNewline(function (assert, nl) { + var input = new SourceNode(null, null, null, [ + "/***/" + nl + nl, + new SourceNode(1, 0, "a.js", "'use strict';" + nl), + new SourceNode(2, 0, "a.js", "a();"), + ]); + input = input.toStringWithSourceMap({ + file: 'foo.js' + }); + + assert.equal(input.code, [ + "/***/", + "", + "'use strict';", + "a();", + ].join(nl)); + + var correctMap = new SourceMapGenerator({ + file: 'foo.js' + }); + correctMap.addMapping({ + generated: { line: 3, column: 0 }, + source: 'a.js', + original: { line: 1, column: 0 } + }); + correctMap.addMapping({ + generated: { line: 4, column: 0 }, + source: 'a.js', + original: { line: 2, column: 0 } + }); + + var inputMap = input.map.toJSON(); + correctMap = correctMap.toJSON(); + util.assertEqualMaps(assert, inputMap, correctMap); + }); + + exports['test setSourceContent with toStringWithSourceMap'] = function (assert) { + var aNode = new SourceNode(1, 1, 'a.js', 'a'); + aNode.setSourceContent('a.js', 'someContent'); + var node = new SourceNode(null, null, null, + ['(function () {\n', + ' ', aNode, + ' ', new SourceNode(1, 1, 'b.js', 'b'), + '}());']); + node.setSourceContent('b.js', 'otherContent'); + var map = node.toStringWithSourceMap({ + file: 'foo.js' + }).map; + + assert.ok(map instanceof SourceMapGenerator, 'map instanceof SourceMapGenerator'); + map = new SourceMapConsumer(map.toString()); + + assert.equal(map.sources.length, 2); + assert.equal(map.sources[0], 'a.js'); + assert.equal(map.sources[1], 'b.js'); + assert.equal(map.sourcesContent.length, 2); + assert.equal(map.sourcesContent[0], 'someContent'); + assert.equal(map.sourcesContent[1], 'otherContent'); + }; + + exports['test walkSourceContents'] = function (assert) { + var aNode = new SourceNode(1, 1, 'a.js', 'a'); + aNode.setSourceContent('a.js', 'someContent'); + var node = new SourceNode(null, null, null, + ['(function () {\n', + ' ', aNode, + ' ', new SourceNode(1, 1, 'b.js', 'b'), + '}());']); + node.setSourceContent('b.js', 'otherContent'); + var results = []; + node.walkSourceContents(function (sourceFile, sourceContent) { + results.push([sourceFile, sourceContent]); + }); + assert.equal(results.length, 2); + assert.equal(results[0][0], 'a.js'); + assert.equal(results[0][1], 'someContent'); + assert.equal(results[1][0], 'b.js'); + assert.equal(results[1][1], 'otherContent'); + }; + } + + +/***/ }, +/* 1 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var util = __webpack_require__(2); + + // This is a test mapping which maps functions from two different files + // (one.js and two.js) to a minified generated source. + // + // Here is one.js: + // + // ONE.foo = function (bar) { + // return baz(bar); + // }; + // + // Here is two.js: + // + // TWO.inc = function (n) { + // return n + 1; + // }; + // + // And here is the generated code (min.js): + // + // ONE.foo=function(a){return baz(a);}; + // TWO.inc=function(a){return a+1;}; + exports.testGeneratedCode = " ONE.foo=function(a){return baz(a);};\n"+ + " TWO.inc=function(a){return a+1;};"; + exports.testMap = { + version: 3, + file: 'min.js', + names: ['bar', 'baz', 'n'], + sources: ['one.js', 'two.js'], + sourceRoot: '/the/root', + mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA' + }; + exports.testMapNoSourceRoot = { + version: 3, + file: 'min.js', + names: ['bar', 'baz', 'n'], + sources: ['one.js', 'two.js'], + mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA' + }; + exports.testMapEmptySourceRoot = { + version: 3, + file: 'min.js', + names: ['bar', 'baz', 'n'], + sources: ['one.js', 'two.js'], + sourceRoot: '', + mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA' + }; + // This mapping is identical to above, but uses the indexed format instead. + exports.indexedTestMap = { + version: 3, + file: 'min.js', + sections: [ + { + offset: { + line: 0, + column: 0 + }, + map: { + version: 3, + sources: [ + "one.js" + ], + sourcesContent: [ + ' ONE.foo = function (bar) {\n' + + ' return baz(bar);\n' + + ' };', + ], + names: [ + "bar", + "baz" + ], + mappings: "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID", + file: "min.js", + sourceRoot: "/the/root" + } + }, + { + offset: { + line: 1, + column: 0 + }, + map: { + version: 3, + sources: [ + "two.js" + ], + sourcesContent: [ + ' TWO.inc = function (n) {\n' + + ' return n + 1;\n' + + ' };' + ], + names: [ + "n" + ], + mappings: "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOA", + file: "min.js", + sourceRoot: "/the/root" + } + } + ] + }; + exports.indexedTestMapDifferentSourceRoots = { + version: 3, + file: 'min.js', + sections: [ + { + offset: { + line: 0, + column: 0 + }, + map: { + version: 3, + sources: [ + "one.js" + ], + sourcesContent: [ + ' ONE.foo = function (bar) {\n' + + ' return baz(bar);\n' + + ' };', + ], + names: [ + "bar", + "baz" + ], + mappings: "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID", + file: "min.js", + sourceRoot: "/the/root" + } + }, + { + offset: { + line: 1, + column: 0 + }, + map: { + version: 3, + sources: [ + "two.js" + ], + sourcesContent: [ + ' TWO.inc = function (n) {\n' + + ' return n + 1;\n' + + ' };' + ], + names: [ + "n" + ], + mappings: "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOA", + file: "min.js", + sourceRoot: "/different/root" + } + } + ] + }; + exports.testMapWithSourcesContent = { + version: 3, + file: 'min.js', + names: ['bar', 'baz', 'n'], + sources: ['one.js', 'two.js'], + sourcesContent: [ + ' ONE.foo = function (bar) {\n' + + ' return baz(bar);\n' + + ' };', + ' TWO.inc = function (n) {\n' + + ' return n + 1;\n' + + ' };' + ], + sourceRoot: '/the/root', + mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA' + }; + exports.testMapRelativeSources = { + version: 3, + file: 'min.js', + names: ['bar', 'baz', 'n'], + sources: ['./one.js', './two.js'], + sourcesContent: [ + ' ONE.foo = function (bar) {\n' + + ' return baz(bar);\n' + + ' };', + ' TWO.inc = function (n) {\n' + + ' return n + 1;\n' + + ' };' + ], + sourceRoot: '/the/root', + mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA' + }; + exports.emptyMap = { + version: 3, + file: 'min.js', + names: [], + sources: [], + mappings: '' + }; + + + function assertMapping(generatedLine, generatedColumn, originalSource, + originalLine, originalColumn, name, bias, map, assert, + dontTestGenerated, dontTestOriginal) { + if (!dontTestOriginal) { + var origMapping = map.originalPositionFor({ + line: generatedLine, + column: generatedColumn, + bias: bias + }); + assert.equal(origMapping.name, name, + 'Incorrect name, expected ' + JSON.stringify(name) + + ', got ' + JSON.stringify(origMapping.name)); + assert.equal(origMapping.line, originalLine, + 'Incorrect line, expected ' + JSON.stringify(originalLine) + + ', got ' + JSON.stringify(origMapping.line)); + assert.equal(origMapping.column, originalColumn, + 'Incorrect column, expected ' + JSON.stringify(originalColumn) + + ', got ' + JSON.stringify(origMapping.column)); + + var expectedSource; + + if (originalSource && map.sourceRoot && originalSource.indexOf(map.sourceRoot) === 0) { + expectedSource = originalSource; + } else if (originalSource) { + expectedSource = map.sourceRoot + ? util.join(map.sourceRoot, originalSource) + : originalSource; + } else { + expectedSource = null; + } + + assert.equal(origMapping.source, expectedSource, + 'Incorrect source, expected ' + JSON.stringify(expectedSource) + + ', got ' + JSON.stringify(origMapping.source)); + } + + if (!dontTestGenerated) { + var genMapping = map.generatedPositionFor({ + source: originalSource, + line: originalLine, + column: originalColumn, + bias: bias + }); + assert.equal(genMapping.line, generatedLine, + 'Incorrect line, expected ' + JSON.stringify(generatedLine) + + ', got ' + JSON.stringify(genMapping.line)); + assert.equal(genMapping.column, generatedColumn, + 'Incorrect column, expected ' + JSON.stringify(generatedColumn) + + ', got ' + JSON.stringify(genMapping.column)); + } + } + exports.assertMapping = assertMapping; + + function assertEqualMaps(assert, actualMap, expectedMap) { + assert.equal(actualMap.version, expectedMap.version, "version mismatch"); + assert.equal(actualMap.file, expectedMap.file, "file mismatch"); + assert.equal(actualMap.names.length, + expectedMap.names.length, + "names length mismatch: " + + actualMap.names.join(", ") + " != " + expectedMap.names.join(", ")); + for (var i = 0; i < actualMap.names.length; i++) { + assert.equal(actualMap.names[i], + expectedMap.names[i], + "names[" + i + "] mismatch: " + + actualMap.names.join(", ") + " != " + expectedMap.names.join(", ")); + } + assert.equal(actualMap.sources.length, + expectedMap.sources.length, + "sources length mismatch: " + + actualMap.sources.join(", ") + " != " + expectedMap.sources.join(", ")); + for (var i = 0; i < actualMap.sources.length; i++) { + assert.equal(actualMap.sources[i], + expectedMap.sources[i], + "sources[" + i + "] length mismatch: " + + actualMap.sources.join(", ") + " != " + expectedMap.sources.join(", ")); + } + assert.equal(actualMap.sourceRoot, + expectedMap.sourceRoot, + "sourceRoot mismatch: " + + actualMap.sourceRoot + " != " + expectedMap.sourceRoot); + assert.equal(actualMap.mappings, expectedMap.mappings, + "mappings mismatch:\nActual: " + actualMap.mappings + "\nExpected: " + expectedMap.mappings); + if (actualMap.sourcesContent) { + assert.equal(actualMap.sourcesContent.length, + expectedMap.sourcesContent.length, + "sourcesContent length mismatch"); + for (var i = 0; i < actualMap.sourcesContent.length; i++) { + assert.equal(actualMap.sourcesContent[i], + expectedMap.sourcesContent[i], + "sourcesContent[" + i + "] mismatch"); + } + } + } + exports.assertEqualMaps = assertEqualMaps; + } + + +/***/ }, +/* 2 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + /** + * This is a helper function for getting values from parameter/options + * objects. + * + * @param args The object we are extracting values from + * @param name The name of the property we are getting. + * @param defaultValue An optional value to return if the property is missing + * from the object. If this is not specified and the property is missing, an + * error will be thrown. + */ + function getArg(aArgs, aName, aDefaultValue) { + if (aName in aArgs) { + return aArgs[aName]; + } else if (arguments.length === 3) { + return aDefaultValue; + } else { + throw new Error('"' + aName + '" is a required argument.'); + } + } + exports.getArg = getArg; + + var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.]*)(?::(\d+))?(\S*)$/; + var dataUrlRegexp = /^data:.+\,.+$/; + + function urlParse(aUrl) { + var match = aUrl.match(urlRegexp); + if (!match) { + return null; + } + return { + scheme: match[1], + auth: match[2], + host: match[3], + port: match[4], + path: match[5] + }; + } + exports.urlParse = urlParse; + + function urlGenerate(aParsedUrl) { + var url = ''; + if (aParsedUrl.scheme) { + url += aParsedUrl.scheme + ':'; + } + url += '//'; + if (aParsedUrl.auth) { + url += aParsedUrl.auth + '@'; + } + if (aParsedUrl.host) { + url += aParsedUrl.host; + } + if (aParsedUrl.port) { + url += ":" + aParsedUrl.port + } + if (aParsedUrl.path) { + url += aParsedUrl.path; + } + return url; + } + exports.urlGenerate = urlGenerate; + + /** + * Normalizes a path, or the path portion of a URL: + * + * - Replaces consequtive slashes with one slash. + * - Removes unnecessary '.' parts. + * - Removes unnecessary '/..' parts. + * + * Based on code in the Node.js 'path' core module. + * + * @param aPath The path or url to normalize. + */ + function normalize(aPath) { + var path = aPath; + var url = urlParse(aPath); + if (url) { + if (!url.path) { + return aPath; + } + path = url.path; + } + var isAbsolute = exports.isAbsolute(path); + + var parts = path.split(/\/+/); + for (var part, up = 0, i = parts.length - 1; i >= 0; i--) { + part = parts[i]; + if (part === '.') { + parts.splice(i, 1); + } else if (part === '..') { + up++; + } else if (up > 0) { + if (part === '') { + // The first part is blank if the path is absolute. Trying to go + // above the root is a no-op. Therefore we can remove all '..' parts + // directly after the root. + parts.splice(i + 1, up); + up = 0; + } else { + parts.splice(i, 2); + up--; + } + } + } + path = parts.join('/'); + + if (path === '') { + path = isAbsolute ? '/' : '.'; + } + + if (url) { + url.path = path; + return urlGenerate(url); + } + return path; + } + exports.normalize = normalize; + + /** + * Joins two paths/URLs. + * + * @param aRoot The root path or URL. + * @param aPath The path or URL to be joined with the root. + * + * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a + * scheme-relative URL: Then the scheme of aRoot, if any, is prepended + * first. + * - Otherwise aPath is a path. If aRoot is a URL, then its path portion + * is updated with the result and aRoot is returned. Otherwise the result + * is returned. + * - If aPath is absolute, the result is aPath. + * - Otherwise the two paths are joined with a slash. + * - Joining for example 'http://' and 'www.example.com' is also supported. + */ + function join(aRoot, aPath) { + if (aRoot === "") { + aRoot = "."; + } + if (aPath === "") { + aPath = "."; + } + var aPathUrl = urlParse(aPath); + var aRootUrl = urlParse(aRoot); + if (aRootUrl) { + aRoot = aRootUrl.path || '/'; + } + + // `join(foo, '//www.example.org')` + if (aPathUrl && !aPathUrl.scheme) { + if (aRootUrl) { + aPathUrl.scheme = aRootUrl.scheme; + } + return urlGenerate(aPathUrl); + } + + if (aPathUrl || aPath.match(dataUrlRegexp)) { + return aPath; + } + + // `join('http://', 'www.example.com')` + if (aRootUrl && !aRootUrl.host && !aRootUrl.path) { + aRootUrl.host = aPath; + return urlGenerate(aRootUrl); + } + + var joined = aPath.charAt(0) === '/' + ? aPath + : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath); + + if (aRootUrl) { + aRootUrl.path = joined; + return urlGenerate(aRootUrl); + } + return joined; + } + exports.join = join; + + exports.isAbsolute = function (aPath) { + return aPath.charAt(0) === '/' || !!aPath.match(urlRegexp); + }; + + /** + * Make a path relative to a URL or another path. + * + * @param aRoot The root path or URL. + * @param aPath The path or URL to be made relative to aRoot. + */ + function relative(aRoot, aPath) { + if (aRoot === "") { + aRoot = "."; + } + + aRoot = aRoot.replace(/\/$/, ''); + + // It is possible for the path to be above the root. In this case, simply + // checking whether the root is a prefix of the path won't work. Instead, we + // need to remove components from the root one by one, until either we find + // a prefix that fits, or we run out of components to remove. + var level = 0; + while (aPath.indexOf(aRoot + '/') !== 0) { + var index = aRoot.lastIndexOf("/"); + if (index < 0) { + return aPath; + } + + // If the only part of the root that is left is the scheme (i.e. http://, + // file:///, etc.), one or more slashes (/), or simply nothing at all, we + // have exhausted all components, so the path is not relative to the root. + aRoot = aRoot.slice(0, index); + if (aRoot.match(/^([^\/]+:\/)?\/*$/)) { + return aPath; + } + + ++level; + } + + // Make sure we add a "../" for each component we removed from the root. + return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1); + } + exports.relative = relative; + + /** + * Because behavior goes wacky when you set `__proto__` on objects, we + * have to prefix all the strings in our set with an arbitrary character. + * + * See https://github.com/mozilla/source-map/pull/31 and + * https://github.com/mozilla/source-map/issues/30 + * + * @param String aStr + */ + function toSetString(aStr) { + return '$' + aStr; + } + exports.toSetString = toSetString; + + function fromSetString(aStr) { + return aStr.substr(1); + } + exports.fromSetString = fromSetString; + + /** + * Comparator between two mappings where the original positions are compared. + * + * Optionally pass in `true` as `onlyCompareGenerated` to consider two + * mappings with the same original source/line/column, but different generated + * line and column the same. Useful when searching for a mapping with a + * stubbed out mapping. + */ + function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) { + var cmp = mappingA.source - mappingB.source; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0 || onlyCompareOriginal) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + return mappingA.name - mappingB.name; + } + exports.compareByOriginalPositions = compareByOriginalPositions; + + /** + * Comparator between two mappings with deflated source and name indices where + * the generated positions are compared. + * + * Optionally pass in `true` as `onlyCompareGenerated` to consider two + * mappings with the same generated line and column, but different + * source/name/original line and column the same. Useful when searching for a + * mapping with a stubbed out mapping. + */ + function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) { + var cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0 || onlyCompareGenerated) { + return cmp; + } + + cmp = mappingA.source - mappingB.source; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0) { + return cmp; + } + + return mappingA.name - mappingB.name; + } + exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated; + + function strcmp(aStr1, aStr2) { + if (aStr1 === aStr2) { + return 0; + } + + if (aStr1 > aStr2) { + return 1; + } + + return -1; + } + + /** + * Comparator between two mappings with inflated source and name strings where + * the generated positions are compared. + */ + function compareByGeneratedPositionsInflated(mappingA, mappingB) { + var cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0) { + return cmp; + } + + cmp = strcmp(mappingA.source, mappingB.source); + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0) { + return cmp; + } + + return strcmp(mappingA.name, mappingB.name); + } + exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated; + } + + +/***/ }, +/* 3 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var base64VLQ = __webpack_require__(4); + var util = __webpack_require__(2); + var ArraySet = __webpack_require__(6).ArraySet; + var MappingList = __webpack_require__(7).MappingList; + + /** + * An instance of the SourceMapGenerator represents a source map which is + * being built incrementally. You may pass an object with the following + * properties: + * + * - file: The filename of the generated source. + * - sourceRoot: A root for all relative URLs in this source map. + */ + function SourceMapGenerator(aArgs) { + if (!aArgs) { + aArgs = {}; + } + this._file = util.getArg(aArgs, 'file', null); + this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null); + this._skipValidation = util.getArg(aArgs, 'skipValidation', false); + this._sources = new ArraySet(); + this._names = new ArraySet(); + this._mappings = new MappingList(); + this._sourcesContents = null; + } + + SourceMapGenerator.prototype._version = 3; + + /** + * Creates a new SourceMapGenerator based on a SourceMapConsumer + * + * @param aSourceMapConsumer The SourceMap. + */ + SourceMapGenerator.fromSourceMap = + function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) { + var sourceRoot = aSourceMapConsumer.sourceRoot; + var generator = new SourceMapGenerator({ + file: aSourceMapConsumer.file, + sourceRoot: sourceRoot + }); + aSourceMapConsumer.eachMapping(function (mapping) { + var newMapping = { + generated: { + line: mapping.generatedLine, + column: mapping.generatedColumn + } + }; + + if (mapping.source != null) { + newMapping.source = mapping.source; + if (sourceRoot != null) { + newMapping.source = util.relative(sourceRoot, newMapping.source); + } + + newMapping.original = { + line: mapping.originalLine, + column: mapping.originalColumn + }; + + if (mapping.name != null) { + newMapping.name = mapping.name; + } + } + + generator.addMapping(newMapping); + }); + aSourceMapConsumer.sources.forEach(function (sourceFile) { + var content = aSourceMapConsumer.sourceContentFor(sourceFile); + if (content != null) { + generator.setSourceContent(sourceFile, content); + } + }); + return generator; + }; + + /** + * Add a single mapping from original source line and column to the generated + * source's line and column for this source map being created. The mapping + * object should have the following properties: + * + * - generated: An object with the generated line and column positions. + * - original: An object with the original line and column positions. + * - source: The original source file (relative to the sourceRoot). + * - name: An optional original token name for this mapping. + */ + SourceMapGenerator.prototype.addMapping = + function SourceMapGenerator_addMapping(aArgs) { + var generated = util.getArg(aArgs, 'generated'); + var original = util.getArg(aArgs, 'original', null); + var source = util.getArg(aArgs, 'source', null); + var name = util.getArg(aArgs, 'name', null); + + if (!this._skipValidation) { + this._validateMapping(generated, original, source, name); + } + + if (source != null && !this._sources.has(source)) { + this._sources.add(source); + } + + if (name != null && !this._names.has(name)) { + this._names.add(name); + } + + this._mappings.add({ + generatedLine: generated.line, + generatedColumn: generated.column, + originalLine: original != null && original.line, + originalColumn: original != null && original.column, + source: source, + name: name + }); + }; + + /** + * Set the source content for a source file. + */ + SourceMapGenerator.prototype.setSourceContent = + function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) { + var source = aSourceFile; + if (this._sourceRoot != null) { + source = util.relative(this._sourceRoot, source); + } + + if (aSourceContent != null) { + // Add the source content to the _sourcesContents map. + // Create a new _sourcesContents map if the property is null. + if (!this._sourcesContents) { + this._sourcesContents = {}; + } + this._sourcesContents[util.toSetString(source)] = aSourceContent; + } else if (this._sourcesContents) { + // Remove the source file from the _sourcesContents map. + // If the _sourcesContents map is empty, set the property to null. + delete this._sourcesContents[util.toSetString(source)]; + if (Object.keys(this._sourcesContents).length === 0) { + this._sourcesContents = null; + } + } + }; + + /** + * Applies the mappings of a sub-source-map for a specific source file to the + * source map being generated. Each mapping to the supplied source file is + * rewritten using the supplied source map. Note: The resolution for the + * resulting mappings is the minimium of this map and the supplied map. + * + * @param aSourceMapConsumer The source map to be applied. + * @param aSourceFile Optional. The filename of the source file. + * If omitted, SourceMapConsumer's file property will be used. + * @param aSourceMapPath Optional. The dirname of the path to the source map + * to be applied. If relative, it is relative to the SourceMapConsumer. + * This parameter is needed when the two source maps aren't in the same + * directory, and the source map to be applied contains relative source + * paths. If so, those relative source paths need to be rewritten + * relative to the SourceMapGenerator. + */ + SourceMapGenerator.prototype.applySourceMap = + function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) { + var sourceFile = aSourceFile; + // If aSourceFile is omitted, we will use the file property of the SourceMap + if (aSourceFile == null) { + if (aSourceMapConsumer.file == null) { + throw new Error( + 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' + + 'or the source map\'s "file" property. Both were omitted.' + ); + } + sourceFile = aSourceMapConsumer.file; + } + var sourceRoot = this._sourceRoot; + // Make "sourceFile" relative if an absolute Url is passed. + if (sourceRoot != null) { + sourceFile = util.relative(sourceRoot, sourceFile); + } + // Applying the SourceMap can add and remove items from the sources and + // the names array. + var newSources = new ArraySet(); + var newNames = new ArraySet(); + + // Find mappings for the "sourceFile" + this._mappings.unsortedForEach(function (mapping) { + if (mapping.source === sourceFile && mapping.originalLine != null) { + // Check if it can be mapped by the source map, then update the mapping. + var original = aSourceMapConsumer.originalPositionFor({ + line: mapping.originalLine, + column: mapping.originalColumn + }); + if (original.source != null) { + // Copy mapping + mapping.source = original.source; + if (aSourceMapPath != null) { + mapping.source = util.join(aSourceMapPath, mapping.source) + } + if (sourceRoot != null) { + mapping.source = util.relative(sourceRoot, mapping.source); + } + mapping.originalLine = original.line; + mapping.originalColumn = original.column; + if (original.name != null) { + mapping.name = original.name; + } + } + } + + var source = mapping.source; + if (source != null && !newSources.has(source)) { + newSources.add(source); + } + + var name = mapping.name; + if (name != null && !newNames.has(name)) { + newNames.add(name); + } + + }, this); + this._sources = newSources; + this._names = newNames; + + // Copy sourcesContents of applied map. + aSourceMapConsumer.sources.forEach(function (sourceFile) { + var content = aSourceMapConsumer.sourceContentFor(sourceFile); + if (content != null) { + if (aSourceMapPath != null) { + sourceFile = util.join(aSourceMapPath, sourceFile); + } + if (sourceRoot != null) { + sourceFile = util.relative(sourceRoot, sourceFile); + } + this.setSourceContent(sourceFile, content); + } + }, this); + }; + + /** + * A mapping can have one of the three levels of data: + * + * 1. Just the generated position. + * 2. The Generated position, original position, and original source. + * 3. Generated and original position, original source, as well as a name + * token. + * + * To maintain consistency, we validate that any new mapping being added falls + * in to one of these categories. + */ + SourceMapGenerator.prototype._validateMapping = + function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource, + aName) { + if (aGenerated && 'line' in aGenerated && 'column' in aGenerated + && aGenerated.line > 0 && aGenerated.column >= 0 + && !aOriginal && !aSource && !aName) { + // Case 1. + return; + } + else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated + && aOriginal && 'line' in aOriginal && 'column' in aOriginal + && aGenerated.line > 0 && aGenerated.column >= 0 + && aOriginal.line > 0 && aOriginal.column >= 0 + && aSource) { + // Cases 2 and 3. + return; + } + else { + throw new Error('Invalid mapping: ' + JSON.stringify({ + generated: aGenerated, + source: aSource, + original: aOriginal, + name: aName + })); + } + }; + + /** + * Serialize the accumulated mappings in to the stream of base 64 VLQs + * specified by the source map format. + */ + SourceMapGenerator.prototype._serializeMappings = + function SourceMapGenerator_serializeMappings() { + var previousGeneratedColumn = 0; + var previousGeneratedLine = 1; + var previousOriginalColumn = 0; + var previousOriginalLine = 0; + var previousName = 0; + var previousSource = 0; + var result = ''; + var mapping; + var nameIdx; + var sourceIdx; + + var mappings = this._mappings.toArray(); + for (var i = 0, len = mappings.length; i < len; i++) { + mapping = mappings[i]; + + if (mapping.generatedLine !== previousGeneratedLine) { + previousGeneratedColumn = 0; + while (mapping.generatedLine !== previousGeneratedLine) { + result += ';'; + previousGeneratedLine++; + } + } + else { + if (i > 0) { + if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) { + continue; + } + result += ','; + } + } + + result += base64VLQ.encode(mapping.generatedColumn + - previousGeneratedColumn); + previousGeneratedColumn = mapping.generatedColumn; + + if (mapping.source != null) { + sourceIdx = this._sources.indexOf(mapping.source); + result += base64VLQ.encode(sourceIdx - previousSource); + previousSource = sourceIdx; + + // lines are stored 0-based in SourceMap spec version 3 + result += base64VLQ.encode(mapping.originalLine - 1 + - previousOriginalLine); + previousOriginalLine = mapping.originalLine - 1; + + result += base64VLQ.encode(mapping.originalColumn + - previousOriginalColumn); + previousOriginalColumn = mapping.originalColumn; + + if (mapping.name != null) { + nameIdx = this._names.indexOf(mapping.name); + result += base64VLQ.encode(nameIdx - previousName); + previousName = nameIdx; + } + } + } + + return result; + }; + + SourceMapGenerator.prototype._generateSourcesContent = + function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) { + return aSources.map(function (source) { + if (!this._sourcesContents) { + return null; + } + if (aSourceRoot != null) { + source = util.relative(aSourceRoot, source); + } + var key = util.toSetString(source); + return Object.prototype.hasOwnProperty.call(this._sourcesContents, + key) + ? this._sourcesContents[key] + : null; + }, this); + }; + + /** + * Externalize the source map. + */ + SourceMapGenerator.prototype.toJSON = + function SourceMapGenerator_toJSON() { + var map = { + version: this._version, + sources: this._sources.toArray(), + names: this._names.toArray(), + mappings: this._serializeMappings() + }; + if (this._file != null) { + map.file = this._file; + } + if (this._sourceRoot != null) { + map.sourceRoot = this._sourceRoot; + } + if (this._sourcesContents) { + map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot); + } + + return map; + }; + + /** + * Render the source map being generated to a string. + */ + SourceMapGenerator.prototype.toString = + function SourceMapGenerator_toString() { + return JSON.stringify(this.toJSON()); + }; + + exports.SourceMapGenerator = SourceMapGenerator; + } + + +/***/ }, +/* 4 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + * + * Based on the Base 64 VLQ implementation in Closure Compiler: + * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java + * + * Copyright 2011 The Closure Compiler Authors. All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + { + var base64 = __webpack_require__(5); + + // A single base 64 digit can contain 6 bits of data. For the base 64 variable + // length quantities we use in the source map spec, the first bit is the sign, + // the next four bits are the actual value, and the 6th bit is the + // continuation bit. The continuation bit tells us whether there are more + // digits in this value following this digit. + // + // Continuation + // | Sign + // | | + // V V + // 101011 + + var VLQ_BASE_SHIFT = 5; + + // binary: 100000 + var VLQ_BASE = 1 << VLQ_BASE_SHIFT; + + // binary: 011111 + var VLQ_BASE_MASK = VLQ_BASE - 1; + + // binary: 100000 + var VLQ_CONTINUATION_BIT = VLQ_BASE; + + /** + * Converts from a two-complement value to a value where the sign bit is + * placed in the least significant bit. For example, as decimals: + * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary) + * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary) + */ + function toVLQSigned(aValue) { + return aValue < 0 + ? ((-aValue) << 1) + 1 + : (aValue << 1) + 0; + } + + /** + * Converts to a two-complement value from a value where the sign bit is + * placed in the least significant bit. For example, as decimals: + * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1 + * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2 + */ + function fromVLQSigned(aValue) { + var isNegative = (aValue & 1) === 1; + var shifted = aValue >> 1; + return isNegative + ? -shifted + : shifted; + } + + /** + * Returns the base 64 VLQ encoded value. + */ + exports.encode = function base64VLQ_encode(aValue) { + var encoded = ""; + var digit; + + var vlq = toVLQSigned(aValue); + + do { + digit = vlq & VLQ_BASE_MASK; + vlq >>>= VLQ_BASE_SHIFT; + if (vlq > 0) { + // There are still more digits in this value, so we must make sure the + // continuation bit is marked. + digit |= VLQ_CONTINUATION_BIT; + } + encoded += base64.encode(digit); + } while (vlq > 0); + + return encoded; + }; + + /** + * Decodes the next base 64 VLQ value from the given string and returns the + * value and the rest of the string via the out parameter. + */ + exports.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) { + var strLen = aStr.length; + var result = 0; + var shift = 0; + var continuation, digit; + + do { + if (aIndex >= strLen) { + throw new Error("Expected more digits in base 64 VLQ value."); + } + + digit = base64.decode(aStr.charCodeAt(aIndex++)); + if (digit === -1) { + throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1)); + } + + continuation = !!(digit & VLQ_CONTINUATION_BIT); + digit &= VLQ_BASE_MASK; + result = result + (digit << shift); + shift += VLQ_BASE_SHIFT; + } while (continuation); + + aOutParam.value = fromVLQSigned(result); + aOutParam.rest = aIndex; + }; + } + + +/***/ }, +/* 5 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split(''); + + /** + * Encode an integer in the range of 0 to 63 to a single base 64 digit. + */ + exports.encode = function (number) { + if (0 <= number && number < intToCharMap.length) { + return intToCharMap[number]; + } + throw new TypeError("Must be between 0 and 63: " + number); + }; + + /** + * Decode a single base 64 character code digit to an integer. Returns -1 on + * failure. + */ + exports.decode = function (charCode) { + var bigA = 65; // 'A' + var bigZ = 90; // 'Z' + + var littleA = 97; // 'a' + var littleZ = 122; // 'z' + + var zero = 48; // '0' + var nine = 57; // '9' + + var plus = 43; // '+' + var slash = 47; // '/' + + var littleOffset = 26; + var numberOffset = 52; + + // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ + if (bigA <= charCode && charCode <= bigZ) { + return (charCode - bigA); + } + + // 26 - 51: abcdefghijklmnopqrstuvwxyz + if (littleA <= charCode && charCode <= littleZ) { + return (charCode - littleA + littleOffset); + } + + // 52 - 61: 0123456789 + if (zero <= charCode && charCode <= nine) { + return (charCode - zero + numberOffset); + } + + // 62: + + if (charCode == plus) { + return 62; + } + + // 63: / + if (charCode == slash) { + return 63; + } + + // Invalid base64 digit. + return -1; + }; + } + + +/***/ }, +/* 6 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var util = __webpack_require__(2); + + /** + * A data structure which is a combination of an array and a set. Adding a new + * member is O(1), testing for membership is O(1), and finding the index of an + * element is O(1). Removing elements from the set is not supported. Only + * strings are supported for membership. + */ + function ArraySet() { + this._array = []; + this._set = {}; + } + + /** + * Static method for creating ArraySet instances from an existing array. + */ + ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) { + var set = new ArraySet(); + for (var i = 0, len = aArray.length; i < len; i++) { + set.add(aArray[i], aAllowDuplicates); + } + return set; + }; + + /** + * Return how many unique items are in this ArraySet. If duplicates have been + * added, than those do not count towards the size. + * + * @returns Number + */ + ArraySet.prototype.size = function ArraySet_size() { + return Object.getOwnPropertyNames(this._set).length; + }; + + /** + * Add the given string to this set. + * + * @param String aStr + */ + ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) { + var sStr = util.toSetString(aStr); + var isDuplicate = this._set.hasOwnProperty(sStr); + var idx = this._array.length; + if (!isDuplicate || aAllowDuplicates) { + this._array.push(aStr); + } + if (!isDuplicate) { + this._set[sStr] = idx; + } + }; + + /** + * Is the given string a member of this set? + * + * @param String aStr + */ + ArraySet.prototype.has = function ArraySet_has(aStr) { + var sStr = util.toSetString(aStr); + return this._set.hasOwnProperty(sStr); + }; + + /** + * What is the index of the given string in the array? + * + * @param String aStr + */ + ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) { + var sStr = util.toSetString(aStr); + if (this._set.hasOwnProperty(sStr)) { + return this._set[sStr]; + } + throw new Error('"' + aStr + '" is not in the set.'); + }; + + /** + * What is the element at the given index? + * + * @param Number aIdx + */ + ArraySet.prototype.at = function ArraySet_at(aIdx) { + if (aIdx >= 0 && aIdx < this._array.length) { + return this._array[aIdx]; + } + throw new Error('No element indexed by ' + aIdx); + }; + + /** + * Returns the array representation of this set (which has the proper indices + * indicated by indexOf). Note that this is a copy of the internal array used + * for storing the members so that no one can mess with internal state. + */ + ArraySet.prototype.toArray = function ArraySet_toArray() { + return this._array.slice(); + }; + + exports.ArraySet = ArraySet; + } + + +/***/ }, +/* 7 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2014 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var util = __webpack_require__(2); + + /** + * Determine whether mappingB is after mappingA with respect to generated + * position. + */ + function generatedPositionAfter(mappingA, mappingB) { + // Optimized for most common case + var lineA = mappingA.generatedLine; + var lineB = mappingB.generatedLine; + var columnA = mappingA.generatedColumn; + var columnB = mappingB.generatedColumn; + return lineB > lineA || lineB == lineA && columnB >= columnA || + util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0; + } + + /** + * A data structure to provide a sorted view of accumulated mappings in a + * performance conscious manner. It trades a neglibable overhead in general + * case for a large speedup in case of mappings being added in order. + */ + function MappingList() { + this._array = []; + this._sorted = true; + // Serves as infimum + this._last = {generatedLine: -1, generatedColumn: 0}; + } + + /** + * Iterate through internal items. This method takes the same arguments that + * `Array.prototype.forEach` takes. + * + * NOTE: The order of the mappings is NOT guaranteed. + */ + MappingList.prototype.unsortedForEach = + function MappingList_forEach(aCallback, aThisArg) { + this._array.forEach(aCallback, aThisArg); + }; + + /** + * Add the given source mapping. + * + * @param Object aMapping + */ + MappingList.prototype.add = function MappingList_add(aMapping) { + if (generatedPositionAfter(this._last, aMapping)) { + this._last = aMapping; + this._array.push(aMapping); + } else { + this._sorted = false; + this._array.push(aMapping); + } + }; + + /** + * Returns the flat, sorted array of mappings. The mappings are sorted by + * generated position. + * + * WARNING: This method returns internal data without copying, for + * performance. The return value must NOT be mutated, and should be treated as + * an immutable borrow. If you want to take ownership, you must make your own + * copy. + */ + MappingList.prototype.toArray = function MappingList_toArray() { + if (!this._sorted) { + this._array.sort(util.compareByGeneratedPositionsInflated); + this._sorted = true; + } + return this._array; + }; + + exports.MappingList = MappingList; + } + + +/***/ }, +/* 8 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var util = __webpack_require__(2); + var binarySearch = __webpack_require__(9); + var ArraySet = __webpack_require__(6).ArraySet; + var base64VLQ = __webpack_require__(4); + var quickSort = __webpack_require__(10).quickSort; + + function SourceMapConsumer(aSourceMap) { + var sourceMap = aSourceMap; + if (typeof aSourceMap === 'string') { + sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); + } + + return sourceMap.sections != null + ? new IndexedSourceMapConsumer(sourceMap) + : new BasicSourceMapConsumer(sourceMap); + } + + SourceMapConsumer.fromSourceMap = function(aSourceMap) { + return BasicSourceMapConsumer.fromSourceMap(aSourceMap); + } + + /** + * The version of the source mapping spec that we are consuming. + */ + SourceMapConsumer.prototype._version = 3; + + // `__generatedMappings` and `__originalMappings` are arrays that hold the + // parsed mapping coordinates from the source map's "mappings" attribute. They + // are lazily instantiated, accessed via the `_generatedMappings` and + // `_originalMappings` getters respectively, and we only parse the mappings + // and create these arrays once queried for a source location. We jump through + // these hoops because there can be many thousands of mappings, and parsing + // them is expensive, so we only want to do it if we must. + // + // Each object in the arrays is of the form: + // + // { + // generatedLine: The line number in the generated code, + // generatedColumn: The column number in the generated code, + // source: The path to the original source file that generated this + // chunk of code, + // originalLine: The line number in the original source that + // corresponds to this chunk of generated code, + // originalColumn: The column number in the original source that + // corresponds to this chunk of generated code, + // name: The name of the original symbol which generated this chunk of + // code. + // } + // + // All properties except for `generatedLine` and `generatedColumn` can be + // `null`. + // + // `_generatedMappings` is ordered by the generated positions. + // + // `_originalMappings` is ordered by the original positions. + + SourceMapConsumer.prototype.__generatedMappings = null; + Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', { + get: function () { + if (!this.__generatedMappings) { + this._parseMappings(this._mappings, this.sourceRoot); + } + + return this.__generatedMappings; + } + }); + + SourceMapConsumer.prototype.__originalMappings = null; + Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', { + get: function () { + if (!this.__originalMappings) { + this._parseMappings(this._mappings, this.sourceRoot); + } + + return this.__originalMappings; + } + }); + + SourceMapConsumer.prototype._charIsMappingSeparator = + function SourceMapConsumer_charIsMappingSeparator(aStr, index) { + var c = aStr.charAt(index); + return c === ";" || c === ","; + }; + + /** + * Parse the mappings in a string in to a data structure which we can easily + * query (the ordered arrays in the `this.__generatedMappings` and + * `this.__originalMappings` properties). + */ + SourceMapConsumer.prototype._parseMappings = + function SourceMapConsumer_parseMappings(aStr, aSourceRoot) { + throw new Error("Subclasses must implement _parseMappings"); + }; + + SourceMapConsumer.GENERATED_ORDER = 1; + SourceMapConsumer.ORIGINAL_ORDER = 2; + + SourceMapConsumer.GREATEST_LOWER_BOUND = 1; + SourceMapConsumer.LEAST_UPPER_BOUND = 2; + + /** + * Iterate over each mapping between an original source/line/column and a + * generated line/column in this source map. + * + * @param Function aCallback + * The function that is called with each mapping. + * @param Object aContext + * Optional. If specified, this object will be the value of `this` every + * time that `aCallback` is called. + * @param aOrder + * Either `SourceMapConsumer.GENERATED_ORDER` or + * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to + * iterate over the mappings sorted by the generated file's line/column + * order or the original's source/line/column order, respectively. Defaults to + * `SourceMapConsumer.GENERATED_ORDER`. + */ + SourceMapConsumer.prototype.eachMapping = + function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) { + var context = aContext || null; + var order = aOrder || SourceMapConsumer.GENERATED_ORDER; + + var mappings; + switch (order) { + case SourceMapConsumer.GENERATED_ORDER: + mappings = this._generatedMappings; + break; + case SourceMapConsumer.ORIGINAL_ORDER: + mappings = this._originalMappings; + break; + default: + throw new Error("Unknown order of iteration."); + } + + var sourceRoot = this.sourceRoot; + mappings.map(function (mapping) { + var source = mapping.source === null ? null : this._sources.at(mapping.source); + if (source != null && sourceRoot != null) { + source = util.join(sourceRoot, source); + } + return { + source: source, + generatedLine: mapping.generatedLine, + generatedColumn: mapping.generatedColumn, + originalLine: mapping.originalLine, + originalColumn: mapping.originalColumn, + name: mapping.name === null ? null : this._names.at(mapping.name) + }; + }, this).forEach(aCallback, context); + }; + + /** + * Returns all generated line and column information for the original source, + * line, and column provided. If no column is provided, returns all mappings + * corresponding to a either the line we are searching for or the next + * closest line that has any mappings. Otherwise, returns all mappings + * corresponding to the given line and either the column we are searching for + * or the next closest column that has any offsets. + * + * The only argument is an object with the following properties: + * + * - source: The filename of the original source. + * - line: The line number in the original source. + * - column: Optional. the column number in the original source. + * + * and an array of objects is returned, each with the following properties: + * + * - line: The line number in the generated source, or null. + * - column: The column number in the generated source, or null. + */ + SourceMapConsumer.prototype.allGeneratedPositionsFor = + function SourceMapConsumer_allGeneratedPositionsFor(aArgs) { + var line = util.getArg(aArgs, 'line'); + + // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping + // returns the index of the closest mapping less than the needle. By + // setting needle.originalColumn to 0, we thus find the last mapping for + // the given line, provided such a mapping exists. + var needle = { + source: util.getArg(aArgs, 'source'), + originalLine: line, + originalColumn: util.getArg(aArgs, 'column', 0) + }; + + if (this.sourceRoot != null) { + needle.source = util.relative(this.sourceRoot, needle.source); + } + if (!this._sources.has(needle.source)) { + return []; + } + needle.source = this._sources.indexOf(needle.source); + + var mappings = []; + + var index = this._findMapping(needle, + this._originalMappings, + "originalLine", + "originalColumn", + util.compareByOriginalPositions, + binarySearch.LEAST_UPPER_BOUND); + if (index >= 0) { + var mapping = this._originalMappings[index]; + + if (aArgs.column === undefined) { + var originalLine = mapping.originalLine; + + // Iterate until either we run out of mappings, or we run into + // a mapping for a different line than the one we found. Since + // mappings are sorted, this is guaranteed to find all mappings for + // the line we found. + while (mapping && mapping.originalLine === originalLine) { + mappings.push({ + line: util.getArg(mapping, 'generatedLine', null), + column: util.getArg(mapping, 'generatedColumn', null), + lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) + }); + + mapping = this._originalMappings[++index]; + } + } else { + var originalColumn = mapping.originalColumn; + + // Iterate until either we run out of mappings, or we run into + // a mapping for a different line than the one we were searching for. + // Since mappings are sorted, this is guaranteed to find all mappings for + // the line we are searching for. + while (mapping && + mapping.originalLine === line && + mapping.originalColumn == originalColumn) { + mappings.push({ + line: util.getArg(mapping, 'generatedLine', null), + column: util.getArg(mapping, 'generatedColumn', null), + lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) + }); + + mapping = this._originalMappings[++index]; + } + } + } + + return mappings; + }; + + exports.SourceMapConsumer = SourceMapConsumer; + + /** + * A BasicSourceMapConsumer instance represents a parsed source map which we can + * query for information about the original file positions by giving it a file + * position in the generated source. + * + * The only parameter is the raw source map (either as a JSON string, or + * already parsed to an object). According to the spec, source maps have the + * following attributes: + * + * - version: Which version of the source map spec this map is following. + * - sources: An array of URLs to the original source files. + * - names: An array of identifiers which can be referrenced by individual mappings. + * - sourceRoot: Optional. The URL root from which all sources are relative. + * - sourcesContent: Optional. An array of contents of the original source files. + * - mappings: A string of base64 VLQs which contain the actual mappings. + * - file: Optional. The generated file this source map is associated with. + * + * Here is an example source map, taken from the source map spec[0]: + * + * { + * version : 3, + * file: "out.js", + * sourceRoot : "", + * sources: ["foo.js", "bar.js"], + * names: ["src", "maps", "are", "fun"], + * mappings: "AA,AB;;ABCDE;" + * } + * + * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1# + */ + function BasicSourceMapConsumer(aSourceMap) { + var sourceMap = aSourceMap; + if (typeof aSourceMap === 'string') { + sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); + } + + var version = util.getArg(sourceMap, 'version'); + var sources = util.getArg(sourceMap, 'sources'); + // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which + // requires the array) to play nice here. + var names = util.getArg(sourceMap, 'names', []); + var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null); + var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null); + var mappings = util.getArg(sourceMap, 'mappings'); + var file = util.getArg(sourceMap, 'file', null); + + // Once again, Sass deviates from the spec and supplies the version as a + // string rather than a number, so we use loose equality checking here. + if (version != this._version) { + throw new Error('Unsupported version: ' + version); + } + + sources = sources + // Some source maps produce relative source paths like "./foo.js" instead of + // "foo.js". Normalize these first so that future comparisons will succeed. + // See bugzil.la/1090768. + .map(util.normalize) + // Always ensure that absolute sources are internally stored relative to + // the source root, if the source root is absolute. Not doing this would + // be particularly problematic when the source root is a prefix of the + // source (valid, but why??). See github issue #199 and bugzil.la/1188982. + .map(function (source) { + return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source) + ? util.relative(sourceRoot, source) + : source; + }); + + // Pass `true` below to allow duplicate names and sources. While source maps + // are intended to be compressed and deduplicated, the TypeScript compiler + // sometimes generates source maps with duplicates in them. See Github issue + // #72 and bugzil.la/889492. + this._names = ArraySet.fromArray(names, true); + this._sources = ArraySet.fromArray(sources, true); + + this.sourceRoot = sourceRoot; + this.sourcesContent = sourcesContent; + this._mappings = mappings; + this.file = file; + } + + BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype); + BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer; + + /** + * Create a BasicSourceMapConsumer from a SourceMapGenerator. + * + * @param SourceMapGenerator aSourceMap + * The source map that will be consumed. + * @returns BasicSourceMapConsumer + */ + BasicSourceMapConsumer.fromSourceMap = + function SourceMapConsumer_fromSourceMap(aSourceMap) { + var smc = Object.create(BasicSourceMapConsumer.prototype); + + var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true); + var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true); + smc.sourceRoot = aSourceMap._sourceRoot; + smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(), + smc.sourceRoot); + smc.file = aSourceMap._file; + + // Because we are modifying the entries (by converting string sources and + // names to indices into the sources and names ArraySets), we have to make + // a copy of the entry or else bad things happen. Shared mutable state + // strikes again! See github issue #191. + + var generatedMappings = aSourceMap._mappings.toArray().slice(); + var destGeneratedMappings = smc.__generatedMappings = []; + var destOriginalMappings = smc.__originalMappings = []; + + for (var i = 0, length = generatedMappings.length; i < length; i++) { + var srcMapping = generatedMappings[i]; + var destMapping = new Mapping; + destMapping.generatedLine = srcMapping.generatedLine; + destMapping.generatedColumn = srcMapping.generatedColumn; + + if (srcMapping.source) { + destMapping.source = sources.indexOf(srcMapping.source); + destMapping.originalLine = srcMapping.originalLine; + destMapping.originalColumn = srcMapping.originalColumn; + + if (srcMapping.name) { + destMapping.name = names.indexOf(srcMapping.name); + } + + destOriginalMappings.push(destMapping); + } + + destGeneratedMappings.push(destMapping); + } + + quickSort(smc.__originalMappings, util.compareByOriginalPositions); + + return smc; + }; + + /** + * The version of the source mapping spec that we are consuming. + */ + BasicSourceMapConsumer.prototype._version = 3; + + /** + * The list of original sources. + */ + Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', { + get: function () { + return this._sources.toArray().map(function (s) { + return this.sourceRoot != null ? util.join(this.sourceRoot, s) : s; + }, this); + } + }); + + /** + * Provide the JIT with a nice shape / hidden class. + */ + function Mapping() { + this.generatedLine = 0; + this.generatedColumn = 0; + this.source = null; + this.originalLine = null; + this.originalColumn = null; + this.name = null; + } + + /** + * Parse the mappings in a string in to a data structure which we can easily + * query (the ordered arrays in the `this.__generatedMappings` and + * `this.__originalMappings` properties). + */ + BasicSourceMapConsumer.prototype._parseMappings = + function SourceMapConsumer_parseMappings(aStr, aSourceRoot) { + var generatedLine = 1; + var previousGeneratedColumn = 0; + var previousOriginalLine = 0; + var previousOriginalColumn = 0; + var previousSource = 0; + var previousName = 0; + var length = aStr.length; + var index = 0; + var cachedSegments = {}; + var temp = {}; + var originalMappings = []; + var generatedMappings = []; + var mapping, str, segment, end, value; + + while (index < length) { + if (aStr.charAt(index) === ';') { + generatedLine++; + index++; + previousGeneratedColumn = 0; + } + else if (aStr.charAt(index) === ',') { + index++; + } + else { + mapping = new Mapping(); + mapping.generatedLine = generatedLine; + + // Because each offset is encoded relative to the previous one, + // many segments often have the same encoding. We can exploit this + // fact by caching the parsed variable length fields of each segment, + // allowing us to avoid a second parse if we encounter the same + // segment again. + for (end = index; end < length; end++) { + if (this._charIsMappingSeparator(aStr, end)) { + break; + } + } + str = aStr.slice(index, end); + + segment = cachedSegments[str]; + if (segment) { + index += str.length; + } else { + segment = []; + while (index < end) { + base64VLQ.decode(aStr, index, temp); + value = temp.value; + index = temp.rest; + segment.push(value); + } + + if (segment.length === 2) { + throw new Error('Found a source, but no line and column'); + } + + if (segment.length === 3) { + throw new Error('Found a source and line, but no column'); + } + + cachedSegments[str] = segment; + } + + // Generated column. + mapping.generatedColumn = previousGeneratedColumn + segment[0]; + previousGeneratedColumn = mapping.generatedColumn; + + if (segment.length > 1) { + // Original source. + mapping.source = previousSource + segment[1]; + previousSource += segment[1]; + + // Original line. + mapping.originalLine = previousOriginalLine + segment[2]; + previousOriginalLine = mapping.originalLine; + // Lines are stored 0-based + mapping.originalLine += 1; + + // Original column. + mapping.originalColumn = previousOriginalColumn + segment[3]; + previousOriginalColumn = mapping.originalColumn; + + if (segment.length > 4) { + // Original name. + mapping.name = previousName + segment[4]; + previousName += segment[4]; + } + } + + generatedMappings.push(mapping); + if (typeof mapping.originalLine === 'number') { + originalMappings.push(mapping); + } + } + } + + quickSort(generatedMappings, util.compareByGeneratedPositionsDeflated); + this.__generatedMappings = generatedMappings; + + quickSort(originalMappings, util.compareByOriginalPositions); + this.__originalMappings = originalMappings; + }; + + /** + * Find the mapping that best matches the hypothetical "needle" mapping that + * we are searching for in the given "haystack" of mappings. + */ + BasicSourceMapConsumer.prototype._findMapping = + function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName, + aColumnName, aComparator, aBias) { + // To return the position we are searching for, we must first find the + // mapping for the given position and then return the opposite position it + // points to. Because the mappings are sorted, we can use binary search to + // find the best mapping. + + if (aNeedle[aLineName] <= 0) { + throw new TypeError('Line must be greater than or equal to 1, got ' + + aNeedle[aLineName]); + } + if (aNeedle[aColumnName] < 0) { + throw new TypeError('Column must be greater than or equal to 0, got ' + + aNeedle[aColumnName]); + } + + return binarySearch.search(aNeedle, aMappings, aComparator, aBias); + }; + + /** + * Compute the last column for each generated mapping. The last column is + * inclusive. + */ + BasicSourceMapConsumer.prototype.computeColumnSpans = + function SourceMapConsumer_computeColumnSpans() { + for (var index = 0; index < this._generatedMappings.length; ++index) { + var mapping = this._generatedMappings[index]; + + // Mappings do not contain a field for the last generated columnt. We + // can come up with an optimistic estimate, however, by assuming that + // mappings are contiguous (i.e. given two consecutive mappings, the + // first mapping ends where the second one starts). + if (index + 1 < this._generatedMappings.length) { + var nextMapping = this._generatedMappings[index + 1]; + + if (mapping.generatedLine === nextMapping.generatedLine) { + mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1; + continue; + } + } + + // The last mapping for each line spans the entire line. + mapping.lastGeneratedColumn = Infinity; + } + }; + + /** + * Returns the original source, line, and column information for the generated + * source's line and column positions provided. The only argument is an object + * with the following properties: + * + * - line: The line number in the generated source. + * - column: The column number in the generated source. + * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or + * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. + * + * and an object is returned with the following properties: + * + * - source: The original source file, or null. + * - line: The line number in the original source, or null. + * - column: The column number in the original source, or null. + * - name: The original identifier, or null. + */ + BasicSourceMapConsumer.prototype.originalPositionFor = + function SourceMapConsumer_originalPositionFor(aArgs) { + var needle = { + generatedLine: util.getArg(aArgs, 'line'), + generatedColumn: util.getArg(aArgs, 'column') + }; + + var index = this._findMapping( + needle, + this._generatedMappings, + "generatedLine", + "generatedColumn", + util.compareByGeneratedPositionsDeflated, + util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND) + ); + + if (index >= 0) { + var mapping = this._generatedMappings[index]; + + if (mapping.generatedLine === needle.generatedLine) { + var source = util.getArg(mapping, 'source', null); + if (source !== null) { + source = this._sources.at(source); + if (this.sourceRoot != null) { + source = util.join(this.sourceRoot, source); + } + } + var name = util.getArg(mapping, 'name', null); + if (name !== null) { + name = this._names.at(name); + } + return { + source: source, + line: util.getArg(mapping, 'originalLine', null), + column: util.getArg(mapping, 'originalColumn', null), + name: name + }; + } + } + + return { + source: null, + line: null, + column: null, + name: null + }; + }; + + /** + * Return true if we have the source content for every source in the source + * map, false otherwise. + */ + BasicSourceMapConsumer.prototype.hasContentsOfAllSources = + function BasicSourceMapConsumer_hasContentsOfAllSources() { + if (!this.sourcesContent) { + return false; + } + return this.sourcesContent.length >= this._sources.size() && + !this.sourcesContent.some(function (sc) { return sc == null; }); + }; + + /** + * Returns the original source content. The only argument is the url of the + * original source file. Returns null if no original source content is + * availible. + */ + BasicSourceMapConsumer.prototype.sourceContentFor = + function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) { + if (!this.sourcesContent) { + return null; + } + + if (this.sourceRoot != null) { + aSource = util.relative(this.sourceRoot, aSource); + } + + if (this._sources.has(aSource)) { + return this.sourcesContent[this._sources.indexOf(aSource)]; + } + + var url; + if (this.sourceRoot != null + && (url = util.urlParse(this.sourceRoot))) { + // XXX: file:// URIs and absolute paths lead to unexpected behavior for + // many users. We can help them out when they expect file:// URIs to + // behave like it would if they were running a local HTTP server. See + // https://bugzilla.mozilla.org/show_bug.cgi?id=885597. + var fileUriAbsPath = aSource.replace(/^file:\/\//, ""); + if (url.scheme == "file" + && this._sources.has(fileUriAbsPath)) { + return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)] + } + + if ((!url.path || url.path == "/") + && this._sources.has("/" + aSource)) { + return this.sourcesContent[this._sources.indexOf("/" + aSource)]; + } + } + + // This function is used recursively from + // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we + // don't want to throw if we can't find the source - we just want to + // return null, so we provide a flag to exit gracefully. + if (nullOnMissing) { + return null; + } + else { + throw new Error('"' + aSource + '" is not in the SourceMap.'); + } + }; + + /** + * Returns the generated line and column information for the original source, + * line, and column positions provided. The only argument is an object with + * the following properties: + * + * - source: The filename of the original source. + * - line: The line number in the original source. + * - column: The column number in the original source. + * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or + * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. + * + * and an object is returned with the following properties: + * + * - line: The line number in the generated source, or null. + * - column: The column number in the generated source, or null. + */ + BasicSourceMapConsumer.prototype.generatedPositionFor = + function SourceMapConsumer_generatedPositionFor(aArgs) { + var source = util.getArg(aArgs, 'source'); + if (this.sourceRoot != null) { + source = util.relative(this.sourceRoot, source); + } + if (!this._sources.has(source)) { + return { + line: null, + column: null, + lastColumn: null + }; + } + source = this._sources.indexOf(source); + + var needle = { + source: source, + originalLine: util.getArg(aArgs, 'line'), + originalColumn: util.getArg(aArgs, 'column') + }; + + var index = this._findMapping( + needle, + this._originalMappings, + "originalLine", + "originalColumn", + util.compareByOriginalPositions, + util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND) + ); + + if (index >= 0) { + var mapping = this._originalMappings[index]; + + if (mapping.source === needle.source) { + return { + line: util.getArg(mapping, 'generatedLine', null), + column: util.getArg(mapping, 'generatedColumn', null), + lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) + }; + } + } + + return { + line: null, + column: null, + lastColumn: null + }; + }; + + exports.BasicSourceMapConsumer = BasicSourceMapConsumer; + + /** + * An IndexedSourceMapConsumer instance represents a parsed source map which + * we can query for information. It differs from BasicSourceMapConsumer in + * that it takes "indexed" source maps (i.e. ones with a "sections" field) as + * input. + * + * The only parameter is a raw source map (either as a JSON string, or already + * parsed to an object). According to the spec for indexed source maps, they + * have the following attributes: + * + * - version: Which version of the source map spec this map is following. + * - file: Optional. The generated file this source map is associated with. + * - sections: A list of section definitions. + * + * Each value under the "sections" field has two fields: + * - offset: The offset into the original specified at which this section + * begins to apply, defined as an object with a "line" and "column" + * field. + * - map: A source map definition. This source map could also be indexed, + * but doesn't have to be. + * + * Instead of the "map" field, it's also possible to have a "url" field + * specifying a URL to retrieve a source map from, but that's currently + * unsupported. + * + * Here's an example source map, taken from the source map spec[0], but + * modified to omit a section which uses the "url" field. + * + * { + * version : 3, + * file: "app.js", + * sections: [{ + * offset: {line:100, column:10}, + * map: { + * version : 3, + * file: "section.js", + * sources: ["foo.js", "bar.js"], + * names: ["src", "maps", "are", "fun"], + * mappings: "AAAA,E;;ABCDE;" + * } + * }], + * } + * + * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt + */ + function IndexedSourceMapConsumer(aSourceMap) { + var sourceMap = aSourceMap; + if (typeof aSourceMap === 'string') { + sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); + } + + var version = util.getArg(sourceMap, 'version'); + var sections = util.getArg(sourceMap, 'sections'); + + if (version != this._version) { + throw new Error('Unsupported version: ' + version); + } + + this._sources = new ArraySet(); + this._names = new ArraySet(); + + var lastOffset = { + line: -1, + column: 0 + }; + this._sections = sections.map(function (s) { + if (s.url) { + // The url field will require support for asynchronicity. + // See https://github.com/mozilla/source-map/issues/16 + throw new Error('Support for url field in sections not implemented.'); + } + var offset = util.getArg(s, 'offset'); + var offsetLine = util.getArg(offset, 'line'); + var offsetColumn = util.getArg(offset, 'column'); + + if (offsetLine < lastOffset.line || + (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) { + throw new Error('Section offsets must be ordered and non-overlapping.'); + } + lastOffset = offset; + + return { + generatedOffset: { + // The offset fields are 0-based, but we use 1-based indices when + // encoding/decoding from VLQ. + generatedLine: offsetLine + 1, + generatedColumn: offsetColumn + 1 + }, + consumer: new SourceMapConsumer(util.getArg(s, 'map')) + } + }); + } + + IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype); + IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer; + + /** + * The version of the source mapping spec that we are consuming. + */ + IndexedSourceMapConsumer.prototype._version = 3; + + /** + * The list of original sources. + */ + Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', { + get: function () { + var sources = []; + for (var i = 0; i < this._sections.length; i++) { + for (var j = 0; j < this._sections[i].consumer.sources.length; j++) { + sources.push(this._sections[i].consumer.sources[j]); + } + } + return sources; + } + }); + + /** + * Returns the original source, line, and column information for the generated + * source's line and column positions provided. The only argument is an object + * with the following properties: + * + * - line: The line number in the generated source. + * - column: The column number in the generated source. + * + * and an object is returned with the following properties: + * + * - source: The original source file, or null. + * - line: The line number in the original source, or null. + * - column: The column number in the original source, or null. + * - name: The original identifier, or null. + */ + IndexedSourceMapConsumer.prototype.originalPositionFor = + function IndexedSourceMapConsumer_originalPositionFor(aArgs) { + var needle = { + generatedLine: util.getArg(aArgs, 'line'), + generatedColumn: util.getArg(aArgs, 'column') + }; + + // Find the section containing the generated position we're trying to map + // to an original position. + var sectionIndex = binarySearch.search(needle, this._sections, + function(needle, section) { + var cmp = needle.generatedLine - section.generatedOffset.generatedLine; + if (cmp) { + return cmp; + } + + return (needle.generatedColumn - + section.generatedOffset.generatedColumn); + }); + var section = this._sections[sectionIndex]; + + if (!section) { + return { + source: null, + line: null, + column: null, + name: null + }; + } + + return section.consumer.originalPositionFor({ + line: needle.generatedLine - + (section.generatedOffset.generatedLine - 1), + column: needle.generatedColumn - + (section.generatedOffset.generatedLine === needle.generatedLine + ? section.generatedOffset.generatedColumn - 1 + : 0), + bias: aArgs.bias + }); + }; + + /** + * Return true if we have the source content for every source in the source + * map, false otherwise. + */ + IndexedSourceMapConsumer.prototype.hasContentsOfAllSources = + function IndexedSourceMapConsumer_hasContentsOfAllSources() { + return this._sections.every(function (s) { + return s.consumer.hasContentsOfAllSources(); + }); + }; + + /** + * Returns the original source content. The only argument is the url of the + * original source file. Returns null if no original source content is + * available. + */ + IndexedSourceMapConsumer.prototype.sourceContentFor = + function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) { + for (var i = 0; i < this._sections.length; i++) { + var section = this._sections[i]; + + var content = section.consumer.sourceContentFor(aSource, true); + if (content) { + return content; + } + } + if (nullOnMissing) { + return null; + } + else { + throw new Error('"' + aSource + '" is not in the SourceMap.'); + } + }; + + /** + * Returns the generated line and column information for the original source, + * line, and column positions provided. The only argument is an object with + * the following properties: + * + * - source: The filename of the original source. + * - line: The line number in the original source. + * - column: The column number in the original source. + * + * and an object is returned with the following properties: + * + * - line: The line number in the generated source, or null. + * - column: The column number in the generated source, or null. + */ + IndexedSourceMapConsumer.prototype.generatedPositionFor = + function IndexedSourceMapConsumer_generatedPositionFor(aArgs) { + for (var i = 0; i < this._sections.length; i++) { + var section = this._sections[i]; + + // Only consider this section if the requested source is in the list of + // sources of the consumer. + if (section.consumer.sources.indexOf(util.getArg(aArgs, 'source')) === -1) { + continue; + } + var generatedPosition = section.consumer.generatedPositionFor(aArgs); + if (generatedPosition) { + var ret = { + line: generatedPosition.line + + (section.generatedOffset.generatedLine - 1), + column: generatedPosition.column + + (section.generatedOffset.generatedLine === generatedPosition.line + ? section.generatedOffset.generatedColumn - 1 + : 0) + }; + return ret; + } + } + + return { + line: null, + column: null + }; + }; + + /** + * Parse the mappings in a string in to a data structure which we can easily + * query (the ordered arrays in the `this.__generatedMappings` and + * `this.__originalMappings` properties). + */ + IndexedSourceMapConsumer.prototype._parseMappings = + function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) { + this.__generatedMappings = []; + this.__originalMappings = []; + for (var i = 0; i < this._sections.length; i++) { + var section = this._sections[i]; + var sectionMappings = section.consumer._generatedMappings; + for (var j = 0; j < sectionMappings.length; j++) { + var mapping = sectionMappings[i]; + + var source = section.consumer._sources.at(mapping.source); + if (section.consumer.sourceRoot !== null) { + source = util.join(section.consumer.sourceRoot, source); + } + this._sources.add(source); + source = this._sources.indexOf(source); + + var name = section.consumer._names.at(mapping.name); + this._names.add(name); + name = this._names.indexOf(name); + + // The mappings coming from the consumer for the section have + // generated positions relative to the start of the section, so we + // need to offset them to be relative to the start of the concatenated + // generated file. + var adjustedMapping = { + source: source, + generatedLine: mapping.generatedLine + + (section.generatedOffset.generatedLine - 1), + generatedColumn: mapping.column + + (section.generatedOffset.generatedLine === mapping.generatedLine) + ? section.generatedOffset.generatedColumn - 1 + : 0, + originalLine: mapping.originalLine, + originalColumn: mapping.originalColumn, + name: name + }; + + this.__generatedMappings.push(adjustedMapping); + if (typeof adjustedMapping.originalLine === 'number') { + this.__originalMappings.push(adjustedMapping); + } + } + } + + quickSort(this.__generatedMappings, util.compareByGeneratedPositionsDeflated); + quickSort(this.__originalMappings, util.compareByOriginalPositions); + }; + + exports.IndexedSourceMapConsumer = IndexedSourceMapConsumer; + } + + +/***/ }, +/* 9 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + exports.GREATEST_LOWER_BOUND = 1; + exports.LEAST_UPPER_BOUND = 2; + + /** + * Recursive implementation of binary search. + * + * @param aLow Indices here and lower do not contain the needle. + * @param aHigh Indices here and higher do not contain the needle. + * @param aNeedle The element being searched for. + * @param aHaystack The non-empty array being searched. + * @param aCompare Function which takes two elements and returns -1, 0, or 1. + * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or + * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + */ + function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) { + // This function terminates when one of the following is true: + // + // 1. We find the exact element we are looking for. + // + // 2. We did not find the exact element, but we can return the index of + // the next-closest element. + // + // 3. We did not find the exact element, and there is no next-closest + // element than the one we are searching for, so we return -1. + var mid = Math.floor((aHigh - aLow) / 2) + aLow; + var cmp = aCompare(aNeedle, aHaystack[mid], true); + if (cmp === 0) { + // Found the element we are looking for. + return mid; + } + else if (cmp > 0) { + // Our needle is greater than aHaystack[mid]. + if (aHigh - mid > 1) { + // The element is in the upper half. + return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias); + } + + // The exact needle element was not found in this haystack. Determine if + // we are in termination case (3) or (2) and return the appropriate thing. + if (aBias == exports.LEAST_UPPER_BOUND) { + return aHigh < aHaystack.length ? aHigh : -1; + } else { + return mid; + } + } + else { + // Our needle is less than aHaystack[mid]. + if (mid - aLow > 1) { + // The element is in the lower half. + return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias); + } + + // we are in termination case (3) or (2) and return the appropriate thing. + if (aBias == exports.LEAST_UPPER_BOUND) { + return mid; + } else { + return aLow < 0 ? -1 : aLow; + } + } + } + + /** + * This is an implementation of binary search which will always try and return + * the index of the closest element if there is no exact hit. This is because + * mappings between original and generated line/col pairs are single points, + * and there is an implicit region between each of them, so a miss just means + * that you aren't on the very start of a region. + * + * @param aNeedle The element you are looking for. + * @param aHaystack The array that is being searched. + * @param aCompare A function which takes the needle and an element in the + * array and returns -1, 0, or 1 depending on whether the needle is less + * than, equal to, or greater than the element, respectively. + * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or + * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'. + */ + exports.search = function search(aNeedle, aHaystack, aCompare, aBias) { + if (aHaystack.length === 0) { + return -1; + } + + var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, + aCompare, aBias || exports.GREATEST_LOWER_BOUND); + if (index < 0) { + return -1; + } + + // We have found either the exact element, or the next-closest element than + // the one we are searching for. However, there may be more than one such + // element. Make sure we always return the smallest of these. + while (index - 1 >= 0) { + if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) { + break; + } + --index; + } + + return index; + }; + } + + +/***/ }, +/* 10 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + // It turns out that some (most?) JavaScript engines don't self-host + // `Array.prototype.sort`. This makes sense because C++ will likely remain + // faster than JS when doing raw CPU-intensive sorting. However, when using a + // custom comparator function, calling back and forth between the VM's C++ and + // JIT'd JS is rather slow *and* loses JIT type information, resulting in + // worse generated code for the comparator function than would be optimal. In + // fact, when sorting with a comparator, these costs outweigh the benefits of + // sorting in C++. By using our own JS-implemented Quick Sort (below), we get + // a ~3500ms mean speed-up in `bench/bench.html`. + + /** + * Swap the elements indexed by `x` and `y` in the array `ary`. + * + * @param {Array} ary + * The array. + * @param {Number} x + * The index of the first item. + * @param {Number} y + * The index of the second item. + */ + function swap(ary, x, y) { + var temp = ary[x]; + ary[x] = ary[y]; + ary[y] = temp; + } + + /** + * Returns a random integer within the range `low .. high` inclusive. + * + * @param {Number} low + * The lower bound on the range. + * @param {Number} high + * The upper bound on the range. + */ + function randomIntInRange(low, high) { + return Math.round(low + (Math.random() * (high - low))); + } + + /** + * The Quick Sort algorithm. + * + * @param {Array} ary + * An array to sort. + * @param {function} comparator + * Function to use to compare two items. + * @param {Number} p + * Start index of the array + * @param {Number} r + * End index of the array + */ + function doQuickSort(ary, comparator, p, r) { + // If our lower bound is less than our upper bound, we (1) partition the + // array into two pieces and (2) recurse on each half. If it is not, this is + // the empty array and our base case. + + if (p < r) { + // (1) Partitioning. + // + // The partitioning chooses a pivot between `p` and `r` and moves all + // elements that are less than or equal to the pivot to the before it, and + // all the elements that are greater than it after it. The effect is that + // once partition is done, the pivot is in the exact place it will be when + // the array is put in sorted order, and it will not need to be moved + // again. This runs in O(n) time. + + // Always choose a random pivot so that an input array which is reverse + // sorted does not cause O(n^2) running time. + var pivotIndex = randomIntInRange(p, r); + var i = p - 1; + + swap(ary, pivotIndex, r); + var pivot = ary[r]; + + // Immediately after `j` is incremented in this loop, the following hold + // true: + // + // * Every element in `ary[p .. i]` is less than or equal to the pivot. + // + // * Every element in `ary[i+1 .. j-1]` is greater than the pivot. + for (var j = p; j < r; j++) { + if (comparator(ary[j], pivot) <= 0) { + i += 1; + swap(ary, i, j); + } + } + + swap(ary, i + 1, j); + var q = i + 1; + + // (2) Recurse on each half. + + doQuickSort(ary, comparator, p, q - 1); + doQuickSort(ary, comparator, q + 1, r); + } + } + + /** + * Sort the given array in-place with the given comparator function. + * + * @param {Array} ary + * An array to sort. + * @param {function} comparator + * Function to use to compare two items. + */ + exports.quickSort = function (ary, comparator) { + doQuickSort(ary, comparator, 0, ary.length - 1); + }; + } + + +/***/ }, +/* 11 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var SourceMapGenerator = __webpack_require__(3).SourceMapGenerator; + var util = __webpack_require__(2); + + // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other + // operating systems these days (capturing the result). + var REGEX_NEWLINE = /(\r?\n)/; + + // Newline character code for charCodeAt() comparisons + var NEWLINE_CODE = 10; + + // Private symbol for identifying `SourceNode`s when multiple versions of + // the source-map library are loaded. This MUST NOT CHANGE across + // versions! + var isSourceNode = "$$$isSourceNode$$$"; + + /** + * SourceNodes provide a way to abstract over interpolating/concatenating + * snippets of generated JavaScript source code while maintaining the line and + * column information associated with the original source code. + * + * @param aLine The original line number. + * @param aColumn The original column number. + * @param aSource The original source's filename. + * @param aChunks Optional. An array of strings which are snippets of + * generated JS, or other SourceNodes. + * @param aName The original identifier. + */ + function SourceNode(aLine, aColumn, aSource, aChunks, aName) { + this.children = []; + this.sourceContents = {}; + this.line = aLine == null ? null : aLine; + this.column = aColumn == null ? null : aColumn; + this.source = aSource == null ? null : aSource; + this.name = aName == null ? null : aName; + this[isSourceNode] = true; + if (aChunks != null) this.add(aChunks); + } + + /** + * Creates a SourceNode from generated code and a SourceMapConsumer. + * + * @param aGeneratedCode The generated code + * @param aSourceMapConsumer The SourceMap for the generated code + * @param aRelativePath Optional. The path that relative sources in the + * SourceMapConsumer should be relative to. + */ + SourceNode.fromStringWithSourceMap = + function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) { + // The SourceNode we want to fill with the generated code + // and the SourceMap + var node = new SourceNode(); + + // All even indices of this array are one line of the generated code, + // while all odd indices are the newlines between two adjacent lines + // (since `REGEX_NEWLINE` captures its match). + // Processed fragments are removed from this array, by calling `shiftNextLine`. + var remainingLines = aGeneratedCode.split(REGEX_NEWLINE); + var shiftNextLine = function() { + var lineContents = remainingLines.shift(); + // The last line of a file might not have a newline. + var newLine = remainingLines.shift() || ""; + return lineContents + newLine; + }; + + // We need to remember the position of "remainingLines" + var lastGeneratedLine = 1, lastGeneratedColumn = 0; + + // The generate SourceNodes we need a code range. + // To extract it current and last mapping is used. + // Here we store the last mapping. + var lastMapping = null; + + aSourceMapConsumer.eachMapping(function (mapping) { + if (lastMapping !== null) { + // We add the code from "lastMapping" to "mapping": + // First check if there is a new line in between. + if (lastGeneratedLine < mapping.generatedLine) { + var code = ""; + // Associate first line with "lastMapping" + addMappingWithCode(lastMapping, shiftNextLine()); + lastGeneratedLine++; + lastGeneratedColumn = 0; + // The remaining code is added without mapping + } else { + // There is no new line in between. + // Associate the code between "lastGeneratedColumn" and + // "mapping.generatedColumn" with "lastMapping" + var nextLine = remainingLines[0]; + var code = nextLine.substr(0, mapping.generatedColumn - + lastGeneratedColumn); + remainingLines[0] = nextLine.substr(mapping.generatedColumn - + lastGeneratedColumn); + lastGeneratedColumn = mapping.generatedColumn; + addMappingWithCode(lastMapping, code); + // No more remaining code, continue + lastMapping = mapping; + return; + } + } + // We add the generated code until the first mapping + // to the SourceNode without any mapping. + // Each line is added as separate string. + while (lastGeneratedLine < mapping.generatedLine) { + node.add(shiftNextLine()); + lastGeneratedLine++; + } + if (lastGeneratedColumn < mapping.generatedColumn) { + var nextLine = remainingLines[0]; + node.add(nextLine.substr(0, mapping.generatedColumn)); + remainingLines[0] = nextLine.substr(mapping.generatedColumn); + lastGeneratedColumn = mapping.generatedColumn; + } + lastMapping = mapping; + }, this); + // We have processed all mappings. + if (remainingLines.length > 0) { + if (lastMapping) { + // Associate the remaining code in the current line with "lastMapping" + addMappingWithCode(lastMapping, shiftNextLine()); + } + // and add the remaining lines without any mapping + node.add(remainingLines.join("")); + } + + // Copy sourcesContent into SourceNode + aSourceMapConsumer.sources.forEach(function (sourceFile) { + var content = aSourceMapConsumer.sourceContentFor(sourceFile); + if (content != null) { + if (aRelativePath != null) { + sourceFile = util.join(aRelativePath, sourceFile); + } + node.setSourceContent(sourceFile, content); + } + }); + + return node; + + function addMappingWithCode(mapping, code) { + if (mapping === null || mapping.source === undefined) { + node.add(code); + } else { + var source = aRelativePath + ? util.join(aRelativePath, mapping.source) + : mapping.source; + node.add(new SourceNode(mapping.originalLine, + mapping.originalColumn, + source, + code, + mapping.name)); + } + } + }; + + /** + * Add a chunk of generated JS to this source node. + * + * @param aChunk A string snippet of generated JS code, another instance of + * SourceNode, or an array where each member is one of those things. + */ + SourceNode.prototype.add = function SourceNode_add(aChunk) { + if (Array.isArray(aChunk)) { + aChunk.forEach(function (chunk) { + this.add(chunk); + }, this); + } + else if (aChunk[isSourceNode] || typeof aChunk === "string") { + if (aChunk) { + this.children.push(aChunk); + } + } + else { + throw new TypeError( + "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk + ); + } + return this; + }; + + /** + * Add a chunk of generated JS to the beginning of this source node. + * + * @param aChunk A string snippet of generated JS code, another instance of + * SourceNode, or an array where each member is one of those things. + */ + SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) { + if (Array.isArray(aChunk)) { + for (var i = aChunk.length-1; i >= 0; i--) { + this.prepend(aChunk[i]); + } + } + else if (aChunk[isSourceNode] || typeof aChunk === "string") { + this.children.unshift(aChunk); + } + else { + throw new TypeError( + "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk + ); + } + return this; + }; + + /** + * Walk over the tree of JS snippets in this node and its children. The + * walking function is called once for each snippet of JS and is passed that + * snippet and the its original associated source's line/column location. + * + * @param aFn The traversal function. + */ + SourceNode.prototype.walk = function SourceNode_walk(aFn) { + var chunk; + for (var i = 0, len = this.children.length; i < len; i++) { + chunk = this.children[i]; + if (chunk[isSourceNode]) { + chunk.walk(aFn); + } + else { + if (chunk !== '') { + aFn(chunk, { source: this.source, + line: this.line, + column: this.column, + name: this.name }); + } + } + } + }; + + /** + * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between + * each of `this.children`. + * + * @param aSep The separator. + */ + SourceNode.prototype.join = function SourceNode_join(aSep) { + var newChildren; + var i; + var len = this.children.length; + if (len > 0) { + newChildren = []; + for (i = 0; i < len-1; i++) { + newChildren.push(this.children[i]); + newChildren.push(aSep); + } + newChildren.push(this.children[i]); + this.children = newChildren; + } + return this; + }; + + /** + * Call String.prototype.replace on the very right-most source snippet. Useful + * for trimming whitespace from the end of a source node, etc. + * + * @param aPattern The pattern to replace. + * @param aReplacement The thing to replace the pattern with. + */ + SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) { + var lastChild = this.children[this.children.length - 1]; + if (lastChild[isSourceNode]) { + lastChild.replaceRight(aPattern, aReplacement); + } + else if (typeof lastChild === 'string') { + this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement); + } + else { + this.children.push(''.replace(aPattern, aReplacement)); + } + return this; + }; + + /** + * Set the source content for a source file. This will be added to the SourceMapGenerator + * in the sourcesContent field. + * + * @param aSourceFile The filename of the source file + * @param aSourceContent The content of the source file + */ + SourceNode.prototype.setSourceContent = + function SourceNode_setSourceContent(aSourceFile, aSourceContent) { + this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent; + }; + + /** + * Walk over the tree of SourceNodes. The walking function is called for each + * source file content and is passed the filename and source content. + * + * @param aFn The traversal function. + */ + SourceNode.prototype.walkSourceContents = + function SourceNode_walkSourceContents(aFn) { + for (var i = 0, len = this.children.length; i < len; i++) { + if (this.children[i][isSourceNode]) { + this.children[i].walkSourceContents(aFn); + } + } + + var sources = Object.keys(this.sourceContents); + for (var i = 0, len = sources.length; i < len; i++) { + aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]); + } + }; + + /** + * Return the string representation of this source node. Walks over the tree + * and concatenates all the various snippets together to one string. + */ + SourceNode.prototype.toString = function SourceNode_toString() { + var str = ""; + this.walk(function (chunk) { + str += chunk; + }); + return str; + }; + + /** + * Returns the string representation of this source node along with a source + * map. + */ + SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) { + var generated = { + code: "", + line: 1, + column: 0 + }; + var map = new SourceMapGenerator(aArgs); + var sourceMappingActive = false; + var lastOriginalSource = null; + var lastOriginalLine = null; + var lastOriginalColumn = null; + var lastOriginalName = null; + this.walk(function (chunk, original) { + generated.code += chunk; + if (original.source !== null + && original.line !== null + && original.column !== null) { + if(lastOriginalSource !== original.source + || lastOriginalLine !== original.line + || lastOriginalColumn !== original.column + || lastOriginalName !== original.name) { + map.addMapping({ + source: original.source, + original: { + line: original.line, + column: original.column + }, + generated: { + line: generated.line, + column: generated.column + }, + name: original.name + }); + } + lastOriginalSource = original.source; + lastOriginalLine = original.line; + lastOriginalColumn = original.column; + lastOriginalName = original.name; + sourceMappingActive = true; + } else if (sourceMappingActive) { + map.addMapping({ + generated: { + line: generated.line, + column: generated.column + } + }); + lastOriginalSource = null; + sourceMappingActive = false; + } + for (var idx = 0, length = chunk.length; idx < length; idx++) { + if (chunk.charCodeAt(idx) === NEWLINE_CODE) { + generated.line++; + generated.column = 0; + // Mappings end at eol + if (idx + 1 === length) { + lastOriginalSource = null; + sourceMappingActive = false; + } else if (sourceMappingActive) { + map.addMapping({ + source: original.source, + original: { + line: original.line, + column: original.column + }, + generated: { + line: generated.line, + column: generated.column + }, + name: original.name + }); + } + } else { + generated.column++; + } + } + }); + this.walkSourceContents(function (sourceFile, sourceContent) { + map.setSourceContent(sourceFile, sourceContent); + }); + + return { code: generated.code, map: map }; + }; + + exports.SourceNode = SourceNode; + } + + +/***/ } +/******/ ]); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly8vd2VicGFjay9ib290c3RyYXAgNWY2ODNjMjEwMTc4ZjE5OGUxOWMiLCJ3ZWJwYWNrOi8vLy4vdGVzdC90ZXN0LXNvdXJjZS1ub2RlLmpzIiwid2VicGFjazovLy8uL3Rlc3QvdXRpbC5qcyIsIndlYnBhY2s6Ly8vLi9saWIvdXRpbC5qcyIsIndlYnBhY2s6Ly8vLi9saWIvc291cmNlLW1hcC1nZW5lcmF0b3IuanMiLCJ3ZWJwYWNrOi8vLy4vbGliL2Jhc2U2NC12bHEuanMiLCJ3ZWJwYWNrOi8vLy4vbGliL2Jhc2U2NC5qcyIsIndlYnBhY2s6Ly8vLi9saWIvYXJyYXktc2V0LmpzIiwid2VicGFjazovLy8uL2xpYi9tYXBwaW5nLWxpc3QuanMiLCJ3ZWJwYWNrOi8vLy4vbGliL3NvdXJjZS1tYXAtY29uc3VtZXIuanMiLCJ3ZWJwYWNrOi8vLy4vbGliL2JpbmFyeS1zZWFyY2guanMiLCJ3ZWJwYWNrOi8vLy4vbGliL3F1aWNrLXNvcnQuanMiLCJ3ZWJwYWNrOi8vLy4vbGliL3NvdXJjZS1ub2RlLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7O0FBQUE7QUFDQT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wb3J0c1sndGVzdCAudG9TdHJpbmcoKSddID0gZnVuY3Rpb24gKGFzc2VydCkge1xuICAgIGFzc2VydC5lcXVhbCgobmV3IFNvdXJjZU5vZGUobnVsbCwgbnVsbCwgbnVsbCxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFsnZnVuY3Rpb24gZm9vKCkgeycsXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbmV3IFNvdXJjZU5vZGUobnVsbCwgbnVsbCwgbnVsbCwgJ3JldHVybiAxMDsnKSxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAnfSddKSkudG9TdHJpbmcoKSxcbiAgICAgICAgICAgICAgICAgJ2Z1bmN0aW9uIGZvbygpIHtyZXR1cm4gMTA7fScpO1xuICB9O1xuXG4gIGV4cG9ydHNbJ3Rlc3QgLmpvaW4oKSddID0gZnVuY3Rpb24gKGFzc2VydCkge1xuICAgIGFzc2VydC5lcXVhbCgobmV3IFNvdXJjZU5vZGUobnVsbCwgbnVsbCwgbnVsbCxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFsnYScsICdiJywgJ2MnLCAnZCddKSkuam9pbignLCAnKS50b1N0cmluZygpLFxuICAgICAgICAgICAgICAgICAnYSwgYiwgYywgZCcpO1xuICB9O1xuXG4gIGV4cG9ydHNbJ3Rlc3QgLndhbGsoKSddID0gZnVuY3Rpb24gKGFzc2VydCkge1xuICAgIHZhciBub2RlID0gbmV3IFNvdXJjZU5vZGUobnVsbCwgbnVsbCwgbnVsbCxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFsnKGZ1bmN0aW9uICgpIHtcXG4nLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICcgICcsIG5ldyBTb3VyY2VOb2RlKDEsIDAsICdhLmpzJywgWydzb21lQ2FsbCgpJ10pLCAnO1xcbicsXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJyAgJywgbmV3IFNvdXJjZU5vZGUoMiwgMCwgJ2IuanMnLCBbJ2lmIChmb28pIGJhcigpJ10pLCAnO1xcbicsXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJ30oKSk7J10pO1xuICAgIHZhciBleHBlY3RlZCA9IFtcbiAgICAgIHsgc3RyOiAnKGZ1bmN0aW9uICgpIHtcXG4nLCBzb3VyY2U6IG51bGwsICAgbGluZTogbnVsbCwgY29sdW1uOiBudWxsIH0sXG4gICAgICB7IHN0cjogJyAgJywgICAgICAgICAgICAgICBzb3VyY2U6IG51bGwsICAgbGluZTogbnVsbCwgY29sdW1uOiBudWxsIH0sXG4gICAgICB7IHN0cjogJ3NvbWVDYWxsKCknLCAgICAgICBzb3VyY2U6ICdhLmpzJywgbGluZTogMSwgICAgY29sdW1uOiAwICAgIH0sXG4gICAgICB7IHN0cjogJztcXG4nLCAgICAgICAgICAgICAgc291cmNlOiBudWxsLCAgIGxpbmU6IG51bGwsIGNvbHVtbjogbnVsbCB9LFxuICAgICAgeyBzdHI6ICcgICcsICAgICAgICAgICAgICAgc291cmNlOiBudWxsLCAgIGxpbmU6IG51bGwsIGNvbHVtbjogbnVsbCB9LFxuICAgICAgeyBzdHI6ICdpZiAoZm9vKSBiYXIoKScsICAgc291cmNlOiAnYi5qcycsIGxpbmU6IDIsICAgIGNvbHVtbjogMCAgICB9LFxuICAgICAgeyBzdHI6ICc7XFxuJywgICAgICAgICAgICAgIHNvdXJjZTogbnVsbCwgICBsaW5lOiBudWxsLCBjb2x1bW46IG51bGwgfSxcbiAgICAgIHsgc3RyOiAnfSgpKTsnLCAgICAgICAgICAgIHNvdXJjZTogbnVsbCwgICBsaW5lOiBudWxsLCBjb2x1bW46IG51bGwgfSxcbiAgICBdO1xuICAgIHZhciBpID0gMDtcbiAgICBub2RlLndhbGsoZnVuY3Rpb24gKGNodW5rLCBsb2MpIHtcbiAgICAgIGFzc2VydC5lcXVhbChleHBlY3RlZFtpXS5zdHIsIGNodW5rKTtcbiAgICAgIGFzc2VydC5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W5nV2l0aFNvdXJjZU1hcCgpJ10gPSBmb3JFYWNoTmV3bGluZShmdW5jdGlvbiAoYXNzZXJ0LCBubCkge1xuICAgIHZhciBub2RlID0gbmV3IFNvdXJjZU5vZGUobnVsbCwgbnVsbCwgbnVsbCxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFsnKGZ1bmN0aW9uICgpIHsnICsgbmwsXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJyAgJyxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG5ldyBTb3VyY2VOb2RlKDEsIDAsICdhLmpzJywgJ3NvbWVDYWxsJywgJ29yaWdpbmFsQ2FsbCcpLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbmV3IFNvdXJjZU5vZGUoMSwgOCwgJ2EuanMnLCAnKCknKSxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICc7JyArIG5sLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICcgICcsIG5ldyBTb3VyY2VOb2RlKDIsIDAsICdiLmpzJywgWydpZiAoZm9vKSBiYXIoKSddKSwgJzsnICsgbmwsXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJ30oKSk7J10pO1xuICAgIHZhciByZXN1bHQgPSBub2RlLnRvU3RyaW5nV2l0aFNvdXJjZU1hcCh7XG4gICAgICBmaWxlOiAnZm9vLmpzJ1xuICAgIH0pO1xuXG4gICAgYXNzZXJ0LmVxdWFsKHJlc3VsdC5jb2RlLCBbXG4gICAgICAnKGZ1bmN0aW9uICgpIHsnLFxuICAgICAgJyAgc29tZUNhbGwoKTsnLFxuICAgICAgJyAgaWYgKGZvbykgYmFyKCk7JyxcbiAgICAgICd9KCkpOydcbiAgICBdLmpvaW4obmwpKTtcblxuICAgIHZhciBtYXAgPSByZXN1bHQubWFwO1xuICAgIHZhciBtYXBXaXRob3V0T3B0aW9ucyA9IG5vZGUudG9TdHJpbmdXaXRoU291cmNlTWFwKC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4gICAgICAgICAgXSxcbiAgICAgICAgICBtYXBwaW5nczogXCJDQUFDLElBQUksSUFBTSxTQUFVQSxHQUNsQixPQUFPQyxJQUFJRFwiLFxuICAgICAgICAgIGZpbGU6IFwibWluLmpzXCIsXG4gICAgICAgICAgc291cmNlUm9vdDogXCIvdGhlL3Jvb3RcIlxuICAgICAgICB9XG4gICAgICB9LFxuICAgICAge1xuICAgICAgICBvZmZzZXQ6IHtcbiAgICAgICAgICBsaW5lOiAxLFxuICAgICAgICAgIGNvbHVtbjogMFxuICAgICAgICB9LFxuICAgICAgICBtYXA6IHtcbiAgICAgICAgICB2ZXJzaW9uOiAzLFxuICAgICAgICAgIHNvdXJjZXM6IFtcbiAgICAgICAgICAgIFwidHdvLmpzXCJcbiAgICAgICAgICBdLFxuICAgICAgICAgIHNvdXJjZXNDb250ZW50OiBbXG4gICAgICAgICAgICAnIFRXTy5pbmMgPSBmdW5jdGlvbiAobikge1xcbicgK1xuICAgICAgICAgICAgJyAgIHJldHVybiBuICsgMTtcXG4nICtcbiAgICAgICAgICAgICcgfTsnXG4gICAgICAgICAgXSxcbiAgICAgICAgICBuYW1lczogW1xuICAgICAgICAgICAgXCJuXCJcbiAgICAgICAgICBdLFxuICAgICAgICAgIG1hcHBpbmdzOiBcIkNBQUMsSUFBSSxJQUFNLFNBQVVBLEdBQ2xCLE9BQU9BXCIsXG4gICAgICAgICAgZmlsZTogXCJtaW4uanNcIixcbiAgICAgICAgICBzb3VyY2VSb290OiBcIi90aGUvcm9vdFwiXG4gICAgICAgIH1cbiAgICAgIH1cbiAgICBdXG4gIH07XG4gIGV4cG9ydHMuaW5kZXhlZFRlc3RNYXBEaWZmZXJlbnRTb3VyY2VSb290cyA9IHtcbiAgICB2ZXJzaW9uOiAzLFxuICAgIGZpbGU6ICdtaW4uanMnLFxuICAgIHNlY3Rpb25zOiBbXG4gICAgICB7XG4gICAgICAgIG9mZnNldDoge1xuICAgICAgICAgIGxpbmU6IDAsXG4gICAgICAgICAgY29sdW1uOiAwXG4gICAgICAgIH0sXG4gICAgICAgIG1hcDoge1xuICAgICAgICAgIHZlcnNpb246IDMsXG4gICAgICAgICAgc291cmNlczogW1xuICAgICAgICAgICAgXCJvbmUuanNcIlxuICAgICAgICAgIF0sXG4gICAgICAgICAgc291cmNlc0NvbnRlbnQ6IFtcbiAgICAgICAgICAgICcgT05FLmZvbyA9IGZ1bmN0aW9uIChiYXIpIHtcXG4nICtcbiAgICAgICAgICAgICcgICByZXR1cm4gYmF6KGJhcik7XFxuJyArXG4gICAgICAgICAgICAnIH07JyxcbiAgICAgICAgICBdLFxuICAgICAgICAgIG5hbWVzOiBbXG4gICAgICAgICAgICBcImJhclwiLFxuICAgICAgICAgICAgXCJiYXpcIlxuICAgICAgICAgIF0sXG4gICAgICAgICAgbWFwcGluZ3M6IFwiQ0FBQyxJQUFJLElBQU0sU0FBVUEsR0FDbEIsT0FBT0MsSUFBSURcIixcbiAgICAgICAgICBmaWxlOiBcIm1pbi5qc1wiLFxuICAgICAgICAgIHNvdXJjZVJvb3Q6IFwiL3RoZS9yb290XCJcbiAgICAgICAgfVxuICAgICAgfSxcbiAgICAgIHtcbiAgICAgICAgb2Zmc2V0OiB7XG4gICAgICAgICAgbGluZTogMSxcbiAgICAgICAgICBjb2x1bW46IDBcbiAgICAgICAgfSxcbiAgICAgICAgbWFwOiB7XG4gICAgICAgICAgdmVyc2lvbjogMyxcbiAgICAgICAgICBzb3VyY2VzOiBbXG4gICAgICAgICAgICBcInR3by5qc1wiXG4gICAgICAgICAgXSxcbiAgICAgICAgICBzb3VyY2VzQ29udGVudDogW1xuICAgICAgICAgICAgJyBUV08uaW5jID0gZnVuY3Rpb24gKG4pIHtcXG4nICtcbiAgICAgICAgICAgICcgICByZXR1cm4gbiArIDE7XFxuJyArXG4gICAgICAgICAgICAnIH07J1xuICAgICAgICAgIF0sXG4gICAgICAgICAgbmFtZXM6IFtcbiAgICAgICAgICAgIFwiblwiXG4gICAgICAgICAgXSxcbiAgICAgICAgICBtYXBwaW5nczogXCJDQUFDLElBQUksSUFBTSxTQUFVQSxHQUNsQixPQUFPQVwiLFxuICAgICAgICAgIGZpbGU6IFwibWluLmpzXCIsXG4gICAgICAgICAgc291cmNlUm9vdDogXCIvZGlmZmVyZW50L3Jvb3RcIlxuICAgICAgICB9XG4gICAgICB9XG4gICAgXVxuICB9O1xuICBleHBvcnRzLnRlc3RNYXBXaXRoU291cmNlc0NvbnRlbnQgPSB7XG4gICAgdmVyc2lvbjogMyxcbiAgICBmaWxlOiAnbWluLmpzJyxcbiAgICBuYW1lczogWydiYXInLCAnYmF6JywgJ24nXSxcbiAgICBzb3VyY2VzOiBbJ29uZS5qcycsICd0d28uanMnXSxcbiAgICBzb3VyY2VzQ29udGVudDogW1xuICAgICAgJyBPTkUuZm9vID0gZnVuY3Rpb24gKGJhcikge1xcbicgK1xuICAgICAgJyAgIHJldHVybiBiYXooYmFyKTtcXG4nICtcbiAgICAgICcgfTsnLFxuICAgICAgJyBUV08uaW5jID0gZnVuY3Rpb24gKG4pIHtcXG4nICtcbiAgICAgICcgICByZXR1cm4gbiArIDE7XFxuJyArXG4gICAgICAnIH07J1xuICAgIF0sXG4gICAgc291cmNlUm9vdDogJy90aGUvcm9vdCcsXG4gICAgbWFwcGluZ3M6ICdDQUFDLElBQUksSUFBTSxTQUFVQSxHQUNsQixPQUFPQyxJQUFJRDtDQ0RiLElBQUksSUFBTSxTQUFVRSxHQUNsQixPQUFPQSdcbiAgfTtcbiAgZXhwb3J0cy50ZXN0TWFwUmVsYXRpdmVTb3VyY2VzID0ge1xuICAgIHZlcnNpb246IDMsXG4gICAgZmlsZTogJ21pbi5qcycsXG4gICAgbmFtZXM6IFsnYmFyJywgJ2JheicsICduJ10sXG4gICAgc291cmNlczogWycuL29uZS5qcycsICcuL3R3by5qcyddLFxuICAgIHNvdXJjZXNDb250ZW50OiBbXG4gICAgICAnIE9ORS5mb28gPSBmdW5jdGlvbiAoYmFyKSB7XFxuJyArXG4gICAgICAnIC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W5lOiBtYXBwaW5nLmdlbmVyYXRlZExpbmUsXG4gICAgICAgICAgICBjb2x1bW46IG1hcHBpbmcuZ2VuZXJhdGVkQ29sdW1uXG4gICAgICAgICAgfVxuICAgICAgICB9O1xuXG4gICAgICAgIGlmIChtYXBwaW5nLnNvdXJjZSAhPSBudWxsKSB7XG4gICAgICAgICAgbmV3TWFwcGluZy5zb3VyY2UgPSBtYXBwaW5nLnNvdXJjZTtcbiAgICAgICAgICBpZiAoc291cmNlUm9vdCAhPSBudWxsKSB7XG4gICAgICAgICAgICBuZXdNYXBwaW5nLnNvdXJjZSA9IHV0aWwucmVsYXRpdmUoc291cmNlUm9vdCwgbmV3TWFwcGluZy5zb3VyY2UpO1xuICAgICAgICAgIH1cblxuICAgICAgICAgIG5ld01hcHBpbmcub3JpZ2luYWwgPSB7XG4gICAgICAgICAgICBsaW5lOiBtYXBwaW5nLm9yaWdpbmFsTGluZSxcbiAgICAgICAgICAgIGNvbHVtbjogbWFwcGluZy5vcmlnaW5hbENvbHVtblxuICAgICAgICAgIH07XG5cbiAgICAgICAgICBpZiAobWFwcGluZy5uYW1lICE9IG51bGwpIHtcbiAgICAgICAgICAgIG5ld01hcHBpbmcubmFtZSA9IG1hcHBpbmcubmFtZTtcbiAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICBnZW5lcmF0b3IuYWRkTWFwcGluZyhuZXdNYXBwaW5nKTtcbiAgICAgIH0pO1xuICAgICAgYVNvdXJjZU1hcENvbnN1bWVyLnNvdXJjZXMuZm9yRWFjaChmdW5jdGlvbiAoc291cmNlRmlsZSkge1xuICAgICAgICB2YXIgY29udGVudCA9IGFTb3VyY2VNYXBDb25zdW1lci5zb3VyY2VDb250ZW50Rm9yKHNvdXJjZUZpbGUpO1xuICAgICAgICBpZiAoY29udGVudCAhPSBudWxsKSB7XG4gICAgICAgICAgZ2VuZXJhdG9yLnNldFNvdXJjZUNvbnRlbnQoc291cmNlRmlsZSwgY29udGVudCk7XG4gICAgICAg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3Ioe1xuICAgICAgICAgICAgbGluZTogbWFwcGluZy5vcmlnaW5hbExpbmUsXG4gICAgICAgICAgICBjb2x1bW46IG1hcHBpbmcub3JpZ2luYWxDb2x1bW5cbiAgICAgICAgICB9KTtcbiAgICAgICAgICBpZiAob3JpZ2luYWwuc291cmNlICE9IG51bGwpIHtcbiAgICAgICAgICAgIC8vIENvcHkgbWFwcGluZ1xuICAgICAgICAgICAgbWFwcGluZy5zb3VyY2UgPSBvcmlnaW5hbC5zb3VyY2U7XG4gICAgICAgICAgICBpZiAoYVNvdXJjZU1hcFBhdGggIT0gbnVsbCkge1xuICAgICAgICAgICAgICBtYXBwaW5nLnNvdXJjZSA9IHV0aWwuam9pbihhU291cmNlTWFwUGF0aCwgbWFwcGluZy5zb3VyY2UpXG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAoc291cmNlUm9vdCAhPSBudWxsKSB7XG4gICAgICAgICAgICAgIG1hcHBpbmcuc291cmNlID0gdXRpbC5yZWxhdGl2ZShzb3VyY2VSb290LCBtYXBwaW5nLnNvdXJjZSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBtYXBwaW5nLm9yaWdpbmFsTGluZSA9IG9yaWdpbmFsLmxpbmU7XG4gICAgICAgICAgICBtYXBwaW5nLm9yaWdpbmFsQ29sdW1uID0gb3JpZ2luYWwuY29sdW1uO1xuICAgICAgICAgICAgaWYgKG9yaWdpbmFsLm5hbWUgIT0gbnVsbCkge1xuICAgICAgICAgICAgICBtYXBwaW5nLm5hbWUgPSBvcmlnaW5hbC5uYW1lO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIHZhciBzb3VyY2UgPSBtYXBwaW5nLnNvdXJjZTtcbiAgICAgICAgaWYgKHNvdXJjZSAhPSBudWxsICYmICFuZXdTb3VyY2VzLmhhcyhzb3VyY2UpKSB7XG4gICAgICAgICAgbmV3U291cmNlcy5hZGQoc291cmNlKTtcbiAgICAgICAgf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MaW5lID0gMTtcbiAgICAgIHZhciBwcmV2aW91c09yaWdpbmFsQ29sdW1uID0gMDtcbiAgICAgIHZhciBwcmV2aW91c09yaWdpbmFsTGluZSA9IDA7XG4gICAgICB2YXIgcHJldmlvdXNOYW1lID0gMDtcbiAgICAgIHZhciBwcmV2aW91c1NvdXJjZSA9IDA7XG4gICAgICB2YXIgcmVzdWx0ID0gJyc7XG4gICAgICB2YXIgbWFwcGluZztcbiAgICAgIHZhciBuYW1lSWR4O1xuICAgICAgdmFyIHNvdXJjZUlkeDtcblxuICAgICAgdmFyIG1hcHBpbmdzID0gdGhpcy5fbWFwcGluZ3MudG9BcnJheSgpO1xuICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IG1hcHBpbmdzLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XG4gICAgICAgIG1hcHBpbmcgPSBtYXBwaW5nc1tpXTtcblxuICAgICAgICBpZiAobWFwcGluZy5nZW5lcmF0ZWRMaW5lICE9PSBwcmV2aW91c0dlbmVyYXRlZExpbmUpIHtcbiAgICAgICAgICBwcmV2aW91c0dlbmVyYXRlZENvbHVtbiA9IDA7XG4gICAgICAgICAgd2hpbGUgKG1hcHBpbmcuZ2VuZXJhdGVkTGluZSAhPT0gcHJldmlvdXNHZW5lcmF0ZWRMaW5lKSB7XG4gICAgICAgICAgICByZXN1bHQgKz0gJzsnO1xuICAgICAgICAgICAgcHJldmlvdXNHZW5lcmF0ZWRMaW5lKys7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGVsc2Uge1xuICAgICAgICAgIGlmIChpID4gMCkge1xuICAgICAgICAgICAgaWYgKCF1dGlsLmNvbXBhcmVCeUdlbmVyYXRlZFBvc2l0aW9uc0luZmxhdGVkKG1hcHBpbmcsIG1hcHBpbmdzW2kgLSAxXSkpIHtcbiAgICAgICAgICAgICAgY29udGludWU7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICByZXN1bHQgKz0gJywnO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIHJlc3VsdCArPSBiYXNlNjRWTFEuZW5jb2RlKG1hcHBpbmcuZ2VuZXJhdGVkQ29sdW1uXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC0gcHJldmlvdXNHZW5lcmF0ZWRDb2x1bW4pO1xuICAgICAgICBwcmV2aW91c0dlbmVyYXRlZENvbHVtbiA9IG1hcHBpbmcuZ2VuZXJhdGVkQ29sdW1uO1xuXG4gICAgICAgIGlmIChtYXBwaW5nLnNvdXJjZSAhPSBudWxsKSB7XG4gICAgICAgICAgc291cmNlSWR4ID0gdGhpcy5fc291cmNlcy5pbmRleE9mKG1hcHBpbmcuc291cmNlKTtcbiAgICAgICAgICByZXN1bHQgKz0gYmFzZTY0VkxRLmVuY29kZShzb3VyY2VJZHggLSBwcmV2aW91c1NvdXJjZSk7XG4gICAgICAgICAgcHJldmlvdXNTb3VyY2UgPSBzb3VyY2VJZHg7XG5cbiAgICAgICAgICAvLyBsaW5lcyBhcmUgc3RvcmVkIDAtYmFzZWQgaW4gU291cmNlTWFwIHNwZWMgdmVyc2lvbiAzXG4gICAgICAgICAgcmVzdWx0ICs9IGJhc2U2NFZMUS5lbmNvZGUobWFwcGluZy5vcmlnaW5hbExpbmUgLSAxXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLSBwcmV2aW91c09yaWdpbmFsTGluZSk7XG4gICAgICAgICAgcHJldmlvdXNPcmlnaW5hbExpbmUgPSBtYXBwaW5nLm9yaWdpbmFsTGluZSAtIDE7XG5cbiAgICAgICAgICByZXN1bHQgKz0gYmFzZTY0VkxRLmVuY29kZShtYXBwaW5nLm9yaWdpbmFsQ29sdW1uXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLSBwcmV2aW91c09yaWdpbmFsQ29sdW1uKTtcbiAgICAgICAgICBwcmV2aW91c09yaWdpbmFsQ29sdW1uID0gbWFwcGluZy5vcmlnaW5hbENvbHVtbjtcblxuICAgICAgICAgIGlmIChtYXBwaW5nLm5hbWUgIT0gbnVsbCkge1xuICAgICAgICAgICAgbmFtZUlkeCA9IHRoaXMuX25hbWVzLmluZGV4T2YobWFwcGluZy5uYW1lKTtcbiAgICAgICAgICAgIHJlc3VsdCArPSBiYXNlNjRWTFEuZW5jb2RlKG5hbWVJZHggLSBwcmV2aW91c05hbWUpO1xuICAgICAgICAgICAgcHJldmlvdXNOYW1lID0gbmFtZUlkeDtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cblxuICAgICAgcmV0dXJuIHJlc3VsdDtcbiAgICB9O1xuXG4gIFNvdXJjZU1hcEdlbmVyYXRvci5wcm90b3R5cGUuX2dlbmVyYXRlU291cmNlc0NvbnRlbnQgPVxuICAgIGZ1bmN0aW9uIFNvdXJjZU1hcEdlbmVyYXRvcl9nZW5lcmF0ZVNvdXJjZXNDb250ZW50KGFTb3VyY2VzLCBhU291cmNlUm9vdCkge1xuICAgICAgcmV0dXJuIGFTb3VyY2VzLm1hcChmdW5jdGlvbiAoc291cmNlKSB7XG4gICAgICAgIGlmICghdGhpcy5fc291cmNlc0NvbnRlbnRzKSB7XG4gICAgICAgICAgcmV0dXJuIG51bGw7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKGFTb3VyY2VSb290ICE9IG51bGwpIHtcbiAgICAgICAgICBzb3VyY2UgPSB1dGlsLnJlbGF0aXZlKGFTb3VyY2VSb290LCBzb3VyY2UpO1xuICAgICAgICB9XG4gICAgICAgIHZhciBrZXkgPSB1dGlsLnRvU2V0U3RyaW5nKHNvdXJjZSk7XG4gICAgICAgIHJldHVybiBPYmplY3QucHJvdG90eXBlLmhhc093blByb3BlcnR5LmNhbGwodGhpcy5fc291cmNlc0NvbnRlbnRzLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGtleSlcbiAgICAgICAgICA/IHRoaXMuX3NvdXJjZXNDb250ZW50c1trZXldXG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KTtcbiAgQmFzaWNTb3VyY2VNYXBDb25zdW1lci5wcm90b3R5cGUuY29uc3VtZXIgPSBTb3VyY2VNYXBDb25zdW1lcjtcblxuICAvKipcbiAgICogQ3JlYXRlIGEgQmFzaWNTb3VyY2VNYXBDb25zdW1lciBmcm9tIGEgU291cmNlTWFwR2VuZXJhdG9yLlxuICAgKlxuICAgKiBAcGFyYW0gU291cmNlTWFwR2VuZXJhdG9yIGFTb3VyY2VNYXBcbiAgICogICAgICAgIFRoZSBzb3VyY2UgbWFwIHRoYXQgd2lsbCBiZSBjb25zdW1lZC5cbiAgICogQHJldHVybnMgQmFzaWNTb3VyY2VNYXBDb25zdW1lclxuICAgKi9cbiAgQmFzaWNTb3VyY2VNYXBDb25zdW1lci5mcm9tU291cmNlTWFwID1cbiAgICBmdW5jdGlvbiBTb3VyY2VNYXBDb25zdW1lcl9mcm9tU291cmNlTWFwKGFTb3VyY2VNYXApIHtcbiAgICAgIHZhciBzbWMgPSBPYmplY3QuY3JlYXRlKEJhc2ljU291cmNlTWFwQ29uc3VtZXIucHJvdG90eXBlKTtcblxuICAgICAgdmFyIG5hbWVzID0gc21jLl9uYW1lcyA9IEFycmF5U2V0LmZyb21BcnJheShhU291cmNlTWFwLl9uYW1lcy50b0FycmF5KCksIHRydWUpO1xuICAgICAgdmFyIHNvdXJjZXMgPSBzbWMuX3NvdXJjZXMgPSBBcnJheVNldC5mcm9tQXJyYXkoYVNvdXJjZU1hcC5fc291cmNlcy50b0FycmF5KCksIHRydWUpO1xuICAgICAgc21jLnNvdXJjZVJvb3QgPSBhU291cmNlTWFwLl9zb3VyY2VSb290O1xuICAgICAgc21jLnNvdXJjZXNDb250ZW50ID0gYVNvdXJjZU1hcC5fZ2VuZXJhdGVTb3VyY2VzQ29udGVudChzbWMuX3NvdXJjZXMudG9BcnJheSgpLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzbWMuc291cmNlUm9vdC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biAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHNlZ21lbnQubGVuZ3RoID09PSAyKSB7XG4gICAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcignRm91bmQgYSBzb3VyY2UsIGJ1dCBubyBsaW5lIGFuZCBjb2x1bW4nKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHNlZ21lbnQubGVuZ3RoID09PSAzKSB7XG4gICAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcignRm91bmQgYSBzb3VyY2UgYW5kIGxpbmUsIGJ1dCBubyBjb2x1bW4nKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgY2FjaGVkU2VnbWVudHNbc3RyXSA9IHNlZ21lbnQ7XG4gICAgICAgICAgfVxuXG4gICAgICAgICAgLy8gR2VuZXJhdGVkIGNvbHVtbi5cbiAgICAgICAgICBtYXBwaW5nLmdlbmVyYXRlZENvbHVtbiA9IHByZXZpb3VzR2VuZXJhdGVkQ29sdW1uICsgc2VnbWVudFswXTtcbiAgICAgICAgICBwcmV2aW91c0dlbmVyYXRlZENvbHVtbiA9IG1hcHBpbmcuZ2VuZXJhdGVkQ29sdW1uO1xuXG4gICAgICAgICAgaWYgKHNlZ21lbnQubGVuZ3RoID4gMSkge1xuICAgICAgICAgICAgLy8gT3JpZ2luYWwgc291cmNlLlxuICAgICAgICAgICAgbWFwcGluZy5zb3VyY2UgPSBwcmV2aW91c1NvdXJjZSArIHNlZ21lbnRbMV07XG4gICAgICAgICAgICBwcmV2aW91c1NvdXJjZSArPSBzZWdtZW50WzFdO1xuXG4gICAgICAgICAgICAvLyBPcmlnaW5hbCBsaW5lLlxuICAgICAgICAgICAgbWFwcGluZy5vcmlnaW5hbExpbmUgPSBwcmV2aW91c09yaWdpbmFsTGluZSArIHNlZ21lbnRbMl07XG4gICAgICAgICAgICBwcmV2aW91c09yaWdpbmFsTGluZSA9IG1hcHBpbmcub3JpZ2luYWxMaW5lO1xuICAgICAgICAg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l9zb3VyY2VzLmF0KHNvdXJjZSk7XG4gICAgICAgICAgICBpZiAodGhpcy5zb3VyY2VSb290ICE9IG51bGwpIHtcbiAgICAgICAgICAgICAgc291cmNlID0gdXRpbC5qb2luKHRoaXMuc291cmNlUm9vdCwgc291cmNlKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgICAgdmFyIG5hbWUgPSB1dGlsLmdldEFyZyhtYXBwaW5nLCAnbmFtZScsIG51bGwpO1xuICAgICAgICAgIGlmIChuYW1lICE9PSBudWxsKSB7XG4gICAgICAgICAgICBuYW1lID0gdGhpcy5fbmFtZXMuYXQobmFtZSk7XG4gICAgICAgICAgfVxuICAgICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICBzb3VyY2U6IHNvdXJjZSxcbiAgICAgICAgICAgIGxpbmU6IHV0aWwuZ2V0QXJnKG1hcHBpbmcsICdvcmlnaW5hbExpbmUnLCBudWxsKSxcbiAgICAgICAgICAgIGNvbHVtbjogdXRpbC5nZXRBcmcobWFwcGluZywgJ29yaWdpbmFsQ29sdW1uJywgbnVsbCksXG4gICAgICAgICAgICBuYW1lOiBuYW1lXG4gICAgICAgICAgfTtcbiAgICAgICAgfVxuICAgICAgfVxuXG4gICAgICByZXR1cm4ge1xuICAgICAgICBzb3VyY2U6IG51bGwsXG4gICAgICAgIGxpbmU6IG51bGwsXG4gICAgICAgIGNvbHVtbjogbnVsbCxcbiAgICAgICAgbmFtZTogbnVsbFxuICAgICAgfTtcbiAgICB9O1xuXG4gIC8qKlxuICAgKiBSZXR1cm4gdHJ1ZSBpZiB3ZSBoYXZlIHRoZSBzb3VyY2UgY29udGVudCBmb3IgZXZlcnkgc291cmNlIGluIHRoZSBzb3VyY2VcbiAgICogbWFwLCBmYWxzZSBvdGhlcndpc2UuXG4gICAqL1xuICBCYXNpY1NvdXJjZU1hcENvbnN1bWVyLnByb3RvdHlwZS5oYXNDb250ZW50c09mQWxsU291cmNlcyA9XG4gICAgZnVuY3Rpb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WYgKHRoaXMuc291cmNlUm9vdCAhPSBudWxsKSB7XG4gICAgICAgIHNvdXJjZSA9IHV0aWwucmVsYXRpdmUodGhpcy5zb3VyY2VSb290LCBzb3VyY2UpO1xuICAgICAgfVxuICAgICAgaWYgKCF0aGlzLl9zb3VyY2VzLmhhcyhzb3VyY2UpKSB7XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgbGluZTogbnVsbCxcbiAgICAgICAgICBjb2x1bW46IG51bGwsXG4gICAgICAgICAgbGFzdENvbHVtbjogbnVsbFxuICAgICAgICB9O1xuICAgICAgfVxuICAgICAgc291cmNlID0gdGhpcy5fc291cmNlcy5pbmRleE9mKHNvdXJjZSk7XG5cbiAgICAgIHZhciBuZWVkbGUgPSB7XG4gICAgICAgIHNvdXJjZTogc291cmNlLFxuICAgICAgICBvcmlnaW5hbExpbmU6IHV0aWwuZ2V0QXJnKGFBcmdzLCAnbGluZScpLFxuICAgICAgICBvcmlnaW5hbENvbHVtbjogdXRpbC5nZXRBcmcoYUFyZ3MsICdjb2x1bW4nKVxuICAgICAgfTtcblxuICAgICAgdmFyIGluZGV4ID0gdGhpcy5fZmluZE1hcHBpbmcoXG4gICAgICAgIG5lZWRsZSxcbiAgICAgICAgdGhpcy5fb3JpZ2luYWxNYXBwaW5ncyxcbiAgICAgICAgXCJvcmlnaW5hbExpbmVcIixcbiAgICAgICAgXCJvcmlnaW5hbENvbHVtblwiLFxuICAgICAgICB1dGlsLmNvbXBhcmVCeU9yaWdpbmFsUG9zaXRpb25zLFxuICAgICAgICB1dGlsLmdldEFyZyhhQXJncywgJ2JpYXMnLCBTb3VyY2VNYXBDb25zdW1lci5HUkVBVEVTVF9MT1dFUl9CT1VORClcbiAgICAgICk7XG5cbiAgICAgIGlmIChpbmRleCA+PSAwKSB7XG4gICAgICAgIHZhciBtYXBwaW5nID0gdGhpcy5fb3JpZ2luYWxNYXBwaW5nc1tpbmRleF07XG5cbiAgICAgICAgaWYgKG1hcHBpbmcuc291cmNlID09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W1haW5pbmcgY29kZSBpcyBhZGRlZCB3aXRob3V0IG1hcHBpbmdcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgLy8gVGhlcmUgaXMgbm8gbmV3IGxpbmUgaW4gYmV0d2Vlbi5cbiAgICAgICAgICAgIC8vIEFzc29jaWF0ZSB0aGUgY29kZSBiZXR3ZWVuIFwibGFzdEdlbmVyYXRlZENvbHVtblwiIGFuZFxuICAgICAgICAgICAgLy8gXCJtYXBwaW5nLmdlbmVyYXRlZENvbHVtblwiIHdpdGggXCJsYXN0TWFwcGluZ1wiXG4gICAgICAgICAgICB2YXIgbmV4dExpbmUgPSByZW1haW5pbmdMaW5lc1swXTtcbiAgICAgICAgICAgIHZhciBjb2RlID0gbmV4dExpbmUuc3Vic3RyKDAsIG1hcHBpbmcuZ2VuZXJhdGVkQ29sdW1uIC1cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxhc3RHZW5lcmF0ZWRDb2x1bW4pO1xuICAgICAgICAgICAgcmVtYWluaW5nTGluZXNbMF0gPSBuZXh0TGluZS5zdWJzdHIobWFwcGluZy5nZW5lcmF0ZWRDb2x1bW4gLVxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGFzdEdlbmVyYXRlZENvbHVtbik7XG4gICAgICAgICAgICBsYXN0R2VuZXJhdGVkQ29sdW1uID0gbWFwcGluZy5nZW5lcmF0ZWRDb2x1bW47XG4gICAgICAgICAgICBhZGRNYXBwaW5nV2l0aENvZGUobGFzdE1hcHBpbmcsIGNvZGUpO1xuICAgICAgICAgICAgLy8gTm8gbW9yZSByZW1haW5pbmcgY29kZSwgY29udGludWVcbiAgICAgICAgICAgIGxhc3RNYXBwaW5nID0gbWFwcGluZztcbiAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgLy8gV2UgYWRkIHRoZSBnZW5lcmF0ZWQgY29kZSB1bnR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ge1xuICAgICAgICAgIGdlbmVyYXRlZC5saW5lKys7XG4gICAgICAgICAgZ2VuZXJhdGVkLmNvbHVtbiA9IDA7XG4gICAgICAgICAgLy8gTWFwcGluZ3MgZW5kIGF0IGVvbFxuICAgICAgICAgIGlmIChpZHggKyAxID09PSBsZW5ndGgpIHtcbiAgICAgICAgICAgIGxhc3RPcmlnaW5hbFNvdXJjZSA9IG51bGw7XG4gICAgICAgICAgICBzb3VyY2VNYXBwaW5nQWN0aXZlID0gZmFsc2U7XG4gICAgICAgICAgfSBlbHNlIGlmIChzb3VyY2VNYXBwaW5nQWN0aXZlKSB7XG4gICAgICAgICAgICBtYXAuYWRkTWFwcGluZyh7XG4gICAgICAgICAgICAgIHNvdXJjZTogb3JpZ2luYWwuc291cmNlLFxuICAgICAgICAgICAgICBvcmlnaW5hbDoge1xuICAgICAgICAgICAgICAgIGxpbmU6IG9yaWdpbmFsLmxpbmUsXG4gICAgICAgICAgICAgICAgY29sdW1uOiBvcmlnaW5hbC5jb2x1bW5cbiAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgZ2VuZXJhdGVkOiB7XG4gICAgICAgICAgICAgICAgbGluZTogZ2VuZXJhdGVkLmxpbmUsXG4gICAgICAgICAgICAgICAgY29sdW1uOiBnZW5lcmF0ZWQuY29sdW1uXG4gICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgIG5hbWU6IG9yaWdpbmFsLm5hbWVcbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICBnZW5lcmF0ZWQuY29sdW1uKys7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9KTtcbiAgICB0aGlzLndhbGtTb3VyY2VDb250ZW50cyhmdW5jdGlvbiAoc291cmNlRmlsZSwgc291cmNlQ29udGVudCkge1xuICAgICAgbWFwLnNldFNvdXJjZUNvbnRlbnQoc291cmNlRmlsZSwgc291cmNlQ29udGVudCk7XG4gICAgfSk7XG5cbiAgICByZXR1cm4geyBjb2RlOiBnZW5lcmF0ZWQuY29kZSwgbWFwOiBtYXAgfTtcbiAgfTtcblxuICBleHBvcnRzLlNvdXJjZU5vZGUgPSBTb3VyY2VOb2RlO1xufVxuXG5cblxuLyoqKioqKioqKioqKioqKioqXG4gKiogV0VCUEFDSyBGT09URVJcbiAqKiAuL2xpYi9zb3VyY2Utbm9kZS5qc1xuICoqIG1vZHVsZSBpZCA9IDExXG4gKiogbW9kdWxlIGNodW5rcyA9IDBcbiAqKi8iXSwic291cmNlUm9vdCI6IiJ9 \ No newline at end of file diff --git a/devtools/shared/sourcemap/tests/unit/test_util.js b/devtools/shared/sourcemap/tests/unit/test_util.js new file mode 100644 index 000000000..f47fc5315 --- /dev/null +++ b/devtools/shared/sourcemap/tests/unit/test_util.js @@ -0,0 +1,651 @@ +function run_test() { + for (var k in SOURCE_MAP_TEST_MODULE) { + if (/^test/.test(k)) { + SOURCE_MAP_TEST_MODULE[k](assert); + } + } +} + + +var SOURCE_MAP_TEST_MODULE = +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; +/******/ +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.loaded = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2014 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + var libUtil = __webpack_require__(1); + + exports['test urls'] = function (assert) { + var assertUrl = function (url) { + assert.equal(url, libUtil.urlGenerate(libUtil.urlParse(url))); + }; + assertUrl('http://'); + assertUrl('http://www.example.com'); + assertUrl('http://user:pass@www.example.com'); + assertUrl('http://www.example.com:80'); + assertUrl('http://www.example.com/'); + assertUrl('http://www.example.com/foo/bar'); + assertUrl('http://www.example.com/foo/bar/'); + assertUrl('http://user:pass@www.example.com:80/foo/bar/'); + + assertUrl('//'); + assertUrl('//www.example.com'); + assertUrl('file:///www.example.com'); + + assert.equal(libUtil.urlParse(''), null); + assert.equal(libUtil.urlParse('.'), null); + assert.equal(libUtil.urlParse('..'), null); + assert.equal(libUtil.urlParse('a'), null); + assert.equal(libUtil.urlParse('a/b'), null); + assert.equal(libUtil.urlParse('a//b'), null); + assert.equal(libUtil.urlParse('/a'), null); + assert.equal(libUtil.urlParse('data:foo,bar'), null); + }; + + exports['test normalize()'] = function (assert) { + assert.equal(libUtil.normalize('/..'), '/'); + assert.equal(libUtil.normalize('/../'), '/'); + assert.equal(libUtil.normalize('/../../../..'), '/'); + assert.equal(libUtil.normalize('/../../../../a/b/c'), '/a/b/c'); + assert.equal(libUtil.normalize('/a/b/c/../../../d/../../e'), '/e'); + + assert.equal(libUtil.normalize('..'), '..'); + assert.equal(libUtil.normalize('../'), '../'); + assert.equal(libUtil.normalize('../../a/'), '../../a/'); + assert.equal(libUtil.normalize('a/..'), '.'); + assert.equal(libUtil.normalize('a/../../..'), '../..'); + + assert.equal(libUtil.normalize('/.'), '/'); + assert.equal(libUtil.normalize('/./'), '/'); + assert.equal(libUtil.normalize('/./././.'), '/'); + assert.equal(libUtil.normalize('/././././a/b/c'), '/a/b/c'); + assert.equal(libUtil.normalize('/a/b/c/./././d/././e'), '/a/b/c/d/e'); + + assert.equal(libUtil.normalize(''), '.'); + assert.equal(libUtil.normalize('.'), '.'); + assert.equal(libUtil.normalize('./'), '.'); + assert.equal(libUtil.normalize('././a'), 'a'); + assert.equal(libUtil.normalize('a/./'), 'a/'); + assert.equal(libUtil.normalize('a/././.'), 'a'); + + assert.equal(libUtil.normalize('/a/b//c////d/////'), '/a/b/c/d/'); + assert.equal(libUtil.normalize('///a/b//c////d/////'), '///a/b/c/d/'); + assert.equal(libUtil.normalize('a/b//c////d'), 'a/b/c/d'); + + assert.equal(libUtil.normalize('.///.././../a/b//./..'), '../../a') + + assert.equal(libUtil.normalize('http://www.example.com'), 'http://www.example.com'); + assert.equal(libUtil.normalize('http://www.example.com/'), 'http://www.example.com/'); + assert.equal(libUtil.normalize('http://www.example.com/./..//a/b/c/.././d//'), 'http://www.example.com/a/b/d/'); + }; + + exports['test join()'] = function (assert) { + assert.equal(libUtil.join('a', 'b'), 'a/b'); + assert.equal(libUtil.join('a/', 'b'), 'a/b'); + assert.equal(libUtil.join('a//', 'b'), 'a/b'); + assert.equal(libUtil.join('a', 'b/'), 'a/b/'); + assert.equal(libUtil.join('a', 'b//'), 'a/b/'); + assert.equal(libUtil.join('a/', '/b'), '/b'); + assert.equal(libUtil.join('a//', '//b'), '//b'); + + assert.equal(libUtil.join('a', '..'), '.'); + assert.equal(libUtil.join('a', '../b'), 'b'); + assert.equal(libUtil.join('a/b', '../c'), 'a/c'); + + assert.equal(libUtil.join('a', '.'), 'a'); + assert.equal(libUtil.join('a', './b'), 'a/b'); + assert.equal(libUtil.join('a/b', './c'), 'a/b/c'); + + assert.equal(libUtil.join('a', 'http://www.example.com'), 'http://www.example.com'); + assert.equal(libUtil.join('a', 'data:foo,bar'), 'data:foo,bar'); + + + assert.equal(libUtil.join('', 'b'), 'b'); + assert.equal(libUtil.join('.', 'b'), 'b'); + assert.equal(libUtil.join('', 'b/'), 'b/'); + assert.equal(libUtil.join('.', 'b/'), 'b/'); + assert.equal(libUtil.join('', 'b//'), 'b/'); + assert.equal(libUtil.join('.', 'b//'), 'b/'); + + assert.equal(libUtil.join('', '..'), '..'); + assert.equal(libUtil.join('.', '..'), '..'); + assert.equal(libUtil.join('', '../b'), '../b'); + assert.equal(libUtil.join('.', '../b'), '../b'); + + assert.equal(libUtil.join('', '.'), '.'); + assert.equal(libUtil.join('.', '.'), '.'); + assert.equal(libUtil.join('', './b'), 'b'); + assert.equal(libUtil.join('.', './b'), 'b'); + + assert.equal(libUtil.join('', 'http://www.example.com'), 'http://www.example.com'); + assert.equal(libUtil.join('.', 'http://www.example.com'), 'http://www.example.com'); + assert.equal(libUtil.join('', 'data:foo,bar'), 'data:foo,bar'); + assert.equal(libUtil.join('.', 'data:foo,bar'), 'data:foo,bar'); + + + assert.equal(libUtil.join('..', 'b'), '../b'); + assert.equal(libUtil.join('..', 'b/'), '../b/'); + assert.equal(libUtil.join('..', 'b//'), '../b/'); + + assert.equal(libUtil.join('..', '..'), '../..'); + assert.equal(libUtil.join('..', '../b'), '../../b'); + + assert.equal(libUtil.join('..', '.'), '..'); + assert.equal(libUtil.join('..', './b'), '../b'); + + assert.equal(libUtil.join('..', 'http://www.example.com'), 'http://www.example.com'); + assert.equal(libUtil.join('..', 'data:foo,bar'), 'data:foo,bar'); + + + assert.equal(libUtil.join('a', ''), 'a'); + assert.equal(libUtil.join('a', '.'), 'a'); + assert.equal(libUtil.join('a/', ''), 'a'); + assert.equal(libUtil.join('a/', '.'), 'a'); + assert.equal(libUtil.join('a//', ''), 'a'); + assert.equal(libUtil.join('a//', '.'), 'a'); + assert.equal(libUtil.join('/a', ''), '/a'); + assert.equal(libUtil.join('/a', '.'), '/a'); + assert.equal(libUtil.join('', ''), '.'); + assert.equal(libUtil.join('.', ''), '.'); + assert.equal(libUtil.join('.', ''), '.'); + assert.equal(libUtil.join('.', '.'), '.'); + assert.equal(libUtil.join('..', ''), '..'); + assert.equal(libUtil.join('..', '.'), '..'); + assert.equal(libUtil.join('http://foo.org/a', ''), 'http://foo.org/a'); + assert.equal(libUtil.join('http://foo.org/a', '.'), 'http://foo.org/a'); + assert.equal(libUtil.join('http://foo.org/a/', ''), 'http://foo.org/a'); + assert.equal(libUtil.join('http://foo.org/a/', '.'), 'http://foo.org/a'); + assert.equal(libUtil.join('http://foo.org/a//', ''), 'http://foo.org/a'); + assert.equal(libUtil.join('http://foo.org/a//', '.'), 'http://foo.org/a'); + assert.equal(libUtil.join('http://foo.org', ''), 'http://foo.org/'); + assert.equal(libUtil.join('http://foo.org', '.'), 'http://foo.org/'); + assert.equal(libUtil.join('http://foo.org/', ''), 'http://foo.org/'); + assert.equal(libUtil.join('http://foo.org/', '.'), 'http://foo.org/'); + assert.equal(libUtil.join('http://foo.org//', ''), 'http://foo.org/'); + assert.equal(libUtil.join('http://foo.org//', '.'), 'http://foo.org/'); + assert.equal(libUtil.join('//www.example.com', ''), '//www.example.com/'); + assert.equal(libUtil.join('//www.example.com', '.'), '//www.example.com/'); + + + assert.equal(libUtil.join('http://foo.org/a', 'b'), 'http://foo.org/a/b'); + assert.equal(libUtil.join('http://foo.org/a/', 'b'), 'http://foo.org/a/b'); + assert.equal(libUtil.join('http://foo.org/a//', 'b'), 'http://foo.org/a/b'); + assert.equal(libUtil.join('http://foo.org/a', 'b/'), 'http://foo.org/a/b/'); + assert.equal(libUtil.join('http://foo.org/a', 'b//'), 'http://foo.org/a/b/'); + assert.equal(libUtil.join('http://foo.org/a/', '/b'), 'http://foo.org/b'); + assert.equal(libUtil.join('http://foo.org/a//', '//b'), 'http://b'); + + assert.equal(libUtil.join('http://foo.org/a', '..'), 'http://foo.org/'); + assert.equal(libUtil.join('http://foo.org/a', '../b'), 'http://foo.org/b'); + assert.equal(libUtil.join('http://foo.org/a/b', '../c'), 'http://foo.org/a/c'); + + assert.equal(libUtil.join('http://foo.org/a', '.'), 'http://foo.org/a'); + assert.equal(libUtil.join('http://foo.org/a', './b'), 'http://foo.org/a/b'); + assert.equal(libUtil.join('http://foo.org/a/b', './c'), 'http://foo.org/a/b/c'); + + assert.equal(libUtil.join('http://foo.org/a', 'http://www.example.com'), 'http://www.example.com'); + assert.equal(libUtil.join('http://foo.org/a', 'data:foo,bar'), 'data:foo,bar'); + + + assert.equal(libUtil.join('http://foo.org', 'a'), 'http://foo.org/a'); + assert.equal(libUtil.join('http://foo.org/', 'a'), 'http://foo.org/a'); + assert.equal(libUtil.join('http://foo.org//', 'a'), 'http://foo.org/a'); + assert.equal(libUtil.join('http://foo.org', '/a'), 'http://foo.org/a'); + assert.equal(libUtil.join('http://foo.org/', '/a'), 'http://foo.org/a'); + assert.equal(libUtil.join('http://foo.org//', '/a'), 'http://foo.org/a'); + + + assert.equal(libUtil.join('http://', 'www.example.com'), 'http://www.example.com'); + assert.equal(libUtil.join('file:///', 'www.example.com'), 'file:///www.example.com'); + assert.equal(libUtil.join('http://', 'ftp://example.com'), 'ftp://example.com'); + + assert.equal(libUtil.join('http://www.example.com', '//foo.org/bar'), 'http://foo.org/bar'); + assert.equal(libUtil.join('//www.example.com', '//foo.org/bar'), '//foo.org/bar'); + }; + + // TODO Issue #128: Define and test this function properly. + exports['test relative()'] = function (assert) { + assert.equal(libUtil.relative('/the/root', '/the/root/one.js'), 'one.js'); + assert.equal(libUtil.relative('http://the/root', 'http://the/root/one.js'), 'one.js'); + assert.equal(libUtil.relative('/the/root', '/the/rootone.js'), '../rootone.js'); + assert.equal(libUtil.relative('http://the/root', 'http://the/rootone.js'), '../rootone.js'); + assert.equal(libUtil.relative('/the/root', '/therootone.js'), '/therootone.js'); + assert.equal(libUtil.relative('http://the/root', '/therootone.js'), '/therootone.js'); + + assert.equal(libUtil.relative('', '/the/root/one.js'), '/the/root/one.js'); + assert.equal(libUtil.relative('.', '/the/root/one.js'), '/the/root/one.js'); + assert.equal(libUtil.relative('', 'the/root/one.js'), 'the/root/one.js'); + assert.equal(libUtil.relative('.', 'the/root/one.js'), 'the/root/one.js'); + + assert.equal(libUtil.relative('/', '/the/root/one.js'), 'the/root/one.js'); + assert.equal(libUtil.relative('/', 'the/root/one.js'), 'the/root/one.js'); + }; + } + + +/***/ }, +/* 1 */ +/***/ function(module, exports) { + + /* -*- Mode: js; js-indent-level: 2; -*- */ + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + { + /** + * This is a helper function for getting values from parameter/options + * objects. + * + * @param args The object we are extracting values from + * @param name The name of the property we are getting. + * @param defaultValue An optional value to return if the property is missing + * from the object. If this is not specified and the property is missing, an + * error will be thrown. + */ + function getArg(aArgs, aName, aDefaultValue) { + if (aName in aArgs) { + return aArgs[aName]; + } else if (arguments.length === 3) { + return aDefaultValue; + } else { + throw new Error('"' + aName + '" is a required argument.'); + } + } + exports.getArg = getArg; + + var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.]*)(?::(\d+))?(\S*)$/; + var dataUrlRegexp = /^data:.+\,.+$/; + + function urlParse(aUrl) { + var match = aUrl.match(urlRegexp); + if (!match) { + return null; + } + return { + scheme: match[1], + auth: match[2], + host: match[3], + port: match[4], + path: match[5] + }; + } + exports.urlParse = urlParse; + + function urlGenerate(aParsedUrl) { + var url = ''; + if (aParsedUrl.scheme) { + url += aParsedUrl.scheme + ':'; + } + url += '//'; + if (aParsedUrl.auth) { + url += aParsedUrl.auth + '@'; + } + if (aParsedUrl.host) { + url += aParsedUrl.host; + } + if (aParsedUrl.port) { + url += ":" + aParsedUrl.port + } + if (aParsedUrl.path) { + url += aParsedUrl.path; + } + return url; + } + exports.urlGenerate = urlGenerate; + + /** + * Normalizes a path, or the path portion of a URL: + * + * - Replaces consequtive slashes with one slash. + * - Removes unnecessary '.' parts. + * - Removes unnecessary '/..' parts. + * + * Based on code in the Node.js 'path' core module. + * + * @param aPath The path or url to normalize. + */ + function normalize(aPath) { + var path = aPath; + var url = urlParse(aPath); + if (url) { + if (!url.path) { + return aPath; + } + path = url.path; + } + var isAbsolute = exports.isAbsolute(path); + + var parts = path.split(/\/+/); + for (var part, up = 0, i = parts.length - 1; i >= 0; i--) { + part = parts[i]; + if (part === '.') { + parts.splice(i, 1); + } else if (part === '..') { + up++; + } else if (up > 0) { + if (part === '') { + // The first part is blank if the path is absolute. Trying to go + // above the root is a no-op. Therefore we can remove all '..' parts + // directly after the root. + parts.splice(i + 1, up); + up = 0; + } else { + parts.splice(i, 2); + up--; + } + } + } + path = parts.join('/'); + + if (path === '') { + path = isAbsolute ? '/' : '.'; + } + + if (url) { + url.path = path; + return urlGenerate(url); + } + return path; + } + exports.normalize = normalize; + + /** + * Joins two paths/URLs. + * + * @param aRoot The root path or URL. + * @param aPath The path or URL to be joined with the root. + * + * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a + * scheme-relative URL: Then the scheme of aRoot, if any, is prepended + * first. + * - Otherwise aPath is a path. If aRoot is a URL, then its path portion + * is updated with the result and aRoot is returned. Otherwise the result + * is returned. + * - If aPath is absolute, the result is aPath. + * - Otherwise the two paths are joined with a slash. + * - Joining for example 'http://' and 'www.example.com' is also supported. + */ + function join(aRoot, aPath) { + if (aRoot === "") { + aRoot = "."; + } + if (aPath === "") { + aPath = "."; + } + var aPathUrl = urlParse(aPath); + var aRootUrl = urlParse(aRoot); + if (aRootUrl) { + aRoot = aRootUrl.path || '/'; + } + + // `join(foo, '//www.example.org')` + if (aPathUrl && !aPathUrl.scheme) { + if (aRootUrl) { + aPathUrl.scheme = aRootUrl.scheme; + } + return urlGenerate(aPathUrl); + } + + if (aPathUrl || aPath.match(dataUrlRegexp)) { + return aPath; + } + + // `join('http://', 'www.example.com')` + if (aRootUrl && !aRootUrl.host && !aRootUrl.path) { + aRootUrl.host = aPath; + return urlGenerate(aRootUrl); + } + + var joined = aPath.charAt(0) === '/' + ? aPath + : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath); + + if (aRootUrl) { + aRootUrl.path = joined; + return urlGenerate(aRootUrl); + } + return joined; + } + exports.join = join; + + exports.isAbsolute = function (aPath) { + return aPath.charAt(0) === '/' || !!aPath.match(urlRegexp); + }; + + /** + * Make a path relative to a URL or another path. + * + * @param aRoot The root path or URL. + * @param aPath The path or URL to be made relative to aRoot. + */ + function relative(aRoot, aPath) { + if (aRoot === "") { + aRoot = "."; + } + + aRoot = aRoot.replace(/\/$/, ''); + + // It is possible for the path to be above the root. In this case, simply + // checking whether the root is a prefix of the path won't work. Instead, we + // need to remove components from the root one by one, until either we find + // a prefix that fits, or we run out of components to remove. + var level = 0; + while (aPath.indexOf(aRoot + '/') !== 0) { + var index = aRoot.lastIndexOf("/"); + if (index < 0) { + return aPath; + } + + // If the only part of the root that is left is the scheme (i.e. http://, + // file:///, etc.), one or more slashes (/), or simply nothing at all, we + // have exhausted all components, so the path is not relative to the root. + aRoot = aRoot.slice(0, index); + if (aRoot.match(/^([^\/]+:\/)?\/*$/)) { + return aPath; + } + + ++level; + } + + // Make sure we add a "../" for each component we removed from the root. + return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1); + } + exports.relative = relative; + + /** + * Because behavior goes wacky when you set `__proto__` on objects, we + * have to prefix all the strings in our set with an arbitrary character. + * + * See https://github.com/mozilla/source-map/pull/31 and + * https://github.com/mozilla/source-map/issues/30 + * + * @param String aStr + */ + function toSetString(aStr) { + return '$' + aStr; + } + exports.toSetString = toSetString; + + function fromSetString(aStr) { + return aStr.substr(1); + } + exports.fromSetString = fromSetString; + + /** + * Comparator between two mappings where the original positions are compared. + * + * Optionally pass in `true` as `onlyCompareGenerated` to consider two + * mappings with the same original source/line/column, but different generated + * line and column the same. Useful when searching for a mapping with a + * stubbed out mapping. + */ + function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) { + var cmp = mappingA.source - mappingB.source; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0 || onlyCompareOriginal) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + return mappingA.name - mappingB.name; + } + exports.compareByOriginalPositions = compareByOriginalPositions; + + /** + * Comparator between two mappings with deflated source and name indices where + * the generated positions are compared. + * + * Optionally pass in `true` as `onlyCompareGenerated` to consider two + * mappings with the same generated line and column, but different + * source/name/original line and column the same. Useful when searching for a + * mapping with a stubbed out mapping. + */ + function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) { + var cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0 || onlyCompareGenerated) { + return cmp; + } + + cmp = mappingA.source - mappingB.source; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0) { + return cmp; + } + + return mappingA.name - mappingB.name; + } + exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated; + + function strcmp(aStr1, aStr2) { + if (aStr1 === aStr2) { + return 0; + } + + if (aStr1 > aStr2) { + return 1; + } + + return -1; + } + + /** + * Comparator between two mappings with inflated source and name strings where + * the generated positions are compared. + */ + function compareByGeneratedPositionsInflated(mappingA, mappingB) { + var cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0) { + return cmp; + } + + cmp = strcmp(mappingA.source, mappingB.source); + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0) { + return cmp; + } + + return strcmp(mappingA.name, mappingB.name); + } + exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated; + } + + +/***/ } +/******/ ]); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly8vd2VicGFjay9ib290c3RyYXAgYWVhNDgxM2ZiZGRjOWE3MDI3MTgiLCJ3ZWJwYWNrOi8vLy4vdGVzdC90ZXN0LXV0aWwuanMiLCJ3ZWJwYWNrOi8vLy4vbGliL3V0aWwuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7QUFBQTtBQUNBOztBQUVBO0FBQ0E7O0FBRUE7QUFDQTtBQUNBOztBQUVBO0FBQ0E7QUFDQSx1QkFBZTtBQUNmO0FBQ0E7QUFDQTs7QUFFQTtBQUNBOztBQUVBO0FBQ0E7O0FBRUE7QUFDQTtBQUNBOzs7QUFHQTtBQUNBOztBQUVBO0FBQ0E7O0FBRUE7QUFDQTs7QUFFQTtBQUNBOzs7Ozs7O0FDdENBLGlCQUFnQixvQkFBb0I7QUFDcEM7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7O0FBRUE7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBOztBQUVBO0FBQ0E7QUFDQTs7QUFFQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7O0FBRUE7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBOztBQUVBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7O0FBRUE7QUFDQTtBQUNBO0FBQ0E7QUFDQTs7QUFFQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7O0FBRUE7QUFDQTtBQUNBOztBQUVBOztBQUVBO0FBQ0E7QUFDQTtBQUNBOztBQUVBO0FBQ0E7QU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gfSBlbHNlIGlmIChwYXJ0ID09PSAnLi4nKSB7XG4gICAgICAgIHVwKys7XG4gICAgICB9IGVsc2UgaWYgKHVwID4gMCkge1xuICAgICAgICBpZiAocGFydCA9PT0gJycpIHtcbiAgICAgICAgICAvLyBUaGUgZmlyc3QgcGFydCBpcyBibGFuayBpZiB0aGUgcGF0aCBpcyBhYnNvbHV0ZS4gVHJ5aW5nIHRvIGdvXG4gICAgICAgICAgLy8gYWJvdmUgdGhlIHJvb3QgaXMgYSBuby1vcC4gVGhlcmVmb3JlIHdlIGNhbiByZW1vdmUgYWxsICcuLicgcGFydHNcbiAgICAgICAgICAvLyBkaXJlY3RseSBhZnRlciB0aGUgcm9vdC5cbiAgICAgICAgICBwYXJ0cy5zcGxpY2UoaSArIDEsIHVwKTtcbiAgICAgICAgICB1cCA9IDA7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgcGFydHMuc3BsaWNlKGksIDIpO1xuICAgICAgICAgIHVwLS07XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9XG4gICAgcGF0aCA9IHBhcnRzLmpvaW4oJy8nKTtcblxuICAgIGlmIChwYXRoID09PSAnJykge1xuICAgICAgcGF0aCA9IGlzQWJzb2x1dGUgPyAnLycgOiAnLic7XG4gICAgfVxuXG4gICAgaWYgKHVybCkge1xuICAgICAgdXJsLnBhdGggPSBwYXRoO1xuICAgICAgcmV0dXJuIHVybEdlbmVyYXRlKHVybCk7XG4gICAgfVxuICAgIHJldHVybiBwYXRoO1xuICB9XG4gIGV4cG9ydHMubm9ybWFsaXplID0gbm9ybWFsaXplO1xuXG4gIC8qKlxuICAgKiBKb2lucyB0d28gcGF0aHMvVVJMcy5cbiAgICpcbiAgICogQHBhcmFtIGFSb290IFRoZSByb290IHBhdGggb3IgVVJMLlxuICAgKiBAcGFyYW0gYVBhdGggVGhlIHBhdGggb3IgVVJMIHRvIGJlIGpvaW5lZCB3aXRoIHRoZSByb290LlxuICAgKlxuICAgKiAtIElmIGFQ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Y21wKG1hcHBpbmdBLnNvdXJjZSwgbWFwcGluZ0Iuc291cmNlKTtcbiAgICBpZiAoY21wICE9PSAwKSB7XG4gICAgICByZXR1cm4gY21wO1xuICAgIH1cblxuICAgIGNtcCA9IG1hcHBpbmdBLm9yaWdpbmFsTGluZSAtIG1hcHBpbmdCLm9yaWdpbmFsTGluZTtcbiAgICBpZiAoY21wICE9PSAwKSB7XG4gICAgICByZXR1cm4gY21wO1xuICAgIH1cblxuICAgIGNtcCA9IG1hcHBpbmdBLm9yaWdpbmFsQ29sdW1uIC0gbWFwcGluZ0Iub3JpZ2luYWxDb2x1bW47XG4gICAgaWYgKGNtcCAhPT0gMCkge1xuICAgICAgcmV0dXJuIGNtcDtcbiAgICB9XG5cbiAgICByZXR1cm4gc3RyY21wKG1hcHBpbmdBLm5hbWUsIG1hcHBpbmdCLm5hbWUpO1xuICB9XG4gIGV4cG9ydHMuY29tcGFyZUJ5R2VuZXJhdGVkUG9zaXRpb25zSW5mbGF0ZWQgPSBjb21wYXJlQnlHZW5lcmF0ZWRQb3NpdGlvbnNJbmZsYXRlZDtcbn1cblxuXG5cbi8qKioqKioqKioqKioqKioqKlxuICoqIFdFQlBBQ0sgRk9PVEVSXG4gKiogLi9saWIvdXRpbC5qc1xuICoqIG1vZHVsZSBpZCA9IDFcbiAqKiBtb2R1bGUgY2h1bmtzID0gMFxuICoqLyJdLCJzb3VyY2VSb290IjoiIn0= \ No newline at end of file diff --git a/devtools/shared/sourcemap/tests/unit/xpcshell.ini b/devtools/shared/sourcemap/tests/unit/xpcshell.ini new file mode 100644 index 000000000..f83e4a1c9 --- /dev/null +++ b/devtools/shared/sourcemap/tests/unit/xpcshell.ini @@ -0,0 +1,16 @@ +[DEFAULT] +tags = devtools +head = head_sourcemap.js +tail = + +[test_util.js] +[test_source_node.js] +[test_source_map_generator.js] +[test_source_map_consumer.js] +[test_quick_sort.js] +[test_dog_fooding.js] +[test_binary_search.js] +[test_base64_vlq.js] +[test_base64.js] +[test_array_set.js] +[test_api.js] diff --git a/devtools/shared/specs/actor-registry.js b/devtools/shared/specs/actor-registry.js new file mode 100644 index 000000000..0f57dc8d2 --- /dev/null +++ b/devtools/shared/specs/actor-registry.js @@ -0,0 +1,43 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const { + Arg, + RetVal, + generateActorSpec, +} = require("devtools/shared/protocol"); + +const actorActorSpec = generateActorSpec({ + typeName: "actorActor", + + methods: { + unregister: { + request: {}, + response: {} + } + }, +}); + +exports.actorActorSpec = actorActorSpec; + +const actorRegistrySpec = generateActorSpec({ + typeName: "actorRegistry", + + methods: { + registerActor: { + request: { + sourceText: Arg(0, "string"), + filename: Arg(1, "string"), + options: Arg(2, "json") + }, + + response: { + actorActor: RetVal("actorActor") + } + } + } +}); + +exports.actorRegistrySpec = actorRegistrySpec; diff --git a/devtools/shared/specs/addons.js b/devtools/shared/specs/addons.js new file mode 100644 index 000000000..6246b9d1f --- /dev/null +++ b/devtools/shared/specs/addons.js @@ -0,0 +1,19 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const {Arg, RetVal, generateActorSpec} = require("devtools/shared/protocol"); + +const addonsSpec = generateActorSpec({ + typeName: "addons", + + methods: { + installTemporaryAddon: { + request: { addonPath: Arg(0, "string") }, + response: { addon: RetVal("json") }, + }, + }, +}); + +exports.addonsSpec = addonsSpec; diff --git a/devtools/shared/specs/animation.js b/devtools/shared/specs/animation.js new file mode 100644 index 000000000..20af12c23 --- /dev/null +++ b/devtools/shared/specs/animation.js @@ -0,0 +1,151 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const { + Arg, + RetVal, + generateActorSpec, + types +} = require("devtools/shared/protocol"); +require("devtools/shared/specs/inspector"); + +/** + * Sent with the 'mutations' event as part of an array of changes, used to + * inform fronts of the type of change that occured. + */ +types.addDictType("animationMutationChange", { + // The type of change ("added" or "removed"). + type: "string", + // The changed AnimationPlayerActor. + player: "animationplayer" +}); + +const animationPlayerSpec = generateActorSpec({ + typeName: "animationplayer", + + events: { + "changed": { + type: "changed", + state: Arg(0, "json") + } + }, + + methods: { + release: { release: true }, + getCurrentState: { + request: {}, + response: { + data: RetVal("json") + } + }, + pause: { + request: {}, + response: {} + }, + play: { + request: {}, + response: {} + }, + ready: { + request: {}, + response: {} + }, + setCurrentTime: { + request: { + currentTime: Arg(0, "number") + }, + response: {} + }, + setPlaybackRate: { + request: { + currentTime: Arg(0, "number") + }, + response: {} + }, + getFrames: { + request: {}, + response: { + frames: RetVal("json") + } + }, + getProperties: { + request: {}, + response: { + properties: RetVal("array:json") + } + } + } +}); + +exports.animationPlayerSpec = animationPlayerSpec; + +const animationsSpec = generateActorSpec({ + typeName: "animations", + + events: { + "mutations": { + type: "mutations", + changes: Arg(0, "array:animationMutationChange") + } + }, + + methods: { + setWalkerActor: { + request: { + walker: Arg(0, "domwalker") + }, + response: {} + }, + getAnimationPlayersForNode: { + request: { + actorID: Arg(0, "domnode") + }, + response: { + players: RetVal("array:animationplayer") + } + }, + stopAnimationPlayerUpdates: { + request: {}, + response: {} + }, + pauseAll: { + request: {}, + response: {} + }, + playAll: { + request: {}, + response: {} + }, + toggleAll: { + request: {}, + response: {} + }, + toggleSeveral: { + request: { + players: Arg(0, "array:animationplayer"), + shouldPause: Arg(1, "boolean") + }, + response: {} + }, + setCurrentTimes: { + request: { + players: Arg(0, "array:animationplayer"), + time: Arg(1, "number"), + shouldPause: Arg(2, "boolean") + }, + response: {} + }, + setPlaybackRates: { + request: { + players: Arg(0, "array:animationplayer"), + rate: Arg(1, "number") + }, + response: {} + } + } +}); + +exports.animationsSpec = animationsSpec; + diff --git a/devtools/shared/specs/breakpoint.js b/devtools/shared/specs/breakpoint.js new file mode 100644 index 000000000..e30c03ce8 --- /dev/null +++ b/devtools/shared/specs/breakpoint.js @@ -0,0 +1,16 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const {generateActorSpec} = require("devtools/shared/protocol"); + +const breakpointSpec = generateActorSpec({ + typeName: "breakpoint", + + methods: { + delete: {} + }, +}); + +exports.breakpointSpec = breakpointSpec; diff --git a/devtools/shared/specs/call-watcher.js b/devtools/shared/specs/call-watcher.js new file mode 100644 index 000000000..34d63111a --- /dev/null +++ b/devtools/shared/specs/call-watcher.js @@ -0,0 +1,79 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const protocol = require("devtools/shared/protocol"); +const { Arg, RetVal, Option, generateActorSpec } = protocol; + +/** + * Type describing a single function call in a stack trace. + */ +protocol.types.addDictType("call-stack-item", { + name: "string", + file: "string", + line: "number" +}); + +/** + * Type describing an overview of a function call. + */ +protocol.types.addDictType("call-details", { + type: "number", + name: "string", + stack: "array:call-stack-item" +}); + +const functionCallSpec = generateActorSpec({ + typeName: "function-call", + + methods: { + getDetails: { + response: { info: RetVal("call-details") } + }, + }, +}); + +exports.functionCallSpec = functionCallSpec; + +const callWatcherSpec = generateActorSpec({ + typeName: "call-watcher", + + events: { + /** + * Events emitted when the `onCall` function isn't provided. + */ + "call": { + type: "call", + function: Arg(0, "function-call") + } + }, + + methods: { + setup: { + request: { + tracedGlobals: Option(0, "nullable:array:string"), + tracedFunctions: Option(0, "nullable:array:string"), + startRecording: Option(0, "boolean"), + performReload: Option(0, "boolean"), + holdWeak: Option(0, "boolean"), + storeCalls: Option(0, "boolean") + }, + oneway: true + }, + finalize: { + oneway: true + }, + isRecording: { + response: RetVal("boolean") + }, + initTimestampEpoch: {}, + resumeRecording: {}, + pauseRecording: { + response: { calls: RetVal("array:function-call") } + }, + eraseRecording: {}, + } +}); + +exports.callWatcherSpec = callWatcherSpec; diff --git a/devtools/shared/specs/canvas.js b/devtools/shared/specs/canvas.js new file mode 100644 index 000000000..dcb26f9a9 --- /dev/null +++ b/devtools/shared/specs/canvas.js @@ -0,0 +1,131 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const protocol = require("devtools/shared/protocol"); +const {Arg, Option, RetVal, generateActorSpec} = protocol; + +/** + * Type representing an ArrayBufferView, serialized fast(er). + * + * Don't create a new array buffer view from the parsed array on the frontend. + * Consumers may copy the data into an existing buffer, or create a new one if + * necesasry. For example, this avoids the need for a redundant copy when + * populating ImageData objects, at the expense of transferring char views + * of a pixel buffer over the protocol instead of a packed int view. + * + * XXX: It would be nice if on local connections (only), we could just *give* + * the buffer directly to the front, instead of going through all this + * serialization redundancy. + */ +protocol.types.addType("array-buffer-view", { + write: (v) => "[" + Array.join(v, ",") + "]", + read: (v) => JSON.parse(v) +}); + +/** + * Type describing a thumbnail or screenshot in a recorded animation frame. + */ +protocol.types.addDictType("snapshot-image", { + index: "number", + width: "number", + height: "number", + scaling: "number", + flipped: "boolean", + pixels: "array-buffer-view" +}); + +/** + * Type describing an overview of a recorded animation frame. + */ +protocol.types.addDictType("snapshot-overview", { + calls: "array:function-call", + thumbnails: "array:snapshot-image", + screenshot: "snapshot-image" +}); + +exports.CANVAS_CONTEXTS = [ + "CanvasRenderingContext2D", + "WebGLRenderingContext" +]; + +exports.ANIMATION_GENERATORS = [ + "requestAnimationFrame" +]; + +exports.LOOP_GENERATORS = [ + "setTimeout" +]; + +exports.DRAW_CALLS = [ + // 2D canvas + "fill", + "stroke", + "clearRect", + "fillRect", + "strokeRect", + "fillText", + "strokeText", + "drawImage", + + // WebGL + "clear", + "drawArrays", + "drawElements", + "finish", + "flush" +]; + +exports.INTERESTING_CALLS = [ + // 2D canvas + "save", + "restore", + + // WebGL + "useProgram" +]; + +const frameSnapshotSpec = generateActorSpec({ + typeName: "frame-snapshot", + + methods: { + getOverview: { + response: { overview: RetVal("snapshot-overview") } + }, + generateScreenshotFor: { + request: { call: Arg(0, "function-call") }, + response: { screenshot: RetVal("snapshot-image") } + }, + }, +}); + +exports.frameSnapshotSpec = frameSnapshotSpec; + +const canvasSpec = generateActorSpec({ + typeName: "canvas", + + methods: { + setup: { + request: { reload: Option(0, "boolean") }, + oneway: true + }, + finalize: { + oneway: true + }, + isInitialized: { + response: { initialized: RetVal("boolean") } + }, + isRecording: { + response: { recording: RetVal("boolean") } + }, + recordAnimationFrame: { + response: { snapshot: RetVal("nullable:frame-snapshot") } + }, + stopRecordingAnimationFrame: { + oneway: true + }, + } +}); + +exports.canvasSpec = canvasSpec; diff --git a/devtools/shared/specs/css-properties.js b/devtools/shared/specs/css-properties.js new file mode 100644 index 000000000..76c85bd74 --- /dev/null +++ b/devtools/shared/specs/css-properties.js @@ -0,0 +1,20 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const { RetVal, generateActorSpec } = require("devtools/shared/protocol"); + +const cssPropertiesSpec = generateActorSpec({ + typeName: "cssProperties", + + methods: { + getCSSDatabase: { + request: {}, + + response: RetVal("json"), + } + } +}); + +exports.cssPropertiesSpec = cssPropertiesSpec; diff --git a/devtools/shared/specs/csscoverage.js b/devtools/shared/specs/csscoverage.js new file mode 100644 index 000000000..4c58b09a9 --- /dev/null +++ b/devtools/shared/specs/csscoverage.js @@ -0,0 +1,44 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const {Arg, RetVal, generateActorSpec} = require("devtools/shared/protocol"); + +require("devtools/shared/specs/stylesheets"); + +const cssUsageSpec = generateActorSpec({ + typeName: "cssUsage", + + events: { + "state-change": { + type: "stateChange", + stateChange: Arg(0, "json") + } + }, + + methods: { + start: { + request: { url: Arg(0, "boolean") } + }, + stop: {}, + toggle: {}, + oneshot: {}, + createEditorReport: { + request: { url: Arg(0, "string") }, + response: { reports: RetVal("array:json") } + }, + createEditorReportForSheet: { + request: { url: Arg(0, "stylesheet") }, + response: { reports: RetVal("array:json") } + }, + createPageReport: { + response: RetVal("json") + }, + _testOnlyVisitedPages: { + response: { value: RetVal("array:string") } + }, + }, +}); + +exports.cssUsageSpec = cssUsageSpec; diff --git a/devtools/shared/specs/device.js b/devtools/shared/specs/device.js new file mode 100644 index 000000000..3237d1593 --- /dev/null +++ b/devtools/shared/specs/device.js @@ -0,0 +1,19 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const {RetVal, generateActorSpec} = require("devtools/shared/protocol"); + +const deviceSpec = generateActorSpec({ + typeName: "device", + + methods: { + getDescription: {request: {}, response: { value: RetVal("json")}}, + getWallpaper: {request: {}, response: { value: RetVal("longstring")}}, + screenshotToDataURL: {request: {}, response: { value: RetVal("longstring")}}, + getRawPermissionsTable: {request: {}, response: { value: RetVal("json")}}, + }, +}); + +exports.deviceSpec = deviceSpec; diff --git a/devtools/shared/specs/director-manager.js b/devtools/shared/specs/director-manager.js new file mode 100644 index 000000000..8a9bf77ee --- /dev/null +++ b/devtools/shared/specs/director-manager.js @@ -0,0 +1,190 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const { + types, + Arg, + Option, + RetVal, + generateActorSpec, +} = require("devtools/shared/protocol"); + +/** + * Type describing a messageport event + */ +types.addDictType("messageportevent", { + isTrusted: "boolean", + data: "nullable:primitive", + origin: "nullable:string", + lastEventId: "nullable:string", + source: "messageport", + ports: "nullable:array:messageport" +}); + +const messagePortSpec = generateActorSpec({ + typeName: "messageport", + + /** + * Events emitted by this actor. + */ + events: { + message: { + type: "message", + msg: Arg(0, "nullable:messageportevent") + } + }, + + methods: { + postMessage: { + oneway: true, + request: { + msg: Arg(0, "nullable:json") + } + }, + start: { + oneway: true, + request: {} + }, + close: { + oneway: true, + request: {} + }, + finalize: { + oneway: true + }, + }, +}); + +exports.messagePortSpec = messagePortSpec; + +/** + * Type describing a director-script error + */ +types.addDictType("director-script-error", { + directorScriptId: "string", + message: "nullable:string", + stack: "nullable:string", + fileName: "nullable:string", + lineNumber: "nullable:number", + columnNumber: "nullable:number" +}); + +/** + * Type describing a director-script attach event + */ +types.addDictType("director-script-attach", { + directorScriptId: "string", + url: "string", + innerId: "number", + port: "nullable:messageport" +}); + +/** + * Type describing a director-script detach event + */ +types.addDictType("director-script-detach", { + directorScriptId: "string", + innerId: "number" +}); + +const directorScriptSpec = generateActorSpec({ + typeName: "director-script", + + /** + * Events emitted by this actor. + */ + events: { + error: { + type: "error", + data: Arg(0, "director-script-error") + }, + attach: { + type: "attach", + data: Arg(0, "director-script-attach") + }, + detach: { + type: "detach", + data: Arg(0, "director-script-detach") + } + }, + + methods: { + setup: { + request: { + reload: Option(0, "boolean"), + skipAttach: Option(0, "boolean") + }, + oneway: true + }, + getMessagePort: { + request: { }, + response: { + port: RetVal("nullable:messageport") + } + }, + finalize: { + oneway: true + }, + }, +}); + +exports.directorScriptSpec = directorScriptSpec; + +const directorManagerSpec = generateActorSpec({ + typeName: "director-manager", + + /** + * Events emitted by this actor. + */ + events: { + "director-script-error": { + type: "error", + data: Arg(0, "director-script-error") + }, + "director-script-attach": { + type: "attach", + data: Arg(0, "director-script-attach") + }, + "director-script-detach": { + type: "detach", + data: Arg(0, "director-script-detach") + } + }, + + methods: { + list: { + response: { + directorScripts: RetVal("json") + } + }, + enableByScriptIds: { + oneway: true, + request: { + selectedIds: Arg(0, "array:string"), + reload: Option(1, "boolean") + } + }, + disableByScriptIds: { + oneway: true, + request: { + selectedIds: Arg(0, "array:string"), + reload: Option(1, "boolean") + } + }, + getByScriptId: { + request: { + scriptId: Arg(0, "string") + }, + response: { + directorScript: RetVal("director-script") + } + }, + finalize: { + oneway: true + }, + }, +}); + +exports.directorManagerSpec = directorManagerSpec; diff --git a/devtools/shared/specs/director-registry.js b/devtools/shared/specs/director-registry.js new file mode 100644 index 000000000..8ebb08eea --- /dev/null +++ b/devtools/shared/specs/director-registry.js @@ -0,0 +1,41 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const {Arg, Option, RetVal, generateActorSpec} = require("devtools/shared/protocol"); + +const directorRegistrySpec = generateActorSpec({ + typeName: "director-registry", + + methods: { + finalize: { + oneway: true + }, + install: { + request: { + scriptId: Arg(0, "string"), + scriptCode: Option(1, "string"), + scriptOptions: Option(1, "nullable:json") + }, + response: { + success: RetVal("boolean") + } + }, + uninstall: { + request: { + scritpId: Arg(0, "string") + }, + response: { + success: RetVal("boolean") + } + }, + list: { + response: { + directorScripts: RetVal("array:string") + } + }, + }, +}); + +exports.directorRegistrySpec = directorRegistrySpec; diff --git a/devtools/shared/specs/emulation.js b/devtools/shared/specs/emulation.js new file mode 100644 index 000000000..1267feaf9 --- /dev/null +++ b/devtools/shared/specs/emulation.js @@ -0,0 +1,106 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const { Arg, RetVal, generateActorSpec } = require("devtools/shared/protocol"); + +const emulationSpec = generateActorSpec({ + typeName: "emulation", + + methods: { + setDPPXOverride: { + request: { + dppx: Arg(0, "number") + }, + response: { + valueChanged: RetVal("boolean") + } + }, + + getDPPXOverride: { + request: {}, + response: { + dppx: RetVal("number") + } + }, + + clearDPPXOverride: { + request: {}, + response: { + valueChanged: RetVal("boolean") + } + }, + + setNetworkThrottling: { + request: { + options: Arg(0, "json") + }, + response: { + valueChanged: RetVal("boolean") + } + }, + + getNetworkThrottling: { + request: {}, + response: { + state: RetVal("json") + } + }, + + clearNetworkThrottling: { + request: {}, + response: { + valueChanged: RetVal("boolean") + } + }, + + setTouchEventsOverride: { + request: { + flag: Arg(0, "number") + }, + response: { + valueChanged: RetVal("boolean") + } + }, + + getTouchEventsOverride: { + request: {}, + response: { + flag: RetVal("number") + } + }, + + clearTouchEventsOverride: { + request: {}, + response: { + valueChanged: RetVal("boolean") + } + }, + + setUserAgentOverride: { + request: { + flag: Arg(0, "string") + }, + response: { + valueChanged: RetVal("boolean") + } + }, + + getUserAgentOverride: { + request: {}, + response: { + userAgent: RetVal("string") + } + }, + + clearUserAgentOverride: { + request: {}, + response: { + valueChanged: RetVal("boolean") + } + }, + } +}); + +exports.emulationSpec = emulationSpec; diff --git a/devtools/shared/specs/environment.js b/devtools/shared/specs/environment.js new file mode 100644 index 000000000..d320d98a4 --- /dev/null +++ b/devtools/shared/specs/environment.js @@ -0,0 +1,27 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const {Arg, RetVal, generateActorSpec} = require("devtools/shared/protocol"); + +const environmentSpec = generateActorSpec({ + typeName: "environment", + + methods: { + assign: { + request: { + name: Arg(1), + value: Arg(2) + } + }, + bindings: { + request: {}, + response: { + bindings: RetVal("json") + } + }, + }, +}); + +exports.environmentSpec = environmentSpec; diff --git a/devtools/shared/specs/eventlooplag.js b/devtools/shared/specs/eventlooplag.js new file mode 100644 index 000000000..1498d5f63 --- /dev/null +++ b/devtools/shared/specs/eventlooplag.js @@ -0,0 +1,31 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const { Arg, RetVal, generateActorSpec } = require("devtools/shared/protocol"); + +const eventLoopLagSpec = generateActorSpec({ + typeName: "eventLoopLag", + + events: { + "event-loop-lag": { + type: "event-loop-lag", + // duration of the lag in milliseconds. + time: Arg(0, "number") + } + }, + + methods: { + start: { + request: {}, + response: {success: RetVal("number")} + }, + stop: { + request: {}, + response: {} + } + } +}); + +exports.eventLoopLagSpec = eventLoopLagSpec; diff --git a/devtools/shared/specs/frame.js b/devtools/shared/specs/frame.js new file mode 100644 index 000000000..6365d6e90 --- /dev/null +++ b/devtools/shared/specs/frame.js @@ -0,0 +1,14 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const {generateActorSpec} = require("devtools/shared/protocol"); + +const frameSpec = generateActorSpec({ + typeName: "frame", + + methods: {}, +}); + +exports.frameSpec = frameSpec; diff --git a/devtools/shared/specs/framerate.js b/devtools/shared/specs/framerate.js new file mode 100644 index 000000000..9fb2dff5d --- /dev/null +++ b/devtools/shared/specs/framerate.js @@ -0,0 +1,34 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const { Arg, RetVal, generateActorSpec } = require("devtools/shared/protocol"); + +const framerateSpec = generateActorSpec({ + typeName: "framerate", + + methods: { + startRecording: {}, + stopRecording: { + request: { + beginAt: Arg(0, "nullable:number"), + endAt: Arg(1, "nullable:number") + }, + response: { ticks: RetVal("array:number") } + }, + cancelRecording: {}, + isRecording: { + response: { recording: RetVal("boolean") } + }, + getPendingTicks: { + request: { + beginAt: Arg(0, "nullable:number"), + endAt: Arg(1, "nullable:number") + }, + response: { ticks: RetVal("array:number") } + } + } +}); + +exports.framerateSpec = framerateSpec; diff --git a/devtools/shared/specs/gcli.js b/devtools/shared/specs/gcli.js new file mode 100644 index 000000000..2e0768bc8 --- /dev/null +++ b/devtools/shared/specs/gcli.js @@ -0,0 +1,86 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const { Arg, RetVal, generateActorSpec } = require("devtools/shared/protocol"); + +const gcliSpec = generateActorSpec({ + typeName: "gcli", + + events: { + "commands-changed": { + type: "commandsChanged" + } + }, + + methods: { + _testOnlyAddItemsByModule: { + request: { + customProps: Arg(0, "array:string") + } + }, + _testOnlyRemoveItemsByModule: { + request: { + customProps: Arg(0, "array:string") + } + }, + specs: { + request: { + customProps: Arg(0, "nullable:array:string") + }, + response: { + value: RetVal("array:json") + } + }, + execute: { + request: { + // The command string + typed: Arg(0, "string") + }, + response: RetVal("json") + }, + state: { + request: { + // The command string + typed: Arg(0, "string"), + // Cursor start position + start: Arg(1, "number"), + // The prediction offset (# times UP/DOWN pressed) + rank: Arg(2, "number") + }, + response: RetVal("json") + }, + parseType: { + request: { + // The command string + typed: Arg(0, "string"), + // The name of the parameter to parse + paramName: Arg(1, "string") + }, + response: RetVal("json") + }, + nudgeType: { + request: { + // The command string + typed: Arg(0, "string"), + // +1/-1 for increment / decrement + by: Arg(1, "number"), + // The name of the parameter to parse + paramName: Arg(2, "string") + }, + response: RetVal("string") + }, + getSelectionLookup: { + request: { + // The command containing the parameter in question + commandName: Arg(0, "string"), + // The name of the parameter + paramName: Arg(1, "string"), + }, + response: RetVal("json") + } + } +}); + +exports.gcliSpec = gcliSpec; diff --git a/devtools/shared/specs/heap-snapshot-file.js b/devtools/shared/specs/heap-snapshot-file.js new file mode 100644 index 000000000..dfd03e1fa --- /dev/null +++ b/devtools/shared/specs/heap-snapshot-file.js @@ -0,0 +1,20 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const { Arg, generateActorSpec } = require("devtools/shared/protocol"); + +const heapSnapshotFileSpec = generateActorSpec({ + typeName: "heapSnapshotFile", + + methods: { + transferHeapSnapshot: { + request: { + snapshotId: Arg(0, "string") + } + } + }, +}); + +exports.heapSnapshotFileSpec = heapSnapshotFileSpec; diff --git a/devtools/shared/specs/highlighters.js b/devtools/shared/specs/highlighters.js new file mode 100644 index 000000000..8335b22d9 --- /dev/null +++ b/devtools/shared/specs/highlighters.js @@ -0,0 +1,63 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const { + Arg, + Option, + RetVal, + generateActorSpec +} = require("devtools/shared/protocol"); + +const highlighterSpec = generateActorSpec({ + typeName: "highlighter", + + methods: { + showBoxModel: { + request: { + node: Arg(0, "domnode"), + region: Option(1), + hideInfoBar: Option(1), + hideGuides: Option(1), + showOnly: Option(1), + onlyRegionArea: Option(1) + } + }, + hideBoxModel: { + request: {} + }, + pick: {}, + pickAndFocus: {}, + cancelPick: {} + } +}); + +exports.highlighterSpec = highlighterSpec; + +const customHighlighterSpec = generateActorSpec({ + typeName: "customhighlighter", + + methods: { + release: { + release: true + }, + show: { + request: { + node: Arg(0, "domnode"), + options: Arg(1, "nullable:json") + }, + response: { + value: RetVal("nullable:boolean") + } + }, + hide: { + request: {} + }, + finalize: { + oneway: true + } + } +}); + +exports.customHighlighterSpec = customHighlighterSpec; diff --git a/devtools/shared/specs/inspector.js b/devtools/shared/specs/inspector.js new file mode 100644 index 000000000..28736ed34 --- /dev/null +++ b/devtools/shared/specs/inspector.js @@ -0,0 +1,445 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const { + Arg, + Option, + RetVal, + generateActorSpec, + types +} = require("devtools/shared/protocol"); +const { nodeSpec } = require("devtools/shared/specs/node"); +require("devtools/shared/specs/styles"); +require("devtools/shared/specs/highlighters"); +require("devtools/shared/specs/layout"); + +exports.nodeSpec = nodeSpec; + +/** + * Returned from any call that might return a node that isn't connected to root + * by nodes the child has seen, such as querySelector. + */ +types.addDictType("disconnectedNode", { + // The actual node to return + node: "domnode", + + // Nodes that are needed to connect the node to a node the client has already + // seen + newParents: "array:domnode" +}); + +types.addDictType("disconnectedNodeArray", { + // The actual node list to return + nodes: "array:domnode", + + // Nodes that are needed to connect those nodes to the root. + newParents: "array:domnode" +}); + +types.addDictType("dommutation", {}); + +types.addDictType("searchresult", { + list: "domnodelist", + // Right now there is isn't anything required for metadata, + // but it's json so it can be extended with extra data. + metadata: "array:json" +}); + +const nodeListSpec = generateActorSpec({ + typeName: "domnodelist", + + methods: { + item: { + request: { item: Arg(0) }, + response: RetVal("disconnectedNode") + }, + items: { + request: { + start: Arg(0, "nullable:number"), + end: Arg(1, "nullable:number") + }, + response: RetVal("disconnectedNodeArray") + }, + release: { + release: true + } + } +}); + +exports.nodeListSpec = nodeListSpec; + +// Some common request/response templates for the dom walker + +var nodeArrayMethod = { + request: { + node: Arg(0, "domnode"), + maxNodes: Option(1), + center: Option(1, "domnode"), + start: Option(1, "domnode"), + whatToShow: Option(1) + }, + response: RetVal(types.addDictType("domtraversalarray", { + nodes: "array:domnode" + })) +}; + +var traversalMethod = { + request: { + node: Arg(0, "domnode"), + whatToShow: Option(1) + }, + response: { + node: RetVal("nullable:domnode") + } +}; + +const walkerSpec = generateActorSpec({ + typeName: "domwalker", + + events: { + "new-mutations": { + type: "newMutations" + }, + "picker-node-picked": { + type: "pickerNodePicked", + node: Arg(0, "disconnectedNode") + }, + "picker-node-previewed": { + type: "pickerNodePreviewed", + node: Arg(0, "disconnectedNode") + }, + "picker-node-hovered": { + type: "pickerNodeHovered", + node: Arg(0, "disconnectedNode") + }, + "picker-node-canceled": { + type: "pickerNodeCanceled" + }, + "highlighter-ready": { + type: "highlighter-ready" + }, + "highlighter-hide": { + type: "highlighter-hide" + }, + "display-change": { + type: "display-change", + nodes: Arg(0, "array:domnode") + }, + // The walker actor emits a useful "resize" event to its front to let + // clients know when the browser window gets resized. This may be useful + // for refreshing a DOM node's styles for example, since those may depend on + // media-queries. + "resize": { + type: "resize" + } + }, + + methods: { + release: { + release: true + }, + pick: { + request: {}, + response: RetVal("disconnectedNode") + }, + cancelPick: {}, + highlight: { + request: {node: Arg(0, "nullable:domnode")} + }, + document: { + request: { node: Arg(0, "nullable:domnode") }, + response: { node: RetVal("domnode") }, + }, + documentElement: { + request: { node: Arg(0, "nullable:domnode") }, + response: { node: RetVal("domnode") }, + }, + parents: { + request: { + node: Arg(0, "domnode"), + sameDocument: Option(1), + sameTypeRootTreeItem: Option(1) + }, + response: { + nodes: RetVal("array:domnode") + }, + }, + retainNode: { + request: { node: Arg(0, "domnode") }, + response: {} + }, + unretainNode: { + request: { node: Arg(0, "domnode") }, + response: {}, + }, + releaseNode: { + request: { + node: Arg(0, "domnode"), + force: Option(1) + } + }, + children: nodeArrayMethod, + siblings: nodeArrayMethod, + nextSibling: traversalMethod, + previousSibling: traversalMethod, + findInspectingNode: { + request: {}, + response: RetVal("disconnectedNode") + }, + querySelector: { + request: { + node: Arg(0, "domnode"), + selector: Arg(1) + }, + response: RetVal("disconnectedNode") + }, + querySelectorAll: { + request: { + node: Arg(0, "domnode"), + selector: Arg(1) + }, + response: { + list: RetVal("domnodelist") + } + }, + multiFrameQuerySelectorAll: { + request: { + selector: Arg(0) + }, + response: { + list: RetVal("domnodelist") + } + }, + search: { + request: { + query: Arg(0), + }, + response: { + list: RetVal("searchresult"), + } + }, + getSuggestionsForQuery: { + request: { + query: Arg(0), + completing: Arg(1), + selectorState: Arg(2) + }, + response: { + list: RetVal("array:array:string") + } + }, + addPseudoClassLock: { + request: { + node: Arg(0, "domnode"), + pseudoClass: Arg(1), + parents: Option(2) + }, + response: {} + }, + hideNode: { + request: { node: Arg(0, "domnode") } + }, + unhideNode: { + request: { node: Arg(0, "domnode") } + }, + removePseudoClassLock: { + request: { + node: Arg(0, "domnode"), + pseudoClass: Arg(1), + parents: Option(2) + }, + response: {} + }, + clearPseudoClassLocks: { + request: { + node: Arg(0, "nullable:domnode") + }, + response: {} + }, + innerHTML: { + request: { + node: Arg(0, "domnode") + }, + response: { + value: RetVal("longstring") + } + }, + setInnerHTML: { + request: { + node: Arg(0, "domnode"), + value: Arg(1, "string"), + }, + response: {} + }, + outerHTML: { + request: { + node: Arg(0, "domnode") + }, + response: { + value: RetVal("longstring") + } + }, + setOuterHTML: { + request: { + node: Arg(0, "domnode"), + value: Arg(1, "string"), + }, + response: {} + }, + insertAdjacentHTML: { + request: { + node: Arg(0, "domnode"), + position: Arg(1, "string"), + value: Arg(2, "string") + }, + response: RetVal("disconnectedNodeArray") + }, + duplicateNode: { + request: { + node: Arg(0, "domnode") + }, + response: {} + }, + removeNode: { + request: { + node: Arg(0, "domnode") + }, + response: { + nextSibling: RetVal("nullable:domnode") + } + }, + removeNodes: { + request: { + node: Arg(0, "array:domnode") + }, + response: {} + }, + insertBefore: { + request: { + node: Arg(0, "domnode"), + parent: Arg(1, "domnode"), + sibling: Arg(2, "nullable:domnode") + }, + response: {} + }, + editTagName: { + request: { + node: Arg(0, "domnode"), + tagName: Arg(1, "string") + }, + response: {} + }, + getMutations: { + request: { + cleanup: Option(0) + }, + response: { + mutations: RetVal("array:dommutation") + } + }, + isInDOMTree: { + request: { node: Arg(0, "domnode") }, + response: { attached: RetVal("boolean") } + }, + getNodeActorFromObjectActor: { + request: { + objectActorID: Arg(0, "string") + }, + response: { + nodeFront: RetVal("nullable:disconnectedNode") + } + }, + getStyleSheetOwnerNode: { + request: { + styleSheetActorID: Arg(0, "string") + }, + response: { + ownerNode: RetVal("nullable:disconnectedNode") + } + }, + getNodeFromActor: { + request: { + actorID: Arg(0, "string"), + path: Arg(1, "array:string") + }, + response: { + node: RetVal("nullable:disconnectedNode") + } + }, + getLayoutInspector: { + request: {}, + response: { + actor: RetVal("layout") + } + } + } +}); + +exports.walkerSpec = walkerSpec; + +const inspectorSpec = generateActorSpec({ + typeName: "inspector", + + events: { + "color-picked": { + type: "colorPicked", + color: Arg(0, "string") + }, + "color-pick-canceled": { + type: "colorPickCanceled" + } + }, + + methods: { + getWalker: { + request: { + options: Arg(0, "nullable:json") + }, + response: { + walker: RetVal("domwalker") + } + }, + getPageStyle: { + request: {}, + response: { + pageStyle: RetVal("pagestyle") + } + }, + getHighlighter: { + request: { + autohide: Arg(0, "boolean") + }, + response: { + highligter: RetVal("highlighter") + } + }, + getHighlighterByType: { + request: { + typeName: Arg(0) + }, + response: { + highlighter: RetVal("nullable:customhighlighter") + } + }, + getImageDataFromURL: { + request: {url: Arg(0), maxDim: Arg(1, "nullable:number")}, + response: RetVal("imageData") + }, + resolveRelativeURL: { + request: {url: Arg(0, "string"), node: Arg(1, "nullable:domnode")}, + response: {value: RetVal("string")} + }, + pickColorFromPage: { + request: {options: Arg(0, "nullable:json")}, + response: {} + }, + cancelPickColorFromPage: { + request: {}, + response: {} + } + } +}); + +exports.inspectorSpec = inspectorSpec; diff --git a/devtools/shared/specs/layout.js b/devtools/shared/specs/layout.js new file mode 100644 index 000000000..80a0d5f9b --- /dev/null +++ b/devtools/shared/specs/layout.js @@ -0,0 +1,33 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const { Arg, generateActorSpec, RetVal } = require("devtools/shared/protocol"); +require("devtools/shared/specs/node"); + +const gridSpec = generateActorSpec({ + typeName: "grid", + + methods: {}, +}); + +const layoutSpec = generateActorSpec({ + typeName: "layout", + + methods: { + getAllGrids: { + request: { + rootNode: Arg(0, "domnode"), + traverseFrames: Arg(1, "boolean") + }, + response: { + grids: RetVal("array:grid") + } + } + }, +}); + +exports.gridSpec = gridSpec; +exports.layoutSpec = layoutSpec; diff --git a/devtools/shared/specs/memory.js b/devtools/shared/specs/memory.js new file mode 100644 index 000000000..3bff6dc38 --- /dev/null +++ b/devtools/shared/specs/memory.js @@ -0,0 +1,124 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const { + Arg, + RetVal, + types, + generateActorSpec, +} = require("devtools/shared/protocol"); + +types.addDictType("AllocationsRecordingOptions", { + // The probability we sample any given allocation when recording + // allocations. Must be between 0.0 and 1.0. Defaults to 1.0, or sampling + // every allocation. + probability: "number", + + // The maximum number of of allocation events to keep in the allocations + // log. If new allocations arrive, when we are already at capacity, the oldest + // allocation event is lost. This number must fit in a 32 bit signed integer. + maxLogLength: "number" +}); + +const memorySpec = generateActorSpec({ + typeName: "memory", + + /** + * The set of unsolicited events the MemoryActor emits that will be sent over + * the RDP (by protocol.js). + */ + events: { + // Same format as the data passed to the + // `Debugger.Memory.prototype.onGarbageCollection` hook. See + // `js/src/doc/Debugger/Debugger.Memory.md` for documentation. + "garbage-collection": { + type: "garbage-collection", + data: Arg(0, "json"), + }, + + // Same data as the data from `getAllocations` -- only fired if + // `autoDrain` set during `startRecordingAllocations`. + "allocations": { + type: "allocations", + data: Arg(0, "json"), + }, + }, + + methods: { + attach: { + request: {}, + response: { + type: "attached" + } + }, + detach: { + request: {}, + response: { + type: "detached" + } + }, + getState: { + response: { + state: RetVal(0, "string") + } + }, + takeCensus: { + request: {}, + response: RetVal("json") + }, + startRecordingAllocations: { + request: { + options: Arg(0, "nullable:AllocationsRecordingOptions") + }, + response: { + // Accept `nullable` in the case of server Gecko <= 37, handled on the front + value: RetVal(0, "nullable:number") + } + }, + stopRecordingAllocations: { + request: {}, + response: { + // Accept `nullable` in the case of server Gecko <= 37, handled on the front + value: RetVal(0, "nullable:number") + } + }, + getAllocationsSettings: { + request: {}, + response: { + options: RetVal(0, "json") + } + }, + getAllocations: { + request: {}, + response: RetVal("json") + }, + forceGarbageCollection: { + request: {}, + response: {} + }, + forceCycleCollection: { + request: {}, + response: {} + }, + measure: { + request: {}, + response: RetVal("json"), + }, + residentUnique: { + request: {}, + response: { value: RetVal("number") } + }, + saveHeapSnapshot: { + request: { + boundaries: Arg(0, "nullable:json") + }, + response: { + snapshotId: RetVal("string") + } + }, + }, +}); + +exports.memorySpec = memorySpec; diff --git a/devtools/shared/specs/moz.build b/devtools/shared/specs/moz.build new file mode 100644 index 000000000..52a810637 --- /dev/null +++ b/devtools/shared/specs/moz.build @@ -0,0 +1,50 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +DevToolsModules( + 'actor-registry.js', + 'addons.js', + 'animation.js', + 'breakpoint.js', + 'call-watcher.js', + 'canvas.js', + 'css-properties.js', + 'csscoverage.js', + 'device.js', + 'director-manager.js', + 'director-registry.js', + 'emulation.js', + 'environment.js', + 'eventlooplag.js', + 'frame.js', + 'framerate.js', + 'gcli.js', + 'heap-snapshot-file.js', + 'highlighters.js', + 'inspector.js', + 'layout.js', + 'memory.js', + 'node.js', + 'performance-entries.js', + 'performance-recording.js', + 'performance.js', + 'preference.js', + 'profiler.js', + 'promises.js', + 'reflow.js', + 'script.js', + 'settings.js', + 'source.js', + 'storage.js', + 'string.js', + 'styleeditor.js', + 'styles.js', + 'stylesheets.js', + 'timeline.js', + 'webaudio.js', + 'webgl.js', + 'worker.js' +) diff --git a/devtools/shared/specs/node.js b/devtools/shared/specs/node.js new file mode 100644 index 000000000..ea3d1b264 --- /dev/null +++ b/devtools/shared/specs/node.js @@ -0,0 +1,67 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const { + Arg, + RetVal, + generateActorSpec, + types +} = require("devtools/shared/protocol.js"); + +types.addDictType("imageData", { + // The image data + data: "nullable:longstring", + // The original image dimensions + size: "json" +}); + +const nodeSpec = generateActorSpec({ + typeName: "domnode", + + methods: { + getNodeValue: { + request: {}, + response: { + value: RetVal("longstring") + } + }, + setNodeValue: { + request: { value: Arg(0) }, + response: {} + }, + getUniqueSelector: { + request: {}, + response: { + value: RetVal("string") + } + }, + scrollIntoView: { + request: {}, + response: {} + }, + getImageData: { + request: {maxDim: Arg(0, "nullable:number")}, + response: RetVal("imageData") + }, + getEventListenerInfo: { + request: {}, + response: { + events: RetVal("json") + } + }, + modifyAttributes: { + request: { + modifications: Arg(0, "array:json") + }, + response: {} + }, + getFontFamilyDataURL: { + request: {font: Arg(0, "string"), fillStyle: Arg(1, "nullable:string")}, + response: RetVal("imageData") + } + } +}); + +exports.nodeSpec = nodeSpec; diff --git a/devtools/shared/specs/performance-entries.js b/devtools/shared/specs/performance-entries.js new file mode 100644 index 000000000..107afb779 --- /dev/null +++ b/devtools/shared/specs/performance-entries.js @@ -0,0 +1,25 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const { Arg, generateActorSpec } = require("devtools/shared/protocol"); + +const performanceEntriesSpec = generateActorSpec({ + typeName: "performanceEntries", + + events: { + "entry": { + type: "entry", + // object containing performance entry name, type, origin, and epoch. + detail: Arg(0, "json") + } + }, + + methods: { + start: {}, + stop: {} + } +}); + +exports.performanceEntriesSpec = performanceEntriesSpec; diff --git a/devtools/shared/specs/performance-recording.js b/devtools/shared/specs/performance-recording.js new file mode 100644 index 000000000..562abc6f7 --- /dev/null +++ b/devtools/shared/specs/performance-recording.js @@ -0,0 +1,12 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const { generateActorSpec } = require("devtools/shared/protocol"); + +const performanceRecordingSpec = generateActorSpec({ + typeName: "performance-recording" +}); + +exports.performanceRecordingSpec = performanceRecordingSpec; diff --git a/devtools/shared/specs/performance.js b/devtools/shared/specs/performance.js new file mode 100644 index 000000000..30a570e9a --- /dev/null +++ b/devtools/shared/specs/performance.js @@ -0,0 +1,88 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const { Arg, RetVal, generateActorSpec } = require("devtools/shared/protocol"); +require("devtools/shared/specs/performance-recording"); + +const performanceSpec = generateActorSpec({ + typeName: "performance", + + /** + * The set of events the PerformanceActor emits over RDP. + */ + events: { + "recording-started": { + recording: Arg(0, "performance-recording"), + }, + "recording-stopping": { + recording: Arg(0, "performance-recording"), + }, + "recording-stopped": { + recording: Arg(0, "performance-recording"), + data: Arg(1, "json"), + }, + "profiler-status": { + data: Arg(0, "json"), + }, + "console-profile-start": {}, + "timeline-data": { + name: Arg(0, "string"), + data: Arg(1, "json"), + recordings: Arg(2, "array:performance-recording"), + }, + }, + + methods: { + connect: { + request: { options: Arg(0, "nullable:json") }, + response: RetVal("json") + }, + + canCurrentlyRecord: { + request: {}, + response: { value: RetVal("json") } + }, + + startRecording: { + request: { + options: Arg(0, "nullable:json"), + }, + response: { + recording: RetVal("nullable:performance-recording") + } + }, + + stopRecording: { + request: { + options: Arg(0, "performance-recording"), + }, + response: { + recording: RetVal("performance-recording") + } + }, + + isRecording: { + request: {}, + response: { isRecording: RetVal("boolean") } + }, + + getRecordings: { + request: {}, + response: { recordings: RetVal("array:performance-recording") } + }, + + getConfiguration: { + request: {}, + response: { config: RetVal("json") } + }, + + setProfilerStatusInterval: { + request: { interval: Arg(0, "number") }, + response: { oneway: true } + }, + } +}); + +exports.performanceSpec = performanceSpec; diff --git a/devtools/shared/specs/preference.js b/devtools/shared/specs/preference.js new file mode 100644 index 000000000..54123d813 --- /dev/null +++ b/devtools/shared/specs/preference.js @@ -0,0 +1,47 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const {Arg, RetVal, generateActorSpec} = require("devtools/shared/protocol"); + +const preferenceSpec = generateActorSpec({ + typeName: "preference", + + methods: { + getBoolPref: { + request: { value: Arg(0) }, + response: { value: RetVal("boolean") } + }, + getCharPref: { + request: { value: Arg(0) }, + response: { value: RetVal("string") } + }, + getIntPref: { + request: { value: Arg(0) }, + response: { value: RetVal("number") } + }, + getAllPrefs: { + request: {}, + response: { value: RetVal("json") } + }, + setBoolPref: { + request: { name: Arg(0), value: Arg(1) }, + response: {} + }, + setCharPref: { + request: { name: Arg(0), value: Arg(1) }, + response: {} + }, + setIntPref: { + request: { name: Arg(0), value: Arg(1) }, + response: {} + }, + clearUserPref: { + request: { name: Arg(0) }, + response: {} + } + }, +}); + +exports.preferenceSpec = preferenceSpec; diff --git a/devtools/shared/specs/profiler.js b/devtools/shared/specs/profiler.js new file mode 100644 index 000000000..a4a6f384e --- /dev/null +++ b/devtools/shared/specs/profiler.js @@ -0,0 +1,121 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const { + Arg, + Option, + RetVal, + generateActorSpec, + types +} = require("devtools/shared/protocol"); + +types.addType("profiler-data", { + // On Fx42+, the profile is only deserialized on the front; older + // servers will get the profiler data as an object from nsIProfiler, + // causing one parse/stringify cycle, then again implicitly in a packet. + read: (v) => { + if (typeof v.profile === "string") { + // Create a new response object since `profile` is read only. + let newValue = Object.create(null); + newValue.profile = JSON.parse(v.profile); + newValue.currentTime = v.currentTime; + return newValue; + } + return v; + } +}); + +const profilerSpec = generateActorSpec({ + typeName: "profiler", + + /** + * The set of events the ProfilerActor emits over RDP. + */ + events: { + "console-api-profiler": { + data: Arg(0, "json"), + }, + "profiler-started": { + data: Arg(0, "json"), + }, + "profiler-stopped": { + data: Arg(0, "json"), + }, + "profiler-status": { + data: Arg(0, "json"), + }, + + // Only for older geckos, pre-protocol.js ProfilerActor ( actor.grip(), + read: grip => grip +}); + +const promisesSpec = generateActorSpec({ + typeName: "promises", + + events: { + // Event emitted for new promises allocated in debuggee and bufferred by + // sending the list of promise objects in a batch. + "new-promises": { + type: "new-promises", + data: Arg(0, "array:ObjectActor"), + }, + // Event emitted for promise settlements. + "promises-settled": { + type: "promises-settled", + data: Arg(0, "array:ObjectActor") + } + }, + + methods: { + attach: { + request: {}, + response: {}, + }, + + detach: { + request: {}, + response: {}, + }, + + listPromises: { + request: {}, + response: { + promises: RetVal("array:ObjectActor"), + }, + } + } +}); + +exports.promisesSpec = promisesSpec; diff --git a/devtools/shared/specs/reflow.js b/devtools/shared/specs/reflow.js new file mode 100644 index 000000000..a33c7a2cf --- /dev/null +++ b/devtools/shared/specs/reflow.js @@ -0,0 +1,33 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const {Arg, generateActorSpec} = require("devtools/shared/protocol"); + +const reflowSpec = generateActorSpec({ + typeName: "reflow", + + events: { + /** + * The reflows event is emitted when reflows have been detected. The event + * is sent with an array of reflows that occured. Each item has the + * following properties: + * - start {Number} + * - end {Number} + * - isInterruptible {Boolean} + */ + reflows: { + type: "reflows", + reflows: Arg(0, "array:json") + } + }, + + methods: { + start: {oneway: true}, + stop: {oneway: true}, + }, +}); + +exports.reflowSpec = reflowSpec; diff --git a/devtools/shared/specs/script.js b/devtools/shared/specs/script.js new file mode 100644 index 000000000..f24426dee --- /dev/null +++ b/devtools/shared/specs/script.js @@ -0,0 +1,14 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const {generateActorSpec} = require("devtools/shared/protocol"); + +const threadSpec = generateActorSpec({ + typeName: "context", + + methods: {}, +}); + +exports.threadSpec = threadSpec; diff --git a/devtools/shared/specs/settings.js b/devtools/shared/specs/settings.js new file mode 100644 index 000000000..482c8f473 --- /dev/null +++ b/devtools/shared/specs/settings.js @@ -0,0 +1,31 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const {Arg, RetVal, generateActorSpec} = require("devtools/shared/protocol"); + +const settingsSpec = generateActorSpec({ + typeName: "settings", + + methods: { + getSetting: { + request: { value: Arg(0) }, + response: { value: RetVal("json") } + }, + setSetting: { + request: { name: Arg(0), value: Arg(1) }, + response: {} + }, + getAllSettings: { + request: {}, + response: { value: RetVal("json") } + }, + clearUserSetting: { + request: { name: Arg(0) }, + response: {} + } + }, +}); + +exports.settingsSpec = settingsSpec; diff --git a/devtools/shared/specs/source.js b/devtools/shared/specs/source.js new file mode 100644 index 000000000..66bcf89e2 --- /dev/null +++ b/devtools/shared/specs/source.js @@ -0,0 +1,40 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const {Arg, RetVal, generateActorSpec} = require("devtools/shared/protocol"); + +const sourceSpec = generateActorSpec({ + typeName: "source", + + methods: { + getExecutableLines: { response: { lines: RetVal("json") } }, + onSource: { + request: { type: "source" }, + response: RetVal("json") + }, + prettyPrint: { + request: { indent: Arg(0, "number") }, + response: RetVal("json") + }, + disablePrettyPrint: { + response: RetVal("json") + }, + blackbox: { response: { pausedInSource: RetVal("boolean") } }, + unblackbox: {}, + setBreakpoint: { + request: { + location: { + line: Arg(0, "number"), + column: Arg(1, "nullable:number") + }, + condition: Arg(2, "nullable:string"), + noSliding: Arg(3, "nullable:boolean") + }, + response: RetVal("json") + }, + }, +}); + +exports.sourceSpec = sourceSpec; diff --git a/devtools/shared/specs/storage.js b/devtools/shared/specs/storage.js new file mode 100644 index 000000000..d6ddaefe5 --- /dev/null +++ b/devtools/shared/specs/storage.js @@ -0,0 +1,279 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const protocol = require("devtools/shared/protocol"); +const { Arg, RetVal, types } = protocol; + +let childSpecs = {}; + +function createStorageSpec(options) { + // common methods for all storage types + let methods = { + getStoreObjects: { + request: { + host: Arg(0), + names: Arg(1, "nullable:array:string"), + options: Arg(2, "nullable:json") + }, + response: RetVal(options.storeObjectType) + }, + getFields: { + request: { + subType: Arg(0, "nullable:string") + }, + response: { + value: RetVal("json") + } + } + }; + + // extra methods specific for storage type + Object.assign(methods, options.methods); + + childSpecs[options.typeName] = protocol.generateActorSpec({ + typeName: options.typeName, + methods + }); +} + +// Cookies store object +types.addDictType("cookieobject", { + name: "string", + value: "longstring", + path: "nullable:string", + host: "string", + isDomain: "boolean", + isSecure: "boolean", + isHttpOnly: "boolean", + creationTime: "number", + lastAccessed: "number", + expires: "number" +}); + +// Array of cookie store objects +types.addDictType("cookiestoreobject", { + total: "number", + offset: "number", + data: "array:nullable:cookieobject" +}); + +// Common methods for edit/remove +const editRemoveMethods = { + getEditableFields: { + request: {}, + response: { + value: RetVal("json") + } + }, + editItem: { + request: { + data: Arg(0, "json"), + }, + response: {} + }, + removeItem: { + request: { + host: Arg(0, "string"), + name: Arg(1, "string"), + }, + response: {} + }, +}; + +// Cookies actor spec +createStorageSpec({ + typeName: "cookies", + storeObjectType: "cookiestoreobject", + methods: Object.assign({}, + editRemoveMethods, + { + removeAll: { + request: { + host: Arg(0, "string"), + domain: Arg(1, "nullable:string") + }, + response: {} + } + } + ) +}); + +// Local Storage / Session Storage store object +types.addDictType("storageobject", { + name: "string", + value: "longstring" +}); + +// Common methods for local/session storage +const storageMethods = Object.assign({}, + editRemoveMethods, + { + removeAll: { + request: { + host: Arg(0, "string") + }, + response: {} + } + } +); + +// Array of Local Storage / Session Storage store objects +types.addDictType("storagestoreobject", { + total: "number", + offset: "number", + data: "array:nullable:storageobject" +}); + +createStorageSpec({ + typeName: "localStorage", + storeObjectType: "storagestoreobject", + methods: storageMethods +}); + +createStorageSpec({ + typeName: "sessionStorage", + storeObjectType: "storagestoreobject", + methods: storageMethods +}); + +types.addDictType("cacheobject", { + "url": "string", + "status": "string" +}); + +// Array of Cache store objects +types.addDictType("cachestoreobject", { + total: "number", + offset: "number", + data: "array:nullable:cacheobject" +}); + +// Cache storage spec +createStorageSpec({ + typeName: "Cache", + storeObjectType: "cachestoreobject", + methods: { + removeAll: { + request: { + host: Arg(0, "string"), + name: Arg(1, "string"), + }, + response: {} + }, + removeItem: { + request: { + host: Arg(0, "string"), + name: Arg(1, "string"), + }, + response: {} + }, + } +}); + +// Indexed DB store object +// This is a union on idb object, db metadata object and object store metadata +// object +types.addDictType("idbobject", { + name: "nullable:string", + db: "nullable:string", + objectStore: "nullable:string", + origin: "nullable:string", + version: "nullable:number", + objectStores: "nullable:number", + keyPath: "nullable:string", + autoIncrement: "nullable:boolean", + indexes: "nullable:string", + value: "nullable:longstring" +}); + +// Array of Indexed DB store objects +types.addDictType("idbstoreobject", { + total: "number", + offset: "number", + data: "array:nullable:idbobject" +}); + +// Result of Indexed DB delete operation: can block or throw error +types.addDictType("idbdeleteresult", { + blocked: "nullable:boolean", + error: "nullable:string" +}); + +createStorageSpec({ + typeName: "indexedDB", + storeObjectType: "idbstoreobject", + methods: { + removeDatabase: { + request: { + host: Arg(0, "string"), + name: Arg(1, "string"), + }, + response: RetVal("idbdeleteresult") + }, + removeAll: { + request: { + host: Arg(0, "string"), + name: Arg(1, "string"), + }, + response: {} + }, + removeItem: { + request: { + host: Arg(0, "string"), + name: Arg(1, "string"), + }, + response: {} + }, + } +}); + +// Update notification object +types.addDictType("storeUpdateObject", { + changed: "nullable:json", + deleted: "nullable:json", + added: "nullable:json" +}); + +// Generate a type definition for an object with actors for all storage types. +types.addDictType("storelist", Object.keys(childSpecs).reduce((obj, type) => { + obj[type] = type; + return obj; +}, {})); + +exports.childSpecs = childSpecs; + +exports.storageSpec = protocol.generateActorSpec({ + typeName: "storage", + + /** + * List of event notifications that the server can send to the client. + * + * - stores-update : When any store object in any storage type changes. + * - stores-cleared : When all the store objects are removed. + * - stores-reloaded : When all stores are reloaded. This generally mean that + * we should refetch everything again. + */ + events: { + "stores-update": { + type: "storesUpdate", + data: Arg(0, "storeUpdateObject") + }, + "stores-cleared": { + type: "storesCleared", + data: Arg(0, "json") + }, + "stores-reloaded": { + type: "storesReloaded", + data: Arg(0, "json") + } + }, + + methods: { + listStores: { + request: {}, + response: RetVal("storelist") + }, + } +}); diff --git a/devtools/shared/specs/string.js b/devtools/shared/specs/string.js new file mode 100644 index 000000000..f759d4052 --- /dev/null +++ b/devtools/shared/specs/string.js @@ -0,0 +1,87 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const protocol = require("devtools/shared/protocol"); +const {Arg, RetVal, generateActorSpec} = protocol; +const promise = require("promise"); +const {Class} = require("sdk/core/heritage"); + +const longStringSpec = generateActorSpec({ + typeName: "longstractor", + + methods: { + substring: { + request: { + start: Arg(0), + end: Arg(1) + }, + response: { substring: RetVal() }, + }, + release: { release: true }, + }, +}); + +exports.longStringSpec = longStringSpec; + +/** + * When a caller is expecting a LongString actor but the string is already available on + * client, the SimpleStringFront can be used as it shares the same API as a + * LongStringFront but will not make unnecessary trips to the server. + */ +const SimpleStringFront = Class({ + initialize: function (str) { + this.str = str; + }, + + get length() { + return this.str.length; + }, + + get initial() { + return this.str; + }, + + string: function () { + return promise.resolve(this.str); + }, + + substring: function (start, end) { + return promise.resolve(this.str.substring(start, end)); + }, + + release: function () { + this.str = null; + return promise.resolve(undefined); + } +}); + +exports.SimpleStringFront = SimpleStringFront; + +// The long string actor needs some custom marshalling, because it is sometimes +// returned as a primitive rather than a complete form. + +var stringActorType = protocol.types.getType("longstractor"); +protocol.types.addType("longstring", { + _actor: true, + write: (value, context, detail) => { + if (!(context instanceof protocol.Actor)) { + throw Error("Passing a longstring as an argument isn't supported."); + } + + if (value.short) { + return value.str; + } + return stringActorType.write(value, context, detail); + }, + read: (value, context, detail) => { + if (context instanceof protocol.Actor) { + throw Error("Passing a longstring as an argument isn't supported."); + } + if (typeof (value) === "string") { + return new SimpleStringFront(value); + } + return stringActorType.read(value, context, detail); + } +}); diff --git a/devtools/shared/specs/styleeditor.js b/devtools/shared/specs/styleeditor.js new file mode 100644 index 000000000..e93b7e56f --- /dev/null +++ b/devtools/shared/specs/styleeditor.js @@ -0,0 +1,61 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const { Arg, RetVal, generateActorSpec } = require("devtools/shared/protocol"); + +const oldStyleSheetSpec = generateActorSpec({ + typeName: "old-stylesheet", + + events: { + "property-change": { + type: "propertyChange", + property: Arg(0, "string"), + value: Arg(1, "json") + }, + "source-load": { + type: "sourceLoad", + source: Arg(0, "string") + }, + "style-applied": { + type: "styleApplied" + } + }, + + methods: { + toggleDisabled: { + response: { disabled: RetVal("boolean")} + }, + fetchSource: {}, + update: { + request: { + text: Arg(0, "string"), + transition: Arg(1, "boolean") + } + } + } +}); + +exports.oldStyleSheetSpec = oldStyleSheetSpec; + +const styleEditorSpec = generateActorSpec({ + typeName: "styleeditor", + + events: { + "document-load": { + type: "documentLoad", + styleSheets: Arg(0, "array:old-stylesheet") + } + }, + + method: { + newDocument: {}, + newStyleSheet: { + request: { text: Arg(0, "string") }, + response: { styleSheet: RetVal("old-stylesheet") } + } + } +}); + +exports.styleEditorSpec = styleEditorSpec; diff --git a/devtools/shared/specs/styles.js b/devtools/shared/specs/styles.js new file mode 100644 index 000000000..225d712a4 --- /dev/null +++ b/devtools/shared/specs/styles.js @@ -0,0 +1,206 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const { + Arg, + Option, + RetVal, + generateActorSpec, + types +} = require("devtools/shared/protocol"); +require("devtools/shared/specs/node"); +require("devtools/shared/specs/stylesheets"); + +// Predeclare the domstylerule actor type +types.addActorType("domstylerule"); + +/** + * DOM Nodes returned by the style actor will be owned by the DOM walker + * for the connection. + */ +types.addLifetime("walker", "walker"); + +/** + * When asking for the styles applied to a node, we return a list of + * appliedstyle json objects that lists the rules that apply to the node + * and which element they were inherited from (if any). + * + * Note appliedstyle only sends the list of actorIDs and is not a valid return + * value on its own. appliedstyle should be returned with the actual list of + * StyleRuleActor and StyleSheetActor. See appliedStylesReturn. + */ +types.addDictType("appliedstyle", { + rule: "domstylerule#actorid", + inherited: "nullable:domnode#actorid", + keyframes: "nullable:domstylerule#actorid" +}); + +types.addDictType("matchedselector", { + rule: "domstylerule#actorid", + selector: "string", + value: "string", + status: "number" +}); + +types.addDictType("appliedStylesReturn", { + entries: "array:appliedstyle", + rules: "array:domstylerule", + sheets: "array:stylesheet" +}); + +types.addDictType("modifiedStylesReturn", { + isMatching: RetVal("boolean"), + ruleProps: RetVal("nullable:appliedStylesReturn") +}); + +types.addDictType("fontpreview", { + data: "nullable:longstring", + size: "json" +}); + +types.addDictType("fontface", { + name: "string", + CSSFamilyName: "string", + rule: "nullable:domstylerule", + srcIndex: "number", + URI: "string", + format: "string", + preview: "nullable:fontpreview", + localName: "string", + metadata: "string" +}); + +const pageStyleSpec = generateActorSpec({ + typeName: "pagestyle", + + events: { + "stylesheet-updated": { + type: "styleSheetUpdated", + styleSheet: Arg(0, "stylesheet") + } + }, + + methods: { + getComputed: { + request: { + node: Arg(0, "domnode"), + markMatched: Option(1, "boolean"), + onlyMatched: Option(1, "boolean"), + filter: Option(1, "string"), + }, + response: { + computed: RetVal("json") + } + }, + getAllUsedFontFaces: { + request: { + includePreviews: Option(0, "boolean"), + previewText: Option(0, "string"), + previewFontSize: Option(0, "string"), + previewFillStyle: Option(0, "string") + }, + response: { + fontFaces: RetVal("array:fontface") + } + }, + getUsedFontFaces: { + request: { + node: Arg(0, "domnode"), + includePreviews: Option(1, "boolean"), + previewText: Option(1, "string"), + previewFontSize: Option(1, "string"), + previewFillStyle: Option(1, "string") + }, + response: { + fontFaces: RetVal("array:fontface") + } + }, + getMatchedSelectors: { + request: { + node: Arg(0, "domnode"), + property: Arg(1, "string"), + filter: Option(2, "string") + }, + response: RetVal(types.addDictType("matchedselectorresponse", { + rules: "array:domstylerule", + sheets: "array:stylesheet", + matched: "array:matchedselector" + })) + }, + getApplied: { + request: { + node: Arg(0, "domnode"), + inherited: Option(1, "boolean"), + matchedSelectors: Option(1, "boolean"), + filter: Option(1, "string") + }, + response: RetVal("appliedStylesReturn") + }, + isPositionEditable: { + request: { node: Arg(0, "domnode")}, + response: { value: RetVal("boolean") } + }, + getLayout: { + request: { + node: Arg(0, "domnode"), + autoMargins: Option(1, "boolean") + }, + response: RetVal("json") + }, + addNewRule: { + request: { + node: Arg(0, "domnode"), + pseudoClasses: Arg(1, "nullable:array:string"), + editAuthored: Arg(2, "boolean") + }, + response: RetVal("appliedStylesReturn") + } + } +}); + +exports.pageStyleSpec = pageStyleSpec; + +const styleRuleSpec = generateActorSpec({ + typeName: "domstylerule", + + events: { + "location-changed": { + type: "locationChanged", + line: Arg(0, "number"), + column: Arg(1, "number") + }, + }, + + methods: { + setRuleText: { + request: { modification: Arg(0, "string") }, + response: { rule: RetVal("domstylerule") } + }, + modifyProperties: { + request: { modifications: Arg(0, "array:json") }, + response: { rule: RetVal("domstylerule") } + }, + modifySelector: { + request: { selector: Arg(0, "string") }, + response: { isModified: RetVal("boolean") }, + }, + modifySelector2: { + request: { + node: Arg(0, "domnode"), + value: Arg(1, "string"), + editAuthored: Arg(2, "boolean") + }, + response: RetVal("modifiedStylesReturn") + } + } +}); + +exports.styleRuleSpec = styleRuleSpec; + +// The PageStyle actor flattens the DOM CSS objects a little bit, merging +// Rules and their Styles into one actor. For elements (which have a style +// but no associated rule) we fake a rule with the following style id. +const ELEMENT_STYLE = 100; +exports.ELEMENT_STYLE = ELEMENT_STYLE; diff --git a/devtools/shared/specs/stylesheets.js b/devtools/shared/specs/stylesheets.js new file mode 100644 index 000000000..c89a7c088 --- /dev/null +++ b/devtools/shared/specs/stylesheets.js @@ -0,0 +1,120 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const { + Arg, + RetVal, + generateActorSpec, + types +} = require("devtools/shared/protocol"); + +const originalSourceSpec = generateActorSpec({ + typeName: "originalsource", + + methods: { + getText: { + response: { + text: RetVal("longstring") + } + } + } +}); + +exports.originalSourceSpec = originalSourceSpec; + +const mediaRuleSpec = generateActorSpec({ + typeName: "mediarule", + + events: { + "matches-change": { + type: "matchesChange", + matches: Arg(0, "boolean"), + } + } +}); + +exports.mediaRuleSpec = mediaRuleSpec; + +types.addActorType("stylesheet"); + +const styleSheetSpec = generateActorSpec({ + typeName: "stylesheet", + + events: { + "property-change": { + type: "propertyChange", + property: Arg(0, "string"), + value: Arg(1, "json") + }, + "style-applied": { + type: "styleApplied", + kind: Arg(0, "number"), + styleSheet: Arg(1, "stylesheet") + }, + "media-rules-changed": { + type: "mediaRulesChanged", + rules: Arg(0, "array:mediarule") + } + }, + + methods: { + toggleDisabled: { + response: { disabled: RetVal("boolean")} + }, + getText: { + response: { + text: RetVal("longstring") + } + }, + getOriginalSources: { + request: {}, + response: { + originalSources: RetVal("nullable:array:originalsource") + } + }, + getOriginalLocation: { + request: { + line: Arg(0, "number"), + column: Arg(1, "number") + }, + response: RetVal(types.addDictType("originallocationresponse", { + source: "string", + line: "number", + column: "number" + })) + }, + getMediaRules: { + request: {}, + response: { + mediaRules: RetVal("nullable:array:mediarule") + } + }, + update: { + request: { + text: Arg(0, "string"), + transition: Arg(1, "boolean") + } + } + } +}); + +exports.styleSheetSpec = styleSheetSpec; + +const styleSheetsSpec = generateActorSpec({ + typeName: "stylesheets", + + methods: { + getStyleSheets: { + request: {}, + response: { styleSheets: RetVal("array:stylesheet") } + }, + addStyleSheet: { + request: { text: Arg(0, "string") }, + response: { styleSheet: RetVal("stylesheet") } + } + } +}); + +exports.styleSheetsSpec = styleSheetsSpec; diff --git a/devtools/shared/specs/timeline.js b/devtools/shared/specs/timeline.js new file mode 100644 index 000000000..653ebef49 --- /dev/null +++ b/devtools/shared/specs/timeline.js @@ -0,0 +1,118 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const { + Arg, + RetVal, + Option, + generateActorSpec, + types +} = require("devtools/shared/protocol"); + +/** + * Type representing an array of numbers as strings, serialized fast(er). + * http://jsperf.com/json-stringify-parse-vs-array-join-split/3 + * + * XXX: It would be nice if on local connections (only), we could just *give* + * the array directly to the front, instead of going through all this + * serialization redundancy. + */ +types.addType("array-of-numbers-as-strings", { + write: (v) => v.join(","), + // In Gecko <= 37, `v` is an array; do not transform in this case. + read: (v) => typeof v === "string" ? v.split(",") : v +}); + +const timelineSpec = generateActorSpec({ + typeName: "timeline", + + events: { + /** + * Events emitted when "DOMContentLoaded" and "Load" markers are received. + */ + "doc-loading": { + type: "doc-loading", + marker: Arg(0, "json"), + endTime: Arg(0, "number") + }, + + /** + * The "markers" events emitted every DEFAULT_TIMELINE_DATA_PULL_TIMEOUT ms + * at most, when profile markers are found. The timestamps on each marker + * are relative to when recording was started. + */ + "markers": { + type: "markers", + markers: Arg(0, "json"), + endTime: Arg(1, "number") + }, + + /** + * The "memory" events emitted in tandem with "markers", if this was enabled + * when the recording started. The `delta` timestamp on this measurement is + * relative to when recording was started. + */ + "memory": { + type: "memory", + delta: Arg(0, "number"), + measurement: Arg(1, "json") + }, + + /** + * The "ticks" events (from the refresh driver) emitted in tandem with + * "markers", if this was enabled when the recording started. All ticks + * are timestamps with a zero epoch. + */ + "ticks": { + type: "ticks", + delta: Arg(0, "number"), + timestamps: Arg(1, "array-of-numbers-as-strings") + }, + + /** + * The "frames" events emitted in tandem with "markers", containing + * JS stack frames. The `delta` timestamp on this frames packet is + * relative to when recording was started. + */ + "frames": { + type: "frames", + delta: Arg(0, "number"), + frames: Arg(1, "json") + } + }, + + methods: { + isRecording: { + request: {}, + response: { + value: RetVal("boolean") + } + }, + + start: { + request: { + withMarkers: Option(0, "boolean"), + withTicks: Option(0, "boolean"), + withMemory: Option(0, "boolean"), + withFrames: Option(0, "boolean"), + withGCEvents: Option(0, "boolean"), + withDocLoadingEvents: Option(0, "boolean") + }, + response: { + value: RetVal("number") + } + }, + + stop: { + response: { + // Set as possibly nullable due to the end time possibly being + // undefined during destruction + value: RetVal("nullable:number") + } + }, + }, +}); + +exports.timelineSpec = timelineSpec; diff --git a/devtools/shared/specs/webaudio.js b/devtools/shared/specs/webaudio.js new file mode 100644 index 000000000..9dfb92467 --- /dev/null +++ b/devtools/shared/specs/webaudio.js @@ -0,0 +1,163 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const { + Arg, + Option, + RetVal, + generateActorSpec, + types, +} = require("devtools/shared/protocol"); + +exports.NODE_CREATION_METHODS = [ + "createBufferSource", "createMediaElementSource", "createMediaStreamSource", + "createMediaStreamDestination", "createScriptProcessor", "createAnalyser", + "createGain", "createDelay", "createBiquadFilter", "createWaveShaper", + "createPanner", "createConvolver", "createChannelSplitter", "createChannelMerger", + "createDynamicsCompressor", "createOscillator", "createStereoPanner" +]; + +exports.AUTOMATION_METHODS = [ + "setValueAtTime", "linearRampToValueAtTime", "exponentialRampToValueAtTime", + "setTargetAtTime", "setValueCurveAtTime", "cancelScheduledValues" +]; + +exports.NODE_ROUTING_METHODS = [ + "connect", "disconnect" +]; + +types.addActorType("audionode"); +const audionodeSpec = generateActorSpec({ + typeName: "audionode", + + methods: { + getType: { response: { type: RetVal("string") }}, + isBypassed: { + response: { bypassed: RetVal("boolean") } + }, + bypass: { + request: { enable: Arg(0, "boolean") }, + response: { bypassed: RetVal("boolean") } + }, + setParam: { + request: { + param: Arg(0, "string"), + value: Arg(1, "nullable:primitive") + }, + response: { error: RetVal("nullable:json") } + }, + getParam: { + request: { + param: Arg(0, "string") + }, + response: { text: RetVal("nullable:primitive") } + }, + getParamFlags: { + request: { param: Arg(0, "string") }, + response: { flags: RetVal("nullable:primitive") } + }, + getParams: { + response: { params: RetVal("json") } + }, + connectParam: { + request: { + destActor: Arg(0, "audionode"), + paramName: Arg(1, "string"), + output: Arg(2, "nullable:number") + }, + response: { error: RetVal("nullable:json") } + }, + connectNode: { + request: { + destActor: Arg(0, "audionode"), + output: Arg(1, "nullable:number"), + input: Arg(2, "nullable:number") + }, + response: { error: RetVal("nullable:json") } + }, + disconnect: { + request: { output: Arg(0, "nullable:number") }, + response: { error: RetVal("nullable:json") } + }, + getAutomationData: { + request: { paramName: Arg(0, "string") }, + response: { values: RetVal("nullable:json") } + }, + addAutomationEvent: { + request: { + paramName: Arg(0, "string"), + eventName: Arg(1, "string"), + args: Arg(2, "nullable:json") + }, + response: { error: RetVal("nullable:json") } + }, + } +}); + +exports.audionodeSpec = audionodeSpec; + +const webAudioSpec = generateActorSpec({ + typeName: "webaudio", + + /** + * Events emitted by this actor. + */ + events: { + "start-context": { + type: "startContext" + }, + "connect-node": { + type: "connectNode", + source: Option(0, "audionode"), + dest: Option(0, "audionode") + }, + "disconnect-node": { + type: "disconnectNode", + source: Arg(0, "audionode") + }, + "connect-param": { + type: "connectParam", + source: Option(0, "audionode"), + dest: Option(0, "audionode"), + param: Option(0, "string") + }, + "change-param": { + type: "changeParam", + source: Option(0, "audionode"), + param: Option(0, "string"), + value: Option(0, "string") + }, + "create-node": { + type: "createNode", + source: Arg(0, "audionode") + }, + "destroy-node": { + type: "destroyNode", + source: Arg(0, "audionode") + }, + "automation-event": { + type: "automationEvent", + node: Option(0, "audionode"), + paramName: Option(0, "string"), + eventName: Option(0, "string"), + args: Option(0, "json") + } + }, + + methods: { + getDefinition: { + response: { definition: RetVal("json") } + }, + setup: { + request: { reload: Option(0, "boolean") }, + oneway: true + }, + finalize: { + oneway: true + } + } +}); + +exports.webAudioSpec = webAudioSpec; diff --git a/devtools/shared/specs/webgl.js b/devtools/shared/specs/webgl.js new file mode 100644 index 000000000..f97610f3c --- /dev/null +++ b/devtools/shared/specs/webgl.js @@ -0,0 +1,101 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const {Arg, Option, RetVal, generateActorSpec} = require("devtools/shared/protocol"); + +const shaderSpec = generateActorSpec({ + typeName: "gl-shader", + + methods: { + getText: { + response: { text: RetVal("string") } + }, + compile: { + request: { text: Arg(0, "string") }, + response: { error: RetVal("nullable:json") } + }, + }, +}); + +exports.shaderSpec = shaderSpec; + +const programSpec = generateActorSpec({ + typeName: "gl-program", + + methods: { + getVertexShader: { + response: { shader: RetVal("gl-shader") } + }, + getFragmentShader: { + response: { shader: RetVal("gl-shader") } + }, + highlight: { + request: { tint: Arg(0, "array:number") }, + oneway: true + }, + unhighlight: { + oneway: true + }, + blackbox: { + oneway: true + }, + unblackbox: { + oneway: true + }, + } +}); + +exports.programSpec = programSpec; + +const webGLSpec = generateActorSpec({ + typeName: "webgl", + + /** + * Events emitted by this actor. The "program-linked" event is fired every + * time a WebGL program was linked with its respective two shaders. + */ + events: { + "program-linked": { + type: "programLinked", + program: Arg(0, "gl-program") + }, + "global-destroyed": { + type: "globalDestroyed", + program: Arg(0, "number") + }, + "global-created": { + type: "globalCreated", + program: Arg(0, "number") + } + }, + + methods: { + setup: { + request: { reload: Option(0, "boolean") }, + oneway: true + }, + finalize: { + oneway: true + }, + getPrograms: { + response: { programs: RetVal("array:gl-program") } + }, + waitForFrame: { + response: { success: RetVal("nullable:json") } + }, + getPixel: { + request: { + selector: Option(0, "string"), + position: Option(0, "json") + }, + response: { pixels: RetVal("json") } + }, + _getAllPrograms: { + response: { programs: RetVal("array:gl-program") } + } + } +}); + +exports.webGLSpec = webGLSpec; diff --git a/devtools/shared/specs/worker.js b/devtools/shared/specs/worker.js new file mode 100644 index 000000000..568f55ec0 --- /dev/null +++ b/devtools/shared/specs/worker.js @@ -0,0 +1,78 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const {Arg, RetVal, generateActorSpec} = require("devtools/shared/protocol"); + +const workerSpec = generateActorSpec({ + typeName: "worker", + + methods: { + attach: { + request: {}, + response: RetVal("json") + }, + detach: { + request: {}, + response: RetVal("json") + }, + connect: { + request: { + options: Arg(0, "json"), + }, + response: RetVal("json") + }, + push: { + request: {}, + response: RetVal("json") + }, + }, +}); + +exports.workerSpec = workerSpec; + +const pushSubscriptionSpec = generateActorSpec({ + typeName: "pushSubscription", +}); + +exports.pushSubscriptionSpec = pushSubscriptionSpec; + +const serviceWorkerRegistrationSpec = generateActorSpec({ + typeName: "serviceWorkerRegistration", + + events: { + "push-subscription-modified": { + type: "push-subscription-modified" + }, + "registration-changed": { + type: "registration-changed" + } + }, + + methods: { + start: { + request: {}, + response: RetVal("json") + }, + unregister: { + request: {}, + response: RetVal("json") + }, + getPushSubscription: { + request: {}, + response: { + subscription: RetVal("nullable:pushSubscription") + } + }, + }, +}); + +exports.serviceWorkerRegistrationSpec = serviceWorkerRegistrationSpec; + +const serviceWorkerSpec = generateActorSpec({ + typeName: "serviceWorker", +}); + +exports.serviceWorkerSpec = serviceWorkerSpec; + diff --git a/devtools/shared/sprintfjs/UPGRADING.md b/devtools/shared/sprintfjs/UPGRADING.md new file mode 100644 index 000000000..482361f3f --- /dev/null +++ b/devtools/shared/sprintfjs/UPGRADING.md @@ -0,0 +1,12 @@ +SPRINTF JS UPGRADING + +Original library at https://github.com/alexei/sprintf.js +By default the library only supports string placeholders using %s (lowercase) while we use +%S (uppercase). The library has to be manually patched in order to support it. + +- grab the unminified version at https://github.com/alexei/sprintf.js/blob/master/src/sprintf.js +- update the re.placeholder regexp to allow "S" as well as "s" +- update the switch statement in the format() method to make case "S" equivalent to case "s" + +The original changeset adding support for "%S" can be found on this fork: +- https://github.com/juliandescottes/sprintf.js/commit/a60ea5d7c4cd9a006002ba9f0afc1e2689107eec \ No newline at end of file diff --git a/devtools/shared/sprintfjs/moz.build b/devtools/shared/sprintfjs/moz.build new file mode 100644 index 000000000..6f4f1f873 --- /dev/null +++ b/devtools/shared/sprintfjs/moz.build @@ -0,0 +1,9 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +DevToolsModules( + 'sprintf.js' +) diff --git a/devtools/shared/sprintfjs/sprintf.js b/devtools/shared/sprintfjs/sprintf.js new file mode 100644 index 000000000..8e3344e02 --- /dev/null +++ b/devtools/shared/sprintfjs/sprintf.js @@ -0,0 +1,274 @@ +/** + * Copyright (c) 2007-2016, Alexandru Marasteanu + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of this software nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* globals window, exports, define */ + +(function(window) { + 'use strict' + + var re = { + not_string: /[^s]/, + not_bool: /[^t]/, + not_type: /[^T]/, + not_primitive: /[^v]/, + number: /[diefg]/, + numeric_arg: /bcdiefguxX/, + json: /[j]/, + not_json: /[^j]/, + text: /^[^\x25]+/, + modulo: /^\x25{2}/, + placeholder: /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijosStTuvxX])/, + key: /^([a-z_][a-z_\d]*)/i, + key_access: /^\.([a-z_][a-z_\d]*)/i, + index_access: /^\[(\d+)\]/, + sign: /^[\+\-]/ + } + + function sprintf() { + var key = arguments[0], cache = sprintf.cache + if (!(cache[key] && cache.hasOwnProperty(key))) { + cache[key] = sprintf.parse(key) + } + return sprintf.format.call(null, cache[key], arguments) + } + + sprintf.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length, is_positive = true, sign = '' + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]) + if (node_type === 'string') { + output[output.length] = parse_tree[i] + } + else if (node_type === 'array') { + match = parse_tree[i] // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor] + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw new Error(sprintf('[sprintf] property "%s" does not exist', match[2][k])) + } + arg = arg[match[2][k]] + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]] + } + else { // positional argument (implicit) + arg = argv[cursor++] + } + + if (re.not_type.test(match[8]) && re.not_primitive.test(match[8]) && get_type(arg) == 'function') { + arg = arg() + } + + if (re.numeric_arg.test(match[8]) && (get_type(arg) != 'number' && isNaN(arg))) { + throw new TypeError(sprintf("[sprintf] expecting number but found %s", get_type(arg))) + } + + if (re.number.test(match[8])) { + is_positive = arg >= 0 + } + + switch (match[8]) { + case 'b': + arg = parseInt(arg, 10).toString(2) + break + case 'c': + arg = String.fromCharCode(parseInt(arg, 10)) + break + case 'd': + case 'i': + arg = parseInt(arg, 10) + break + case 'j': + arg = JSON.stringify(arg, null, match[6] ? parseInt(match[6]) : 0) + break + case 'e': + arg = match[7] ? parseFloat(arg).toExponential(match[7]) : parseFloat(arg).toExponential() + break + case 'f': + arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg) + break + case 'g': + arg = match[7] ? parseFloat(arg).toPrecision(match[7]) : parseFloat(arg) + break + case 'o': + arg = arg.toString(8) + break + case 's': + case 'S': + arg = String(arg) + arg = (match[7] ? arg.substring(0, match[7]) : arg) + break + case 't': + arg = String(!!arg) + arg = (match[7] ? arg.substring(0, match[7]) : arg) + break + case 'T': + arg = get_type(arg) + arg = (match[7] ? arg.substring(0, match[7]) : arg) + break + case 'u': + arg = parseInt(arg, 10) >>> 0 + break + case 'v': + arg = arg.valueOf() + arg = (match[7] ? arg.substring(0, match[7]) : arg) + break + case 'x': + arg = parseInt(arg, 10).toString(16) + break + case 'X': + arg = parseInt(arg, 10).toString(16).toUpperCase() + break + } + if (re.json.test(match[8])) { + output[output.length] = arg + } + else { + if (re.number.test(match[8]) && (!is_positive || match[3])) { + sign = is_positive ? '+' : '-' + arg = arg.toString().replace(re.sign, '') + } + else { + sign = '' + } + pad_character = match[4] ? match[4] === '0' ? '0' : match[4].charAt(1) : ' ' + pad_length = match[6] - (sign + arg).length + pad = match[6] ? (pad_length > 0 ? str_repeat(pad_character, pad_length) : '') : '' + output[output.length] = match[5] ? sign + arg + pad : (pad_character === '0' ? sign + pad + arg : pad + sign + arg) + } + } + } + return output.join('') + } + + sprintf.cache = {} + + sprintf.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0 + while (_fmt) { + if ((match = re.text.exec(_fmt)) !== null) { + parse_tree[parse_tree.length] = match[0] + } + else if ((match = re.modulo.exec(_fmt)) !== null) { + parse_tree[parse_tree.length] = '%' + } + else if ((match = re.placeholder.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1 + var field_list = [], replacement_field = match[2], field_match = [] + if ((field_match = re.key.exec(replacement_field)) !== null) { + field_list[field_list.length] = field_match[1] + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = re.key_access.exec(replacement_field)) !== null) { + field_list[field_list.length] = field_match[1] + } + else if ((field_match = re.index_access.exec(replacement_field)) !== null) { + field_list[field_list.length] = field_match[1] + } + else { + throw new SyntaxError("[sprintf] failed to parse named argument key") + } + } + } + else { + throw new SyntaxError("[sprintf] failed to parse named argument key") + } + match[2] = field_list + } + else { + arg_names |= 2 + } + if (arg_names === 3) { + throw new Error("[sprintf] mixing positional and named placeholders is not (yet) supported") + } + parse_tree[parse_tree.length] = match + } + else { + throw new SyntaxError("[sprintf] unexpected placeholder") + } + _fmt = _fmt.substring(match[0].length) + } + return parse_tree + } + + var vsprintf = function(fmt, argv, _argv) { + _argv = (argv || []).slice(0) + _argv.splice(0, 0, fmt) + return sprintf.apply(null, _argv) + } + + /** + * helpers + */ + function get_type(variable) { + if (typeof variable === 'number') { + return 'number' + } + else if (typeof variable === 'string') { + return 'string' + } + else { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase() + } + } + + var preformattedPadding = { + '0': ['', '0', '00', '000', '0000', '00000', '000000', '0000000'], + ' ': ['', ' ', ' ', ' ', ' ', ' ', ' ', ' '], + '_': ['', '_', '__', '___', '____', '_____', '______', '_______'], + } + function str_repeat(input, multiplier) { + if (multiplier >= 0 && multiplier <= 7 && preformattedPadding[input]) { + return preformattedPadding[input][multiplier] + } + return Array(multiplier + 1).join(input) + } + + /** + * export to either browser or node.js + */ + if (typeof exports !== 'undefined') { + exports.sprintf = sprintf + exports.vsprintf = vsprintf + } + else { + window.sprintf = sprintf + window.vsprintf = vsprintf + + if (typeof define === 'function' && define.amd) { + define(function() { + return { + sprintf: sprintf, + vsprintf: vsprintf + } + }) + } + } +})(typeof window === 'undefined' ? this : window); diff --git a/devtools/shared/system.js b/devtools/shared/system.js new file mode 100644 index 000000000..ae46016e7 --- /dev/null +++ b/devtools/shared/system.js @@ -0,0 +1,339 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const { Cc, Ci, Cu } = require("chrome"); +const { Task } = require("devtools/shared/task"); + +loader.lazyRequireGetter(this, "Services"); +loader.lazyRequireGetter(this, "promise"); +loader.lazyRequireGetter(this, "defer", "devtools/shared/defer"); +loader.lazyRequireGetter(this, "OS", "resource://gre/modules/commonjs/node/os.js"); +loader.lazyRequireGetter(this, "DebuggerServer", "devtools/server/main", true); +loader.lazyRequireGetter(this, "AppConstants", + "resource://gre/modules/AppConstants.jsm", true); +loader.lazyGetter(this, "screenManager", () => { + return Cc["@mozilla.org/gfx/screenmanager;1"].getService(Ci.nsIScreenManager); +}); +loader.lazyGetter(this, "oscpu", () => { + return Cc["@mozilla.org/network/protocol;1?name=http"] + .getService(Ci.nsIHttpProtocolHandler).oscpu; +}); + +const APP_MAP = { + "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}": "firefox", + "{3550f703-e582-4d05-9a08-453d09bdfdc6}": "thunderbird", + "{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}": "seamonkey", + "{718e30fb-e89b-41dd-9da7-e25a45638b28}": "sunbird", + "{3c2e2abc-06d4-11e1-ac3b-374f68613e61}": "b2g", + "{aa3c5121-dab2-40e2-81ca-7ea25febc110}": "mobile/android", + "{a23983c0-fd0e-11dc-95ff-0800200c9a66}": "mobile/xul" +}; + +var CACHED_INFO = null; + +function* getSystemInfo() { + if (CACHED_INFO) { + return CACHED_INFO; + } + + let appInfo = Services.appinfo; + let win = Services.wm.getMostRecentWindow(DebuggerServer.chromeWindowType); + let [processor, compiler] = appInfo.XPCOMABI.split("-"); + let dpi, + useragent, + width, + height, + physicalWidth, + physicalHeight, + os, + brandName; + let appid = appInfo.ID; + let apptype = APP_MAP[appid]; + let geckoVersion = appInfo.platformVersion; + let hardware = "unknown"; + let version = "unknown"; + + // B2G specific + if (apptype === "b2g") { + os = "B2G"; + // `getSetting` does not work in child processes on b2g. + // TODO bug 1205797, make this work in child processes. + try { + hardware = yield exports.getSetting("deviceinfo.hardware"); + version = yield exports.getSetting("deviceinfo.os"); + } catch (e) { + } + } + // Not B2G + else { + os = appInfo.OS; + version = appInfo.version; + } + + let bundle = Services.strings.createBundle("chrome://branding/locale/brand.properties"); + if (bundle) { + brandName = bundle.GetStringFromName("brandFullName"); + } else { + brandName = null; + } + + if (win) { + let utils = win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils); + dpi = utils.displayDPI; + useragent = win.navigator.userAgent; + width = win.screen.width; + height = win.screen.height; + physicalWidth = win.screen.width * win.devicePixelRatio; + physicalHeight = win.screen.height * win.devicePixelRatio; + } + + let info = { + + /** + * Information from nsIXULAppInfo, regarding + * the application itself. + */ + + // The XUL application's UUID. + appid, + + // Name of the app, "firefox", "thunderbird", etc., listed in APP_MAP + apptype, + + // Mixed-case or empty string of vendor, like "Mozilla" + vendor: appInfo.vendor, + + // Name of the application, like "Firefox", "Thunderbird". + name: appInfo.name, + + // The application's version, for example "0.8.0+" or "3.7a1pre". + // Typically, the version of Firefox, for example. + // It is different than the version of Gecko or the XULRunner platform. + // On B2G, this is the Gaia version. + version, + + // The application's build ID/date, for example "2004051604". + appbuildid: appInfo.appBuildID, + + // The application's changeset. + changeset: exports.getAppIniString("App", "SourceStamp"), + + // The build ID/date of Gecko and the XULRunner platform. + platformbuildid: appInfo.platformBuildID, + geckobuildid: appInfo.platformBuildID, + + // The version of Gecko or XULRunner platform, for example "1.8.1.19" or + // "1.9.3pre". In "Firefox 3.7 alpha 1" the application version is "3.7a1pre" + // while the platform version is "1.9.3pre" + platformversion: geckoVersion, + geckoversion: geckoVersion, + + // Locale used in this build + locale: Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIXULChromeRegistry).getSelectedLocale("global"), + + /** + * Information regarding the operating system. + */ + + // Returns the endianness of the architecture: either "LE" or "BE" + endianness: OS.endianness(), + + // Returns the hostname of the machine + hostname: OS.hostname(), + + // Name of the OS type. Typically the same as `uname -s`. Possible values: + // https://developer.mozilla.org/en/OS_TARGET + // Also may be "B2G". + os, + platform: os, + + // hardware and version info from `deviceinfo.hardware` + // and `deviceinfo.os`. + hardware, + + // Type of process architecture running: + // "arm", "ia32", "x86", "x64" + // Alias to both `arch` and `processor` for node/deviceactor compat + arch: processor, + processor, + + // Name of compiler used for build: + // `'msvc', 'n32', 'gcc2', 'gcc3', 'sunc', 'ibmc'...` + compiler, + + // Location for the current profile + profile: getProfileLocation(), + + // Update channel + channel: AppConstants.MOZ_UPDATE_CHANNEL, + + dpi, + useragent, + width, + height, + physicalWidth, + physicalHeight, + brandName, + }; + + CACHED_INFO = info; + return info; +} + +function getProfileLocation() { + // In child processes, we cannot access the profile location. + try { + let profd = Services.dirsvc.get("ProfD", Ci.nsILocalFile); + let profservice = Cc["@mozilla.org/toolkit/profile-service;1"].getService(Ci.nsIToolkitProfileService); + var profiles = profservice.profiles; + while (profiles.hasMoreElements()) { + let profile = profiles.getNext().QueryInterface(Ci.nsIToolkitProfile); + if (profile.rootDir.path == profd.path) { + return profile = profile.name; + } + } + + return profd.leafName; + } catch (e) { + return ""; + } +} + +function getAppIniString(section, key) { + let inifile = Services.dirsvc.get("GreD", Ci.nsIFile); + inifile.append("application.ini"); + + if (!inifile.exists()) { + inifile = Services.dirsvc.get("CurProcD", Ci.nsIFile); + inifile.append("application.ini"); + } + + if (!inifile.exists()) { + return undefined; + } + + let iniParser = Cc["@mozilla.org/xpcom/ini-parser-factory;1"].getService(Ci.nsIINIParserFactory).createINIParser(inifile); + try { + return iniParser.getString(section, key); + } catch (e) { + return undefined; + } +} + +/** + * Function for fetching screen dimensions and returning + * an enum for Telemetry. + */ +function getScreenDimensions() { + let width = {}; + let height = {}; + + screenManager.primaryScreen.GetRect({}, {}, width, height); + let dims = width.value + "x" + height.value; + + if (width.value < 800 || height.value < 600) { + return 0; + } + if (dims === "800x600") { + return 1; + } + if (dims === "1024x768") { + return 2; + } + if (dims === "1280x800") { + return 3; + } + if (dims === "1280x1024") { + return 4; + } + if (dims === "1366x768") { + return 5; + } + if (dims === "1440x900") { + return 6; + } + if (dims === "1920x1080") { + return 7; + } + if (dims === "2560×1440") { + return 8; + } + if (dims === "2560×1600") { + return 9; + } + if (dims === "2880x1800") { + return 10; + } + if (width.value > 2880 || height.value > 1800) { + return 12; + } + + // Other dimension such as a VM. + return 11; +} + +/** + * Function for fetching OS CPU and returning + * an enum for Telemetry. + */ +function getOSCPU() { + if (oscpu.includes("NT 5.1") || oscpu.includes("NT 5.2")) { + return 0; + } + if (oscpu.includes("NT 6.0")) { + return 1; + } + if (oscpu.includes("NT 6.1")) { + return 2; + } + if (oscpu.includes("NT 6.2")) { + return 3; + } + if (oscpu.includes("NT 6.3")) { + return 4; + } + if (oscpu.includes("OS X")) { + return 5; + } + if (oscpu.includes("Linux")) { + return 6; + } + if (oscpu.includes("NT 10.")) { + return 7; + } + // Other OS. + return 12; +} + +function getSetting(name) { + let deferred = defer(); + + if ("@mozilla.org/settingsService;1" in Cc) { + let settingsService; + + // settingsService fails in b2g child processes + // TODO bug 1205797, make this work in child processes. + try { + settingsService = Cc["@mozilla.org/settingsService;1"].getService(Ci.nsISettingsService); + } catch (e) { + return promise.reject(e); + } + + let req = settingsService.createLock().get(name, { + handle: (name, value) => deferred.resolve(value), + handleError: (error) => deferred.reject(error), + }); + } else { + deferred.reject(new Error("No settings service")); + } + return deferred.promise; +} + +exports.getSystemInfo = Task.async(getSystemInfo); +exports.getAppIniString = getAppIniString; +exports.getSetting = getSetting; +exports.getScreenDimensions = getScreenDimensions; +exports.getOSCPU = getOSCPU; +exports.constants = AppConstants; diff --git a/devtools/shared/task.js b/devtools/shared/task.js new file mode 100644 index 000000000..501e05e5b --- /dev/null +++ b/devtools/shared/task.js @@ -0,0 +1,515 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set ts=2 et sw=2 tw=80 filetype=javascript: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/* eslint-disable spaced-comment */ +/* globals StopIteration */ + +/** + * This module implements a subset of "Task.js" . + * It is a copy of toolkit/modules/Task.jsm. Please try not to + * diverge the API here. + * + * Paraphrasing from the Task.js site, tasks make sequential, asynchronous + * operations simple, using the power of JavaScript's "yield" operator. + * + * Tasks are built upon generator functions and promises, documented here: + * + * + * + * + * The "Task.spawn" function takes a generator function and starts running it as + * a task. Every time the task yields a promise, it waits until the promise is + * fulfilled. "Task.spawn" returns a promise that is resolved when the task + * completes successfully, or is rejected if an exception occurs. + * + * ----------------------------------------------------------------------------- + * + * const {Task} = require("devtools/shared/task"); + * + * Task.spawn(function* () { + * + * // This is our task. Let's create a promise object, wait on it and capture + * // its resolution value. + * let myPromise = getPromiseResolvedOnTimeoutWithValue(1000, "Value"); + * let result = yield myPromise; + * + * // This part is executed only after the promise above is fulfilled (after + * // one second, in this imaginary example). We can easily loop while + * // calling asynchronous functions, and wait multiple times. + * for (let i = 0; i < 3; i++) { + * result += yield getPromiseResolvedOnTimeoutWithValue(50, "!"); + * } + * + * return "Resolution result for the task: " + result; + * }).then(function (result) { + * + * // result == "Resolution result for the task: Value!!!" + * + * // The result is undefined if no value was returned. + * + * }, function (exception) { + * + * // Failure! We can inspect or report the exception. + * + * }); + * + * ----------------------------------------------------------------------------- + * + * This module implements only the "Task.js" interfaces described above, with no + * additional features to control the task externally, or do custom scheduling. + * It also provides the following extensions that simplify task usage in the + * most common cases: + * + * - The "Task.spawn" function also accepts an iterator returned by a generator + * function, in addition to a generator function. This way, you can call into + * the generator function with the parameters you want, and with "this" bound + * to the correct value. Also, "this" is never bound to the task object when + * "Task.spawn" calls the generator function. + * + * - In addition to a promise object, a task can yield the iterator returned by + * a generator function. The iterator is turned into a task automatically. + * This reduces the syntax overhead of calling "Task.spawn" explicitly when + * you want to recurse into other task functions. + * + * - The "Task.spawn" function also accepts a primitive value, or a function + * returning a primitive value, and treats the value as the result of the + * task. This makes it possible to call an externally provided function and + * spawn a task from it, regardless of whether it is an asynchronous generator + * or a synchronous function. This comes in handy when iterating over + * function lists where some items have been converted to tasks and some not. + */ + +//////////////////////////////////////////////////////////////////////////////// +//// Globals + +const Promise = require("promise"); +const defer = require("devtools/shared/defer"); + +// The following error types are considered programmer errors, which should be +// reported (possibly redundantly) so as to let programmers fix their code. +const ERRORS_TO_REPORT = ["EvalError", "RangeError", "ReferenceError", + "TypeError"]; + +/** + * The Task currently being executed + */ +var gCurrentTask = null; + +/** + * If `true`, capture stacks whenever entering a Task and rewrite the + * stack any exception thrown through a Task. + */ +var gMaintainStack = false; + +/** + * Iterate through the lines of a string. + * + * @return Iterator + */ +function* linesOf(string) { + let reLine = /([^\r\n])+/g; + let match; + while ((match = reLine.exec(string))) { + yield [match[0], match.index]; + } +} + +/** + * Detect whether a value is a generator. + * + * @param aValue + * The value to identify. + * @return A boolean indicating whether the value is a generator. + */ +function isGenerator(value) { + return Object.prototype.toString.call(value) == "[object Generator]"; +} + +//////////////////////////////////////////////////////////////////////////////// +//// Task + +/** + * This object provides the public module functions. + */ +var Task = { + /** + * Creates and starts a new task. + * + * @param task + * - If you specify a generator function, it is called with no + * arguments to retrieve the associated iterator. The generator + * function is a task, that is can yield promise objects to wait + * upon. + * - If you specify the iterator returned by a generator function you + * called, the generator function is also executed as a task. This + * allows you to call the function with arguments. + * - If you specify a function that is not a generator, it is called + * with no arguments, and its return value is used to resolve the + * returned promise. + * - If you specify anything else, you get a promise that is already + * resolved with the specified value. + * + * @return A promise object where you can register completion callbacks to be + * called when the task terminates. + */ + spawn: function (task) { + return createAsyncFunction(task).call(undefined); + }, + + /** + * Create and return an 'async function' that starts a new task. + * + * This is similar to 'spawn' except that it doesn't immediately start + * the task, it binds the task to the async function's 'this' object and + * arguments, and it requires the task to be a function. + * + * It simplifies the common pattern of implementing a method via a task, + * like this simple object with a 'greet' method that has a 'name' parameter + * and spawns a task to send a greeting and return its reply: + * + * let greeter = { + * message: "Hello, NAME!", + * greet: function(name) { + * return Task.spawn((function* () { + * return yield sendGreeting(this.message.replace(/NAME/, name)); + * }).bind(this); + * }) + * }; + * + * With Task.async, the method can be declared succinctly: + * + * let greeter = { + * message: "Hello, NAME!", + * greet: Task.async(function* (name) { + * return yield sendGreeting(this.message.replace(/NAME/, name)); + * }) + * }; + * + * While maintaining identical semantics: + * + * greeter.greet("Mitchell").then((reply) => { ... }); // behaves the same + * + * @param task + * The task function to start. + * + * @return A function that starts the task function and returns its promise. + */ + async: function (task) { + if (typeof (task) != "function") { + throw new TypeError("task argument must be a function"); + } + + return createAsyncFunction(task); + }, + + /** + * Constructs a special exception that, when thrown inside a legacy generator + * function (non-star generator), allows the associated task to be resolved + * with a specific value. + * + * Example: throw new Task.Result("Value"); + */ + Result: function (value) { + this.value = value; + } +}; + +function createAsyncFunction(task) { + let asyncFunction = function () { + let result = task; + if (task && typeof (task) == "function") { + if (task.isAsyncFunction) { + throw new TypeError( + "Cannot use an async function in place of a promise. " + + "You should either invoke the async function first " + + "or use 'Task.spawn' instead of 'Task.async' to start " + + "the Task and return its promise."); + } + + try { + // Let's call into the function ourselves. + result = task.apply(this, arguments); + } catch (ex) { + if (ex instanceof Task.Result) { + return Promise.resolve(ex.value); + } + return Promise.reject(ex); + } + } + + if (isGenerator(result)) { + // This is an iterator resulting from calling a generator function. + return new TaskImpl(result).deferred.promise; + } + + // Just propagate the given value to the caller as a resolved promise. + return Promise.resolve(result); + }; + + asyncFunction.isAsyncFunction = true; + + return asyncFunction; +} + +//////////////////////////////////////////////////////////////////////////////// +//// TaskImpl + +/** + * Executes the specified iterator as a task, and gives access to the promise + * that is fulfilled when the task terminates. + */ +function TaskImpl(iterator) { + if (gMaintainStack) { + this._stack = (new Error()).stack; + } + this.deferred = defer(); + this._iterator = iterator; + this._isStarGenerator = !("send" in iterator); + this._run(true); +} + +TaskImpl.prototype = { + /** + * Includes the promise object where task completion callbacks are registered, + * and methods to resolve or reject the promise at task completion. + */ + deferred: null, + + /** + * The iterator returned by the generator function associated with this task. + */ + _iterator: null, + + /** + * Whether this Task is using a star generator. + */ + _isStarGenerator: false, + + /** + * Main execution routine, that calls into the generator function. + * + * @param sendResolved + * If true, indicates that we should continue into the generator + * function regularly (if we were waiting on a promise, it was + * resolved). If true, indicates that we should cause an exception to + * be thrown into the generator function (if we were waiting on a + * promise, it was rejected). + * @param sendValue + * Resolution result or rejection exception, if any. + */ + _run: function (sendResolved, sendValue) { + try { + gCurrentTask = this; + + if (this._isStarGenerator) { + try { + let result = sendResolved ? this._iterator.next(sendValue) + : this._iterator.throw(sendValue); + + if (result.done) { + // The generator function returned. + this.deferred.resolve(result.value); + } else { + // The generator function yielded. + this._handleResultValue(result.value); + } + } catch (ex) { + // The generator function failed with an uncaught exception. + this._handleException(ex); + } + } else { + try { + let yielded = sendResolved ? this._iterator.send(sendValue) + : this._iterator.throw(sendValue); + this._handleResultValue(yielded); + } catch (ex) { + if (ex instanceof Task.Result) { + // The generator function threw the special exception that + // allows it to return a specific value on resolution. + this.deferred.resolve(ex.value); + } else if (ex instanceof StopIteration) { + // The generator function terminated with no specific result. + this.deferred.resolve(undefined); + } else { + // The generator function failed with an uncaught exception. + this._handleException(ex); + } + } + } + } finally { + // + // At this stage, the Task may have finished executing, or have + // walked through a `yield` or passed control to a sub-Task. + // Regardless, if we still own `gCurrentTask`, reset it. If we + // have not finished execution of this Task, re-entering `_run` + // will set `gCurrentTask` to `this` as needed. + // + // We just need to be careful here in case we hit the following + // pattern: + // + // Task.spawn(foo); + // Task.spawn(bar); + // + // Here, `foo` and `bar` may be interleaved, so when we finish + // executing `foo`, `gCurrentTask` may actually either `foo` or + // `bar`. If `gCurrentTask` has already been set to `bar`, leave + // it be and it will be reset to `null` once `bar` is complete. + // + if (gCurrentTask == this) { + gCurrentTask = null; + } + } + }, + + /** + * Handle a value yielded by a generator. + * + * @param value + * The yielded value to handle. + */ + _handleResultValue: function (value) { + // If our task yielded an iterator resulting from calling another + // generator function, automatically spawn a task from it, effectively + // turning it into a promise that is fulfilled on task completion. + if (isGenerator(value)) { + value = Task.spawn(value); + } + + if (value && typeof (value.then) == "function") { + // We have a promise object now. When fulfilled, call again into this + // function to continue the task, with either a resolution or rejection + // condition. + value.then(this._run.bind(this, true), + this._run.bind(this, false)); + } else { + // If our task yielded a value that is not a promise, just continue and + // pass it directly as the result of the yield statement. + this._run(true, value); + } + }, + + /** + * Handle an uncaught exception thrown from a generator. + * + * @param exception + * The uncaught exception to handle. + */ + _handleException: function (exception) { + gCurrentTask = this; + + if (exception && typeof exception == "object" && "stack" in exception) { + let stack = exception.stack; + + if (gMaintainStack && + exception._capturedTaskStack != this._stack && + typeof stack == "string") { + // Rewrite the stack for more readability. + + let bottomStack = this._stack; + + stack = Task.Debugging.generateReadableStack(stack); + + exception.stack = stack; + + // If exception is reinjected in the same task and rethrown, + // we don't want to perform the rewrite again. + exception._capturedTaskStack = bottomStack; + } else if (!stack) { + stack = "Not available"; + } + + if ("name" in exception && + ERRORS_TO_REPORT.indexOf(exception.name) != -1) { + // We suspect that the exception is a programmer error, so we now + // display it using dump(). Note that we do not use Cu.reportError as + // we assume that this is a programming error, so we do not want end + // users to see it. Also, if the programmer handles errors correctly, + // they will either treat the error or log them somewhere. + + dump("*************************\n"); + dump("A coding exception was thrown and uncaught in a Task.\n\n"); + dump("Full message: " + exception + "\n"); + dump("Full stack: " + exception.stack + "\n"); + dump("*************************\n"); + } + } + + this.deferred.reject(exception); + }, + + get callerStack() { + // Cut `this._stack` at the last line of the first block that + // contains task.js, keep the tail. + for (let [line, index] of linesOf(this._stack || "")) { + if (line.indexOf("/task.js:") == -1) { + return this._stack.substring(index); + } + } + return ""; + } +}; + +Task.Debugging = { + + /** + * Control stack rewriting. + * + * If `true`, any exception thrown from a Task will be rewritten to + * provide a human-readable stack trace. Otherwise, stack traces will + * be left unchanged. + * + * There is a (small but existing) runtime cost associated to stack + * rewriting, so you should probably not activate this in production + * code. + * + * @type {bool} + */ + get maintainStack() { + return gMaintainStack; + }, + set maintainStack(x) { + if (!x) { + gCurrentTask = null; + } + gMaintainStack = x; + return x; + }, + + /** + * Generate a human-readable stack for an error raised in + * a Task. + * + * @param {string} topStack The stack provided by the error. + * @param {string=} prefix Optionally, a prefix for each line. + */ + generateReadableStack: function (topStack, prefix = "") { + if (!gCurrentTask) { + return topStack; + } + + // Cut `topStack` at the first line that contains task.js, keep the head. + let lines = []; + for (let [line] of linesOf(topStack)) { + if (line.indexOf("/task.js:") != -1) { + break; + } + lines.push(prefix + line); + } + if (!prefix) { + lines.push(gCurrentTask.callerStack); + } else { + for (let [line] of linesOf(gCurrentTask.callerStack)) { + lines.push(prefix + line); + } + } + + return lines.join("\n"); + } +}; + +exports.Task = Task; diff --git a/devtools/shared/tests/browser/.eslintrc.js b/devtools/shared/tests/browser/.eslintrc.js new file mode 100644 index 000000000..8d15a76d9 --- /dev/null +++ b/devtools/shared/tests/browser/.eslintrc.js @@ -0,0 +1,6 @@ +"use strict"; + +module.exports = { + // Extend from the shared list of defined globals for mochitests. + "extends": "../../../.eslintrc.mochitests.js" +}; diff --git a/devtools/shared/tests/browser/browser.ini b/devtools/shared/tests/browser/browser.ini new file mode 100644 index 000000000..4acac6521 --- /dev/null +++ b/devtools/shared/tests/browser/browser.ini @@ -0,0 +1,8 @@ +[DEFAULT] +tags = devtools +subsuite = devtools +support-files = + ../../../server/tests/browser/head.js + +[browser_async_storage.js] +[browser_l10n_localizeMarkup.js] diff --git a/devtools/shared/tests/browser/browser_async_storage.js b/devtools/shared/tests/browser/browser_async_storage.js new file mode 100644 index 000000000..4329d639a --- /dev/null +++ b/devtools/shared/tests/browser/browser_async_storage.js @@ -0,0 +1,77 @@ +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test the basic functionality of async-storage. +// Adapted from https://github.com/mozilla-b2g/gaia/blob/f09993563fb5fec4393eb71816ce76cb00463190/apps/sharedtest/test/unit/async_storage_test.js. + +const asyncStorage = require("devtools/shared/async-storage"); +add_task(function* () { + is(typeof asyncStorage.length, "function", "API exists."); + is(typeof asyncStorage.key, "function", "API exists."); + is(typeof asyncStorage.getItem, "function", "API exists."); + is(typeof asyncStorage.setItem, "function", "API exists."); + is(typeof asyncStorage.removeItem, "function", "API exists."); + is(typeof asyncStorage.clear, "function", "API exists."); +}); + +add_task(function* () { + yield asyncStorage.setItem("foo", "bar"); + let value = yield asyncStorage.getItem("foo"); + is(value, "bar", "value is correct"); + yield asyncStorage.setItem("foo", "overwritten"); + value = yield asyncStorage.getItem("foo"); + is(value, "overwritten", "value is correct"); + yield asyncStorage.removeItem("foo"); + value = yield asyncStorage.getItem("foo"); + is(value, null, "value is correct"); +}); + +add_task(function* () { + var object = { + x: 1, + y: "foo", + z: true + }; + + yield asyncStorage.setItem("myobj", object); + let value = yield asyncStorage.getItem("myobj"); + is(object.x, value.x, "value is correct"); + is(object.y, value.y, "value is correct"); + is(object.z, value.z, "value is correct"); + yield asyncStorage.removeItem("myobj"); + value = yield asyncStorage.getItem("myobj"); + is(value, null, "value is correct"); +}); + +add_task(function* () { + yield asyncStorage.clear(); + let len = yield asyncStorage.length(); + is(len, 0, "length is correct"); + yield asyncStorage.setItem("key1", "value1"); + len = yield asyncStorage.length(); + is(len, 1, "length is correct"); + yield asyncStorage.setItem("key2", "value2"); + len = yield asyncStorage.length(); + is(len, 2, "length is correct"); + yield asyncStorage.setItem("key3", "value3"); + len = yield asyncStorage.length(); + is(len, 3, "length is correct"); + + let key = yield asyncStorage.key(0); + is(key, "key1", "key is correct"); + key = yield asyncStorage.key(1); + is(key, "key2", "key is correct"); + key = yield asyncStorage.key(2); + is(key, "key3", "key is correct"); + key = yield asyncStorage.key(3); + is(key, null, "key is correct"); + yield asyncStorage.clear(); + key = yield asyncStorage.key(0); + is(key, null, "key is correct"); + + len = yield asyncStorage.length(); + is(len, 0, "length is correct"); +}); diff --git a/devtools/shared/tests/browser/browser_l10n_localizeMarkup.js b/devtools/shared/tests/browser/browser_l10n_localizeMarkup.js new file mode 100644 index 000000000..f33a5a331 --- /dev/null +++ b/devtools/shared/tests/browser/browser_l10n_localizeMarkup.js @@ -0,0 +1,54 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Tests that the markup localization works properly. + +const { localizeMarkup, LocalizationHelper } = require("devtools/shared/l10n"); + +add_task(function* () { + info("Check that the strings used for this test are still valid"); + let STARTUP_L10N = new LocalizationHelper("devtools/client/locales/startup.properties"); + let TOOLBOX_L10N = new LocalizationHelper("devtools/client/locales/toolbox.properties"); + let str1 = STARTUP_L10N.getStr("inspector.label"); + let str2 = STARTUP_L10N.getStr("inspector.commandkey"); + let str3 = TOOLBOX_L10N.getStr("toolbox.defaultTitle"); + ok(str1 && str2 && str3, "If this failed, strings should be updated in the test"); + + info("Create the test markup"); + let div = document.createElement("div"); + div.innerHTML = + `
+
+
Text will disappear
+
+
+ +
+
Some content
+
+
+
+
+ `; + + info("Use localization helper to localize the test markup"); + localizeMarkup(div); + + let div1 = div.querySelector("#d1"); + let div2 = div.querySelector("#d2"); + let div3 = div.querySelector("#d3"); + let div4 = div.querySelector("#d4"); + let div5 = div.querySelector("#d5"); + + is(div1.innerHTML, str1, "The content of #d1 is localized"); + is(div2.innerHTML, str1, "The content of #d2 is localized"); + is(div2.getAttribute("title"), str2, "The title of #d2 is localized"); + is(div3.innerHTML, str1, "The content of #d3 is localized"); + is(div3.getAttribute("title"), str2, "The title of #d3 is localized"); + is(div4.innerHTML, "Some content", "The content of #d4 is not replaced"); + is(div4.getAttribute("aria-label"), str1, "The aria-label of #d4 is localized"); + is(div5.innerHTML, str3, "The content of #d5 is localized with another bundle"); +}); diff --git a/devtools/shared/tests/mochitest/chrome.ini b/devtools/shared/tests/mochitest/chrome.ini new file mode 100644 index 000000000..85ece7c48 --- /dev/null +++ b/devtools/shared/tests/mochitest/chrome.ini @@ -0,0 +1,7 @@ +[DEFAULT] +tags = devtools +skip-if = os == 'android' + +[test_eventemitter_basic.html] +[test_devtools_extensions.html] +skip-if = os == 'linux' && debug # Bug 1205739 diff --git a/devtools/shared/tests/mochitest/test_devtools_extensions.html b/devtools/shared/tests/mochitest/test_devtools_extensions.html new file mode 100644 index 000000000..04cc82b22 --- /dev/null +++ b/devtools/shared/tests/mochitest/test_devtools_extensions.html @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + diff --git a/devtools/shared/tests/mochitest/test_eventemitter_basic.html b/devtools/shared/tests/mochitest/test_eventemitter_basic.html new file mode 100644 index 000000000..9826eebca --- /dev/null +++ b/devtools/shared/tests/mochitest/test_eventemitter_basic.html @@ -0,0 +1,194 @@ + + + + + + + + + + + + + + + + + + diff --git a/devtools/shared/tests/unit/.eslintrc.js b/devtools/shared/tests/unit/.eslintrc.js new file mode 100644 index 000000000..012428019 --- /dev/null +++ b/devtools/shared/tests/unit/.eslintrc.js @@ -0,0 +1,6 @@ +"use strict"; + +module.exports = { + // Extend from the common devtools xpcshell eslintrc config. + "extends": "../../../.eslintrc.xpcshell.js" +}; diff --git a/devtools/shared/tests/unit/exposeLoader.js b/devtools/shared/tests/unit/exposeLoader.js new file mode 100644 index 000000000..949640a03 --- /dev/null +++ b/devtools/shared/tests/unit/exposeLoader.js @@ -0,0 +1,8 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +exports.exerciseLazyRequire = (name, path) => { + const o = {}; + loader.lazyRequireGetter(o, name, path); + return o; +}; diff --git a/devtools/shared/tests/unit/head_devtools.js b/devtools/shared/tests/unit/head_devtools.js new file mode 100644 index 000000000..f0f47c93a --- /dev/null +++ b/devtools/shared/tests/unit/head_devtools.js @@ -0,0 +1,60 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cu = Components.utils; +var Cr = Components.results; + +const {require, DevToolsLoader, devtools} = Cu.import("resource://devtools/shared/Loader.jsm", {}); +const DevToolsUtils = require("devtools/shared/DevToolsUtils"); +const flags = require("devtools/shared/flags"); + +flags.testing = true; +do_register_cleanup(() => { + flags.testing = false; +}); + +// Register a console listener, so console messages don't just disappear +// into the ether. + +// If for whatever reason the test needs to post console errors that aren't +// failures, set this to true. +var ALLOW_CONSOLE_ERRORS = false; + +var errorCount = 0; +var listener = { + observe: function (aMessage) { + errorCount++; + try { + // If we've been given an nsIScriptError, then we can print out + // something nicely formatted, for tools like Emacs to pick up. + var scriptError = aMessage.QueryInterface(Ci.nsIScriptError); + dump(aMessage.sourceName + ":" + aMessage.lineNumber + ": " + + scriptErrorFlagsToKind(aMessage.flags) + ": " + + aMessage.errorMessage + "\n"); + var string = aMessage.errorMessage; + } catch (x) { + // Be a little paranoid with message, as the whole goal here is to lose + // no information. + try { + var string = "" + aMessage.message; + } catch (x) { + var string = ""; + } + } + + // Make sure we exit all nested event loops so that the test can finish. + while (DebuggerServer.xpcInspector.eventLoopNestLevel > 0) { + DebuggerServer.xpcInspector.exitNestedEventLoop(); + } + + if (!ALLOW_CONSOLE_ERRORS) { + do_throw("head_devtools.js got console message: " + string + "\n"); + } + } +}; + +var consoleService = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService); +consoleService.registerListener(listener); diff --git a/devtools/shared/tests/unit/test_assert.js b/devtools/shared/tests/unit/test_assert.js new file mode 100644 index 000000000..b87171751 --- /dev/null +++ b/devtools/shared/tests/unit/test_assert.js @@ -0,0 +1,36 @@ +/* -*- js-indent-level: 2; indent-tabs-mode: nil -*- */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test DevToolsUtils.assert + +ALLOW_CONSOLE_ERRORS = true; + +function run_test() { + // Enable assertions. + flags.testing = true; + + const { assert } = DevToolsUtils; + equal(typeof assert, "function"); + + try { + assert(true, "this assertion should not fail"); + } catch (e) { + // If you catch assertion failures in practice, I will hunt you down. I get + // email notifications every time it happens. + ok(false, "Should not get an error for an assertion that should not fail. Got " + + DevToolsUtils.safeErrorString(e)); + } + + let assertionFailed = false; + try { + assert(false, "this assertion should fail"); + } catch (e) { + ok(e.message.startsWith("Assertion failure:"), + "Should be an assertion failure error"); + assertionFailed = true; + } + + ok(assertionFailed, + "The assertion should have failed, which should throw an error when assertions are enabled."); +} diff --git a/devtools/shared/tests/unit/test_async-utils.js b/devtools/shared/tests/unit/test_async-utils.js new file mode 100644 index 000000000..2b09b8260 --- /dev/null +++ b/devtools/shared/tests/unit/test_async-utils.js @@ -0,0 +1,157 @@ +/* -*- js-indent-level: 2; indent-tabs-mode: nil -*- */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test async-utils.js + +const {Task} = require("devtools/shared/task"); +// |const| will not work because +// it will make the Promise object immutable before assigning. +// Using Object.defineProperty() instead. +Object.defineProperty(this, "Promise", { + value: require("promise"), + writable: false, configurable: false +}); +const {asyncOnce, promiseInvoke, promiseCall} = require("devtools/shared/async-utils"); + +function run_test() { + do_test_pending(); + Task.spawn(function* () { + yield test_async_args(asyncOnce); + yield test_async_return(asyncOnce); + yield test_async_throw(asyncOnce); + + yield test_async_once(); + yield test_async_invoke(); + do_test_finished(); + }).then(null, error => { + do_throw(error); + }); +} + +// Test that arguments are correctly passed through to the async function. +function test_async_args(async) { + let obj = { + method: async(function* (a, b) { + do_check_eq(this, obj); + do_check_eq(a, "foo"); + do_check_eq(b, "bar"); + }) + }; + + return obj.method("foo", "bar"); +} + +// Test that the return value from the async function is resolution value of +// the promise. +function test_async_return(async) { + let obj = { + method: async(function* (a, b) { + return a + b; + }) + }; + + return obj.method("foo", "bar").then(ret => { + do_check_eq(ret, "foobar"); + }); +} + +// Test that the throwing from an async function rejects the promise. +function test_async_throw(async) { + let obj = { + method: async(function* () { + throw "boom"; + }) + }; + + return obj.method().then(null, error => { + do_check_eq(error, "boom"); + }); +} + +// Test that asyncOnce only runs the async function once per instance and +// returns the same promise for that instance. +function test_async_once() { + let counter = 0; + + function Foo() {} + Foo.prototype = { + ran: false, + method: asyncOnce(function* () { + yield Promise.resolve(); + if (this.ran) { + do_throw("asyncOnce function unexpectedly ran twice on the same object"); + } + this.ran = true; + return counter++; + }) + }; + + let foo1 = new Foo(); + let foo2 = new Foo(); + let p1 = foo1.method(); + let p2 = foo2.method(); + + do_check_neq(p1, p2); + + let p3 = foo1.method(); + do_check_eq(p1, p3); + do_check_false(foo1.ran); + + let p4 = foo2.method(); + do_check_eq(p2, p4); + do_check_false(foo2.ran); + + return p1.then(ret => { + do_check_true(foo1.ran); + do_check_eq(ret, 0); + return p2; + }).then(ret => { + do_check_true(foo2.ran); + do_check_eq(ret, 1); + }); +} + +// Test invoke and call. +function test_async_invoke() { + return Task.spawn(function* () { + function func(a, b, expectedThis, callback) { + "use strict"; + do_check_eq(a, "foo"); + do_check_eq(b, "bar"); + do_check_eq(this, expectedThis); + callback(a + b); + } + + // Test call. + let callResult = yield promiseCall(func, "foo", "bar", undefined); + do_check_eq(callResult, "foobar"); + + + // Test invoke. + let obj = { method: func }; + let invokeResult = yield promiseInvoke(obj, obj.method, "foo", "bar", obj); + do_check_eq(invokeResult, "foobar"); + + + // Test passing multiple values to the callback. + function multipleResults(callback) { + callback("foo", "bar"); + } + + let results = yield promiseCall(multipleResults); + do_check_eq(results.length, 2); + do_check_eq(results[0], "foo"); + do_check_eq(results[1], "bar"); + + + // Test throwing from the function. + function thrower() { + throw "boom"; + } + + yield promiseCall(thrower).then(null, error => { + do_check_eq(error, "boom"); + }); + }); +} diff --git a/devtools/shared/tests/unit/test_console_filtering.js b/devtools/shared/tests/unit/test_console_filtering.js new file mode 100644 index 000000000..431e2b234 --- /dev/null +++ b/devtools/shared/tests/unit/test_console_filtering.js @@ -0,0 +1,133 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { console, ConsoleAPI } = require("resource://gre/modules/Console.jsm"); +const { ConsoleAPIListener } = require("devtools/server/actors/utils/webconsole-utils"); +const Services = require("Services"); + +var seenMessages = 0; +var seenTypes = 0; + +var callback = { + onConsoleAPICall: function (aMessage) { + if (aMessage.consoleID && aMessage.consoleID == "addon/foo") { + do_check_eq(aMessage.level, "warn"); + do_check_eq(aMessage.arguments[0], "Warning from foo"); + seenTypes |= 1; + } else if (aMessage.originAttributes && + aMessage.originAttributes.addonId == "bar") { + do_check_eq(aMessage.level, "error"); + do_check_eq(aMessage.arguments[0], "Error from bar"); + seenTypes |= 2; + } else { + do_check_eq(aMessage.level, "log"); + do_check_eq(aMessage.arguments[0], "Hello from default console"); + seenTypes |= 4; + } + seenMessages++; + } +}; + +function createFakeAddonWindow({addonId} = {}) { + let baseURI = Services.io.newURI("about:blank", null, null); + let originAttributes = {addonId}; + let principal = Services.scriptSecurityManager + .createCodebasePrincipal(baseURI, originAttributes); + let chromeWebNav = Services.appShell.createWindowlessBrowser(true); + let docShell = chromeWebNav.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDocShell); + docShell.createAboutBlankContentViewer(principal); + let addonWindow = docShell.contentViewer.DOMDocument.defaultView; + + return {addonWindow, chromeWebNav}; +} + +/** + * Tests that the consoleID property of the ConsoleAPI options gets passed + * through to console messages. + */ +function run_test() { + // console1 Test Console.jsm messages tagged by the Addon SDK + // are still filtered correctly. + let console1 = new ConsoleAPI({ + consoleID: "addon/foo" + }); + + // console2 - WebExtension page's console messages tagged + // by 'originAttributes.addonId' are filtered correctly. + let {addonWindow, chromeWebNav} = createFakeAddonWindow({addonId: "bar"}); + let console2 = addonWindow.console; + + // console - Plain console object (messages are tagged with window ids + // and originAttributes, but the addonId will be empty). + console.log("Hello from default console"); + + console1.warn("Warning from foo"); + console2.error("Error from bar"); + + let listener = new ConsoleAPIListener(null, callback); + listener.init(); + let messages = listener.getCachedMessages(); + + seenTypes = 0; + seenMessages = 0; + messages.forEach(callback.onConsoleAPICall); + do_check_eq(seenMessages, 3); + do_check_eq(seenTypes, 7); + + seenTypes = 0; + seenMessages = 0; + console.log("Hello from default console"); + console1.warn("Warning from foo"); + console2.error("Error from bar"); + do_check_eq(seenMessages, 3); + do_check_eq(seenTypes, 7); + + listener.destroy(); + + listener = new ConsoleAPIListener(null, callback, {addonId: "foo"}); + listener.init(); + messages = listener.getCachedMessages(); + + seenTypes = 0; + seenMessages = 0; + messages.forEach(callback.onConsoleAPICall); + do_check_eq(seenMessages, 2); + do_check_eq(seenTypes, 1); + + seenTypes = 0; + seenMessages = 0; + console.log("Hello from default console"); + console1.warn("Warning from foo"); + console2.error("Error from bar"); + do_check_eq(seenMessages, 1); + do_check_eq(seenTypes, 1); + + listener.destroy(); + + listener = new ConsoleAPIListener(null, callback, {addonId: "bar"}); + listener.init(); + messages = listener.getCachedMessages(); + + seenTypes = 0; + seenMessages = 0; + messages.forEach(callback.onConsoleAPICall); + do_check_eq(seenMessages, 3); + do_check_eq(seenTypes, 2); + + seenTypes = 0; + seenMessages = 0; + console.log("Hello from default console"); + console1.warn("Warning from foo"); + console2.error("Error from bar"); + + do_check_eq(seenMessages, 1); + do_check_eq(seenTypes, 2); + + listener.destroy(); + + // Close the addon window's chromeWebNav. + chromeWebNav.close(); +} diff --git a/devtools/shared/tests/unit/test_css-properties-db.js b/devtools/shared/tests/unit/test_css-properties-db.js new file mode 100644 index 000000000..108650a3e --- /dev/null +++ b/devtools/shared/tests/unit/test_css-properties-db.js @@ -0,0 +1,136 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * Test that the devtool's client-side CSS properties database is in sync with the values + * on the platform (in Nightly only). If they are not, then `mach devtools-css-db` needs + * to be run to make everything up to date. Nightly, aurora, beta, and release may have + * different CSS properties and values. These are based on preferences and compiler flags. + * + * This test broke uplifts as the database needed to be regenerated every uplift. The + * combination of compiler flags and preferences means that it's too difficult to + * statically determine which properties are enabled between Firefox releases. + * + * Because of these difficulties, the database only needs to be up to date with Nightly. + * It is a fallback that is only used if the remote debugging protocol doesn't support + * providing a CSS database, so it's ok if the provided properties don't exactly match + * the inspected target in this particular case. + */ + +"use strict"; + +const DOMUtils = Components.classes["@mozilla.org/inspector/dom-utils;1"] + .getService(Components.interfaces.inIDOMUtils); + +const {PSEUDO_ELEMENTS, CSS_PROPERTIES} = require("devtools/shared/css/generated/properties-db"); +const {generateCssProperties} = require("devtools/server/actors/css-properties"); + +function run_test() { + const propertiesErrorMessage = "If this assertion fails, then the client side CSS " + + "properties list in devtools is out of sync with the " + + "CSS properties on the platform. To fix this " + + "assertion run `mach devtools-css-db` to re-generate " + + "the client side properties."; + + // Check that the platform and client match for pseudo elements. + deepEqual(PSEUDO_ELEMENTS, DOMUtils.getCSSPseudoElementNames(), `The pseudo elements ` + + `match on the client and platform. ${propertiesErrorMessage}`); + + /** + * Check that the platform and client match for the details on their CSS properties. + * Enumerate each property to aid in debugging. + */ + const platformProperties = generateCssProperties(); + + for (let propertyName in CSS_PROPERTIES) { + const platformProperty = platformProperties[propertyName]; + const clientProperty = CSS_PROPERTIES[propertyName]; + const deepEqual = isJsonDeepEqual(platformProperty, clientProperty); + + if (deepEqual) { + ok(true, `The static database and platform match for "${propertyName}".`); + } else { + const prefMessage = `The static database and platform do not match ` + + `for "${propertyName}".`; + if (getPreference(propertyName) === false) { + ok(true, `${prefMessage} However, there is a preference for disabling this ` + + `property on the current build.`); + } else { + ok(false, `${prefMessage} ${propertiesErrorMessage}`); + } + } + } + + /** + * Check that the list of properties on the platform and client are the same. If + * they are not, check that there may be preferences that are disabling them on the + * target platform. + */ + const mismatches = getKeyMismatches(platformProperties, CSS_PROPERTIES) + // Filter out OS-specific properties. + .filter(name => name && name.indexOf("-moz-osx-") === -1); + + if (mismatches.length === 0) { + ok(true, "No client and platform CSS property database mismatches were found."); + } + + mismatches.forEach(propertyName => { + ok(false, `The static database and platform do not agree on the property ` + + `"${propertyName}" ${propertiesErrorMessage}`); + }); +} + +/** + * Check JSON-serializable objects for deep equality. + */ +function isJsonDeepEqual(a, b) { + // Handle primitives. + if (a === b) { + return true; + } + + // Handle arrays. + if (Array.isArray(a) && Array.isArray(b)) { + if (a.length !== b.length) { + return false; + } + for (let i = 0; i < a.length; i++) { + if (!isJsonDeepEqual(a[i], b[i])) { + return false; + } + } + return true; + } + + // Handle objects + if (typeof a === "object" && typeof b === "object") { + for (let key in a) { + if (!isJsonDeepEqual(a[key], b[key])) { + return false; + } + } + + return Object.keys(a).length === Object.keys(b).length; + } + + // Not something handled by these cases, therefore not equal. + return false; +} + +/** + * Take the keys of two objects, and return the ones that don't match. + * + * @param {Object} a + * @param {Object} b + * @return {Array} keys + */ +function getKeyMismatches(a, b) { + const aNames = Object.keys(a); + const bNames = Object.keys(b); + const aMismatches = aNames.filter(key => !bNames.includes(key)); + const bMismatches = bNames.filter(key => { + return !aNames.includes(key) && !aMismatches.includes(key); + }); + + return aMismatches.concat(bMismatches); +} diff --git a/devtools/shared/tests/unit/test_csslexer.js b/devtools/shared/tests/unit/test_csslexer.js new file mode 100644 index 000000000..35855640b --- /dev/null +++ b/devtools/shared/tests/unit/test_csslexer.js @@ -0,0 +1,242 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +// This file is a copy of layout/style/test/test_csslexer.js, modified +// to use both our pure-JS lexer and the DOMUtils lexer for +// cross-checking. + +"use strict"; + +const jsLexer = require("devtools/shared/css/lexer"); +const domutils = Components.classes["@mozilla.org/inspector/dom-utils;1"] + .getService(Components.interfaces.inIDOMUtils); + +// An object that acts like a CSSLexer but verifies that the DOM lexer +// and the JS lexer do the same thing. +function DoubleLexer(input) { + do_print("DoubleLexer input: " + input); + this.domLexer = domutils.getCSSLexer(input); + this.jsLexer = jsLexer.getCSSLexer(input); +} + +DoubleLexer.prototype = { + checkState: function () { + equal(this.domLexer.lineNumber, this.jsLexer.lineNumber, + "check line number"); + equal(this.domLexer.columnNumber, this.jsLexer.columnNumber, + "check column number"); + }, + + get lineNumber() { + return this.domLexer.lineNumber; + }, + + get columnNumber() { + return this.domLexer.columnNumber; + }, + + performEOFFixup: function (inputString, preserveBackslash) { + let d = this.domLexer.performEOFFixup(inputString, preserveBackslash); + let j = this.jsLexer.performEOFFixup(inputString, preserveBackslash); + + equal(d, j); + return d; + }, + + mungeNumber: function (token) { + if (token && (token.tokenType === "number" || + token.tokenType === "percentage") && + !token.isInteger) { + // The JS lexer does its computations in double, but the + // platform lexer does its computations in float. Account for + // this discrepancy in a way that's sufficient for this test. + // See https://bugzilla.mozilla.org/show_bug.cgi?id=1163047 + token.number = parseFloat(token.number.toPrecision(8)); + } + }, + + nextToken: function () { + // Check state both before and after. + this.checkState(); + + let d = this.domLexer.nextToken(); + let j = this.jsLexer.nextToken(); + + this.mungeNumber(d); + this.mungeNumber(j); + + deepEqual(d, j); + + this.checkState(); + + return d; + } +}; + +function test_lexer(cssText, tokenTypes) { + let lexer = new DoubleLexer(cssText); + let reconstructed = ""; + let lastTokenEnd = 0; + let i = 0; + while (true) { + let token = lexer.nextToken(); + if (!token) { + break; + } + let combined = token.tokenType; + if (token.text) { + combined += ":" + token.text; + } + equal(combined, tokenTypes[i]); + ok(token.endOffset > token.startOffset); + equal(token.startOffset, lastTokenEnd); + lastTokenEnd = token.endOffset; + reconstructed += cssText.substring(token.startOffset, token.endOffset); + ++i; + } + // Ensure that we saw the correct number of tokens. + equal(i, tokenTypes.length); + // Ensure that the reported offsets cover all the text. + equal(reconstructed, cssText); +} + +var LEX_TESTS = [ + ["simple", ["ident:simple"]], + ["simple: { hi; }", + ["ident:simple", "symbol::", + "whitespace", "symbol:{", + "whitespace", "ident:hi", + "symbol:;", "whitespace", + "symbol:}"]], + ["/* whatever */", ["comment"]], + ["'string'", ["string:string"]], + ['"string"', ["string:string"]], + ["rgb(1,2,3)", ["function:rgb", "number", + "symbol:,", "number", + "symbol:,", "number", + "symbol:)"]], + ["@media", ["at:media"]], + ["#hibob", ["id:hibob"]], + ["#123", ["hash:123"]], + ["23px", ["dimension:px"]], + ["23%", ["percentage"]], + ["url(http://example.com)", ["url:http://example.com"]], + ["url('http://example.com')", ["url:http://example.com"]], + ["url( 'http://example.com' )", + ["url:http://example.com"]], + // In CSS Level 3, this is an ordinary URL, not a BAD_URL. + ["url(http://example.com", ["url:http://example.com"]], + // See bug 1153981 to understand why this gets a SYMBOL token. + ["url(http://example.com @", ["bad_url:http://example.com", "symbol:@"]], + ["quo\\ting", ["ident:quoting"]], + ["'bad string\n", ["bad_string:bad string", "whitespace"]], + ["~=", ["includes"]], + ["|=", ["dashmatch"]], + ["^=", ["beginsmatch"]], + ["$=", ["endsmatch"]], + ["*=", ["containsmatch"]], + + // URANGE may be on the way out, and it isn't used by devutils, so + // let's skip it. + + ["", ["htmlcomment", "whitespace", "ident:html", + "whitespace", "ident:comment", "whitespace", + "htmlcomment"]], + + // earlier versions of CSS had "bad comment" tokens, but in level 3, + // unterminated comments are just comments. + ["/* bad comment", ["comment"]] +]; + +function test_lexer_linecol(cssText, locations) { + let lexer = new DoubleLexer(cssText); + let i = 0; + while (true) { + let token = lexer.nextToken(); + let startLine = lexer.lineNumber; + let startColumn = lexer.columnNumber; + + // We do this in a bit of a funny way so that we can also test the + // location of the EOF. + let combined = ":" + startLine + ":" + startColumn; + if (token) { + combined = token.tokenType + combined; + } + + equal(combined, locations[i]); + ++i; + + if (!token) { + break; + } + } + // Ensure that we saw the correct number of tokens. + equal(i, locations.length); +} + +function test_lexer_eofchar(cssText, argText, expectedAppend, + expectedNoAppend) { + let lexer = new DoubleLexer(cssText); + while (lexer.nextToken()) { + // Nothing. + } + + do_print("EOF char test, input = " + cssText); + + let result = lexer.performEOFFixup(argText, true); + equal(result, expectedAppend); + + result = lexer.performEOFFixup(argText, false); + equal(result, expectedNoAppend); +} + +var LINECOL_TESTS = [ + ["simple", ["ident:0:0", ":0:6"]], + ["\n stuff", ["whitespace:0:0", "ident:1:4", ":1:9"]], + ['"string with \\\nnewline" \r\n', ["string:0:0", "whitespace:1:8", + ":2:0"]] +]; + +var EOFCHAR_TESTS = [ + ["hello", "hello"], + ["hello \\", "hello \\\\", "hello \\\uFFFD"], + ["'hello", "'hello'"], + ["\"hello", "\"hello\""], + ["'hello\\", "'hello\\\\'", "'hello'"], + ["\"hello\\", "\"hello\\\\\"", "\"hello\""], + ["/*hello", "/*hello*/"], + ["/*hello*", "/*hello*/"], + ["/*hello\\", "/*hello\\*/"], + ["url(hello", "url(hello)"], + ["url('hello", "url('hello')"], + ["url(\"hello", "url(\"hello\")"], + ["url(hello\\", "url(hello\\\\)", "url(hello\\\uFFFD)"], + ["url('hello\\", "url('hello\\\\')", "url('hello')"], + ["url(\"hello\\", "url(\"hello\\\\\")", "url(\"hello\")"], +]; + +function run_test() { + let text, result; + for ([text, result] of LEX_TESTS) { + test_lexer(text, result); + } + + for ([text, result] of LINECOL_TESTS) { + test_lexer_linecol(text, result); + } + + let expectedAppend, expectedNoAppend; + for ([text, expectedAppend, expectedNoAppend] of EOFCHAR_TESTS) { + if (!expectedNoAppend) { + expectedNoAppend = expectedAppend; + } + test_lexer_eofchar(text, text, expectedAppend, expectedNoAppend); + } + + // Ensure that passing a different inputString to performEOFFixup + // doesn't cause an assertion trying to strip a backslash from the + // end of an empty string. + test_lexer_eofchar("'\\", "", "\\'", "'"); +} diff --git a/devtools/shared/tests/unit/test_defer.js b/devtools/shared/tests/unit/test_defer.js new file mode 100644 index 000000000..c0babe961 --- /dev/null +++ b/devtools/shared/tests/unit/test_defer.js @@ -0,0 +1,32 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const defer = require("devtools/shared/defer"); + +function testResolve() { + const deferred = defer(); + deferred.resolve("success"); + return deferred.promise; +} + +function testReject() { + const deferred = defer(); + deferred.reject("error"); + return deferred.promise; +} + +add_task(function* () { + const success = yield testResolve(); + equal(success, "success"); + + let error; + try { + yield testReject(); + } catch (e) { + error = e; + } + + equal(error, "error"); +}); diff --git a/devtools/shared/tests/unit/test_defineLazyPrototypeGetter.js b/devtools/shared/tests/unit/test_defineLazyPrototypeGetter.js new file mode 100644 index 000000000..d729e7473 --- /dev/null +++ b/devtools/shared/tests/unit/test_defineLazyPrototypeGetter.js @@ -0,0 +1,68 @@ +/* -*- js-indent-level: 2; indent-tabs-mode: nil -*- */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test DevToolsUtils.defineLazyPrototypeGetter + +function Class() {} +DevToolsUtils.defineLazyPrototypeGetter(Class.prototype, "foo", () => []); + + +function run_test() { + test_prototype_attributes(); + test_instance_attributes(); + test_multiple_instances(); + test_callback_receiver(); +} + +function test_prototype_attributes() { + // Check that the prototype has a getter property with expected attributes. + let descriptor = Object.getOwnPropertyDescriptor(Class.prototype, "foo"); + do_check_eq(typeof descriptor.get, "function"); + do_check_eq(descriptor.set, undefined); + do_check_eq(descriptor.enumerable, false); + do_check_eq(descriptor.configurable, true); +} + +function test_instance_attributes() { + // Instances should not have an own property until the lazy getter has been + // activated. + let instance = new Class(); + do_check_false(instance.hasOwnProperty("foo")); + instance.foo; + do_check_true(instance.hasOwnProperty("foo")); + + // Check that the instance has an own property with the expecred value and + // attributes after the lazy getter is activated. + let descriptor = Object.getOwnPropertyDescriptor(instance, "foo"); + do_check_true(descriptor.value instanceof Array); + do_check_eq(descriptor.writable, true); + do_check_eq(descriptor.enumerable, false); + do_check_eq(descriptor.configurable, true); +} + +function test_multiple_instances() { + let instance1 = new Class(); + let instance2 = new Class(); + let foo1 = instance1.foo; + let foo2 = instance2.foo; + // Check that the lazy getter returns the expected type of value. + do_check_true(foo1 instanceof Array); + do_check_true(foo2 instanceof Array); + // Make sure the lazy getter runs once and only once per instance. + do_check_eq(instance1.foo, foo1); + do_check_eq(instance2.foo, foo2); + // Make sure each instance gets its own unique value. + do_check_neq(foo1, foo2); +} + +function test_callback_receiver() { + function Foo() {} + DevToolsUtils.defineLazyPrototypeGetter(Foo.prototype, "foo", function () { + return this; + }); + + // Check that the |this| value in the callback is the instance itself. + let instance = new Foo(); + do_check_eq(instance.foo, instance); +} diff --git a/devtools/shared/tests/unit/test_executeSoon.js b/devtools/shared/tests/unit/test_executeSoon.js new file mode 100644 index 000000000..6154a3e67 --- /dev/null +++ b/devtools/shared/tests/unit/test_executeSoon.js @@ -0,0 +1,48 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +/** + * Client request stacks should span the entire process from before making the + * request to handling the reply from the server. The server frames are not + * included, nor can they be in most cases, since the server can be a remote + * device. + */ + +var { executeSoon } = require("devtools/shared/DevToolsUtils"); +var promise = require("promise"); +var defer = require("devtools/shared/defer"); +var Services = require("Services"); + +var asyncStackEnabled = + Services.prefs.getBoolPref("javascript.options.asyncstack"); + +do_register_cleanup(() => { + Services.prefs.setBoolPref("javascript.options.asyncstack", + asyncStackEnabled); +}); + +add_task(function* () { + Services.prefs.setBoolPref("javascript.options.asyncstack", true); + + yield waitForTick(); + + let stack = Components.stack; + while (stack) { + do_print(stack.name); + if (stack.name == "waitForTick") { + // Reached back to outer function before executeSoon + ok(true, "Complete stack"); + return; + } + stack = stack.asyncCaller || stack.caller; + } + ok(false, "Incomplete stack"); +}); + +function waitForTick() { + let deferred = defer(); + executeSoon(deferred.resolve); + return deferred.promise; +} diff --git a/devtools/shared/tests/unit/test_fetch-bom.js b/devtools/shared/tests/unit/test_fetch-bom.js new file mode 100644 index 000000000..7f299b1ce --- /dev/null +++ b/devtools/shared/tests/unit/test_fetch-bom.js @@ -0,0 +1,76 @@ +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +// Tests for DevToolsUtils.fetch BOM detection. + +const CC = Components.Constructor; + +const { HttpServer } = Cu.import("resource://testing-common/httpd.js", {}); +const BinaryOutputStream = CC("@mozilla.org/binaryoutputstream;1", + "nsIBinaryOutputStream", "setOutputStream"); + +function write8(bos) { + bos.write8(0xef); + bos.write8(0xbb); + bos.write8(0xbf); + bos.write8(0x68); + bos.write8(0xc4); + bos.write8(0xb1); +} + +function write16be(bos) { + bos.write8(0xfe); + bos.write8(0xff); + bos.write8(0x00); + bos.write8(0x68); + bos.write8(0x01); + bos.write8(0x31); +} + +function write16le(bos) { + bos.write8(0xff); + bos.write8(0xfe); + bos.write8(0x68); + bos.write8(0x00); + bos.write8(0x31); + bos.write8(0x01); +} + +function getHandler(writer) { + return function (request, response) { + response.setStatusLine(request.httpVersion, 200, "OK"); + + let bos = new BinaryOutputStream(response.bodyOutputStream); + writer(bos); + }; +} + +const server = new HttpServer(); +server.registerDirectory("/", do_get_cwd()); +server.registerPathHandler("/u8", getHandler(write8)); +server.registerPathHandler("/u16be", getHandler(write16be)); +server.registerPathHandler("/u16le", getHandler(write16le)); +server.start(-1); + +const port = server.identity.primaryPort; +const serverURL = "http://localhost:" + port; + +do_register_cleanup(() => { + return new Promise(resolve => server.stop(resolve)); +}); + +add_task(function* () { + yield test_one(serverURL + "/u8", "UTF-8"); + yield test_one(serverURL + "/u16be", "UTF-16BE"); + yield test_one(serverURL + "/u16le", "UTF-16LE"); +}); + +function* test_one(url, encoding) { + // Be sure to set the encoding to something that will yield an + // invalid result if BOM sniffing is not done. + yield DevToolsUtils.fetch(url, { charset: "ISO-8859-1" }).then(({content}) => { + do_check_eq(content, "hı", "The content looks correct for " + encoding); + }); +} diff --git a/devtools/shared/tests/unit/test_fetch-chrome.js b/devtools/shared/tests/unit/test_fetch-chrome.js new file mode 100644 index 000000000..441d4c7ba --- /dev/null +++ b/devtools/shared/tests/unit/test_fetch-chrome.js @@ -0,0 +1,31 @@ +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +// Tests for DevToolsUtils.fetch on chrome:// URI's. + +const URL_FOUND = "chrome://devtools-shared/locale/debugger.properties"; +const URL_NOT_FOUND = "chrome://this/is/not/here.js"; + +/** + * Test that non-existent files are handled correctly. + */ +add_task(function* test_missing() { + yield DevToolsUtils.fetch(URL_NOT_FOUND).then(result => { + do_print(result); + ok(false, "fetch resolved unexpectedly for non-existent chrome:// URI"); + }, () => { + ok(true, "fetch rejected as the chrome:// URI was non-existent."); + }); +}); + +/** + * Tests that existing files are handled correctly. + */ +add_task(function* test_normal() { + yield DevToolsUtils.fetch(URL_FOUND).then(result => { + notDeepEqual(result.content, "", + "chrome:// URI seems to be read correctly."); + }); +}); diff --git a/devtools/shared/tests/unit/test_fetch-file.js b/devtools/shared/tests/unit/test_fetch-file.js new file mode 100644 index 000000000..d9d712322 --- /dev/null +++ b/devtools/shared/tests/unit/test_fetch-file.js @@ -0,0 +1,104 @@ +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +// Tests for DevToolsUtils.fetch on file:// URI's. + +const { FileUtils } = Cu.import("resource://gre/modules/FileUtils.jsm", {}); +const { OS } = Cu.import("resource://gre/modules/osfile.jsm", {}); + +const TEST_CONTENT = "aéd"; + +// The TEST_CONTENT encoded as UTF-8. +const UTF8_TEST_BUFFER = new Uint8Array([0x61, 0xc3, 0xa9, 0x64]); + +// The TEST_CONTENT encoded as ISO 8859-1. +const ISO_8859_1_BUFFER = new Uint8Array([0x61, 0xe9, 0x64]); + +/** + * Tests that URLs with arrows pointing to an actual source are handled properly + * (bug 808960). For example 'resource://gre/modules/XPIProvider.jsm -> + * file://l10n.js' should load 'file://l10n.js'. + */ +add_task(function* test_arrow_urls() { + let { path } = createTemporaryFile(".js"); + let url = "resource://gre/modules/XPIProvider.jsm -> file://" + path; + + yield OS.File.writeAtomic(path, TEST_CONTENT, { encoding: "utf-8" }); + let { content } = yield DevToolsUtils.fetch(url); + + deepEqual(content, TEST_CONTENT, "The file contents were correctly read."); +}); + +/** + * Tests that empty files are read correctly. + */ +add_task(function* test_empty() { + let { path } = createTemporaryFile(); + let { content } = yield DevToolsUtils.fetch("file://" + path); + deepEqual(content, "", "The empty file was read correctly."); +}); + +/** + * Tests that UTF-8 encoded files are correctly read. + */ +add_task(function* test_encoding_utf8() { + let { path } = createTemporaryFile(); + yield OS.File.writeAtomic(path, UTF8_TEST_BUFFER); + + let { content } = yield DevToolsUtils.fetch(path); + deepEqual(content, TEST_CONTENT, + "The UTF-8 encoded file was correctly read."); +}); + +/** + * Tests that ISO 8859-1 (Latin-1) encoded files are correctly read. + */ +add_task(function* test_encoding_iso_8859_1() { + let { path } = createTemporaryFile(); + yield OS.File.writeAtomic(path, ISO_8859_1_BUFFER); + + let { content } = yield DevToolsUtils.fetch(path); + deepEqual(content, TEST_CONTENT, + "The ISO 8859-1 encoded file was correctly read."); +}); + +/** + * Test that non-existent files are handled correctly. + */ +add_task(function* test_missing() { + yield DevToolsUtils.fetch("file:///file/not/found.right").then(result => { + do_print(result); + ok(false, "Fetch resolved unexpectedly when the file was not found."); + }, () => { + ok(true, "Fetch rejected as expected because the file was not found."); + }); +}); + +/** + * Test that URLs without file:// scheme work. + */ +add_task(function* test_schemeless_files() { + let { path } = createTemporaryFile(); + + yield OS.File.writeAtomic(path, TEST_CONTENT, { encoding: "utf-8" }); + + let { content } = yield DevToolsUtils.fetch(path); + deepEqual(content, TEST_CONTENT, "The content was correct."); +}); + +/** + * Creates a temporary file that is removed after the test completes. + */ +function createTemporaryFile(extension) { + let name = "test_fetch-file-" + Math.random() + (extension || ""); + let file = FileUtils.getFile("TmpD", [name]); + file.create(Ci.nsIFile.NORMAL_FILE_TYPE, parseInt("0755", 8)); + + do_register_cleanup(() => { + file.remove(false); + }); + + return file; +} diff --git a/devtools/shared/tests/unit/test_fetch-http.js b/devtools/shared/tests/unit/test_fetch-http.js new file mode 100644 index 000000000..028fa33ee --- /dev/null +++ b/devtools/shared/tests/unit/test_fetch-http.js @@ -0,0 +1,61 @@ +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +// Tests for DevToolsUtils.fetch on http:// URI's. + +const { HttpServer } = Cu.import("resource://testing-common/httpd.js", {}); + +const server = new HttpServer(); +server.registerDirectory("/", do_get_cwd()); +server.registerPathHandler("/cached.json", cacheRequestHandler); +server.start(-1); + +const port = server.identity.primaryPort; +const serverURL = "http://localhost:" + port; +const CACHED_URL = serverURL + "/cached.json"; +const NORMAL_URL = serverURL + "/test_fetch-http.js"; + +function cacheRequestHandler(request, response) { + do_print("Got request for " + request.path); + response.setHeader("Cache-Control", "max-age=10000", false); + response.setStatusLine(request.httpVersion, 200, "OK"); + response.setHeader("Content-Type", "application/json", false); + + let body = "[" + Math.random() + "]"; + response.bodyOutputStream.write(body, body.length); +} + +do_register_cleanup(() => { + return new Promise(resolve => server.stop(resolve)); +}); + +add_task(function* test_normal() { + yield DevToolsUtils.fetch(NORMAL_URL).then(({content}) => { + ok(content.includes("The content looks correct."), + "The content looks correct."); + }); +}); + +add_task(function* test_caching() { + let initialContent = null; + + do_print("Performing the first request."); + yield DevToolsUtils.fetch(CACHED_URL).then(({content}) => { + do_print("Got the first response: " + content); + initialContent = content; + }); + + do_print("Performing another request, expecting to get cached response."); + yield DevToolsUtils.fetch(CACHED_URL).then(({content}) => { + deepEqual(content, initialContent, "The content was loaded from cache."); + }); + + do_print("Performing a third request with cache bypassed."); + let opts = { loadFromCache: false }; + yield DevToolsUtils.fetch(CACHED_URL, opts).then(({content}) => { + notDeepEqual(content, initialContent, + "The URL wasn't loaded from cache with loadFromCache: false."); + }); +}); diff --git a/devtools/shared/tests/unit/test_fetch-resource.js b/devtools/shared/tests/unit/test_fetch-resource.js new file mode 100644 index 000000000..45e79cfa1 --- /dev/null +++ b/devtools/shared/tests/unit/test_fetch-resource.js @@ -0,0 +1,31 @@ +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +// Tests for DevToolsUtils.fetch on resource:// URI's. + +const URL_FOUND = "resource://devtools/shared/DevToolsUtils.js"; +const URL_NOT_FOUND = "resource://devtools/this/is/not/here.js"; + +/** + * Test that non-existent files are handled correctly. + */ +add_task(function* test_missing() { + yield DevToolsUtils.fetch(URL_NOT_FOUND).then(result => { + do_print(result); + ok(false, "fetch resolved unexpectedly for non-existent resource:// URI"); + }, () => { + ok(true, "fetch rejected as the resource:// URI was non-existent."); + }); +}); + +/** + * Tests that existing files are handled correctly. + */ +add_task(function* test_normal() { + yield DevToolsUtils.fetch(URL_FOUND).then(result => { + notDeepEqual(result.content, "", + "resource:// URI seems to be read correctly."); + }); +}); diff --git a/devtools/shared/tests/unit/test_flatten.js b/devtools/shared/tests/unit/test_flatten.js new file mode 100644 index 000000000..f5a186770 --- /dev/null +++ b/devtools/shared/tests/unit/test_flatten.js @@ -0,0 +1,24 @@ +/* -*- js-indent-level: 2; indent-tabs-mode: nil -*- */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test ThreadSafeDevToolsUtils.flatten + +function run_test() { + const { flatten } = DevToolsUtils; + + const flat = flatten([["a", "b", "c"], + ["d", "e", "f"], + ["g", "h", "i"]]); + + equal(flat.length, 9); + equal(flat[0], "a"); + equal(flat[1], "b"); + equal(flat[2], "c"); + equal(flat[3], "d"); + equal(flat[4], "e"); + equal(flat[5], "f"); + equal(flat[6], "g"); + equal(flat[7], "h"); + equal(flat[8], "i"); +} diff --git a/devtools/shared/tests/unit/test_indentation.js b/devtools/shared/tests/unit/test_indentation.js new file mode 100644 index 000000000..f7e4403d4 --- /dev/null +++ b/devtools/shared/tests/unit/test_indentation.js @@ -0,0 +1,133 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const Services = require("Services"); +const { + EXPAND_TAB, + TAB_SIZE, + DETECT_INDENT, + getIndentationFromPrefs, + getIndentationFromIteration, + getIndentationFromString, +} = require("devtools/shared/indentation"); + +function test_indent_from_prefs() { + Services.prefs.setBoolPref(DETECT_INDENT, true); + equal(getIndentationFromPrefs(), false, + "getIndentationFromPrefs returning false"); + + Services.prefs.setIntPref(TAB_SIZE, 73); + Services.prefs.setBoolPref(EXPAND_TAB, false); + Services.prefs.setBoolPref(DETECT_INDENT, false); + deepEqual(getIndentationFromPrefs(), {indentUnit: 73, indentWithTabs: true}, + "getIndentationFromPrefs basic test"); +} + +const TESTS = [ + { + desc: "two spaces", + input: [ + "/*", + " * tricky comment block", + " */", + "div {", + " color: red;", + " background: blue;", + "}", + " ", + "span {", + " padding-left: 10px;", + "}" + ], + expected: {indentUnit: 2, indentWithTabs: false} + }, + { + desc: "four spaces", + input: [ + "var obj = {", + " addNumbers: function() {", + " var x = 5;", + " var y = 18;", + " return x + y;", + " },", + " ", + " /*", + " * Do some stuff to two numbers", + " * ", + " * @param x", + " * @param y", + " * ", + " * @return the result of doing stuff", + " */", + " subtractNumbers: function(x, y) {", + " var x += 7;", + " var y += 18;", + " var result = x - y;", + " result %= 2;", + " }", + "}" + ], + expected: {indentUnit: 4, indentWithTabs: false} + }, + { + desc: "tabs", + input: [ + "/*", + " * tricky comment block", + " */", + "div {", + "\tcolor: red;", + "\tbackground: blue;", + "}", + "", + "span {", + "\tpadding-left: 10px;", + "}" + ], + expected: {indentUnit: 2, indentWithTabs: true} + }, + { + desc: "no indent", + input: [ + "var x = 0;", + " // stray thing", + "var y = 9;", + " ", + "" + ], + expected: {indentUnit: 2, indentWithTabs: false} + }, +]; + +function test_indent_detection() { + Services.prefs.setIntPref(TAB_SIZE, 2); + Services.prefs.setBoolPref(EXPAND_TAB, true); + Services.prefs.setBoolPref(DETECT_INDENT, true); + + for (let test of TESTS) { + let iterFn = function (start, end, callback) { + test.input.slice(start, end).forEach(callback); + }; + + deepEqual(getIndentationFromIteration(iterFn), test.expected, + "test getIndentationFromIteration " + test.desc); + } + + for (let test of TESTS) { + deepEqual(getIndentationFromString(test.input.join("\n")), test.expected, + "test getIndentationFromString " + test.desc); + } +} + +function run_test() { + try { + test_indent_from_prefs(); + test_indent_detection(); + } finally { + Services.prefs.clearUserPref(TAB_SIZE); + Services.prefs.clearUserPref(EXPAND_TAB); + Services.prefs.clearUserPref(DETECT_INDENT); + } +} diff --git a/devtools/shared/tests/unit/test_independent_loaders.js b/devtools/shared/tests/unit/test_independent_loaders.js new file mode 100644 index 000000000..20abed27d --- /dev/null +++ b/devtools/shared/tests/unit/test_independent_loaders.js @@ -0,0 +1,20 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * Ensure that each instance of the Dev Tools loader contains its own loader + * instance, and also returns unique objects. This ensures there is no sharing + * in place between loaders. + */ +function run_test() { + let loader1 = new DevToolsLoader(); + let loader2 = new DevToolsLoader(); + + let indent1 = loader1.require("devtools/shared/indentation"); + let indent2 = loader2.require("devtools/shared/indentation"); + + do_check_true(indent1 !== indent2); + + do_check_true(loader1._provider !== loader2._provider); + do_check_true(loader1._provider.loader !== loader2._provider.loader); +} diff --git a/devtools/shared/tests/unit/test_invisible_loader.js b/devtools/shared/tests/unit/test_invisible_loader.js new file mode 100644 index 000000000..96a68abc4 --- /dev/null +++ b/devtools/shared/tests/unit/test_invisible_loader.js @@ -0,0 +1,60 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { addDebuggerToGlobal } = Cu.import("resource://gre/modules/jsdebugger.jsm", {}); +addDebuggerToGlobal(this); + +/** + * Ensure that sandboxes created via the Dev Tools loader respect the + * invisibleToDebugger flag. + */ +function run_test() { + visible_loader(); + invisible_loader(); +} + +function visible_loader() { + let loader = new DevToolsLoader(); + loader.invisibleToDebugger = false; + loader.require("devtools/shared/indentation"); + + let dbg = new Debugger(); + let sandbox = loader._provider.loader.sharedGlobalSandbox; + + try { + dbg.addDebuggee(sandbox); + do_check_true(true); + } catch (e) { + do_throw("debugger could not add visible value"); + } + + // Check that for common loader used for tabs, promise modules is Promise.jsm + // Which is required to support unhandled promises rejection in mochitests + const promise = Cu.import("resource://gre/modules/Promise.jsm", {}).Promise; + do_check_eq(loader.require("promise"), promise); +} + +function invisible_loader() { + let loader = new DevToolsLoader(); + loader.invisibleToDebugger = true; + loader.require("devtools/shared/indentation"); + + let dbg = new Debugger(); + let sandbox = loader._provider.loader.sharedGlobalSandbox; + + try { + dbg.addDebuggee(sandbox); + do_throw("debugger added invisible value"); + } catch (e) { + do_check_true(true); + } + + // But for browser toolbox loader, promise is loaded as a regular modules out + // of Promise-backend.js, that to be invisible to the debugger and not step + // into it. + const promise = loader.require("promise"); + const promiseModule = loader._provider.loader.modules["resource://gre/modules/Promise-backend.js"]; + do_check_eq(promise, promiseModule.exports); +} diff --git a/devtools/shared/tests/unit/test_isSet.js b/devtools/shared/tests/unit/test_isSet.js new file mode 100644 index 000000000..f85d6ae3c --- /dev/null +++ b/devtools/shared/tests/unit/test_isSet.js @@ -0,0 +1,25 @@ +/* -*- js-indent-level: 2; indent-tabs-mode: nil -*- */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test ThreadSafeDevToolsUtils.isSet + +function run_test() { + const { isSet } = DevToolsUtils; + + equal(isSet(new Set()), true); + equal(isSet(new Map()), false); + equal(isSet({}), false); + equal(isSet("I swear I'm a Set"), false); + equal(isSet(5), false); + + const systemPrincipal = Cc["@mozilla.org/systemprincipal;1"] + .createInstance(Ci.nsIPrincipal); + const sandbox = new Cu.Sandbox(systemPrincipal); + + equal(isSet(Cu.evalInSandbox("new Set()", sandbox)), true); + equal(isSet(Cu.evalInSandbox("new Map()", sandbox)), false); + equal(isSet(Cu.evalInSandbox("({})", sandbox)), false); + equal(isSet(Cu.evalInSandbox("'I swear I\\'m a Set'", sandbox)), false); + equal(isSet(Cu.evalInSandbox("5", sandbox)), false); +} diff --git a/devtools/shared/tests/unit/test_pluralForm-english.js b/devtools/shared/tests/unit/test_pluralForm-english.js new file mode 100644 index 000000000..67cd3b712 --- /dev/null +++ b/devtools/shared/tests/unit/test_pluralForm-english.js @@ -0,0 +1,29 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * This unit test makes sure the plural form for Irish Gaeilge is working by + * using the makeGetter method instead of using the default language (by + * development), English. + */ + +const {PluralForm} = require("devtools/shared/plural-form"); + +function run_test() { + // English has 2 plural forms + do_check_eq(2, PluralForm.numForms()); + + // Make sure for good inputs, things work as expected + for (let num = 0; num <= 200; num++) { + do_check_eq(num == 1 ? "word" : "words", PluralForm.get(num, "word;words")); + } + + // Not having enough plural forms defaults to the first form + do_check_eq("word", PluralForm.get(2, "word")); + + // Empty forms defaults to the first form + do_check_eq("word", PluralForm.get(2, "word;")); +} diff --git a/devtools/shared/tests/unit/test_pluralForm-makeGetter.js b/devtools/shared/tests/unit/test_pluralForm-makeGetter.js new file mode 100644 index 000000000..a9d4928b1 --- /dev/null +++ b/devtools/shared/tests/unit/test_pluralForm-makeGetter.js @@ -0,0 +1,38 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * This unit test makes sure the plural form for Irish Gaeilge is working by + * using the makeGetter method instead of using the default language (by + * development), English. + */ + +const {PluralForm} = require("devtools/shared/plural-form"); + +function run_test() { + // Irish is plural rule #11 + let [get, numForms] = PluralForm.makeGetter(11); + + // Irish has 5 plural forms + do_check_eq(5, numForms()); + + // I don't really know Irish, so I'll stick in some dummy text + let words = "is 1;is 2;is 3-6;is 7-10;everything else"; + + let test = function (text, low, high) { + for (let num = low; num <= high; num++) { + do_check_eq(text, get(num, words)); + } + }; + + // Make sure for good inputs, things work as expected + test("everything else", 0, 0); + test("is 1", 1, 1); + test("is 2", 2, 2); + test("is 3-6", 3, 6); + test("is 7-10", 7, 10); + test("everything else", 11, 200); +} diff --git a/devtools/shared/tests/unit/test_prettifyCSS.js b/devtools/shared/tests/unit/test_prettifyCSS.js new file mode 100644 index 000000000..8415c9b83 --- /dev/null +++ b/devtools/shared/tests/unit/test_prettifyCSS.js @@ -0,0 +1,68 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test prettifyCSS. + +"use strict"; + +const {prettifyCSS} = require("devtools/shared/inspector/css-logic"); + +const TESTS = [ + { name: "simple test", + input: "div { font-family:'Arial Black', Arial, sans-serif; }", + expected: [ + "div {", + "\tfont-family:'Arial Black', Arial, sans-serif;", + "}" + ] + }, + + { name: "whitespace before open brace", + input: "div{}", + expected: [ + "div {", + "}" + ] + }, + + { name: "minified with trailing newline", + input: "\nbody{background:white;}div{font-size:4em;color:red}span{color:green;}\n", + expected: [ + "body {", + "\tbackground:white;", + "}", + "div {", + "\tfont-size:4em;", + "\tcolor:red", + "}", + "span {", + "\tcolor:green;", + "}" + ] + }, + + { name: "leading whitespace", + input: "\n div{color: red;}", + expected: [ + "div {", + "\tcolor: red;", + "}" + ] + }, +]; + +function run_test() { + // Note that prettifyCSS.LINE_SEPARATOR is computed lazily, so we + // ensure it is set. + prettifyCSS(""); + + for (let test of TESTS) { + do_print(test.name); + + let input = test.input.split("\n").join(prettifyCSS.LINE_SEPARATOR); + let output = prettifyCSS(input); + let expected = test.expected.join(prettifyCSS.LINE_SEPARATOR) + + prettifyCSS.LINE_SEPARATOR; + equal(output, expected, test.name); + } +} diff --git a/devtools/shared/tests/unit/test_require.js b/devtools/shared/tests/unit/test_require.js new file mode 100644 index 000000000..005e56656 --- /dev/null +++ b/devtools/shared/tests/unit/test_require.js @@ -0,0 +1,20 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test require + +// Ensure that DevtoolsLoader.require doesn't spawn multiple +// loader/modules when early cached +function testBug1091706() { + let loader = new DevToolsLoader(); + let require = loader.require; + + let indent1 = require("devtools/shared/indentation"); + let indent2 = require("devtools/shared/indentation"); + + do_check_true(indent1 === indent2); +} + +function run_test() { + testBug1091706(); +} diff --git a/devtools/shared/tests/unit/test_require_lazy.js b/devtools/shared/tests/unit/test_require_lazy.js new file mode 100644 index 000000000..8ef5a7d23 --- /dev/null +++ b/devtools/shared/tests/unit/test_require_lazy.js @@ -0,0 +1,32 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test devtools.lazyRequireGetter + +function run_test() { + const name = "asyncUtils"; + const path = "devtools/shared/async-utils"; + const o = {}; + devtools.lazyRequireGetter(o, name, path); + const asyncUtils = require(path); + // XXX: do_check_eq only works on primitive types, so we have this + // do_check_true of an equality expression. + do_check_true(o.asyncUtils === asyncUtils); + + // A non-main loader should get a new object via |lazyRequireGetter|, just + // as it would via a direct |require|. + const o2 = {}; + let loader = new DevToolsLoader(); + + // We have to init the loader by loading any module before lazyRequireGetter is available + loader.require("devtools/shared/DevToolsUtils"); + + loader.lazyRequireGetter(o2, name, path); + do_check_true(o2.asyncUtils !== asyncUtils); + + // A module required via a non-main loader that then uses |lazyRequireGetter| + // should also get the same object from that non-main loader. + let exposeLoader = loader.require("xpcshell-test/exposeLoader"); + const o3 = exposeLoader.exerciseLazyRequire(name, path); + do_check_true(o3.asyncUtils === o2.asyncUtils); +} diff --git a/devtools/shared/tests/unit/test_require_raw.js b/devtools/shared/tests/unit/test_require_raw.js new file mode 100644 index 000000000..5bec82b55 --- /dev/null +++ b/devtools/shared/tests/unit/test_require_raw.js @@ -0,0 +1,19 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test require using "raw!". + +function run_test() { + let loader = new DevToolsLoader(); + let require = loader.require; + + let variableFileContents = require("raw!devtools/client/themes/variables.css"); + ok(variableFileContents.length > 0, "raw browserRequire worked"); + + let propertiesFileContents = require("raw!devtools/client/locales/shared.properties"); + ok(propertiesFileContents.length > 0, "unprefixed properties raw require worked"); + + let chromePropertiesFileContents = + require("raw!chrome://devtools/locale/shared.properties"); + ok(chromePropertiesFileContents.length > 0, "prefixed properties raw require worked"); +} diff --git a/devtools/shared/tests/unit/test_safeErrorString.js b/devtools/shared/tests/unit/test_safeErrorString.js new file mode 100644 index 000000000..9892f34d1 --- /dev/null +++ b/devtools/shared/tests/unit/test_safeErrorString.js @@ -0,0 +1,58 @@ +/* -*- js-indent-level: 2; indent-tabs-mode: nil -*- */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test DevToolsUtils.safeErrorString + +function run_test() { + test_with_error(); + test_with_tricky_error(); + test_with_string(); + test_with_thrower(); + test_with_psychotic(); +} + +function test_with_error() { + let s = DevToolsUtils.safeErrorString(new Error("foo bar")); + // Got the message. + do_check_true(s.includes("foo bar")); + // Got the stack. + do_check_true(s.includes("test_with_error")); + do_check_true(s.includes("test_safeErrorString.js")); + // Got the lineNumber and columnNumber. + do_check_true(s.includes("Line")); + do_check_true(s.includes("column")); +} + +function test_with_tricky_error() { + let e = new Error("batman"); + e.stack = { toString: Object.create(null) }; + let s = DevToolsUtils.safeErrorString(e); + // Still got the message, despite a bad stack property. + do_check_true(s.includes("batman")); +} + +function test_with_string() { + let s = DevToolsUtils.safeErrorString("not really an error"); + // Still get the message. + do_check_true(s.includes("not really an error")); +} + +function test_with_thrower() { + let s = DevToolsUtils.safeErrorString({ + toString: () => { + throw new Error("Muahahaha"); + } + }); + // Still don't fail, get string back. + do_check_eq(typeof s, "string"); +} + +function test_with_psychotic() { + let s = DevToolsUtils.safeErrorString({ + toString: () => Object.create(null) + }); + // Still get a string out, and no exceptions thrown + do_check_eq(typeof s, "string"); + do_check_eq(s, "[object Object]"); +} diff --git a/devtools/shared/tests/unit/test_stack.js b/devtools/shared/tests/unit/test_stack.js new file mode 100644 index 000000000..ef747c83f --- /dev/null +++ b/devtools/shared/tests/unit/test_stack.js @@ -0,0 +1,45 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test stack.js. + +function run_test() { + let loader = new DevToolsLoader(); + let require = loader.require; + + const {StackFrameCache} = require("devtools/server/actors/utils/stack"); + + let cache = new StackFrameCache(); + cache.initFrames(); + let baseFrame = { + line: 23, + column: 77, + source: "nowhere", + functionDisplayName: "nobody", + parent: null, + asyncParent: null, + asyncCause: null + }; + cache.addFrame(baseFrame); + + let event = cache.makeEvent(); + do_check_eq(event[0], null); + do_check_eq(event[1].functionDisplayName, "nobody"); + do_check_eq(event.length, 2); + + cache.addFrame({ + line: 24, + column: 78, + source: "nowhere", + functionDisplayName: "still nobody", + parent: null, + asyncParent: baseFrame, + asyncCause: "async" + }); + + event = cache.makeEvent(); + do_check_eq(event[0].functionDisplayName, "still nobody"); + do_check_eq(event[0].parent, 0); + do_check_eq(event[0].asyncParent, 1); + do_check_eq(event.length, 1); +} diff --git a/devtools/shared/tests/unit/xpcshell.ini b/devtools/shared/tests/unit/xpcshell.ini new file mode 100644 index 000000000..d0323c813 --- /dev/null +++ b/devtools/shared/tests/unit/xpcshell.ini @@ -0,0 +1,40 @@ +[DEFAULT] +tags = devtools +head = head_devtools.js +tail = +firefox-appdir = browser +skip-if = toolkit == 'android' +support-files = + exposeLoader.js + +[test_assert.js] +[test_csslexer.js] +[test_css-properties-db.js] +# This test only enforces that the CSS database is up to date with nightly. The DB is +# only used when inspecting a target that doesn't support the getCSSDatabase actor. +# CSS properties are behind compile-time flags, and there is no automatic rebuild +# process for uplifts, so this test breaks on uplift. +run-if = nightly_build +[test_fetch-bom.js] +[test_fetch-chrome.js] +[test_fetch-file.js] +[test_fetch-http.js] +[test_fetch-resource.js] +[test_flatten.js] +[test_indentation.js] +[test_independent_loaders.js] +[test_invisible_loader.js] +[test_isSet.js] +[test_safeErrorString.js] +[test_defineLazyPrototypeGetter.js] +[test_async-utils.js] +[test_console_filtering.js] +[test_pluralForm-english.js] +[test_pluralForm-makeGetter.js] +[test_prettifyCSS.js] +[test_require_lazy.js] +[test_require_raw.js] +[test_require.js] +[test_stack.js] +[test_defer.js] +[test_executeSoon.js] diff --git a/devtools/shared/touch/moz.build b/devtools/shared/touch/moz.build new file mode 100644 index 000000000..96fbac8eb --- /dev/null +++ b/devtools/shared/touch/moz.build @@ -0,0 +1,11 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +DevToolsModules( + 'simulator-content.js', + 'simulator-core.js', + 'simulator.js', +) diff --git a/devtools/shared/touch/simulator-content.js b/devtools/shared/touch/simulator-content.js new file mode 100644 index 000000000..0b10579ca --- /dev/null +++ b/devtools/shared/touch/simulator-content.js @@ -0,0 +1,43 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + /* globals addMessageListener, sendAsyncMessage */ +"use strict"; + +const { utils: Cu } = Components; +const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {}); +const { SimulatorCore } = require("devtools/shared/touch/simulator-core"); + +/** + * Launches SimulatorCore in the content window to simulate touch events + * This frame script is managed by `simulator.js`. + */ + +var simulator = { + messages: [ + "TouchEventSimulator:Start", + "TouchEventSimulator:Stop", + ], + + init() { + this.simulatorCore = new SimulatorCore(docShell.chromeEventHandler); + this.messages.forEach(msgName => { + addMessageListener(msgName, this); + }); + }, + + receiveMessage(msg) { + switch (msg.name) { + case "TouchEventSimulator:Start": + this.simulatorCore.start(); + sendAsyncMessage("TouchEventSimulator:Started"); + break; + case "TouchEventSimulator:Stop": + this.simulatorCore.stop(); + sendAsyncMessage("TouchEventSimulator:Stopped"); + break; + } + }, +}; + +simulator.init(); diff --git a/devtools/shared/touch/simulator-core.js b/devtools/shared/touch/simulator-core.js new file mode 100644 index 000000000..6933f9207 --- /dev/null +++ b/devtools/shared/touch/simulator-core.js @@ -0,0 +1,366 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +const { Ci, Cu } = require("chrome"); +const { Services } = Cu.import("resource://gre/modules/Services.jsm", {}); + +var systemAppOrigin = (function () { + let systemOrigin = "_"; + try { + systemOrigin = Services.io.newURI( + Services.prefs.getCharPref("b2g.system_manifest_url"), null, null) + .prePath; + } catch (e) { + // Fall back to default value + } + return systemOrigin; +})(); + +var threshold = 25; +try { + threshold = Services.prefs.getIntPref("ui.dragThresholdX"); +} catch (e) { + // Fall back to default value +} + +var delay = 500; +try { + delay = Services.prefs.getIntPref("ui.click_hold_context_menus.delay"); +} catch (e) { + // Fall back to default value +} + +function SimulatorCore(simulatorTarget) { + this.simulatorTarget = simulatorTarget; +} + +/** + * Simulate touch events for platforms where they aren't generally available. + */ +SimulatorCore.prototype = { + events: [ + "mousedown", + "mousemove", + "mouseup", + "touchstart", + "touchend", + "mouseenter", + "mouseover", + "mouseout", + "mouseleave" + ], + + contextMenuTimeout: null, + + simulatorTarget: null, + + enabled: false, + + start() { + if (this.enabled) { + // Simulator is already started + return; + } + this.events.forEach(evt => { + // Only listen trusted events to prevent messing with + // event dispatched manually within content documents + this.simulatorTarget.addEventListener(evt, this, true, false); + }); + this.enabled = true; + }, + + stop() { + if (!this.enabled) { + // Simulator isn't running + return; + } + this.events.forEach(evt => { + this.simulatorTarget.removeEventListener(evt, this, true); + }); + this.enabled = false; + }, + + handleEvent(evt) { + // The gaia system window use an hybrid system even on the device which is + // a mix of mouse/touch events. So let's not cancel *all* mouse events + // if it is the current target. + let content = this.getContent(evt.target); + if (!content) { + return; + } + let isSystemWindow = content.location.toString() + .startsWith(systemAppOrigin); + + // App touchstart & touchend should also be dispatched on the system app + // to match on-device behavior. + if (evt.type.startsWith("touch") && !isSystemWindow) { + let sysFrame = content.realFrameElement; + if (!sysFrame) { + return; + } + let sysDocument = sysFrame.ownerDocument; + let sysWindow = sysDocument.defaultView; + + let touchEvent = sysDocument.createEvent("touchevent"); + let touch = evt.touches[0] || evt.changedTouches[0]; + let point = sysDocument.createTouch(sysWindow, sysFrame, 0, + touch.pageX, touch.pageY, + touch.screenX, touch.screenY, + touch.clientX, touch.clientY, + 1, 1, 0, 0); + + let touches = sysDocument.createTouchList(point); + let targetTouches = touches; + let changedTouches = touches; + touchEvent.initTouchEvent(evt.type, true, true, sysWindow, 0, + false, false, false, false, + touches, targetTouches, changedTouches); + sysFrame.dispatchEvent(touchEvent); + return; + } + + // Ignore all but real mouse event coming from physical mouse + // (especially ignore mouse event being dispatched from a touch event) + if (evt.button || + evt.mozInputSource != Ci.nsIDOMMouseEvent.MOZ_SOURCE_MOUSE || + evt.isSynthesized) { + return; + } + + let eventTarget = this.target; + let type = ""; + switch (evt.type) { + case "mouseenter": + case "mouseover": + case "mouseout": + case "mouseleave": + // Don't propagate events which are not related to touch events + evt.stopPropagation(); + break; + + case "mousedown": + this.target = evt.target; + + this.contextMenuTimeout = this.sendContextMenu(evt); + + this.cancelClick = false; + this.startX = evt.pageX; + this.startY = evt.pageY; + + // Capture events so if a different window show up the events + // won't be dispatched to something else. + evt.target.setCapture(false); + + type = "touchstart"; + break; + + case "mousemove": + if (!eventTarget) { + // Don't propagate mousemove event when touchstart event isn't fired + evt.stopPropagation(); + return; + } + + if (!this.cancelClick) { + if (Math.abs(this.startX - evt.pageX) > threshold || + Math.abs(this.startY - evt.pageY) > threshold) { + this.cancelClick = true; + content.clearTimeout(this.contextMenuTimeout); + } + } + + type = "touchmove"; + break; + + case "mouseup": + if (!eventTarget) { + return; + } + this.target = null; + + content.clearTimeout(this.contextMenuTimeout); + type = "touchend"; + + // Only register click listener after mouseup to ensure + // catching only real user click. (Especially ignore click + // being dispatched on form submit) + if (evt.detail == 1) { + this.simulatorTarget.addEventListener("click", this, true, false); + } + break; + + case "click": + // Mouse events has been cancelled so dispatch a sequence + // of events to where touchend has been fired + evt.preventDefault(); + evt.stopImmediatePropagation(); + + this.simulatorTarget.removeEventListener("click", this, true, false); + + if (this.cancelClick) { + return; + } + + content.setTimeout(function dispatchMouseEvents(self) { + try { + self.fireMouseEvent("mousedown", evt); + self.fireMouseEvent("mousemove", evt); + self.fireMouseEvent("mouseup", evt); + } catch (e) { + console.error("Exception in touch event helper: " + e); + } + }, this.getDelayBeforeMouseEvent(evt), this); + return; + } + + let target = eventTarget || this.target; + if (target && type) { + this.sendTouchEvent(evt, target, type); + } + + if (!isSystemWindow) { + evt.preventDefault(); + evt.stopImmediatePropagation(); + } + }, + + fireMouseEvent(type, evt) { + let content = this.getContent(evt.target); + let utils = content.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDOMWindowUtils); + utils.sendMouseEvent(type, evt.clientX, evt.clientY, 0, 1, 0, true, 0, + Ci.nsIDOMMouseEvent.MOZ_SOURCE_TOUCH); + }, + + sendContextMenu({ target, clientX, clientY, screenX, screenY }) { + let view = target.ownerDocument.defaultView; + let { MouseEvent } = view; + let evt = new MouseEvent("contextmenu", { + bubbles: true, + cancelable: true, + view, + screenX, + screenY, + clientX, + clientY, + }); + let content = this.getContent(target); + let timeout = content.setTimeout((function contextMenu() { + target.dispatchEvent(evt); + this.cancelClick = true; + }).bind(this), delay); + + return timeout; + }, + + sendTouchEvent(evt, target, name) { + function clone(obj) { + return Cu.cloneInto(obj, target); + } + // When running OOP b2g desktop, we need to send the touch events + // using the mozbrowser api on the unwrapped frame. + if (target.localName == "iframe" && target.mozbrowser === true) { + if (name == "touchstart") { + this.touchstartTime = Date.now(); + } else if (name == "touchend") { + // If we have a "fast" tap, don't send a click as both will be turned + // into a click and that breaks eg. checkboxes. + if (Date.now() - this.touchstartTime < delay) { + this.cancelClick = true; + } + } + let unwrapped = XPCNativeWrapper.unwrap(target); + unwrapped.sendTouchEvent(name, clone([0]), // event type, id + clone([evt.clientX]), // x + clone([evt.clientY]), // y + clone([1]), clone([1]), // rx, ry + clone([0]), clone([0]), // rotation, force + 1); // count + return; + } + let document = target.ownerDocument; + let content = this.getContent(target); + if (!content) { + return; + } + + let touchEvent = document.createEvent("touchevent"); + let point = document.createTouch(content, target, 0, + evt.pageX, evt.pageY, + evt.screenX, evt.screenY, + evt.clientX, evt.clientY, + 1, 1, 0, 0); + + let touches = document.createTouchList(point); + let targetTouches = touches; + let changedTouches = touches; + if (name === "touchend" || name === "touchcancel") { + // "touchend" and "touchcancel" events should not have the removed touch + // neither in touches nor in targetTouches + touches = targetTouches = document.createTouchList(); + } + + touchEvent.initTouchEvent(name, true, true, content, 0, + false, false, false, false, + touches, targetTouches, changedTouches); + target.dispatchEvent(touchEvent); + }, + + getContent(target) { + let win = (target && target.ownerDocument) + ? target.ownerDocument.defaultView + : null; + return win; + }, + + getDelayBeforeMouseEvent(evt) { + // On mobile platforms, Firefox inserts a 300ms delay between + // touch events and accompanying mouse events, except if the + // content window is not zoomable and the content window is + // auto-zoomed to device-width. + + // If the preference dom.meta-viewport.enabled is set to false, + // we couldn't read viewport's information from getViewportInfo(). + // So we always simulate 300ms delay when the + // dom.meta-viewport.enabled is false. + let savedMetaViewportEnabled = + Services.prefs.getBoolPref("dom.meta-viewport.enabled"); + if (!savedMetaViewportEnabled) { + return 300; + } + + let content = this.getContent(evt.target); + if (!content) { + return 0; + } + + let utils = content.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDOMWindowUtils); + + let allowZoom = {}, + minZoom = {}, + maxZoom = {}, + autoSize = {}; + + utils.getViewportInfo(content.innerWidth, content.innerHeight, {}, + allowZoom, minZoom, maxZoom, {}, {}, autoSize); + + // FIXME: On Safari and Chrome mobile platform, if the css property + // touch-action set to none or manipulation would also suppress 300ms + // delay. But Firefox didn't support this property now, we can't get + // this value from utils.getVisitedDependentComputedStyle() to check + // if we should suppress 300ms delay. + if (!allowZoom.value || // user-scalable = no + minZoom.value === maxZoom.value || // minimum-scale = maximum-scale + autoSize.value // width = device-width + ) { + return 0; + } else { + return 300; + } + } +}; + +exports.SimulatorCore = SimulatorCore; diff --git a/devtools/shared/touch/simulator.js b/devtools/shared/touch/simulator.js new file mode 100644 index 000000000..0e6d29282 --- /dev/null +++ b/devtools/shared/touch/simulator.js @@ -0,0 +1,77 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +var promise = require("promise"); +var defer = require("devtools/shared/defer"); +var Services = require("Services"); + +const FRAME_SCRIPT = + "resource://devtools/shared/touch/simulator-content.js"; + +var trackedBrowsers = new WeakMap(); +var savedTouchEventsEnabled = + Services.prefs.getIntPref("dom.w3c_touch_events.enabled"); + +/** + * Simulate touch events for platforms where they aren't generally available. + * Defers to the `simulator-content.js` frame script to perform the real work. + */ +function TouchEventSimulator(browser) { + // Returns an already instantiated simulator for this browser + let simulator = trackedBrowsers.get(browser); + if (simulator) { + return simulator; + } + + let mm = browser.frameLoader.messageManager; + mm.loadFrameScript(FRAME_SCRIPT, true); + + simulator = { + enabled: false, + + start() { + if (this.enabled) { + return promise.resolve({ isReloadNeeded: false }); + } + this.enabled = true; + + let deferred = defer(); + let isReloadNeeded = + Services.prefs.getIntPref("dom.w3c_touch_events.enabled") != 1; + Services.prefs.setIntPref("dom.w3c_touch_events.enabled", 1); + let onStarted = () => { + mm.removeMessageListener("TouchEventSimulator:Started", onStarted); + deferred.resolve({ isReloadNeeded }); + }; + mm.addMessageListener("TouchEventSimulator:Started", onStarted); + mm.sendAsyncMessage("TouchEventSimulator:Start"); + return deferred.promise; + }, + + stop() { + if (!this.enabled) { + return promise.resolve(); + } + this.enabled = false; + + let deferred = defer(); + Services.prefs.setIntPref("dom.w3c_touch_events.enabled", + savedTouchEventsEnabled); + let onStopped = () => { + mm.removeMessageListener("TouchEventSimulator:Stopped", onStopped); + deferred.resolve(); + }; + mm.addMessageListener("TouchEventSimulator:Stopped", onStopped); + mm.sendAsyncMessage("TouchEventSimulator:Stop"); + return deferred.promise; + } + }; + + trackedBrowsers.set(browser, simulator); + + return simulator; +} + +exports.TouchEventSimulator = TouchEventSimulator; diff --git a/devtools/shared/transport/moz.build b/devtools/shared/transport/moz.build new file mode 100644 index 000000000..fbf0444b8 --- /dev/null +++ b/devtools/shared/transport/moz.build @@ -0,0 +1,14 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +XPCSHELL_TESTS_MANIFESTS += ['tests/unit/xpcshell.ini'] + +DevToolsModules( + 'packets.js', + 'stream-utils.js', + 'transport.js', + 'websocket-transport.js', +) diff --git a/devtools/shared/transport/packets.js b/devtools/shared/transport/packets.js new file mode 100644 index 000000000..3ebcd8f13 --- /dev/null +++ b/devtools/shared/transport/packets.js @@ -0,0 +1,414 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * Packets contain read / write functionality for the different packet types + * supported by the debugging protocol, so that a transport can focus on + * delivery and queue management without worrying too much about the specific + * packet types. + * + * They are intended to be "one use only", so a new packet should be + * instantiated for each incoming or outgoing packet. + * + * A complete Packet type should expose at least the following: + * * read(stream, scriptableStream) + * Called when the input stream has data to read + * * write(stream) + * Called when the output stream is ready to write + * * get done() + * Returns true once the packet is done being read / written + * * destroy() + * Called to clean up at the end of use + */ + +const { Cc, Ci, Cu } = require("chrome"); +const DevToolsUtils = require("devtools/shared/DevToolsUtils"); +const { dumpn, dumpv } = DevToolsUtils; +const flags = require("devtools/shared/flags"); +const StreamUtils = require("devtools/shared/transport/stream-utils"); +const promise = require("promise"); +const defer = require("devtools/shared/defer"); + +DevToolsUtils.defineLazyGetter(this, "unicodeConverter", () => { + const unicodeConverter = Cc["@mozilla.org/intl/scriptableunicodeconverter"] + .createInstance(Ci.nsIScriptableUnicodeConverter); + unicodeConverter.charset = "UTF-8"; + return unicodeConverter; +}); + +// The transport's previous check ensured the header length did not exceed 20 +// characters. Here, we opt for the somewhat smaller, but still large limit of +// 1 TiB. +const PACKET_LENGTH_MAX = Math.pow(2, 40); + +/** + * A generic Packet processing object (extended by two subtypes below). + */ +function Packet(transport) { + this._transport = transport; + this._length = 0; +} + +/** + * Attempt to initialize a new Packet based on the incoming packet header we've + * received so far. We try each of the types in succession, trying JSON packets + * first since they are much more common. + * @param header string + * The packet header string to attempt parsing. + * @param transport DebuggerTransport + * The transport instance that will own the packet. + * @return Packet + * The parsed packet of the matching type, or null if no types matched. + */ +Packet.fromHeader = function (header, transport) { + return JSONPacket.fromHeader(header, transport) || + BulkPacket.fromHeader(header, transport); +}; + +Packet.prototype = { + + get length() { + return this._length; + }, + + set length(length) { + if (length > PACKET_LENGTH_MAX) { + throw Error("Packet length " + length + " exceeds the max length of " + + PACKET_LENGTH_MAX); + } + this._length = length; + }, + + destroy: function () { + this._transport = null; + } + +}; + +exports.Packet = Packet; + +/** + * With a JSON packet (the typical packet type sent via the transport), data is + * transferred as a JSON packet serialized into a string, with the string length + * prepended to the packet, followed by a colon ([length]:[packet]). The + * contents of the JSON packet are specified in the Remote Debugging Protocol + * specification. + * @param transport DebuggerTransport + * The transport instance that will own the packet. + */ +function JSONPacket(transport) { + Packet.call(this, transport); + this._data = ""; + this._done = false; +} + +/** + * Attempt to initialize a new JSONPacket based on the incoming packet header + * we've received so far. + * @param header string + * The packet header string to attempt parsing. + * @param transport DebuggerTransport + * The transport instance that will own the packet. + * @return JSONPacket + * The parsed packet, or null if it's not a match. + */ +JSONPacket.fromHeader = function (header, transport) { + let match = this.HEADER_PATTERN.exec(header); + + if (!match) { + return null; + } + + dumpv("Header matches JSON packet"); + let packet = new JSONPacket(transport); + packet.length = +match[1]; + return packet; +}; + +JSONPacket.HEADER_PATTERN = /^(\d+):$/; + +JSONPacket.prototype = Object.create(Packet.prototype); + +Object.defineProperty(JSONPacket.prototype, "object", { + /** + * Gets the object (not the serialized string) being read or written. + */ + get: function () { return this._object; }, + + /** + * Sets the object to be sent when write() is called. + */ + set: function (object) { + this._object = object; + let data = JSON.stringify(object); + this._data = unicodeConverter.ConvertFromUnicode(data); + this.length = this._data.length; + } +}); + +JSONPacket.prototype.read = function (stream, scriptableStream) { + dumpv("Reading JSON packet"); + + // Read in more packet data. + this._readData(stream, scriptableStream); + + if (!this.done) { + // Don't have a complete packet yet. + return; + } + + let json = this._data; + try { + json = unicodeConverter.ConvertToUnicode(json); + this._object = JSON.parse(json); + } catch (e) { + let msg = "Error parsing incoming packet: " + json + " (" + e + + " - " + e.stack + ")"; + console.error(msg); + dumpn(msg); + return; + } + + this._transport._onJSONObjectReady(this._object); +}; + +JSONPacket.prototype._readData = function (stream, scriptableStream) { + if (flags.wantVerbose) { + dumpv("Reading JSON data: _l: " + this.length + " dL: " + + this._data.length + " sA: " + stream.available()); + } + let bytesToRead = Math.min(this.length - this._data.length, + stream.available()); + this._data += scriptableStream.readBytes(bytesToRead); + this._done = this._data.length === this.length; +}; + +JSONPacket.prototype.write = function (stream) { + dumpv("Writing JSON packet"); + + if (this._outgoing === undefined) { + // Format the serialized packet to a buffer + this._outgoing = this.length + ":" + this._data; + } + + let written = stream.write(this._outgoing, this._outgoing.length); + this._outgoing = this._outgoing.slice(written); + this._done = !this._outgoing.length; +}; + +Object.defineProperty(JSONPacket.prototype, "done", { + get: function () { return this._done; } +}); + +JSONPacket.prototype.toString = function () { + return JSON.stringify(this._object, null, 2); +}; + +exports.JSONPacket = JSONPacket; + +/** + * With a bulk packet, data is transferred by temporarily handing over the + * transport's input or output stream to the application layer for writing data + * directly. This can be much faster for large data sets, and avoids various + * stages of copies and data duplication inherent in the JSON packet type. The + * bulk packet looks like: + * + * bulk [actor] [type] [length]:[data] + * + * The interpretation of the data portion depends on the kind of actor and the + * packet's type. See the Remote Debugging Protocol Stream Transport spec for + * more details. + * @param transport DebuggerTransport + * The transport instance that will own the packet. + */ +function BulkPacket(transport) { + Packet.call(this, transport); + this._done = false; + this._readyForWriting = defer(); +} + +/** + * Attempt to initialize a new BulkPacket based on the incoming packet header + * we've received so far. + * @param header string + * The packet header string to attempt parsing. + * @param transport DebuggerTransport + * The transport instance that will own the packet. + * @return BulkPacket + * The parsed packet, or null if it's not a match. + */ +BulkPacket.fromHeader = function (header, transport) { + let match = this.HEADER_PATTERN.exec(header); + + if (!match) { + return null; + } + + dumpv("Header matches bulk packet"); + let packet = new BulkPacket(transport); + packet.header = { + actor: match[1], + type: match[2], + length: +match[3] + }; + return packet; +}; + +BulkPacket.HEADER_PATTERN = /^bulk ([^: ]+) ([^: ]+) (\d+):$/; + +BulkPacket.prototype = Object.create(Packet.prototype); + +BulkPacket.prototype.read = function (stream) { + dumpv("Reading bulk packet, handing off input stream"); + + // Temporarily pause monitoring of the input stream + this._transport.pauseIncoming(); + + let deferred = defer(); + + this._transport._onBulkReadReady({ + actor: this.actor, + type: this.type, + length: this.length, + copyTo: (output) => { + dumpv("CT length: " + this.length); + let copying = StreamUtils.copyStream(stream, output, this.length); + deferred.resolve(copying); + return copying; + }, + stream: stream, + done: deferred + }); + + // Await the result of reading from the stream + deferred.promise.then(() => { + dumpv("onReadDone called, ending bulk mode"); + this._done = true; + this._transport.resumeIncoming(); + }, this._transport.close); + + // Ensure this is only done once + this.read = () => { + throw new Error("Tried to read() a BulkPacket's stream multiple times."); + }; +}; + +BulkPacket.prototype.write = function (stream) { + dumpv("Writing bulk packet"); + + if (this._outgoingHeader === undefined) { + dumpv("Serializing bulk packet header"); + // Format the serialized packet header to a buffer + this._outgoingHeader = "bulk " + this.actor + " " + this.type + " " + + this.length + ":"; + } + + // Write the header, or whatever's left of it to write. + if (this._outgoingHeader.length) { + dumpv("Writing bulk packet header"); + let written = stream.write(this._outgoingHeader, + this._outgoingHeader.length); + this._outgoingHeader = this._outgoingHeader.slice(written); + return; + } + + dumpv("Handing off output stream"); + + // Temporarily pause the monitoring of the output stream + this._transport.pauseOutgoing(); + + let deferred = defer(); + + this._readyForWriting.resolve({ + copyFrom: (input) => { + dumpv("CF length: " + this.length); + let copying = StreamUtils.copyStream(input, stream, this.length); + deferred.resolve(copying); + return copying; + }, + stream: stream, + done: deferred + }); + + // Await the result of writing to the stream + deferred.promise.then(() => { + dumpv("onWriteDone called, ending bulk mode"); + this._done = true; + this._transport.resumeOutgoing(); + }, this._transport.close); + + // Ensure this is only done once + this.write = () => { + throw new Error("Tried to write() a BulkPacket's stream multiple times."); + }; +}; + +Object.defineProperty(BulkPacket.prototype, "streamReadyForWriting", { + get: function () { + return this._readyForWriting.promise; + } +}); + +Object.defineProperty(BulkPacket.prototype, "header", { + get: function () { + return { + actor: this.actor, + type: this.type, + length: this.length + }; + }, + + set: function (header) { + this.actor = header.actor; + this.type = header.type; + this.length = header.length; + }, +}); + +Object.defineProperty(BulkPacket.prototype, "done", { + get: function () { return this._done; }, +}); + + +BulkPacket.prototype.toString = function () { + return "Bulk: " + JSON.stringify(this.header, null, 2); +}; + +exports.BulkPacket = BulkPacket; + +/** + * RawPacket is used to test the transport's error handling of malformed + * packets, by writing data directly onto the stream. + * @param transport DebuggerTransport + * The transport instance that will own the packet. + * @param data string + * The raw string to send out onto the stream. + */ +function RawPacket(transport, data) { + Packet.call(this, transport); + this._data = data; + this.length = data.length; + this._done = false; +} + +RawPacket.prototype = Object.create(Packet.prototype); + +RawPacket.prototype.read = function (stream) { + // This hasn't yet been needed for testing. + throw Error("Not implmented."); +}; + +RawPacket.prototype.write = function (stream) { + let written = stream.write(this._data, this._data.length); + this._data = this._data.slice(written); + this._done = !this._data.length; +}; + +Object.defineProperty(RawPacket.prototype, "done", { + get: function () { return this._done; } +}); + +exports.RawPacket = RawPacket; diff --git a/devtools/shared/transport/stream-utils.js b/devtools/shared/transport/stream-utils.js new file mode 100644 index 000000000..23f67a518 --- /dev/null +++ b/devtools/shared/transport/stream-utils.js @@ -0,0 +1,249 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const { Ci, Cc, Cu, Cr, CC } = require("chrome"); +const Services = require("Services"); +const DevToolsUtils = require("devtools/shared/DevToolsUtils"); +const { dumpv } = DevToolsUtils; +const EventEmitter = require("devtools/shared/event-emitter"); +const promise = require("promise"); +const defer = require("devtools/shared/defer"); + +DevToolsUtils.defineLazyGetter(this, "IOUtil", () => { + return Cc["@mozilla.org/io-util;1"].getService(Ci.nsIIOUtil); +}); + +DevToolsUtils.defineLazyGetter(this, "ScriptableInputStream", () => { + return CC("@mozilla.org/scriptableinputstream;1", + "nsIScriptableInputStream", "init"); +}); + +const BUFFER_SIZE = 0x8000; + +/** + * This helper function (and its companion object) are used by bulk senders and + * receivers to read and write data in and out of other streams. Functions that + * make use of this tool are passed to callers when it is time to read or write + * bulk data. It is highly recommended to use these copier functions instead of + * the stream directly because the copier enforces the agreed upon length. + * Since bulk mode reuses an existing stream, the sender and receiver must write + * and read exactly the agreed upon amount of data, or else the entire transport + * will be left in a invalid state. Additionally, other methods of stream + * copying (such as NetUtil.asyncCopy) close the streams involved, which would + * terminate the debugging transport, and so it is avoided here. + * + * Overall, this *works*, but clearly the optimal solution would be able to just + * use the streams directly. If it were possible to fully implement + * nsIInputStream / nsIOutputStream in JS, wrapper streams could be created to + * enforce the length and avoid closing, and consumers could use familiar stream + * utilities like NetUtil.asyncCopy. + * + * The function takes two async streams and copies a precise number of bytes + * from one to the other. Copying begins immediately, but may complete at some + * future time depending on data size. Use the returned promise to know when + * it's complete. + * + * @param input nsIAsyncInputStream + * The stream to copy from. + * @param output nsIAsyncOutputStream + * The stream to copy to. + * @param length Integer + * The amount of data that needs to be copied. + * @return Promise + * The promise is resolved when copying completes or rejected if any + * (unexpected) errors occur. + */ +function copyStream(input, output, length) { + let copier = new StreamCopier(input, output, length); + return copier.copy(); +} + +function StreamCopier(input, output, length) { + EventEmitter.decorate(this); + this._id = StreamCopier._nextId++; + this.input = input; + // Save off the base output stream, since we know it's async as we've required + this.baseAsyncOutput = output; + if (IOUtil.outputStreamIsBuffered(output)) { + this.output = output; + } else { + this.output = Cc["@mozilla.org/network/buffered-output-stream;1"]. + createInstance(Ci.nsIBufferedOutputStream); + this.output.init(output, BUFFER_SIZE); + } + this._length = length; + this._amountLeft = length; + this._deferred = defer(); + + this._copy = this._copy.bind(this); + this._flush = this._flush.bind(this); + this._destroy = this._destroy.bind(this); + + // Copy promise's then method up to this object. + // Allows the copier to offer a promise interface for the simple succeed or + // fail scenarios, but also emit events (due to the EventEmitter) for other + // states, like progress. + this.then = this._deferred.promise.then.bind(this._deferred.promise); + this.then(this._destroy, this._destroy); + + // Stream ready callback starts as |_copy|, but may switch to |_flush| at end + // if flushing would block the output stream. + this._streamReadyCallback = this._copy; +} +StreamCopier._nextId = 0; + +StreamCopier.prototype = { + + copy: function () { + // Dispatch to the next tick so that it's possible to attach a progress + // event listener, even for extremely fast copies (like when testing). + Services.tm.currentThread.dispatch(() => { + try { + this._copy(); + } catch (e) { + this._deferred.reject(e); + } + }, 0); + return this; + }, + + _copy: function () { + let bytesAvailable = this.input.available(); + let amountToCopy = Math.min(bytesAvailable, this._amountLeft); + this._debug("Trying to copy: " + amountToCopy); + + let bytesCopied; + try { + bytesCopied = this.output.writeFrom(this.input, amountToCopy); + } catch (e) { + if (e.result == Cr.NS_BASE_STREAM_WOULD_BLOCK) { + this._debug("Base stream would block, will retry"); + this._debug("Waiting for output stream"); + this.baseAsyncOutput.asyncWait(this, 0, 0, Services.tm.currentThread); + return; + } else { + throw e; + } + } + + this._amountLeft -= bytesCopied; + this._debug("Copied: " + bytesCopied + + ", Left: " + this._amountLeft); + this._emitProgress(); + + if (this._amountLeft === 0) { + this._debug("Copy done!"); + this._flush(); + return; + } + + this._debug("Waiting for input stream"); + this.input.asyncWait(this, 0, 0, Services.tm.currentThread); + }, + + _emitProgress: function () { + this.emit("progress", { + bytesSent: this._length - this._amountLeft, + totalBytes: this._length + }); + }, + + _flush: function () { + try { + this.output.flush(); + } catch (e) { + if (e.result == Cr.NS_BASE_STREAM_WOULD_BLOCK || + e.result == Cr.NS_ERROR_FAILURE) { + this._debug("Flush would block, will retry"); + this._streamReadyCallback = this._flush; + this._debug("Waiting for output stream"); + this.baseAsyncOutput.asyncWait(this, 0, 0, Services.tm.currentThread); + return; + } else { + throw e; + } + } + this._deferred.resolve(); + }, + + _destroy: function () { + this._destroy = null; + this._copy = null; + this._flush = null; + this.input = null; + this.output = null; + }, + + // nsIInputStreamCallback + onInputStreamReady: function () { + this._streamReadyCallback(); + }, + + // nsIOutputStreamCallback + onOutputStreamReady: function () { + this._streamReadyCallback(); + }, + + _debug: function (msg) { + // Prefix logs with the copier ID, which makes logs much easier to + // understand when several copiers are running simultaneously + dumpv("Copier: " + this._id + " " + msg); + } + +}; + +/** + * Read from a stream, one byte at a time, up to the next |delimiter| + * character, but stopping if we've read |count| without finding it. Reading + * also terminates early if there are less than |count| bytes available on the + * stream. In that case, we only read as many bytes as the stream currently has + * to offer. + * TODO: This implementation could be removed if bug 984651 is fixed, which + * provides a native version of the same idea. + * @param stream nsIInputStream + * The input stream to read from. + * @param delimiter string + * The character we're trying to find. + * @param count integer + * The max number of characters to read while searching. + * @return string + * The data collected. If the delimiter was found, this string will + * end with it. + */ +function delimitedRead(stream, delimiter, count) { + dumpv("Starting delimited read for " + delimiter + " up to " + + count + " bytes"); + + let scriptableStream; + if (stream instanceof Ci.nsIScriptableInputStream) { + scriptableStream = stream; + } else { + scriptableStream = new ScriptableInputStream(stream); + } + + let data = ""; + + // Don't exceed what's available on the stream + count = Math.min(count, stream.available()); + + if (count <= 0) { + return data; + } + + let char; + while (char !== delimiter && count > 0) { + char = scriptableStream.readBytes(1); + count--; + data += char; + } + + return data; +} + +module.exports = { + copyStream: copyStream, + delimitedRead: delimitedRead +}; diff --git a/devtools/shared/transport/tests/unit/.eslintrc.js b/devtools/shared/transport/tests/unit/.eslintrc.js new file mode 100644 index 000000000..59adf410a --- /dev/null +++ b/devtools/shared/transport/tests/unit/.eslintrc.js @@ -0,0 +1,6 @@ +"use strict"; + +module.exports = { + // Extend from the common devtools xpcshell eslintrc config. + "extends": "../../../../.eslintrc.xpcshell.js" +}; diff --git a/devtools/shared/transport/tests/unit/head_dbg.js b/devtools/shared/transport/tests/unit/head_dbg.js new file mode 100644 index 000000000..1f96ad440 --- /dev/null +++ b/devtools/shared/transport/tests/unit/head_dbg.js @@ -0,0 +1,278 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cu = Components.utils; +var Cr = Components.results; +var CC = Components.Constructor; + +const { require } = + Cu.import("resource://devtools/shared/Loader.jsm", {}); +const { NetUtil } = require("resource://gre/modules/NetUtil.jsm"); +const promise = require("promise"); +const defer = require("devtools/shared/defer"); +const { Task } = require("devtools/shared/task"); + +const Services = require("Services"); +const DevToolsUtils = require("devtools/shared/DevToolsUtils"); + +// We do not want to log packets by default, because in some tests, +// we can be sending large amounts of data. The test harness has +// trouble dealing with logging all the data, and we end up with +// intermittent time outs (e.g. bug 775924). +// Services.prefs.setBoolPref("devtools.debugger.log", true); +// Services.prefs.setBoolPref("devtools.debugger.log.verbose", true); +// Enable remote debugging for the relevant tests. +Services.prefs.setBoolPref("devtools.debugger.remote-enabled", true); + +const { DebuggerServer } = require("devtools/server/main"); +const { DebuggerClient } = require("devtools/shared/client/main"); + +function testExceptionHook(ex) { + try { + do_report_unexpected_exception(ex); + } catch (ex) { + return {throw: ex}; + } + return undefined; +} + +// Convert an nsIScriptError 'aFlags' value into an appropriate string. +function scriptErrorFlagsToKind(aFlags) { + var kind; + if (aFlags & Ci.nsIScriptError.warningFlag) + kind = "warning"; + if (aFlags & Ci.nsIScriptError.exceptionFlag) + kind = "exception"; + else + kind = "error"; + + if (aFlags & Ci.nsIScriptError.strictFlag) + kind = "strict " + kind; + + return kind; +} + +// Register a console listener, so console messages don't just disappear +// into the ether. +var errorCount = 0; +var listener = { + observe: function (aMessage) { + errorCount++; + try { + // If we've been given an nsIScriptError, then we can print out + // something nicely formatted, for tools like Emacs to pick up. + var scriptError = aMessage.QueryInterface(Ci.nsIScriptError); + dump(aMessage.sourceName + ":" + aMessage.lineNumber + ": " + + scriptErrorFlagsToKind(aMessage.flags) + ": " + + aMessage.errorMessage + "\n"); + var string = aMessage.errorMessage; + } catch (x) { + // Be a little paranoid with message, as the whole goal here is to lose + // no information. + try { + var string = "" + aMessage.message; + } catch (x) { + var string = ""; + } + } + + // Make sure we exit all nested event loops so that the test can finish. + while (DebuggerServer.xpcInspector.eventLoopNestLevel > 0) { + DebuggerServer.xpcInspector.exitNestedEventLoop(); + } + + // Throw in most cases, but ignore the "strict" messages + if (!(aMessage.flags & Ci.nsIScriptError.strictFlag)) { + do_throw("head_dbg.js got console message: " + string + "\n"); + } + } +}; + +var consoleService = Cc["@mozilla.org/consoleservice;1"] + .getService(Ci.nsIConsoleService); +consoleService.registerListener(listener); + +function check_except(func) { + try { + func(); + } catch (e) { + do_check_true(true); + return; + } + dump("Should have thrown an exception: " + func.toString()); + do_check_true(false); +} + +function testGlobal(aName) { + let systemPrincipal = Cc["@mozilla.org/systemprincipal;1"] + .createInstance(Ci.nsIPrincipal); + + let sandbox = Cu.Sandbox(systemPrincipal); + sandbox.__name = aName; + return sandbox; +} + +function addTestGlobal(aName) +{ + let global = testGlobal(aName); + DebuggerServer.addTestGlobal(global); + return global; +} + +// List the DebuggerClient |aClient|'s tabs, look for one whose title is +// |aTitle|, and apply |aCallback| to the packet's entry for that tab. +function getTestTab(aClient, aTitle, aCallback) { + aClient.listTabs(function (aResponse) { + for (let tab of aResponse.tabs) { + if (tab.title === aTitle) { + aCallback(tab); + return; + } + } + aCallback(null); + }); +} + +// Attach to |aClient|'s tab whose title is |aTitle|; pass |aCallback| the +// response packet and a TabClient instance referring to that tab. +function attachTestTab(aClient, aTitle, aCallback) { + getTestTab(aClient, aTitle, function (aTab) { + aClient.attachTab(aTab.actor, aCallback); + }); +} + +// Attach to |aClient|'s tab whose title is |aTitle|, and then attach to +// that tab's thread. Pass |aCallback| the thread attach response packet, a +// TabClient referring to the tab, and a ThreadClient referring to the +// thread. +function attachTestThread(aClient, aTitle, aCallback) { + attachTestTab(aClient, aTitle, function (aResponse, aTabClient) { + function onAttach(aResponse, aThreadClient) { + aCallback(aResponse, aTabClient, aThreadClient); + } + aTabClient.attachThread({ useSourceMaps: true }, onAttach); + }); +} + +// Attach to |aClient|'s tab whose title is |aTitle|, attach to the tab's +// thread, and then resume it. Pass |aCallback| the thread's response to +// the 'resume' packet, a TabClient for the tab, and a ThreadClient for the +// thread. +function attachTestTabAndResume(aClient, aTitle, aCallback) { + attachTestThread(aClient, aTitle, function (aResponse, aTabClient, aThreadClient) { + aThreadClient.resume(function (aResponse) { + aCallback(aResponse, aTabClient, aThreadClient); + }); + }); +} + +/** + * Initialize the testing debugger server. + */ +function initTestDebuggerServer() { + DebuggerServer.registerModule("devtools/server/actors/script", { + prefix: "script", + constructor: "ScriptActor", + type: { global: true, tab: true } + }); + DebuggerServer.registerModule("xpcshell-test/testactors"); + // Allow incoming connections. + DebuggerServer.init(); +} + +function finishClient(aClient) { + aClient.close().then(function () { + do_test_finished(); + }); +} + +/** + * Takes a relative file path and returns the absolute file url for it. + */ +function getFileUrl(aName, aAllowMissing = false) { + let file = do_get_file(aName, aAllowMissing); + return Services.io.newFileURI(file).spec; +} + +/** + * Returns the full path of the file with the specified name in a + * platform-independent and URL-like form. + */ +function getFilePath(aName, aAllowMissing = false) { + let file = do_get_file(aName, aAllowMissing); + let path = Services.io.newFileURI(file).spec; + let filePrePath = "file://"; + if ("nsILocalFileWin" in Ci && + file instanceof Ci.nsILocalFileWin) { + filePrePath += "/"; + } + return path.slice(filePrePath.length); +} + +/** + * Wrapper around do_get_file to prefix files with the name of current test to + * avoid collisions when running in parallel. + */ +function getTestTempFile(fileName, allowMissing) { + let thisTest = _TEST_FILE.toString().replace(/\\/g, "/"); + thisTest = thisTest.substring(thisTest.lastIndexOf("/") + 1); + thisTest = thisTest.replace(/\..*$/, ""); + return do_get_file(fileName + "-" + thisTest, allowMissing); +} + +function writeTestTempFile(aFileName, aContent) { + let file = getTestTempFile(aFileName, true); + let stream = Cc["@mozilla.org/network/file-output-stream;1"] + .createInstance(Ci.nsIFileOutputStream); + stream.init(file, -1, -1, 0); + try { + do { + let numWritten = stream.write(aContent, aContent.length); + aContent = aContent.slice(numWritten); + } while (aContent.length > 0); + } finally { + stream.close(); + } +} + +/** * Transport Factories ***/ + +var socket_transport = Task.async(function* () { + if (!DebuggerServer.listeningSockets) { + let AuthenticatorType = DebuggerServer.Authenticators.get("PROMPT"); + let authenticator = new AuthenticatorType.Server(); + authenticator.allowConnection = () => { + return DebuggerServer.AuthenticationResult.ALLOW; + }; + let listener = DebuggerServer.createListener(); + listener.portOrPath = -1; + listener.authenticator = authenticator; + yield listener.open(); + } + let port = DebuggerServer._listeners[0].port; + do_print("Debugger server port is " + port); + return DebuggerClient.socketConnect({ host: "127.0.0.1", port }); +}); + +function local_transport() { + return promise.resolve(DebuggerServer.connectPipe()); +} + +/** * Sample Data ***/ + +var gReallyLong; +function really_long() { + if (gReallyLong) { + return gReallyLong; + } + let ret = "0123456789"; + for (let i = 0; i < 18; i++) { + ret += ret; + } + gReallyLong = ret; + return ret; +} diff --git a/devtools/shared/transport/tests/unit/test_bulk_error.js b/devtools/shared/transport/tests/unit/test_bulk_error.js new file mode 100644 index 000000000..954499291 --- /dev/null +++ b/devtools/shared/transport/tests/unit/test_bulk_error.js @@ -0,0 +1,92 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +function run_test() { + initTestDebuggerServer(); + add_test_bulk_actor(); + + add_task(function* () { + yield test_string_error(socket_transport, json_reply); + yield test_string_error(local_transport, json_reply); + DebuggerServer.destroy(); + }); + + run_next_test(); +} + +/** * Sample Bulk Actor ***/ + +function TestBulkActor() {} + +TestBulkActor.prototype = { + + actorPrefix: "testBulk", + + jsonReply: function ({length, reader, reply, done}) { + do_check_eq(length, really_long().length); + + return { + allDone: true + }; + } + +}; + +TestBulkActor.prototype.requestTypes = { + "jsonReply": TestBulkActor.prototype.jsonReply +}; + +function add_test_bulk_actor() { + DebuggerServer.addGlobalActor(TestBulkActor); +} + +/** * Tests ***/ + +var test_string_error = Task.async(function* (transportFactory, onReady) { + let transport = yield transportFactory(); + + let client = new DebuggerClient(transport); + return client.connect().then(([app, traits]) => { + do_check_eq(traits.bulk, true); + return client.listTabs(); + }).then(response => { + return onReady(client, response); + }).then(() => { + client.close(); + transport.close(); + }); +}); + +/** * Reply Types ***/ + +function json_reply(client, response) { + let reallyLong = really_long(); + + let request = client.startBulkRequest({ + actor: response.testBulk, + type: "jsonReply", + length: reallyLong.length + }); + + // Send bulk data to server + let copyDeferred = defer(); + request.on("bulk-send-ready", ({writer, done}) => { + let input = Cc["@mozilla.org/io/string-input-stream;1"]. + createInstance(Ci.nsIStringInputStream); + input.setData(reallyLong, reallyLong.length); + try { + writer.copyFrom(input, () => { + input.close(); + done(); + }); + do_throw(new Error("Copying should fail, the stream is not async.")); + } catch (e) { + do_check_true(true); + copyDeferred.resolve(); + } + }); + + return copyDeferred.promise; +} diff --git a/devtools/shared/transport/tests/unit/test_client_server_bulk.js b/devtools/shared/transport/tests/unit/test_client_server_bulk.js new file mode 100644 index 000000000..e4d17d216 --- /dev/null +++ b/devtools/shared/transport/tests/unit/test_client_server_bulk.js @@ -0,0 +1,271 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +var { FileUtils } = Cu.import("resource://gre/modules/FileUtils.jsm", {}); +var Pipe = CC("@mozilla.org/pipe;1", "nsIPipe", "init"); + +function run_test() { + initTestDebuggerServer(); + add_test_bulk_actor(); + + add_task(function* () { + yield test_bulk_request_cs(socket_transport, "jsonReply", "json"); + yield test_bulk_request_cs(local_transport, "jsonReply", "json"); + yield test_bulk_request_cs(socket_transport, "bulkEcho", "bulk"); + yield test_bulk_request_cs(local_transport, "bulkEcho", "bulk"); + yield test_json_request_cs(socket_transport, "bulkReply", "bulk"); + yield test_json_request_cs(local_transport, "bulkReply", "bulk"); + DebuggerServer.destroy(); + }); + + run_next_test(); +} + +/** * Sample Bulk Actor ***/ + +function TestBulkActor(conn) { + this.conn = conn; +} + +TestBulkActor.prototype = { + + actorPrefix: "testBulk", + + bulkEcho: function ({actor, type, length, copyTo}) { + do_check_eq(length, really_long().length); + this.conn.startBulkSend({ + actor: actor, + type: type, + length: length + }).then(({copyFrom}) => { + // We'll just echo back the same thing + let pipe = new Pipe(true, true, 0, 0, null); + copyTo(pipe.outputStream).then(() => { + pipe.outputStream.close(); + }); + copyFrom(pipe.inputStream).then(() => { + pipe.inputStream.close(); + }); + }); + }, + + bulkReply: function ({to, type}) { + this.conn.startBulkSend({ + actor: to, + type: type, + length: really_long().length + }).then(({copyFrom}) => { + NetUtil.asyncFetch({ + uri: NetUtil.newURI(getTestTempFile("bulk-input")), + loadUsingSystemPrincipal: true + }, input => { + copyFrom(input).then(() => { + input.close(); + }); + }); + }); + }, + + jsonReply: function ({length, copyTo}) { + do_check_eq(length, really_long().length); + + let outputFile = getTestTempFile("bulk-output", true); + outputFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, parseInt("666", 8)); + + let output = FileUtils.openSafeFileOutputStream(outputFile); + + return copyTo(output).then(() => { + FileUtils.closeSafeFileOutputStream(output); + return verify_files(); + }).then(() => { + return { allDone: true }; + }, do_throw); + } + +}; + +TestBulkActor.prototype.requestTypes = { + "bulkEcho": TestBulkActor.prototype.bulkEcho, + "bulkReply": TestBulkActor.prototype.bulkReply, + "jsonReply": TestBulkActor.prototype.jsonReply +}; + +function add_test_bulk_actor() { + DebuggerServer.addGlobalActor(TestBulkActor); +} + +/** * Reply Handlers ***/ + +var replyHandlers = { + + json: function (request) { + // Receive JSON reply from server + let replyDeferred = defer(); + request.on("json-reply", (reply) => { + do_check_true(reply.allDone); + replyDeferred.resolve(); + }); + return replyDeferred.promise; + }, + + bulk: function (request) { + // Receive bulk data reply from server + let replyDeferred = defer(); + request.on("bulk-reply", ({length, copyTo}) => { + do_check_eq(length, really_long().length); + + let outputFile = getTestTempFile("bulk-output", true); + outputFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, parseInt("666", 8)); + + let output = FileUtils.openSafeFileOutputStream(outputFile); + + copyTo(output).then(() => { + FileUtils.closeSafeFileOutputStream(output); + replyDeferred.resolve(verify_files()); + }); + }); + return replyDeferred.promise; + } + +}; + +/** * Tests ***/ + +var test_bulk_request_cs = Task.async(function* (transportFactory, actorType, replyType) { + // Ensure test files are not present from a failed run + cleanup_files(); + writeTestTempFile("bulk-input", really_long()); + + let clientDeferred = defer(); + let serverDeferred = defer(); + let bulkCopyDeferred = defer(); + + let transport = yield transportFactory(); + + let client = new DebuggerClient(transport); + client.connect().then(([app, traits]) => { + do_check_eq(traits.bulk, true); + client.listTabs(clientDeferred.resolve); + }); + + clientDeferred.promise.then(response => { + let request = client.startBulkRequest({ + actor: response.testBulk, + type: actorType, + length: really_long().length + }); + + // Send bulk data to server + request.on("bulk-send-ready", ({copyFrom}) => { + NetUtil.asyncFetch({ + uri: NetUtil.newURI(getTestTempFile("bulk-input")), + loadUsingSystemPrincipal: true + }, input => { + copyFrom(input).then(() => { + input.close(); + bulkCopyDeferred.resolve(); + }); + }); + }); + + // Set up reply handling for this type + replyHandlers[replyType](request).then(() => { + client.close(); + transport.close(); + }); + }).then(null, do_throw); + + DebuggerServer.on("connectionchange", (event, type) => { + if (type === "closed") { + serverDeferred.resolve(); + } + }); + + return promise.all([ + clientDeferred.promise, + bulkCopyDeferred.promise, + serverDeferred.promise + ]); +}); + +var test_json_request_cs = Task.async(function* (transportFactory, actorType, replyType) { + // Ensure test files are not present from a failed run + cleanup_files(); + writeTestTempFile("bulk-input", really_long()); + + let clientDeferred = defer(); + let serverDeferred = defer(); + + let transport = yield transportFactory(); + + let client = new DebuggerClient(transport); + client.connect((app, traits) => { + do_check_eq(traits.bulk, true); + client.listTabs(clientDeferred.resolve); + }); + + clientDeferred.promise.then(response => { + let request = client.request({ + to: response.testBulk, + type: actorType + }); + + // Set up reply handling for this type + replyHandlers[replyType](request).then(() => { + client.close(); + transport.close(); + }); + }).then(null, do_throw); + + DebuggerServer.on("connectionchange", (event, type) => { + if (type === "closed") { + serverDeferred.resolve(); + } + }); + + return promise.all([ + clientDeferred.promise, + serverDeferred.promise + ]); +}); + +/** * Test Utils ***/ + +function verify_files() { + let reallyLong = really_long(); + + let inputFile = getTestTempFile("bulk-input"); + let outputFile = getTestTempFile("bulk-output"); + + do_check_eq(inputFile.fileSize, reallyLong.length); + do_check_eq(outputFile.fileSize, reallyLong.length); + + // Ensure output file contents actually match + let compareDeferred = defer(); + NetUtil.asyncFetch({ + uri: NetUtil.newURI(getTestTempFile("bulk-output")), + loadUsingSystemPrincipal: true + }, input => { + let outputData = NetUtil.readInputStreamToString(input, reallyLong.length); + // Avoid do_check_eq here so we don't log the contents + do_check_true(outputData === reallyLong); + input.close(); + compareDeferred.resolve(); + }); + + return compareDeferred.promise.then(cleanup_files); +} + +function cleanup_files() { + let inputFile = getTestTempFile("bulk-input", true); + if (inputFile.exists()) { + inputFile.remove(false); + } + + let outputFile = getTestTempFile("bulk-output", true); + if (outputFile.exists()) { + outputFile.remove(false); + } +} diff --git a/devtools/shared/transport/tests/unit/test_dbgsocket.js b/devtools/shared/transport/tests/unit/test_dbgsocket.js new file mode 100644 index 000000000..79111f877 --- /dev/null +++ b/devtools/shared/transport/tests/unit/test_dbgsocket.js @@ -0,0 +1,124 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +var gPort; +var gExtraListener; + +function run_test() +{ + do_print("Starting test at " + new Date().toTimeString()); + initTestDebuggerServer(); + + add_task(test_socket_conn); + add_task(test_socket_shutdown); + add_test(test_pipe_conn); + + run_next_test(); +} + +function* test_socket_conn() +{ + do_check_eq(DebuggerServer.listeningSockets, 0); + let AuthenticatorType = DebuggerServer.Authenticators.get("PROMPT"); + let authenticator = new AuthenticatorType.Server(); + authenticator.allowConnection = () => { + return DebuggerServer.AuthenticationResult.ALLOW; + }; + let listener = DebuggerServer.createListener(); + do_check_true(listener); + listener.portOrPath = -1; + listener.authenticator = authenticator; + listener.open(); + do_check_eq(DebuggerServer.listeningSockets, 1); + gPort = DebuggerServer._listeners[0].port; + do_print("Debugger server port is " + gPort); + // Open a second, separate listener + gExtraListener = DebuggerServer.createListener(); + gExtraListener.portOrPath = -1; + gExtraListener.authenticator = authenticator; + gExtraListener.open(); + do_check_eq(DebuggerServer.listeningSockets, 2); + + do_print("Starting long and unicode tests at " + new Date().toTimeString()); + let unicodeString = "(╯°□°)╯︵ ┻━┻"; + let transport = yield DebuggerClient.socketConnect({ + host: "127.0.0.1", + port: gPort + }); + + // Assert that connection settings are available on transport object + let settings = transport.connectionSettings; + do_check_eq(settings.host, "127.0.0.1"); + do_check_eq(settings.port, gPort); + + let closedDeferred = defer(); + transport.hooks = { + onPacket: function (aPacket) { + this.onPacket = function (aPacket) { + do_check_eq(aPacket.unicode, unicodeString); + transport.close(); + }; + // Verify that things work correctly when bigger than the output + // transport buffers and when transporting unicode... + transport.send({to: "root", + type: "echo", + reallylong: really_long(), + unicode: unicodeString}); + do_check_eq(aPacket.from, "root"); + }, + onClosed: function (aStatus) { + closedDeferred.resolve(); + }, + }; + transport.ready(); + return closedDeferred.promise; +} + +function* test_socket_shutdown() +{ + do_check_eq(DebuggerServer.listeningSockets, 2); + gExtraListener.close(); + do_check_eq(DebuggerServer.listeningSockets, 1); + do_check_true(DebuggerServer.closeAllListeners()); + do_check_eq(DebuggerServer.listeningSockets, 0); + // Make sure closing the listener twice does nothing. + do_check_false(DebuggerServer.closeAllListeners()); + do_check_eq(DebuggerServer.listeningSockets, 0); + + do_print("Connecting to a server socket at " + new Date().toTimeString()); + try { + let transport = yield DebuggerClient.socketConnect({ + host: "127.0.0.1", + port: gPort + }); + } catch (e) { + if (e.result == Cr.NS_ERROR_CONNECTION_REFUSED || + e.result == Cr.NS_ERROR_NET_TIMEOUT) { + // The connection should be refused here, but on slow or overloaded + // machines it may just time out. + do_check_true(true); + return; + } else { + throw e; + } + } + + // Shouldn't reach this, should never connect. + do_check_true(false); +} + +function test_pipe_conn() +{ + let transport = DebuggerServer.connectPipe(); + transport.hooks = { + onPacket: function (aPacket) { + do_check_eq(aPacket.from, "root"); + transport.close(); + }, + onClosed: function (aStatus) { + run_next_test(); + } + }; + + transport.ready(); +} diff --git a/devtools/shared/transport/tests/unit/test_dbgsocket_connection_drop.js b/devtools/shared/transport/tests/unit/test_dbgsocket_connection_drop.js new file mode 100644 index 000000000..9221939b1 --- /dev/null +++ b/devtools/shared/transport/tests/unit/test_dbgsocket_connection_drop.js @@ -0,0 +1,81 @@ +/** + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +/** + * Bug 755412 - checks if the server drops the connection on an improperly + * framed packet, i.e. when the length header is invalid. + */ + +const { RawPacket } = require("devtools/shared/transport/packets"); + +function run_test() { + do_print("Starting test at " + new Date().toTimeString()); + initTestDebuggerServer(); + + add_task(test_socket_conn_drops_after_invalid_header); + add_task(test_socket_conn_drops_after_invalid_header_2); + add_task(test_socket_conn_drops_after_too_large_length); + add_task(test_socket_conn_drops_after_too_long_header); + run_next_test(); +} + +function test_socket_conn_drops_after_invalid_header() { + return test_helper('fluff30:27:{"to":"root","type":"echo"}'); +} + +function test_socket_conn_drops_after_invalid_header_2() { + return test_helper('27asd:{"to":"root","type":"echo"}'); +} + +function test_socket_conn_drops_after_too_large_length() { + // Packet length is limited (semi-arbitrarily) to 1 TiB (2^40) + return test_helper("4305724038957487634549823475894325:"); +} + +function test_socket_conn_drops_after_too_long_header() { + // The packet header is currently limited to no more than 200 bytes + let rawPacket = "4305724038957487634549823475894325"; + for (let i = 0; i < 8; i++) { + rawPacket += rawPacket; + } + return test_helper(rawPacket + ":"); +} + +var test_helper = Task.async(function* (payload) { + let AuthenticatorType = DebuggerServer.Authenticators.get("PROMPT"); + let authenticator = new AuthenticatorType.Server(); + authenticator.allowConnection = () => { + return DebuggerServer.AuthenticationResult.ALLOW; + }; + + let listener = DebuggerServer.createListener(); + listener.portOrPath = -1; + listener.authenticator = authenticator; + listener.open(); + + let transport = yield DebuggerClient.socketConnect({ + host: "127.0.0.1", + port: listener.port + }); + let closedDeferred = defer(); + transport.hooks = { + onPacket: function (aPacket) { + this.onPacket = function (aPacket) { + do_throw(new Error("This connection should be dropped.")); + transport.close(); + }; + + // Inject the payload directly into the stream. + transport._outgoing.push(new RawPacket(transport, payload)); + transport._flushOutgoing(); + }, + onClosed: function (aStatus) { + do_check_true(true); + closedDeferred.resolve(); + }, + }; + transport.ready(); + return closedDeferred.promise; +}); diff --git a/devtools/shared/transport/tests/unit/test_delimited_read.js b/devtools/shared/transport/tests/unit/test_delimited_read.js new file mode 100644 index 000000000..a5a7baf7b --- /dev/null +++ b/devtools/shared/transport/tests/unit/test_delimited_read.js @@ -0,0 +1,26 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +const StreamUtils = require("devtools/shared/transport/stream-utils"); + +const StringInputStream = CC("@mozilla.org/io/string-input-stream;1", + "nsIStringInputStream", "setData"); + +function run_test() { + add_task(function* () { + yield test_delimited_read("0123:", "0123:"); + yield test_delimited_read("0123:4567:", "0123:"); + yield test_delimited_read("012345678901:", "0123456789"); + yield test_delimited_read("0123/0123", "0123/0123"); + }); + + run_next_test(); +} + +/** * Tests ***/ + +function test_delimited_read(input, expected) { + input = new StringInputStream(input, input.length); + let result = StreamUtils.delimitedRead(input, ":", 10); + do_check_eq(result, expected); +} diff --git a/devtools/shared/transport/tests/unit/test_no_bulk.js b/devtools/shared/transport/tests/unit/test_no_bulk.js new file mode 100644 index 000000000..f621a2a52 --- /dev/null +++ b/devtools/shared/transport/tests/unit/test_no_bulk.js @@ -0,0 +1,38 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +function run_test() { + DebuggerServer.registerModule("xpcshell-test/testactors-no-bulk"); + // Allow incoming connections. + DebuggerServer.init(); + + add_task(function* () { + yield test_bulk_send_error(socket_transport); + yield test_bulk_send_error(local_transport); + DebuggerServer.destroy(); + }); + + run_next_test(); +} + +/** * Tests ***/ + +var test_bulk_send_error = Task.async(function* (transportFactory) { + let deferred = defer(); + let transport = yield transportFactory(); + + let client = new DebuggerClient(transport); + return client.connect().then(([app, traits]) => { + do_check_false(traits.bulk); + + try { + client.startBulkRequest(); + do_throw(new Error("Can't use bulk since server doesn't support it")); + } catch (e) { + do_check_true(true); + } + + }); +}); diff --git a/devtools/shared/transport/tests/unit/test_packet.js b/devtools/shared/transport/tests/unit/test_packet.js new file mode 100644 index 000000000..7e1896555 --- /dev/null +++ b/devtools/shared/transport/tests/unit/test_packet.js @@ -0,0 +1,21 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +const { JSONPacket, BulkPacket } = + require("devtools/shared/transport/packets"); + +function run_test() { + add_test(test_packet_done); + run_next_test(); +} + +// Ensure done can be checked without getting an error +function test_packet_done() { + let json = new JSONPacket(); + do_check_false(!!json.done); + + let bulk = new BulkPacket(); + do_check_false(!!bulk.done); + + run_next_test(); +} diff --git a/devtools/shared/transport/tests/unit/test_queue.js b/devtools/shared/transport/tests/unit/test_queue.js new file mode 100644 index 000000000..5de14baee --- /dev/null +++ b/devtools/shared/transport/tests/unit/test_queue.js @@ -0,0 +1,177 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +/** + * This test verifies that the transport's queue operates correctly when various + * packets are scheduled simultaneously. + */ + +var { FileUtils } = Cu.import("resource://gre/modules/FileUtils.jsm", {}); + +function run_test() { + initTestDebuggerServer(); + + add_task(function* () { + yield test_transport(socket_transport); + yield test_transport(local_transport); + DebuggerServer.destroy(); + }); + + run_next_test(); +} + +/** * Tests ***/ + +var test_transport = Task.async(function* (transportFactory) { + let clientDeferred = defer(); + let serverDeferred = defer(); + + // Ensure test files are not present from a failed run + cleanup_files(); + let reallyLong = really_long(); + writeTestTempFile("bulk-input", reallyLong); + + do_check_eq(Object.keys(DebuggerServer._connections).length, 0); + + let transport = yield transportFactory(); + + // Sending from client to server + function write_data({copyFrom}) { + NetUtil.asyncFetch({ + uri: NetUtil.newURI(getTestTempFile("bulk-input")), + loadUsingSystemPrincipal: true + }, function (input, status) { + copyFrom(input).then(() => { + input.close(); + }); + }); + } + + // Receiving on server from client + function on_bulk_packet({actor, type, length, copyTo}) { + do_check_eq(actor, "root"); + do_check_eq(type, "file-stream"); + do_check_eq(length, reallyLong.length); + + let outputFile = getTestTempFile("bulk-output", true); + outputFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, parseInt("666", 8)); + + let output = FileUtils.openSafeFileOutputStream(outputFile); + + copyTo(output).then(() => { + FileUtils.closeSafeFileOutputStream(output); + return verify(); + }).then(() => { + // It's now safe to close + transport.hooks.onClosed = () => { + clientDeferred.resolve(); + }; + transport.close(); + }); + } + + // Client + + function send_packets() { + // Specifically, we want to ensure that multiple send()s proceed without + // causing the transport to die. + transport.send({ + actor: "root", + type: "explode" + }); + + transport.startBulkSend({ + actor: "root", + type: "file-stream", + length: reallyLong.length + }).then(write_data); + } + + transport.hooks = { + onPacket: function (packet) { + if (packet.error) { + transport.hooks.onError(packet); + } else if (packet.applicationType) { + transport.hooks.onServerHello(packet); + } else { + do_throw("Unexpected server reply"); + } + }, + + onServerHello: function (packet) { + // We've received the initial start up packet + do_check_eq(packet.from, "root"); + do_check_eq(packet.applicationType, "xpcshell-tests"); + + // Server + do_check_eq(Object.keys(DebuggerServer._connections).length, 1); + do_print(Object.keys(DebuggerServer._connections)); + for (let connId in DebuggerServer._connections) { + DebuggerServer._connections[connId].onBulkPacket = on_bulk_packet; + } + + DebuggerServer.on("connectionchange", (event, type) => { + if (type === "closed") { + serverDeferred.resolve(); + } + }); + + send_packets(); + }, + + onError: function (packet) { + // The explode actor doesn't exist + do_check_eq(packet.from, "root"); + do_check_eq(packet.error, "noSuchActor"); + }, + + onClosed: function () { + do_throw("Transport closed before we expected"); + } + }; + + transport.ready(); + + return promise.all([clientDeferred.promise, serverDeferred.promise]); +}); + +/** * Test Utils ***/ + +function verify() { + let reallyLong = really_long(); + + let inputFile = getTestTempFile("bulk-input"); + let outputFile = getTestTempFile("bulk-output"); + + do_check_eq(inputFile.fileSize, reallyLong.length); + do_check_eq(outputFile.fileSize, reallyLong.length); + + // Ensure output file contents actually match + let compareDeferred = defer(); + NetUtil.asyncFetch({ + uri: NetUtil.newURI(getTestTempFile("bulk-output")), + loadUsingSystemPrincipal: true + }, input => { + let outputData = NetUtil.readInputStreamToString(input, reallyLong.length); + // Avoid do_check_eq here so we don't log the contents + do_check_true(outputData === reallyLong); + input.close(); + compareDeferred.resolve(); + }); + + return compareDeferred.promise.then(cleanup_files); +} + +function cleanup_files() { + let inputFile = getTestTempFile("bulk-input", true); + if (inputFile.exists()) { + inputFile.remove(false); + } + + let outputFile = getTestTempFile("bulk-output", true); + if (outputFile.exists()) { + outputFile.remove(false); + } +} diff --git a/devtools/shared/transport/tests/unit/test_transport_bulk.js b/devtools/shared/transport/tests/unit/test_transport_bulk.js new file mode 100644 index 000000000..a21216acf --- /dev/null +++ b/devtools/shared/transport/tests/unit/test_transport_bulk.js @@ -0,0 +1,148 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +var { FileUtils } = Cu.import("resource://gre/modules/FileUtils.jsm", {}); + +function run_test() { + initTestDebuggerServer(); + + add_task(function* () { + yield test_bulk_transfer_transport(socket_transport); + yield test_bulk_transfer_transport(local_transport); + DebuggerServer.destroy(); + }); + + run_next_test(); +} + +/** * Tests ***/ + +/** + * This tests a one-way bulk transfer at the transport layer. + */ +var test_bulk_transfer_transport = Task.async(function* (transportFactory) { + do_print("Starting bulk transfer test at " + new Date().toTimeString()); + + let clientDeferred = defer(); + let serverDeferred = defer(); + + // Ensure test files are not present from a failed run + cleanup_files(); + let reallyLong = really_long(); + writeTestTempFile("bulk-input", reallyLong); + + do_check_eq(Object.keys(DebuggerServer._connections).length, 0); + + let transport = yield transportFactory(); + + // Sending from client to server + function write_data({copyFrom}) { + NetUtil.asyncFetch({ + uri: NetUtil.newURI(getTestTempFile("bulk-input")), + loadUsingSystemPrincipal: true + }, function (input, status) { + copyFrom(input).then(() => { + input.close(); + }); + }); + } + + // Receiving on server from client + function on_bulk_packet({actor, type, length, copyTo}) { + do_check_eq(actor, "root"); + do_check_eq(type, "file-stream"); + do_check_eq(length, reallyLong.length); + + let outputFile = getTestTempFile("bulk-output", true); + outputFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, parseInt("666", 8)); + + let output = FileUtils.openSafeFileOutputStream(outputFile); + + copyTo(output).then(() => { + FileUtils.closeSafeFileOutputStream(output); + return verify(); + }).then(() => { + // It's now safe to close + transport.hooks.onClosed = () => { + clientDeferred.resolve(); + }; + transport.close(); + }); + } + + // Client + transport.hooks = { + onPacket: function (aPacket) { + // We've received the initial start up packet + do_check_eq(aPacket.from, "root"); + + // Server + do_check_eq(Object.keys(DebuggerServer._connections).length, 1); + do_print(Object.keys(DebuggerServer._connections)); + for (let connId in DebuggerServer._connections) { + DebuggerServer._connections[connId].onBulkPacket = on_bulk_packet; + } + + DebuggerServer.on("connectionchange", (event, type) => { + if (type === "closed") { + serverDeferred.resolve(); + } + }); + + transport.startBulkSend({ + actor: "root", + type: "file-stream", + length: reallyLong.length + }).then(write_data); + }, + + onClosed: function () { + do_throw("Transport closed before we expected"); + } + }; + + transport.ready(); + + return promise.all([clientDeferred.promise, serverDeferred.promise]); +}); + +/** * Test Utils ***/ + +function verify() { + let reallyLong = really_long(); + + let inputFile = getTestTempFile("bulk-input"); + let outputFile = getTestTempFile("bulk-output"); + + do_check_eq(inputFile.fileSize, reallyLong.length); + do_check_eq(outputFile.fileSize, reallyLong.length); + + // Ensure output file contents actually match + let compareDeferred = defer(); + NetUtil.asyncFetch({ + uri: NetUtil.newURI(getTestTempFile("bulk-output")), + loadUsingSystemPrincipal: true + }, input => { + let outputData = NetUtil.readInputStreamToString(input, reallyLong.length); + // Avoid do_check_eq here so we don't log the contents + do_check_true(outputData === reallyLong); + input.close(); + compareDeferred.resolve(); + }); + + return compareDeferred.promise.then(cleanup_files); +} + +function cleanup_files() { + let inputFile = getTestTempFile("bulk-input", true); + if (inputFile.exists()) { + inputFile.remove(false); + } + + let outputFile = getTestTempFile("bulk-output", true); + if (outputFile.exists()) { + outputFile.remove(false); + } +} diff --git a/devtools/shared/transport/tests/unit/test_transport_events.js b/devtools/shared/transport/tests/unit/test_transport_events.js new file mode 100644 index 000000000..ae20f6cf8 --- /dev/null +++ b/devtools/shared/transport/tests/unit/test_transport_events.js @@ -0,0 +1,75 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +function run_test() { + initTestDebuggerServer(); + + add_task(function* () { + yield test_transport_events("socket", socket_transport); + yield test_transport_events("local", local_transport); + DebuggerServer.destroy(); + }); + + run_next_test(); +} + +function* test_transport_events(name, transportFactory) { + do_print(`Started testing of transport: ${name}`); + + do_check_eq(Object.keys(DebuggerServer._connections).length, 0); + + let transport = yield transportFactory(); + + // Transport expects the hooks to be not null + transport.hooks = { + onPacket: () => {}, + onClosed: () => {}, + }; + + let rootReceived = transport.once("packet", (event, packet) => { + do_print(`Packet event: ${event} ${JSON.stringify(packet)}`); + do_check_eq(event, "packet"); + do_check_eq(packet.from, "root"); + }); + + transport.ready(); + yield rootReceived; + + let echoSent = transport.once("send", (event, packet) => { + do_print(`Send event: ${event} ${JSON.stringify(packet)}`); + do_check_eq(event, "send"); + do_check_eq(packet.to, "root"); + do_check_eq(packet.type, "echo"); + }); + + let echoReceived = transport.once("packet", (event, packet) => { + do_print(`Packet event: ${event} ${JSON.stringify(packet)}`); + do_check_eq(event, "packet"); + do_check_eq(packet.from, "root"); + do_check_eq(packet.type, "echo"); + }); + + transport.send({ to: "root", type: "echo" }); + yield echoSent; + yield echoReceived; + + let clientClosed = transport.once("close", (event) => { + do_print(`Close event: ${event}`); + do_check_eq(event, "close"); + }); + + let serverClosed = DebuggerServer.once("connectionchange", (event, type) => { + do_print(`Server closed`); + do_check_eq(event, "connectionchange"); + do_check_eq(type, "closed"); + }); + + transport.close(); + + yield clientClosed; + yield serverClosed; + + do_print(`Finished testing of transport: ${name}`); +} diff --git a/devtools/shared/transport/tests/unit/testactors-no-bulk.js b/devtools/shared/transport/tests/unit/testactors-no-bulk.js new file mode 100644 index 000000000..d2c8193fe --- /dev/null +++ b/devtools/shared/transport/tests/unit/testactors-no-bulk.js @@ -0,0 +1,27 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +const { RootActor } = require("devtools/server/actors/root"); +const { DebuggerServer } = require("devtools/server/main"); + +/** + * Root actor that doesn't have the bulk trait. + */ +function createRootActor(aConnection) { + let root = new RootActor(aConnection, { + globalActorFactories: DebuggerServer.globalActorFactories + }); + root.applicationType = "xpcshell-tests"; + root.traits = { + bulk: false + }; + return root; +} + +exports.register = function (handle) { + handle.setRootActor(createRootActor); +}; + +exports.unregister = function (handle) { + handle.setRootActor(null); +}; diff --git a/devtools/shared/transport/tests/unit/testactors.js b/devtools/shared/transport/tests/unit/testactors.js new file mode 100644 index 000000000..80d5d4e18 --- /dev/null +++ b/devtools/shared/transport/tests/unit/testactors.js @@ -0,0 +1,131 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +const { ActorPool, appendExtraActors, createExtraActors } = + require("devtools/server/actors/common"); +const { RootActor } = require("devtools/server/actors/root"); +const { ThreadActor } = require("devtools/server/actors/script"); +const { DebuggerServer } = require("devtools/server/main"); +const promise = require("promise"); + +var gTestGlobals = []; +DebuggerServer.addTestGlobal = function (aGlobal) { + gTestGlobals.push(aGlobal); +}; + +// A mock tab list, for use by tests. This simply presents each global in +// gTestGlobals as a tab, and the list is fixed: it never calls its +// onListChanged handler. +// +// As implemented now, we consult gTestGlobals when we're constructed, not +// when we're iterated over, so tests have to add their globals before the +// root actor is created. +function TestTabList(aConnection) { + this.conn = aConnection; + + // An array of actors for each global added with + // DebuggerServer.addTestGlobal. + this._tabActors = []; + + // A pool mapping those actors' names to the actors. + this._tabActorPool = new ActorPool(aConnection); + + for (let global of gTestGlobals) { + let actor = new TestTabActor(aConnection, global); + actor.selected = false; + this._tabActors.push(actor); + this._tabActorPool.addActor(actor); + } + if (this._tabActors.length > 0) { + this._tabActors[0].selected = true; + } + + aConnection.addActorPool(this._tabActorPool); +} + +TestTabList.prototype = { + constructor: TestTabList, + getList: function () { + return promise.resolve([...this._tabActors]); + } +}; + +function createRootActor(aConnection) { + let root = new RootActor(aConnection, { + tabList: new TestTabList(aConnection), + globalActorFactories: DebuggerServer.globalActorFactories + }); + root.applicationType = "xpcshell-tests"; + return root; +} + +function TestTabActor(aConnection, aGlobal) { + this.conn = aConnection; + this._global = aGlobal; + this._threadActor = new ThreadActor(this, this._global); + this.conn.addActor(this._threadActor); + this._attached = false; + this._extraActors = {}; +} + +TestTabActor.prototype = { + constructor: TestTabActor, + actorPrefix: "TestTabActor", + + get window() { + return { wrappedJSObject: this._global }; + }, + + get url() { + return this._global.__name; + }, + + form: function () { + let response = { actor: this.actorID, title: this._global.__name }; + + // Walk over tab actors added by extensions and add them to a new ActorPool. + let actorPool = new ActorPool(this.conn); + this._createExtraActors(DebuggerServer.tabActorFactories, actorPool); + if (!actorPool.isEmpty()) { + this._tabActorPool = actorPool; + this.conn.addActorPool(this._tabActorPool); + } + + this._appendExtraActors(response); + + return response; + }, + + onAttach: function (aRequest) { + this._attached = true; + + let response = { type: "tabAttached", threadActor: this._threadActor.actorID }; + this._appendExtraActors(response); + + return response; + }, + + onDetach: function (aRequest) { + if (!this._attached) { + return { "error":"wrongState" }; + } + return { type: "detached" }; + }, + + /* Support for DebuggerServer.addTabActor. */ + _createExtraActors: createExtraActors, + _appendExtraActors: appendExtraActors +}; + +TestTabActor.prototype.requestTypes = { + "attach": TestTabActor.prototype.onAttach, + "detach": TestTabActor.prototype.onDetach +}; + +exports.register = function (handle) { + handle.setRootActor(createRootActor); +}; + +exports.unregister = function (handle) { + handle.setRootActor(null); +}; diff --git a/devtools/shared/transport/tests/unit/xpcshell.ini b/devtools/shared/transport/tests/unit/xpcshell.ini new file mode 100644 index 000000000..b79906e82 --- /dev/null +++ b/devtools/shared/transport/tests/unit/xpcshell.ini @@ -0,0 +1,21 @@ +[DEFAULT] +tags = devtools +head = head_dbg.js +tail = +firefox-appdir = browser +skip-if = toolkit == 'android' + +support-files = + testactors.js + testactors-no-bulk.js + +[test_bulk_error.js] +[test_client_server_bulk.js] +[test_dbgsocket.js] +[test_dbgsocket_connection_drop.js] +[test_delimited_read.js] +[test_no_bulk.js] +[test_packet.js] +[test_queue.js] +[test_transport_bulk.js] +[test_transport_events.js] diff --git a/devtools/shared/transport/transport.js b/devtools/shared/transport/transport.js new file mode 100644 index 000000000..e83bf8de6 --- /dev/null +++ b/devtools/shared/transport/transport.js @@ -0,0 +1,908 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/* global Pipe, ScriptableInputStream, uneval */ + +// TODO: Get rid of this code once the marionette server loads transport.js as +// an SDK module (see bug 1000814) +(function (factory) { + if (this.module && module.id.indexOf("transport") >= 0) { + // require + factory.call(this, require, exports); + } else if (this.require) { + // loadSubScript + factory.call(this, require, this); + } else { + // Cu.import + const Cu = Components.utils; + const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {}); + factory.call(this, require, this); + } +}).call(this, function (require, exports) { + const { Cc, Cr, CC } = require("chrome"); + const DevToolsUtils = require("devtools/shared/DevToolsUtils"); + const { dumpn, dumpv } = DevToolsUtils; + const flags = require("devtools/shared/flags"); + const StreamUtils = require("devtools/shared/transport/stream-utils"); + const { Packet, JSONPacket, BulkPacket } = + require("devtools/shared/transport/packets"); + const promise = require("promise"); + const defer = require("devtools/shared/defer"); + const EventEmitter = require("devtools/shared/event-emitter"); + + DevToolsUtils.defineLazyGetter(this, "Pipe", () => { + return CC("@mozilla.org/pipe;1", "nsIPipe", "init"); + }); + + DevToolsUtils.defineLazyGetter(this, "ScriptableInputStream", () => { + return CC("@mozilla.org/scriptableinputstream;1", + "nsIScriptableInputStream", "init"); + }); + + const PACKET_HEADER_MAX = 200; + + /** + * An adapter that handles data transfers between the debugger client and + * server. It can work with both nsIPipe and nsIServerSocket transports so + * long as the properly created input and output streams are specified. + * (However, for intra-process connections, LocalDebuggerTransport, below, + * is more efficient than using an nsIPipe pair with DebuggerTransport.) + * + * @param input nsIAsyncInputStream + * The input stream. + * @param output nsIAsyncOutputStream + * The output stream. + * + * Given a DebuggerTransport instance dt: + * 1) Set dt.hooks to a packet handler object (described below). + * 2) Call dt.ready() to begin watching for input packets. + * 3) Call dt.send() / dt.startBulkSend() to send packets. + * 4) Call dt.close() to close the connection, and disengage from the event + * loop. + * + * A packet handler is an object with the following methods: + * + * - onPacket(packet) - called when we have received a complete packet. + * |packet| is the parsed form of the packet --- a JavaScript value, not + * a JSON-syntax string. + * + * - onBulkPacket(packet) - called when we have switched to bulk packet + * receiving mode. |packet| is an object containing: + * * actor: Name of actor that will receive the packet + * * type: Name of actor's method that should be called on receipt + * * length: Size of the data to be read + * * stream: This input stream should only be used directly if you can ensure + * that you will read exactly |length| bytes and will not close the + * stream when reading is complete + * * done: If you use the stream directly (instead of |copyTo| below), you + * must signal completion by resolving / rejecting this deferred. + * If it's rejected, the transport will be closed. If an Error is + * supplied as a rejection value, it will be logged via |dumpn|. + * If you do use |copyTo|, resolving is taken care of for you when + * copying completes. + * * copyTo: A helper function for getting your data out of the stream that + * meets the stream handling requirements above, and has the + * following signature: + * @param output nsIAsyncOutputStream + * The stream to copy to. + * @return Promise + * The promise is resolved when copying completes or rejected if any + * (unexpected) errors occur. + * This object also emits "progress" events for each chunk that is + * copied. See stream-utils.js. + * + * - onClosed(reason) - called when the connection is closed. |reason| is + * an optional nsresult or object, typically passed when the transport is + * closed due to some error in a underlying stream. + * + * See ./packets.js and the Remote Debugging Protocol specification for more + * details on the format of these packets. + */ + function DebuggerTransport(input, output) { + EventEmitter.decorate(this); + + this._input = input; + this._scriptableInput = new ScriptableInputStream(input); + this._output = output; + + // The current incoming (possibly partial) header, which will determine which + // type of Packet |_incoming| below will become. + this._incomingHeader = ""; + // The current incoming Packet object + this._incoming = null; + // A queue of outgoing Packet objects + this._outgoing = []; + + this.hooks = null; + this.active = false; + + this._incomingEnabled = true; + this._outgoingEnabled = true; + + this.close = this.close.bind(this); + } + + DebuggerTransport.prototype = { + /** + * Transmit an object as a JSON packet. + * + * This method returns immediately, without waiting for the entire + * packet to be transmitted, registering event handlers as needed to + * transmit the entire packet. Packets are transmitted in the order + * they are passed to this method. + */ + send: function (object) { + this.emit("send", object); + + let packet = new JSONPacket(this); + packet.object = object; + this._outgoing.push(packet); + this._flushOutgoing(); + }, + + /** + * Transmit streaming data via a bulk packet. + * + * This method initiates the bulk send process by queuing up the header data. + * The caller receives eventual access to a stream for writing. + * + * N.B.: Do *not* attempt to close the stream handed to you, as it will + * continue to be used by this transport afterwards. Most users should + * instead use the provided |copyFrom| function instead. + * + * @param header Object + * This is modeled after the format of JSON packets above, but does not + * actually contain the data, but is instead just a routing header: + * * actor: Name of actor that will receive the packet + * * type: Name of actor's method that should be called on receipt + * * length: Size of the data to be sent + * @return Promise + * The promise will be resolved when you are allowed to write to the + * stream with an object containing: + * * stream: This output stream should only be used directly if + * you can ensure that you will write exactly |length| + * bytes and will not close the stream when writing is + * complete + * * done: If you use the stream directly (instead of |copyFrom| + * below), you must signal completion by resolving / + * rejecting this deferred. If it's rejected, the + * transport will be closed. If an Error is supplied as + * a rejection value, it will be logged via |dumpn|. If + * you do use |copyFrom|, resolving is taken care of for + * you when copying completes. + * * copyFrom: A helper function for getting your data onto the + * stream that meets the stream handling requirements + * above, and has the following signature: + * @param input nsIAsyncInputStream + * The stream to copy from. + * @return Promise + * The promise is resolved when copying completes or + * rejected if any (unexpected) errors occur. + * This object also emits "progress" events for each chunk + * that is copied. See stream-utils.js. + */ + startBulkSend: function (header) { + this.emit("startbulksend", header); + + let packet = new BulkPacket(this); + packet.header = header; + this._outgoing.push(packet); + this._flushOutgoing(); + return packet.streamReadyForWriting; + }, + + /** + * Close the transport. + * @param reason nsresult / object (optional) + * The status code or error message that corresponds to the reason for + * closing the transport (likely because a stream closed or failed). + */ + close: function (reason) { + this.emit("close", reason); + + this.active = false; + this._input.close(); + this._scriptableInput.close(); + this._output.close(); + this._destroyIncoming(); + this._destroyAllOutgoing(); + if (this.hooks) { + this.hooks.onClosed(reason); + this.hooks = null; + } + if (reason) { + dumpn("Transport closed: " + DevToolsUtils.safeErrorString(reason)); + } else { + dumpn("Transport closed."); + } + }, + + /** + * The currently outgoing packet (at the top of the queue). + */ + get _currentOutgoing() { + return this._outgoing[0]; + }, + + /** + * Flush data to the outgoing stream. Waits until the output stream notifies + * us that it is ready to be written to (via onOutputStreamReady). + */ + _flushOutgoing: function () { + if (!this._outgoingEnabled || this._outgoing.length === 0) { + return; + } + + // If the top of the packet queue has nothing more to send, remove it. + if (this._currentOutgoing.done) { + this._finishCurrentOutgoing(); + } + + if (this._outgoing.length > 0) { + let threadManager = Cc["@mozilla.org/thread-manager;1"].getService(); + this._output.asyncWait(this, 0, 0, threadManager.currentThread); + } + }, + + /** + * Pause this transport's attempts to write to the output stream. This is + * used when we've temporarily handed off our output stream for writing bulk + * data. + */ + pauseOutgoing: function () { + this._outgoingEnabled = false; + }, + + /** + * Resume this transport's attempts to write to the output stream. + */ + resumeOutgoing: function () { + this._outgoingEnabled = true; + this._flushOutgoing(); + }, + + // nsIOutputStreamCallback + /** + * This is called when the output stream is ready for more data to be written. + * The current outgoing packet will attempt to write some amount of data, but + * may not complete. + */ + onOutputStreamReady: DevToolsUtils.makeInfallible(function (stream) { + if (!this._outgoingEnabled || this._outgoing.length === 0) { + return; + } + + try { + this._currentOutgoing.write(stream); + } catch (e) { + if (e.result != Cr.NS_BASE_STREAM_WOULD_BLOCK) { + this.close(e.result); + return; + } + throw e; + } + + this._flushOutgoing(); + }, "DebuggerTransport.prototype.onOutputStreamReady"), + + /** + * Remove the current outgoing packet from the queue upon completion. + */ + _finishCurrentOutgoing: function () { + if (this._currentOutgoing) { + this._currentOutgoing.destroy(); + this._outgoing.shift(); + } + }, + + /** + * Clear the entire outgoing queue. + */ + _destroyAllOutgoing: function () { + for (let packet of this._outgoing) { + packet.destroy(); + } + this._outgoing = []; + }, + + /** + * Initialize the input stream for reading. Once this method has been called, + * we watch for packets on the input stream, and pass them to the appropriate + * handlers via this.hooks. + */ + ready: function () { + this.active = true; + this._waitForIncoming(); + }, + + /** + * Asks the input stream to notify us (via onInputStreamReady) when it is + * ready for reading. + */ + _waitForIncoming: function () { + if (this._incomingEnabled) { + let threadManager = Cc["@mozilla.org/thread-manager;1"].getService(); + this._input.asyncWait(this, 0, 0, threadManager.currentThread); + } + }, + + /** + * Pause this transport's attempts to read from the input stream. This is + * used when we've temporarily handed off our input stream for reading bulk + * data. + */ + pauseIncoming: function () { + this._incomingEnabled = false; + }, + + /** + * Resume this transport's attempts to read from the input stream. + */ + resumeIncoming: function () { + this._incomingEnabled = true; + this._flushIncoming(); + this._waitForIncoming(); + }, + + // nsIInputStreamCallback + /** + * Called when the stream is either readable or closed. + */ + onInputStreamReady: DevToolsUtils.makeInfallible(function (stream) { + try { + while (stream.available() && this._incomingEnabled && + this._processIncoming(stream, stream.available())) { + // Loop until there is nothing more to process + } + this._waitForIncoming(); + } catch (e) { + if (e.result != Cr.NS_BASE_STREAM_WOULD_BLOCK) { + this.close(e.result); + } else { + throw e; + } + } + }, "DebuggerTransport.prototype.onInputStreamReady"), + + /** + * Process the incoming data. Will create a new currently incoming Packet if + * needed. Tells the incoming Packet to read as much data as it can, but + * reading may not complete. The Packet signals that its data is ready for + * delivery by calling one of this transport's _on*Ready methods (see + * ./packets.js and the _on*Ready methods below). + * @return boolean + * Whether incoming stream processing should continue for any + * remaining data. + */ + _processIncoming: function (stream, count) { + dumpv("Data available: " + count); + + if (!count) { + dumpv("Nothing to read, skipping"); + return false; + } + + try { + if (!this._incoming) { + dumpv("Creating a new packet from incoming"); + + if (!this._readHeader(stream)) { + // Not enough data to read packet type + return false; + } + + // Attempt to create a new Packet by trying to parse each possible + // header pattern. + this._incoming = Packet.fromHeader(this._incomingHeader, this); + if (!this._incoming) { + throw new Error("No packet types for header: " + + this._incomingHeader); + } + } + + if (!this._incoming.done) { + // We have an incomplete packet, keep reading it. + dumpv("Existing packet incomplete, keep reading"); + this._incoming.read(stream, this._scriptableInput); + } + } catch (e) { + let msg = "Error reading incoming packet: (" + e + " - " + e.stack + ")"; + dumpn(msg); + + // Now in an invalid state, shut down the transport. + this.close(); + return false; + } + + if (!this._incoming.done) { + // Still not complete, we'll wait for more data. + dumpv("Packet not done, wait for more"); + return true; + } + + // Ready for next packet + this._flushIncoming(); + return true; + }, + + /** + * Read as far as we can into the incoming data, attempting to build up a + * complete packet header (which terminates with ":"). We'll only read up to + * PACKET_HEADER_MAX characters. + * @return boolean + * True if we now have a complete header. + */ + _readHeader: function () { + let amountToRead = PACKET_HEADER_MAX - this._incomingHeader.length; + this._incomingHeader += + StreamUtils.delimitedRead(this._scriptableInput, ":", amountToRead); + if (flags.wantVerbose) { + dumpv("Header read: " + this._incomingHeader); + } + + if (this._incomingHeader.endsWith(":")) { + if (flags.wantVerbose) { + dumpv("Found packet header successfully: " + this._incomingHeader); + } + return true; + } + + if (this._incomingHeader.length >= PACKET_HEADER_MAX) { + throw new Error("Failed to parse packet header!"); + } + + // Not enough data yet. + return false; + }, + + /** + * If the incoming packet is done, log it as needed and clear the buffer. + */ + _flushIncoming: function () { + if (!this._incoming.done) { + return; + } + if (flags.wantLogging) { + dumpn("Got: " + this._incoming); + } + this._destroyIncoming(); + }, + + /** + * Handler triggered by an incoming JSONPacket completing it's |read| method. + * Delivers the packet to this.hooks.onPacket. + */ + _onJSONObjectReady: function (object) { + DevToolsUtils.executeSoon(DevToolsUtils.makeInfallible(() => { + // Ensure the transport is still alive by the time this runs. + if (this.active) { + this.emit("packet", object); + this.hooks.onPacket(object); + } + }, "DebuggerTransport instance's this.hooks.onPacket")); + }, + + /** + * Handler triggered by an incoming BulkPacket entering the |read| phase for + * the stream portion of the packet. Delivers info about the incoming + * streaming data to this.hooks.onBulkPacket. See the main comment on the + * transport at the top of this file for more details. + */ + _onBulkReadReady: function (...args) { + DevToolsUtils.executeSoon(DevToolsUtils.makeInfallible(() => { + // Ensure the transport is still alive by the time this runs. + if (this.active) { + this.emit("bulkpacket", ...args); + this.hooks.onBulkPacket(...args); + } + }, "DebuggerTransport instance's this.hooks.onBulkPacket")); + }, + + /** + * Remove all handlers and references related to the current incoming packet, + * either because it is now complete or because the transport is closing. + */ + _destroyIncoming: function () { + if (this._incoming) { + this._incoming.destroy(); + } + this._incomingHeader = ""; + this._incoming = null; + } + + }; + + exports.DebuggerTransport = DebuggerTransport; + + /** + * An adapter that handles data transfers between the debugger client and + * server when they both run in the same process. It presents the same API as + * DebuggerTransport, but instead of transmitting serialized messages across a + * connection it merely calls the packet dispatcher of the other side. + * + * @param other LocalDebuggerTransport + * The other endpoint for this debugger connection. + * + * @see DebuggerTransport + */ + function LocalDebuggerTransport(other) { + EventEmitter.decorate(this); + + this.other = other; + this.hooks = null; + + // A packet number, shared between this and this.other. This isn't used by the + // protocol at all, but it makes the packet traces a lot easier to follow. + this._serial = this.other ? this.other._serial : { count: 0 }; + this.close = this.close.bind(this); + } + + LocalDebuggerTransport.prototype = { + /** + * Transmit a message by directly calling the onPacket handler of the other + * endpoint. + */ + send: function (packet) { + this.emit("send", packet); + + let serial = this._serial.count++; + if (flags.wantLogging) { + // Check 'from' first, as 'echo' packets have both. + if (packet.from) { + dumpn("Packet " + serial + " sent from " + uneval(packet.from)); + } else if (packet.to) { + dumpn("Packet " + serial + " sent to " + uneval(packet.to)); + } + } + this._deepFreeze(packet); + let other = this.other; + if (other) { + DevToolsUtils.executeSoon(DevToolsUtils.makeInfallible(() => { + // Avoid the cost of JSON.stringify() when logging is disabled. + if (flags.wantLogging) { + dumpn("Received packet " + serial + ": " + JSON.stringify(packet, null, 2)); + } + if (other.hooks) { + other.emit("packet", packet); + other.hooks.onPacket(packet); + } + }, "LocalDebuggerTransport instance's this.other.hooks.onPacket")); + } + }, + + /** + * Send a streaming bulk packet directly to the onBulkPacket handler of the + * other endpoint. + * + * This case is much simpler than the full DebuggerTransport, since there is + * no primary stream we have to worry about managing while we hand it off to + * others temporarily. Instead, we can just make a single use pipe and be + * done with it. + */ + startBulkSend: function ({actor, type, length}) { + this.emit("startbulksend", {actor, type, length}); + + let serial = this._serial.count++; + + dumpn("Sent bulk packet " + serial + " for actor " + actor); + if (!this.other) { + let error = new Error("startBulkSend: other side of transport missing"); + return promise.reject(error); + } + + let pipe = new Pipe(true, true, 0, 0, null); + + DevToolsUtils.executeSoon(DevToolsUtils.makeInfallible(() => { + dumpn("Received bulk packet " + serial); + if (!this.other.hooks) { + return; + } + + // Receiver + let deferred = defer(); + let packet = { + actor: actor, + type: type, + length: length, + copyTo: (output) => { + let copying = + StreamUtils.copyStream(pipe.inputStream, output, length); + deferred.resolve(copying); + return copying; + }, + stream: pipe.inputStream, + done: deferred + }; + + this.other.emit("bulkpacket", packet); + this.other.hooks.onBulkPacket(packet); + + // Await the result of reading from the stream + deferred.promise.then(() => pipe.inputStream.close(), this.close); + }, "LocalDebuggerTransport instance's this.other.hooks.onBulkPacket")); + + // Sender + let sendDeferred = defer(); + + // The remote transport is not capable of resolving immediately here, so we + // shouldn't be able to either. + DevToolsUtils.executeSoon(() => { + let copyDeferred = defer(); + + sendDeferred.resolve({ + copyFrom: (input) => { + let copying = + StreamUtils.copyStream(input, pipe.outputStream, length); + copyDeferred.resolve(copying); + return copying; + }, + stream: pipe.outputStream, + done: copyDeferred + }); + + // Await the result of writing to the stream + copyDeferred.promise.then(() => pipe.outputStream.close(), this.close); + }); + + return sendDeferred.promise; + }, + + /** + * Close the transport. + */ + close: function () { + this.emit("close"); + + if (this.other) { + // Remove the reference to the other endpoint before calling close(), to + // avoid infinite recursion. + let other = this.other; + this.other = null; + other.close(); + } + if (this.hooks) { + try { + this.hooks.onClosed(); + } catch (ex) { + console.error(ex); + } + this.hooks = null; + } + }, + + /** + * An empty method for emulating the DebuggerTransport API. + */ + ready: function () {}, + + /** + * Helper function that makes an object fully immutable. + */ + _deepFreeze: function (object) { + Object.freeze(object); + for (let prop in object) { + // Freeze the properties that are objects, not on the prototype, and not + // already frozen. Note that this might leave an unfrozen reference + // somewhere in the object if there is an already frozen object containing + // an unfrozen object. + if (object.hasOwnProperty(prop) && typeof object === "object" && + !Object.isFrozen(object)) { + this._deepFreeze(object[prop]); + } + } + } + }; + + exports.LocalDebuggerTransport = LocalDebuggerTransport; + + /** + * A transport for the debugging protocol that uses nsIMessageManagers to + * exchange packets with servers running in child processes. + * + * In the parent process, |mm| should be the nsIMessageSender for the + * child process. In a child process, |mm| should be the child process + * message manager, which sends packets to the parent. + * + * |prefix| is a string included in the message names, to distinguish + * multiple servers running in the same child process. + * + * This transport exchanges messages named 'debug::packet', where + * is |prefix|, whose data is the protocol packet. + */ + function ChildDebuggerTransport(mm, prefix) { + EventEmitter.decorate(this); + + this._mm = mm; + this._messageName = "debug:" + prefix + ":packet"; + } + + /* + * To avoid confusion, we use 'message' to mean something that + * nsIMessageSender conveys, and 'packet' to mean a remote debugging + * protocol packet. + */ + ChildDebuggerTransport.prototype = { + constructor: ChildDebuggerTransport, + + hooks: null, + + _addListener() { + this._mm.addMessageListener(this._messageName, this); + }, + + _removeListener() { + try { + this._mm.removeMessageListener(this._messageName, this); + } catch (e) { + if (e.result != Cr.NS_ERROR_NULL_POINTER) { + throw e; + } + // In some cases, especially when using messageManagers in non-e10s mode, we reach + // this point with a dead messageManager which only throws errors but does not + // seem to indicate in any other way that it is dead. + } + }, + + ready: function () { + this._addListener(); + }, + + close: function () { + this._removeListener(); + this.emit("close"); + this.hooks.onClosed(); + }, + + receiveMessage: function ({data}) { + this.emit("packet", data); + this.hooks.onPacket(data); + }, + + send: function (packet) { + this.emit("send", packet); + try { + this._mm.sendAsyncMessage(this._messageName, packet); + } catch (e) { + if (e.result != Cr.NS_ERROR_NULL_POINTER) { + throw e; + } + // In some cases, especially when using messageManagers in non-e10s mode, we reach + // this point with a dead messageManager which only throws errors but does not + // seem to indicate in any other way that it is dead. + } + }, + + startBulkSend: function () { + throw new Error("Can't send bulk data to child processes."); + }, + + swapBrowser(mm) { + this._removeListener(); + this._mm = mm; + this._addListener(); + }, + }; + + exports.ChildDebuggerTransport = ChildDebuggerTransport; + + // WorkerDebuggerTransport is defined differently depending on whether we are + // on the main thread or a worker thread. In the former case, we are required + // by the devtools loader, and isWorker will be false. Otherwise, we are + // required by the worker loader, and isWorker will be true. + // + // Each worker debugger supports only a single connection to the main thread. + // However, its theoretically possible for multiple servers to connect to the + // same worker. Consequently, each transport has a connection id, to allow + // messages from multiple connections to be multiplexed on a single channel. + + if (!this.isWorker) { + // Main thread + (function () { + /** + * A transport that uses a WorkerDebugger to send packets from the main + * thread to a worker thread. + */ + function WorkerDebuggerTransport(dbg, id) { + this._dbg = dbg; + this._id = id; + this.onMessage = this._onMessage.bind(this); + } + + WorkerDebuggerTransport.prototype = { + constructor: WorkerDebuggerTransport, + + ready: function () { + this._dbg.addListener(this); + }, + + close: function () { + this._dbg.removeListener(this); + if (this.hooks) { + this.hooks.onClosed(); + } + }, + + send: function (packet) { + this._dbg.postMessage(JSON.stringify({ + type: "message", + id: this._id, + message: packet + })); + }, + + startBulkSend: function () { + throw new Error("Can't send bulk data from worker threads!"); + }, + + _onMessage: function (message) { + let packet = JSON.parse(message); + if (packet.type !== "message" || packet.id !== this._id) { + return; + } + + if (this.hooks) { + this.hooks.onPacket(packet.message); + } + } + }; + + exports.WorkerDebuggerTransport = WorkerDebuggerTransport; + }).call(this); + } else { + // Worker thread + (function () { + /** + * A transport that uses a WorkerDebuggerGlobalScope to send packets from a + * worker thread to the main thread. + */ + function WorkerDebuggerTransport(scope, id) { + this._scope = scope; + this._id = id; + this._onMessage = this._onMessage.bind(this); + } + + WorkerDebuggerTransport.prototype = { + constructor: WorkerDebuggerTransport, + + ready: function () { + this._scope.addEventListener("message", this._onMessage); + }, + + close: function () { + this._scope.removeEventListener("message", this._onMessage); + if (this.hooks) { + this.hooks.onClosed(); + } + }, + + send: function (packet) { + this._scope.postMessage(JSON.stringify({ + type: "message", + id: this._id, + message: packet + })); + }, + + startBulkSend: function () { + throw new Error("Can't send bulk data from worker threads!"); + }, + + _onMessage: function (event) { + let packet = JSON.parse(event.data); + if (packet.type !== "message" || packet.id !== this._id) { + return; + } + + if (this.hooks) { + this.hooks.onPacket(packet.message); + } + } + }; + + exports.WorkerDebuggerTransport = WorkerDebuggerTransport; + }).call(this); + } +}); diff --git a/devtools/shared/transport/websocket-transport.js b/devtools/shared/transport/websocket-transport.js new file mode 100644 index 000000000..6ba474106 --- /dev/null +++ b/devtools/shared/transport/websocket-transport.js @@ -0,0 +1,79 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const EventEmitter = require("devtools/shared/event-emitter"); + +function WebSocketDebuggerTransport(socket) { + EventEmitter.decorate(this); + + this.active = false; + this.hooks = null; + this.socket = socket; +} + +WebSocketDebuggerTransport.prototype = { + ready() { + if (this.active) { + return; + } + + this.socket.addEventListener("message", this); + this.socket.addEventListener("close", this); + + this.active = true; + }, + + send(object) { + this.emit("send", object); + if (this.socket) { + this.socket.send(JSON.stringify(object)); + } + }, + + startBulkSend() { + throw new Error("Bulk send is not supported by WebSocket transport"); + }, + + close() { + this.emit("close"); + this.active = false; + + this.socket.removeEventListener("message", this); + this.socket.removeEventListener("close", this); + this.socket.close(); + this.socket = null; + + if (this.hooks) { + this.hooks.onClosed(); + this.hooks = null; + } + }, + + handleEvent(event) { + switch (event.type) { + case "message": + this.onMessage(event); + break; + case "close": + this.close(); + break; + } + }, + + onMessage({ data }) { + if (typeof data !== "string") { + throw new Error("Binary messages are not supported by WebSocket transport"); + } + + let object = JSON.parse(data); + this.emit("packet", object); + if (this.hooks) { + this.hooks.onPacket(object); + } + }, +}; + +module.exports = WebSocketDebuggerTransport; diff --git a/devtools/shared/webconsole/client.js b/devtools/shared/webconsole/client.js new file mode 100644 index 000000000..4cc5deedf --- /dev/null +++ b/devtools/shared/webconsole/client.js @@ -0,0 +1,652 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const DevToolsUtils = require("devtools/shared/DevToolsUtils"); +const EventEmitter = require("devtools/shared/event-emitter"); +const promise = require("promise"); +const defer = require("devtools/shared/defer"); +const {LongStringClient} = require("devtools/shared/client/main"); + +/** + * A WebConsoleClient is used as a front end for the WebConsoleActor that is + * created on the server, hiding implementation details. + * + * @param object debuggerClient + * The DebuggerClient instance we live for. + * @param object response + * The response packet received from the "startListeners" request sent to + * the WebConsoleActor. + */ +function WebConsoleClient(debuggerClient, response) { + this._actor = response.from; + this._client = debuggerClient; + this._longStrings = {}; + this.traits = response.traits || {}; + this.events = []; + this._networkRequests = new Map(); + + this.pendingEvaluationResults = new Map(); + this.onEvaluationResult = this.onEvaluationResult.bind(this); + this.onNetworkEvent = this._onNetworkEvent.bind(this); + this.onNetworkEventUpdate = this._onNetworkEventUpdate.bind(this); + + this._client.addListener("evaluationResult", this.onEvaluationResult); + this._client.addListener("networkEvent", this.onNetworkEvent); + this._client.addListener("networkEventUpdate", this.onNetworkEventUpdate); + EventEmitter.decorate(this); +} + +exports.WebConsoleClient = WebConsoleClient; + +WebConsoleClient.prototype = { + _longStrings: null, + traits: null, + + /** + * Holds the network requests currently displayed by the Web Console. Each key + * represents the connection ID and the value is network request information. + * @private + * @type object + */ + _networkRequests: null, + + getNetworkRequest(actorId) { + return this._networkRequests.get(actorId); + }, + + hasNetworkRequest(actorId) { + return this._networkRequests.has(actorId); + }, + + removeNetworkRequest(actorId) { + this._networkRequests.delete(actorId); + }, + + getNetworkEvents() { + return this._networkRequests.values(); + }, + + get actor() { + return this._actor; + }, + + /** + * The "networkEvent" message type handler. We redirect any message to + * the UI for displaying. + * + * @private + * @param string type + * Message type. + * @param object packet + * The message received from the server. + */ + _onNetworkEvent: function (type, packet) { + if (packet.from == this._actor) { + let actor = packet.eventActor; + let networkInfo = { + _type: "NetworkEvent", + timeStamp: actor.timeStamp, + node: null, + actor: actor.actor, + discardRequestBody: true, + discardResponseBody: true, + startedDateTime: actor.startedDateTime, + request: { + url: actor.url, + method: actor.method, + }, + isXHR: actor.isXHR, + cause: actor.cause, + response: {}, + timings: {}, + // track the list of network event updates + updates: [], + private: actor.private, + fromCache: actor.fromCache, + fromServiceWorker: actor.fromServiceWorker + }; + this._networkRequests.set(actor.actor, networkInfo); + + this.emit("networkEvent", networkInfo); + } + }, + + /** + * The "networkEventUpdate" message type handler. We redirect any message to + * the UI for displaying. + * + * @private + * @param string type + * Message type. + * @param object packet + * The message received from the server. + */ + _onNetworkEventUpdate: function (type, packet) { + let networkInfo = this.getNetworkRequest(packet.from); + if (!networkInfo) { + return; + } + + networkInfo.updates.push(packet.updateType); + + switch (packet.updateType) { + case "requestHeaders": + networkInfo.request.headersSize = packet.headersSize; + break; + case "requestPostData": + networkInfo.discardRequestBody = packet.discardRequestBody; + networkInfo.request.bodySize = packet.dataSize; + break; + case "responseStart": + networkInfo.response.httpVersion = packet.response.httpVersion; + networkInfo.response.status = packet.response.status; + networkInfo.response.statusText = packet.response.statusText; + networkInfo.response.headersSize = packet.response.headersSize; + networkInfo.response.remoteAddress = packet.response.remoteAddress; + networkInfo.response.remotePort = packet.response.remotePort; + networkInfo.discardResponseBody = packet.response.discardResponseBody; + break; + case "responseContent": + networkInfo.response.content = { + mimeType: packet.mimeType, + }; + networkInfo.response.bodySize = packet.contentSize; + networkInfo.response.transferredSize = packet.transferredSize; + networkInfo.discardResponseBody = packet.discardResponseBody; + break; + case "eventTimings": + networkInfo.totalTime = packet.totalTime; + break; + case "securityInfo": + networkInfo.securityInfo = packet.state; + break; + } + + this.emit("networkEventUpdate", { + packet: packet, + networkInfo + }); + }, + + /** + * Retrieve the cached messages from the server. + * + * @see this.CACHED_MESSAGES + * @param array types + * The array of message types you want from the server. See + * this.CACHED_MESSAGES for known types. + * @param function onResponse + * The function invoked when the response is received. + */ + getCachedMessages: function (types, onResponse) { + let packet = { + to: this._actor, + type: "getCachedMessages", + messageTypes: types, + }; + this._client.request(packet, onResponse); + }, + + /** + * Inspect the properties of an object. + * + * @param string actor + * The WebConsoleObjectActor ID to send the request to. + * @param function onResponse + * The function invoked when the response is received. + */ + inspectObjectProperties: function (actor, onResponse) { + let packet = { + to: actor, + type: "inspectProperties", + }; + this._client.request(packet, onResponse); + }, + + /** + * Evaluate a JavaScript expression. + * + * @param string string + * The code you want to evaluate. + * @param function onResponse + * The function invoked when the response is received. + * @param object [options={}] + * Options for evaluation: + * + * - bindObjectActor: an ObjectActor ID. The OA holds a reference to + * a Debugger.Object that wraps a content object. This option allows + * you to bind |_self| to the D.O of the given OA, during string + * evaluation. + * + * See: Debugger.Object.executeInGlobalWithBindings() for information + * about bindings. + * + * Use case: the variable view needs to update objects and it does so + * by knowing the ObjectActor it inspects and binding |_self| to the + * D.O of the OA. As such, variable view sends strings like these for + * eval: + * _self["prop"] = value; + * + * - frameActor: a FrameActor ID. The FA holds a reference to + * a Debugger.Frame. This option allows you to evaluate the string in + * the frame of the given FA. + * + * - url: the url to evaluate the script as. Defaults to + * "debugger eval code". + * + * - selectedNodeActor: the NodeActor ID of the current + * selection in the Inspector, if such a selection + * exists. This is used by helper functions that can + * reference the currently selected node in the Inspector, + * like $0. + */ + evaluateJS: function (string, onResponse, options = {}) { + let packet = { + to: this._actor, + type: "evaluateJS", + text: string, + bindObjectActor: options.bindObjectActor, + frameActor: options.frameActor, + url: options.url, + selectedNodeActor: options.selectedNodeActor, + selectedObjectActor: options.selectedObjectActor, + }; + this._client.request(packet, onResponse); + }, + + /** + * Evaluate a JavaScript expression asynchronously. + * See evaluateJS for parameter and response information. + */ + evaluateJSAsync: function (string, onResponse, options = {}) { + // Pre-37 servers don't support async evaluation. + if (!this.traits.evaluateJSAsync) { + this.evaluateJS(string, onResponse, options); + return; + } + + let packet = { + to: this._actor, + type: "evaluateJSAsync", + text: string, + bindObjectActor: options.bindObjectActor, + frameActor: options.frameActor, + url: options.url, + selectedNodeActor: options.selectedNodeActor, + selectedObjectActor: options.selectedObjectActor, + }; + + this._client.request(packet, response => { + // Null check this in case the client has been detached while waiting + // for a response. + if (this.pendingEvaluationResults) { + this.pendingEvaluationResults.set(response.resultID, onResponse); + } + }); + }, + + /** + * Handler for the actors's unsolicited evaluationResult packet. + */ + onEvaluationResult: function (notification, packet) { + // The client on the main thread can receive notification packets from + // multiple webconsole actors: the one on the main thread and the ones + // on worker threads. So make sure we should be handling this request. + if (packet.from !== this._actor) { + return; + } + + // Find the associated callback based on this ID, and fire it. + // In a sync evaluation, this would have already been called in + // direct response to the client.request function. + let onResponse = this.pendingEvaluationResults.get(packet.resultID); + if (onResponse) { + onResponse(packet); + this.pendingEvaluationResults.delete(packet.resultID); + } else { + DevToolsUtils.reportException("onEvaluationResult", + "No response handler for an evaluateJSAsync result (resultID: " + + packet.resultID + ")"); + } + }, + + /** + * Autocomplete a JavaScript expression. + * + * @param string string + * The code you want to autocomplete. + * @param number cursor + * Cursor location inside the string. Index starts from 0. + * @param function onResponse + * The function invoked when the response is received. + * @param string frameActor + * The id of the frame actor that made the call. + */ + autocomplete: function (string, cursor, onResponse, frameActor) { + let packet = { + to: this._actor, + type: "autocomplete", + text: string, + cursor: cursor, + frameActor: frameActor, + }; + this._client.request(packet, onResponse); + }, + + /** + * Clear the cache of messages (page errors and console API calls). + */ + clearMessagesCache: function () { + let packet = { + to: this._actor, + type: "clearMessagesCache", + }; + this._client.request(packet); + }, + + /** + * Get Web Console-related preferences on the server. + * + * @param array preferences + * An array with the preferences you want to retrieve. + * @param function [onResponse] + * Optional function to invoke when the response is received. + */ + getPreferences: function (preferences, onResponse) { + let packet = { + to: this._actor, + type: "getPreferences", + preferences: preferences, + }; + this._client.request(packet, onResponse); + }, + + /** + * Set Web Console-related preferences on the server. + * + * @param object preferences + * An object with the preferences you want to change. + * @param function [onResponse] + * Optional function to invoke when the response is received. + */ + setPreferences: function (preferences, onResponse) { + let packet = { + to: this._actor, + type: "setPreferences", + preferences: preferences, + }; + this._client.request(packet, onResponse); + }, + + /** + * Retrieve the request headers from the given NetworkEventActor. + * + * @param string actor + * The NetworkEventActor ID. + * @param function onResponse + * The function invoked when the response is received. + */ + getRequestHeaders: function (actor, onResponse) { + let packet = { + to: actor, + type: "getRequestHeaders", + }; + this._client.request(packet, onResponse); + }, + + /** + * Retrieve the request cookies from the given NetworkEventActor. + * + * @param string actor + * The NetworkEventActor ID. + * @param function onResponse + * The function invoked when the response is received. + */ + getRequestCookies: function (actor, onResponse) { + let packet = { + to: actor, + type: "getRequestCookies", + }; + this._client.request(packet, onResponse); + }, + + /** + * Retrieve the request post data from the given NetworkEventActor. + * + * @param string actor + * The NetworkEventActor ID. + * @param function onResponse + * The function invoked when the response is received. + */ + getRequestPostData: function (actor, onResponse) { + let packet = { + to: actor, + type: "getRequestPostData", + }; + this._client.request(packet, onResponse); + }, + + /** + * Retrieve the response headers from the given NetworkEventActor. + * + * @param string actor + * The NetworkEventActor ID. + * @param function onResponse + * The function invoked when the response is received. + */ + getResponseHeaders: function (actor, onResponse) { + let packet = { + to: actor, + type: "getResponseHeaders", + }; + this._client.request(packet, onResponse); + }, + + /** + * Retrieve the response cookies from the given NetworkEventActor. + * + * @param string actor + * The NetworkEventActor ID. + * @param function onResponse + * The function invoked when the response is received. + */ + getResponseCookies: function (actor, onResponse) { + let packet = { + to: actor, + type: "getResponseCookies", + }; + this._client.request(packet, onResponse); + }, + + /** + * Retrieve the response content from the given NetworkEventActor. + * + * @param string actor + * The NetworkEventActor ID. + * @param function onResponse + * The function invoked when the response is received. + */ + getResponseContent: function (actor, onResponse) { + let packet = { + to: actor, + type: "getResponseContent", + }; + this._client.request(packet, onResponse); + }, + + /** + * Retrieve the timing information for the given NetworkEventActor. + * + * @param string actor + * The NetworkEventActor ID. + * @param function onResponse + * The function invoked when the response is received. + */ + getEventTimings: function (actor, onResponse) { + let packet = { + to: actor, + type: "getEventTimings", + }; + this._client.request(packet, onResponse); + }, + + /** + * Retrieve the security information for the given NetworkEventActor. + * + * @param string actor + * The NetworkEventActor ID. + * @param function onResponse + * The function invoked when the response is received. + */ + getSecurityInfo: function (actor, onResponse) { + let packet = { + to: actor, + type: "getSecurityInfo", + }; + this._client.request(packet, onResponse); + }, + + /** + * Send a HTTP request with the given data. + * + * @param string data + * The details of the HTTP request. + * @param function onResponse + * The function invoked when the response is received. + */ + sendHTTPRequest: function (data, onResponse) { + let packet = { + to: this._actor, + type: "sendHTTPRequest", + request: data + }; + this._client.request(packet, onResponse); + }, + + /** + * Start the given Web Console listeners. + * + * @see this.LISTENERS + * @param array listeners + * Array of listeners you want to start. See this.LISTENERS for + * known listeners. + * @param function onResponse + * Function to invoke when the server response is received. + */ + startListeners: function (listeners, onResponse) { + let packet = { + to: this._actor, + type: "startListeners", + listeners: listeners, + }; + this._client.request(packet, onResponse); + }, + + /** + * Stop the given Web Console listeners. + * + * @see this.LISTENERS + * @param array listeners + * Array of listeners you want to stop. See this.LISTENERS for + * known listeners. + * @param function onResponse + * Function to invoke when the server response is received. + */ + stopListeners: function (listeners, onResponse) { + let packet = { + to: this._actor, + type: "stopListeners", + listeners: listeners, + }; + this._client.request(packet, onResponse); + }, + + /** + * Return an instance of LongStringClient for the given long string grip. + * + * @param object grip + * The long string grip returned by the protocol. + * @return object + * The LongStringClient for the given long string grip. + */ + longString: function (grip) { + if (grip.actor in this._longStrings) { + return this._longStrings[grip.actor]; + } + + let client = new LongStringClient(this._client, grip); + this._longStrings[grip.actor] = client; + return client; + }, + + /** + * Close the WebConsoleClient. This stops all the listeners on the server and + * detaches from the console actor. + * + * @param function onResponse + * Function to invoke when the server response is received. + */ + detach: function (onResponse) { + this._client.removeListener("evaluationResult", this.onEvaluationResult); + this._client.removeListener("networkEvent", this.onNetworkEvent); + this._client.removeListener("networkEventUpdate", + this.onNetworkEventUpdate); + this.stopListeners(null, onResponse); + this._longStrings = null; + this._client = null; + this.pendingEvaluationResults.clear(); + this.pendingEvaluationResults = null; + this.clearNetworkRequests(); + this._networkRequests = null; + }, + + clearNetworkRequests: function () { + this._networkRequests.clear(); + }, + + /** + * Fetches the full text of a LongString. + * + * @param object | string stringGrip + * The long string grip containing the corresponding actor. + * If you pass in a plain string (by accident or because you're lazy), + * then a promise of the same string is simply returned. + * @return object Promise + * A promise that is resolved when the full string contents + * are available, or rejected if something goes wrong. + */ + getString: function (stringGrip) { + // Make sure this is a long string. + if (typeof stringGrip != "object" || stringGrip.type != "longString") { + // Go home string, you're drunk. + return promise.resolve(stringGrip); + } + + // Fetch the long string only once. + if (stringGrip._fullText) { + return stringGrip._fullText.promise; + } + + let deferred = stringGrip._fullText = defer(); + let { initial, length } = stringGrip; + let longStringClient = this.longString(stringGrip); + + longStringClient.substring(initial.length, length, response => { + if (response.error) { + DevToolsUtils.reportException("getString", + response.error + ": " + response.message); + + deferred.reject(response); + return; + } + deferred.resolve(initial + response.substring); + }); + + return deferred.promise; + } +}; diff --git a/devtools/shared/webconsole/js-property-provider.js b/devtools/shared/webconsole/js-property-provider.js new file mode 100644 index 000000000..9ada46732 --- /dev/null +++ b/devtools/shared/webconsole/js-property-provider.js @@ -0,0 +1,538 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set ft= javascript ts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const DevToolsUtils = require("devtools/shared/DevToolsUtils"); + +if (!isWorker) { + loader.lazyImporter(this, "Parser", "resource://devtools/shared/Parser.jsm"); +} + +// Provide an easy way to bail out of even attempting an autocompletion +// if an object has way too many properties. Protects against large objects +// with numeric values that wouldn't be tallied towards MAX_AUTOCOMPLETIONS. +const MAX_AUTOCOMPLETE_ATTEMPTS = exports.MAX_AUTOCOMPLETE_ATTEMPTS = 100000; +// Prevent iterating over too many properties during autocomplete suggestions. +const MAX_AUTOCOMPLETIONS = exports.MAX_AUTOCOMPLETIONS = 1500; + +const STATE_NORMAL = 0; +const STATE_QUOTE = 2; +const STATE_DQUOTE = 3; + +const OPEN_BODY = "{[(".split(""); +const CLOSE_BODY = "}])".split(""); +const OPEN_CLOSE_BODY = { + "{": "}", + "[": "]", + "(": ")", +}; + +function hasArrayIndex(str) { + return /\[\d+\]$/.test(str); +} + +/** + * Analyses a given string to find the last statement that is interesting for + * later completion. + * + * @param string str + * A string to analyse. + * + * @returns object + * If there was an error in the string detected, then a object like + * + * { err: "ErrorMesssage" } + * + * is returned, otherwise a object like + * + * { + * state: STATE_NORMAL|STATE_QUOTE|STATE_DQUOTE, + * startPos: index of where the last statement begins + * } + */ +function findCompletionBeginning(str) { + let bodyStack = []; + + let state = STATE_NORMAL; + let start = 0; + let c; + for (let i = 0; i < str.length; i++) { + c = str[i]; + + switch (state) { + // Normal JS state. + case STATE_NORMAL: + if (c == '"') { + state = STATE_DQUOTE; + } else if (c == "'") { + state = STATE_QUOTE; + } else if (c == ";") { + start = i + 1; + } else if (c == " ") { + start = i + 1; + } else if (OPEN_BODY.indexOf(c) != -1) { + bodyStack.push({ + token: c, + start: start + }); + start = i + 1; + } else if (CLOSE_BODY.indexOf(c) != -1) { + let last = bodyStack.pop(); + if (!last || OPEN_CLOSE_BODY[last.token] != c) { + return { + err: "syntax error" + }; + } + if (c == "}") { + start = i + 1; + } else { + start = last.start; + } + } + break; + + // Double quote state > " < + case STATE_DQUOTE: + if (c == "\\") { + i++; + } else if (c == "\n") { + return { + err: "unterminated string literal" + }; + } else if (c == '"') { + state = STATE_NORMAL; + } + break; + + // Single quote state > ' < + case STATE_QUOTE: + if (c == "\\") { + i++; + } else if (c == "\n") { + return { + err: "unterminated string literal" + }; + } else if (c == "'") { + state = STATE_NORMAL; + } + break; + } + } + + return { + state: state, + startPos: start + }; +} + +/** + * Provides a list of properties, that are possible matches based on the passed + * Debugger.Environment/Debugger.Object and inputValue. + * + * @param object dbgObject + * When the debugger is not paused this Debugger.Object wraps + * the scope for autocompletion. + * It is null if the debugger is paused. + * @param object anEnvironment + * When the debugger is paused this Debugger.Environment is the + * scope for autocompletion. + * It is null if the debugger is not paused. + * @param string inputValue + * Value that should be completed. + * @param number [cursor=inputValue.length] + * Optional offset in the input where the cursor is located. If this is + * omitted then the cursor is assumed to be at the end of the input + * value. + * @returns null or object + * If no completion valued could be computed, null is returned, + * otherwise a object with the following form is returned: + * { + * matches: [ string, string, string ], + * matchProp: Last part of the inputValue that was used to find + * the matches-strings. + * } + */ +function JSPropertyProvider(dbgObject, anEnvironment, inputValue, cursor) { + if (cursor === undefined) { + cursor = inputValue.length; + } + + inputValue = inputValue.substring(0, cursor); + + // Analyse the inputValue and find the beginning of the last part that + // should be completed. + let beginning = findCompletionBeginning(inputValue); + + // There was an error analysing the string. + if (beginning.err) { + return null; + } + + // If the current state is not STATE_NORMAL, then we are inside of an string + // which means that no completion is possible. + if (beginning.state != STATE_NORMAL) { + return null; + } + + let completionPart = inputValue.substring(beginning.startPos); + let lastDot = completionPart.lastIndexOf("."); + + // Don't complete on just an empty string. + if (completionPart.trim() == "") { + return null; + } + + // Catch literals like [1,2,3] or "foo" and return the matches from + // their prototypes. + // Don't run this is a worker, migrating to acorn should allow this + // to run in a worker - Bug 1217198. + if (!isWorker && lastDot > 0) { + let parser = new Parser(); + parser.logExceptions = false; + let syntaxTree = parser.get(completionPart.slice(0, lastDot)); + let lastTree = syntaxTree.getLastSyntaxTree(); + let lastBody = lastTree && lastTree.AST.body[lastTree.AST.body.length - 1]; + + // Finding the last expression since we've sliced up until the dot. + // If there were parse errors this won't exist. + if (lastBody) { + let expression = lastBody.expression; + let matchProp = completionPart.slice(lastDot + 1); + if (expression.type === "ArrayExpression") { + return getMatchedProps(Array.prototype, matchProp); + } else if (expression.type === "Literal" && + (typeof expression.value === "string")) { + return getMatchedProps(String.prototype, matchProp); + } + } + } + + // We are completing a variable / a property lookup. + let properties = completionPart.split("."); + let matchProp = properties.pop().trimLeft(); + let obj = dbgObject; + + // The first property must be found in the environment of the paused debugger + // or of the global lexical scope. + let env = anEnvironment || obj.asEnvironment(); + + if (properties.length === 0) { + return getMatchedPropsInEnvironment(env, matchProp); + } + + let firstProp = properties.shift().trim(); + if (firstProp === "this") { + // Special case for 'this' - try to get the Object from the Environment. + // No problem if it throws, we will just not autocomplete. + try { + obj = env.object; + } catch (e) { + // Ignore. + } + } else if (hasArrayIndex(firstProp)) { + obj = getArrayMemberProperty(null, env, firstProp); + } else { + obj = getVariableInEnvironment(env, firstProp); + } + + if (!isObjectUsable(obj)) { + return null; + } + + // We get the rest of the properties recursively starting from the + // Debugger.Object that wraps the first property + for (let i = 0; i < properties.length; i++) { + let prop = properties[i].trim(); + if (!prop) { + return null; + } + + if (hasArrayIndex(prop)) { + // The property to autocomplete is a member of array. For example + // list[i][j]..[n]. Traverse the array to get the actual element. + obj = getArrayMemberProperty(obj, null, prop); + } else { + obj = DevToolsUtils.getProperty(obj, prop); + } + + if (!isObjectUsable(obj)) { + return null; + } + } + + // If the final property is a primitive + if (typeof obj != "object") { + return getMatchedProps(obj, matchProp); + } + + return getMatchedPropsInDbgObject(obj, matchProp); +} + +/** + * Get the array member of obj for the given prop. For example, given + * prop='list[0][1]' the element at [0][1] of obj.list is returned. + * + * @param object obj + * The object to operate on. Should be null if env is passed. + * @param object env + * The Environment to operate in. Should be null if obj is passed. + * @param string prop + * The property to return. + * @return null or Object + * Returns null if the property couldn't be located. Otherwise the array + * member identified by prop. + */ +function getArrayMemberProperty(obj, env, prop) { + // First get the array. + let propWithoutIndices = prop.substr(0, prop.indexOf("[")); + + if (env) { + obj = getVariableInEnvironment(env, propWithoutIndices); + } else { + obj = DevToolsUtils.getProperty(obj, propWithoutIndices); + } + + if (!isObjectUsable(obj)) { + return null; + } + + // Then traverse the list of indices to get the actual element. + let result; + let arrayIndicesRegex = /\[[^\]]*\]/g; + while ((result = arrayIndicesRegex.exec(prop)) !== null) { + let indexWithBrackets = result[0]; + let indexAsText = indexWithBrackets.substr(1, indexWithBrackets.length - 2); + let index = parseInt(indexAsText, 10); + + if (isNaN(index)) { + return null; + } + + obj = DevToolsUtils.getProperty(obj, index); + + if (!isObjectUsable(obj)) { + return null; + } + } + + return obj; +} + +/** + * Check if the given Debugger.Object can be used for autocomplete. + * + * @param Debugger.Object object + * The Debugger.Object to check. + * @return boolean + * True if further inspection into the object is possible, or false + * otherwise. + */ +function isObjectUsable(object) { + if (object == null) { + return false; + } + + if (typeof object == "object" && object.class == "DeadObject") { + return false; + } + + return true; +} + +/** + * @see getExactMatchImpl() + */ +function getVariableInEnvironment(anEnvironment, name) { + return getExactMatchImpl(anEnvironment, name, DebuggerEnvironmentSupport); +} + +/** + * @see getMatchedPropsImpl() + */ +function getMatchedPropsInEnvironment(anEnvironment, match) { + return getMatchedPropsImpl(anEnvironment, match, DebuggerEnvironmentSupport); +} + +/** + * @see getMatchedPropsImpl() + */ +function getMatchedPropsInDbgObject(dbgObject, match) { + return getMatchedPropsImpl(dbgObject, match, DebuggerObjectSupport); +} + +/** + * @see getMatchedPropsImpl() + */ +function getMatchedProps(obj, match) { + if (typeof obj != "object") { + obj = obj.constructor.prototype; + } + return getMatchedPropsImpl(obj, match, JSObjectSupport); +} + +/** + * Get all properties in the given object (and its parent prototype chain) that + * match a given prefix. + * + * @param mixed obj + * Object whose properties we want to filter. + * @param string match + * Filter for properties that match this string. + * @return object + * Object that contains the matchProp and the list of names. + */ +function getMatchedPropsImpl(obj, match, {chainIterator, getProperties}) { + let matches = new Set(); + let numProps = 0; + + // We need to go up the prototype chain. + let iter = chainIterator(obj); + for (obj of iter) { + let props = getProperties(obj); + numProps += props.length; + + // If there are too many properties to event attempt autocompletion, + // or if we have already added the max number, then stop looping + // and return the partial set that has already been discovered. + if (numProps >= MAX_AUTOCOMPLETE_ATTEMPTS || + matches.size >= MAX_AUTOCOMPLETIONS) { + break; + } + + for (let i = 0; i < props.length; i++) { + let prop = props[i]; + if (prop.indexOf(match) != 0) { + continue; + } + if (prop.indexOf("-") > -1) { + continue; + } + // If it is an array index, we can't take it. + // This uses a trick: converting a string to a number yields NaN if + // the operation failed, and NaN is not equal to itself. + if (+prop != +prop) { + matches.add(prop); + } + + if (matches.size >= MAX_AUTOCOMPLETIONS) { + break; + } + } + } + + return { + matchProp: match, + matches: [...matches], + }; +} + +/** + * Returns a property value based on its name from the given object, by + * recursively checking the object's prototype. + * + * @param object obj + * An object to look the property into. + * @param string name + * The property that is looked up. + * @returns object|undefined + * A Debugger.Object if the property exists in the object's prototype + * chain, undefined otherwise. + */ +function getExactMatchImpl(obj, name, {chainIterator, getProperty}) { + // We need to go up the prototype chain. + let iter = chainIterator(obj); + for (obj of iter) { + let prop = getProperty(obj, name, obj); + if (prop) { + return prop.value; + } + } + return undefined; +} + +var JSObjectSupport = { + chainIterator: function* (obj) { + while (obj) { + yield obj; + obj = Object.getPrototypeOf(obj); + } + }, + + getProperties: function (obj) { + return Object.getOwnPropertyNames(obj); + }, + + getProperty: function () { + // getProperty is unsafe with raw JS objects. + throw new Error("Unimplemented!"); + }, +}; + +var DebuggerObjectSupport = { + chainIterator: function* (obj) { + while (obj) { + yield obj; + obj = obj.proto; + } + }, + + getProperties: function (obj) { + return obj.getOwnPropertyNames(); + }, + + getProperty: function (obj, name, rootObj) { + // This is left unimplemented in favor to DevToolsUtils.getProperty(). + throw new Error("Unimplemented!"); + }, +}; + +var DebuggerEnvironmentSupport = { + chainIterator: function* (obj) { + while (obj) { + yield obj; + obj = obj.parent; + } + }, + + getProperties: function (obj) { + let names = obj.names(); + + // Include 'this' in results (in sorted order) + for (let i = 0; i < names.length; i++) { + if (i === names.length - 1 || names[i + 1] > "this") { + names.splice(i + 1, 0, "this"); + break; + } + } + + return names; + }, + + getProperty: function (obj, name) { + let result; + // Try/catch since name can be anything, and getVariable throws if + // it's not a valid ECMAScript identifier name + try { + // TODO: we should use getVariableDescriptor() here - bug 725815. + result = obj.getVariable(name); + } catch (e) { + // Ignore. + } + + // FIXME: Need actual UI, bug 941287. + if (result === undefined || result.optimizedOut || + result.missingArguments) { + return null; + } + return { value: result }; + }, +}; + +exports.JSPropertyProvider = DevToolsUtils.makeInfallible(JSPropertyProvider); + +// Export a version that will throw (for tests) +exports.FallibleJSPropertyProvider = JSPropertyProvider; diff --git a/devtools/shared/webconsole/moz.build b/devtools/shared/webconsole/moz.build new file mode 100644 index 000000000..2ff6ed57f --- /dev/null +++ b/devtools/shared/webconsole/moz.build @@ -0,0 +1,19 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +if CONFIG['OS_TARGET'] != 'Android': + MOCHITEST_CHROME_MANIFESTS += ['test/chrome.ini'] + XPCSHELL_TESTS_MANIFESTS += ['test/unit/xpcshell.ini'] + +DevToolsModules( + 'client.js', + 'js-property-provider.js', + 'network-helper.js', + 'network-monitor.js', + 'server-logger-monitor.js', + 'server-logger.js', + 'throttle.js', +) diff --git a/devtools/shared/webconsole/network-helper.js b/devtools/shared/webconsole/network-helper.js new file mode 100644 index 000000000..af6a2e55b --- /dev/null +++ b/devtools/shared/webconsole/network-helper.js @@ -0,0 +1,814 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/* + * Software License Agreement (BSD License) + * + * Copyright (c) 2007, Parakey Inc. + * All rights reserved. + * + * Redistribution and use of this software in source and binary forms, + * with or without modification, are permitted provided that the + * following conditions are met: + * + * * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * * Neither the name of Parakey Inc. nor the names of its + * contributors may be used to endorse or promote products + * derived from this software without specific prior + * written permission of Parakey Inc. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Creator: + * Joe Hewitt + * Contributors + * John J. Barton (IBM Almaden) + * Jan Odvarko (Mozilla Corp.) + * Max Stepanov (Aptana Inc.) + * Rob Campbell (Mozilla Corp.) + * Hans Hillen (Paciello Group, Mozilla) + * Curtis Bartley (Mozilla Corp.) + * Mike Collins (IBM Almaden) + * Kevin Decker + * Mike Ratcliffe (Comartis AG) + * Hernan Rodríguez Colmeiro + * Austin Andrews + * Christoph Dorn + * Steven Roussey (AppCenter Inc, Network54) + * Mihai Sucan (Mozilla Corp.) + */ + +"use strict"; + +const {components, Cc, Ci} = require("chrome"); +loader.lazyImporter(this, "NetUtil", "resource://gre/modules/NetUtil.jsm"); +const DevToolsUtils = require("devtools/shared/DevToolsUtils"); +const Services = require("Services"); + +// The cache used in the `nsIURL` function. +const gNSURLStore = new Map(); + +/** + * Helper object for networking stuff. + * + * Most of the following functions have been taken from the Firebug source. They + * have been modified to match the Firefox coding rules. + */ +var NetworkHelper = { + /** + * Converts text with a given charset to unicode. + * + * @param string text + * Text to convert. + * @param string charset + * Charset to convert the text to. + * @returns string + * Converted text. + */ + convertToUnicode: function (text, charset) { + let conv = Cc["@mozilla.org/intl/scriptableunicodeconverter"] + .createInstance(Ci.nsIScriptableUnicodeConverter); + try { + conv.charset = charset || "UTF-8"; + return conv.ConvertToUnicode(text); + } catch (ex) { + return text; + } + }, + + /** + * Reads all available bytes from stream and converts them to charset. + * + * @param nsIInputStream stream + * @param string charset + * @returns string + * UTF-16 encoded string based on the content of stream and charset. + */ + readAndConvertFromStream: function (stream, charset) { + let text = null; + try { + text = NetUtil.readInputStreamToString(stream, stream.available()); + return this.convertToUnicode(text, charset); + } catch (err) { + return text; + } + }, + + /** + * Reads the posted text from request. + * + * @param nsIHttpChannel request + * @param string charset + * The content document charset, used when reading the POSTed data. + * @returns string or null + * Returns the posted string if it was possible to read from request + * otherwise null. + */ + readPostTextFromRequest: function (request, charset) { + if (request instanceof Ci.nsIUploadChannel) { + let iStream = request.uploadStream; + + let isSeekableStream = false; + if (iStream instanceof Ci.nsISeekableStream) { + isSeekableStream = true; + } + + let prevOffset; + if (isSeekableStream) { + prevOffset = iStream.tell(); + iStream.seek(Ci.nsISeekableStream.NS_SEEK_SET, 0); + } + + // Read data from the stream. + let text = this.readAndConvertFromStream(iStream, charset); + + // Seek locks the file, so seek to the beginning only if necko hasn't + // read it yet, since necko doesn't seek to 0 before reading (at lest + // not till 459384 is fixed). + if (isSeekableStream && prevOffset == 0) { + iStream.seek(Ci.nsISeekableStream.NS_SEEK_SET, 0); + } + return text; + } + return null; + }, + + /** + * Reads the posted text from the page's cache. + * + * @param nsIDocShell docShell + * @param string charset + * @returns string or null + * Returns the posted string if it was possible to read from + * docShell otherwise null. + */ + readPostTextFromPage: function (docShell, charset) { + let webNav = docShell.QueryInterface(Ci.nsIWebNavigation); + return this.readPostTextFromPageViaWebNav(webNav, charset); + }, + + /** + * Reads the posted text from the page's cache, given an nsIWebNavigation + * object. + * + * @param nsIWebNavigation webNav + * @param string charset + * @returns string or null + * Returns the posted string if it was possible to read from + * webNav, otherwise null. + */ + readPostTextFromPageViaWebNav: function (webNav, charset) { + if (webNav instanceof Ci.nsIWebPageDescriptor) { + let descriptor = webNav.currentDescriptor; + + if (descriptor instanceof Ci.nsISHEntry && descriptor.postData && + descriptor instanceof Ci.nsISeekableStream) { + descriptor.seek(Ci.nsISeekableStream.NS_SEEK_SET, 0); + + return this.readAndConvertFromStream(descriptor, charset); + } + } + return null; + }, + + /** + * Gets the web appId that is associated with request. + * + * @param nsIHttpChannel request + * @returns number|null + * The appId for the given request, if available. + */ + getAppIdForRequest: function (request) { + try { + return this.getRequestLoadContext(request).appId; + } catch (ex) { + // request loadContent is not always available. + } + return null; + }, + + /** + * Gets the topFrameElement that is associated with request. This + * works in single-process and multiprocess contexts. It may cross + * the content/chrome boundary. + * + * @param nsIHttpChannel request + * @returns nsIDOMElement|null + * The top frame element for the given request. + */ + getTopFrameForRequest: function (request) { + try { + return this.getRequestLoadContext(request).topFrameElement; + } catch (ex) { + // request loadContent is not always available. + } + return null; + }, + + /** + * Gets the nsIDOMWindow that is associated with request. + * + * @param nsIHttpChannel request + * @returns nsIDOMWindow or null + */ + getWindowForRequest: function (request) { + try { + return this.getRequestLoadContext(request).associatedWindow; + } catch (ex) { + // TODO: bug 802246 - getWindowForRequest() throws on b2g: there is no + // associatedWindow property. + } + return null; + }, + + /** + * Gets the nsILoadContext that is associated with request. + * + * @param nsIHttpChannel request + * @returns nsILoadContext or null + */ + getRequestLoadContext: function (request) { + try { + return request.notificationCallbacks.getInterface(Ci.nsILoadContext); + } catch (ex) { + // Ignore. + } + + try { + return request.loadGroup.notificationCallbacks + .getInterface(Ci.nsILoadContext); + } catch (ex) { + // Ignore. + } + + return null; + }, + + /** + * Determines whether the request has been made for the top level document. + * + * @param nsIHttpChannel request + * @returns Boolean True if the request represents the top level document. + */ + isTopLevelLoad: function (request) { + if (request instanceof Ci.nsIChannel) { + let loadInfo = request.loadInfo; + if (loadInfo && loadInfo.isTopLevelLoad) { + return (request.loadFlags & Ci.nsIChannel.LOAD_DOCUMENT_URI); + } + } + + return false; + }, + + /** + * Loads the content of url from the cache. + * + * @param string url + * URL to load the cached content for. + * @param string charset + * Assumed charset of the cached content. Used if there is no charset + * on the channel directly. + * @param function callback + * Callback that is called with the loaded cached content if available + * or null if something failed while getting the cached content. + */ + loadFromCache: function (url, charset, callback) { + let channel = NetUtil.newChannel({uri: url, + loadUsingSystemPrincipal: true}); + + // Ensure that we only read from the cache and not the server. + channel.loadFlags = Ci.nsIRequest.LOAD_FROM_CACHE | + Ci.nsICachingChannel.LOAD_ONLY_FROM_CACHE | + Ci.nsICachingChannel.LOAD_BYPASS_LOCAL_CACHE_IF_BUSY; + + NetUtil.asyncFetch( + channel, + (inputStream, statusCode, request) => { + if (!components.isSuccessCode(statusCode)) { + callback(null); + return; + } + + // Try to get the encoding from the channel. If there is none, then use + // the passed assumed charset. + let requestChannel = request.QueryInterface(Ci.nsIChannel); + let contentCharset = requestChannel.contentCharset || charset; + + // Read the content of the stream using contentCharset as encoding. + callback(this.readAndConvertFromStream(inputStream, contentCharset)); + }); + }, + + /** + * Parse a raw Cookie header value. + * + * @param string header + * The raw Cookie header value. + * @return array + * Array holding an object for each cookie. Each object holds the + * following properties: name and value. + */ + parseCookieHeader: function (header) { + let cookies = header.split(";"); + let result = []; + + cookies.forEach(function (cookie) { + let equal = cookie.indexOf("="); + let name = cookie.substr(0, equal); + let value = cookie.substr(equal + 1); + result.push({name: unescape(name.trim()), + value: unescape(value.trim())}); + }); + + return result; + }, + + /** + * Parse a raw Set-Cookie header value. + * + * @param string header + * The raw Set-Cookie header value. + * @return array + * Array holding an object for each cookie. Each object holds the + * following properties: name, value, secure (boolean), httpOnly + * (boolean), path, domain and expires (ISO date string). + */ + parseSetCookieHeader: function (header) { + let rawCookies = header.split(/\r\n|\n|\r/); + let cookies = []; + + rawCookies.forEach(function (cookie) { + let equal = cookie.indexOf("="); + let name = unescape(cookie.substr(0, equal).trim()); + let parts = cookie.substr(equal + 1).split(";"); + let value = unescape(parts.shift().trim()); + + cookie = {name: name, value: value}; + + parts.forEach(function (part) { + part = part.trim(); + if (part.toLowerCase() == "secure") { + cookie.secure = true; + } else if (part.toLowerCase() == "httponly") { + cookie.httpOnly = true; + } else if (part.indexOf("=") > -1) { + let pair = part.split("="); + pair[0] = pair[0].toLowerCase(); + if (pair[0] == "path" || pair[0] == "domain") { + cookie[pair[0]] = pair[1]; + } else if (pair[0] == "expires") { + try { + pair[1] = pair[1].replace(/-/g, " "); + cookie.expires = new Date(pair[1]).toISOString(); + } catch (ex) { + // Ignore. + } + } + } + }); + + cookies.push(cookie); + }); + + return cookies; + }, + + // This is a list of all the mime category maps jviereck could find in the + // firebug code base. + mimeCategoryMap: { + "text/plain": "txt", + "text/html": "html", + "text/xml": "xml", + "text/xsl": "txt", + "text/xul": "txt", + "text/css": "css", + "text/sgml": "txt", + "text/rtf": "txt", + "text/x-setext": "txt", + "text/richtext": "txt", + "text/javascript": "js", + "text/jscript": "txt", + "text/tab-separated-values": "txt", + "text/rdf": "txt", + "text/xif": "txt", + "text/ecmascript": "js", + "text/vnd.curl": "txt", + "text/x-json": "json", + "text/x-js": "txt", + "text/js": "txt", + "text/vbscript": "txt", + "view-source": "txt", + "view-fragment": "txt", + "application/xml": "xml", + "application/xhtml+xml": "xml", + "application/atom+xml": "xml", + "application/rss+xml": "xml", + "application/vnd.mozilla.maybe.feed": "xml", + "application/vnd.mozilla.xul+xml": "xml", + "application/javascript": "js", + "application/x-javascript": "js", + "application/x-httpd-php": "txt", + "application/rdf+xml": "xml", + "application/ecmascript": "js", + "application/http-index-format": "txt", + "application/json": "json", + "application/x-js": "txt", + "application/x-mpegurl": "txt", + "application/vnd.apple.mpegurl": "txt", + "multipart/mixed": "txt", + "multipart/x-mixed-replace": "txt", + "image/svg+xml": "svg", + "application/octet-stream": "bin", + "image/jpeg": "image", + "image/jpg": "image", + "image/gif": "image", + "image/png": "image", + "image/bmp": "image", + "application/x-shockwave-flash": "flash", + "video/x-flv": "flash", + "audio/mpeg3": "media", + "audio/x-mpeg-3": "media", + "video/mpeg": "media", + "video/x-mpeg": "media", + "video/vnd.mpeg.dash.mpd": "xml", + "audio/ogg": "media", + "application/ogg": "media", + "application/x-ogg": "media", + "application/x-midi": "media", + "audio/midi": "media", + "audio/x-mid": "media", + "audio/x-midi": "media", + "music/crescendo": "media", + "audio/wav": "media", + "audio/x-wav": "media", + "text/json": "json", + "application/x-json": "json", + "application/json-rpc": "json", + "application/x-web-app-manifest+json": "json", + "application/manifest+json": "json" + }, + + /** + * Check if the given MIME type is a text-only MIME type. + * + * @param string mimeType + * @return boolean + */ + isTextMimeType: function (mimeType) { + if (mimeType.indexOf("text/") == 0) { + return true; + } + + // XML and JSON often come with custom MIME types, so in addition to the + // standard "application/xml" and "application/json", we also look for + // variants like "application/x-bigcorp+xml". For JSON we allow "+json" and + // "-json" as suffixes. + if (/^application\/\w+(?:[\.-]\w+)*(?:\+xml|[-+]json)$/.test(mimeType)) { + return true; + } + + let category = this.mimeCategoryMap[mimeType] || null; + switch (category) { + case "txt": + case "js": + case "json": + case "css": + case "html": + case "svg": + case "xml": + return true; + + default: + return false; + } + }, + + /** + * Takes a securityInfo object of nsIRequest, the nsIRequest itself and + * extracts security information from them. + * + * @param object securityInfo + * The securityInfo object of a request. If null channel is assumed + * to be insecure. + * @param object httpActivity + * The httpActivity object for the request with at least members + * { private, hostname }. + * + * @return object + * Returns an object containing following members: + * - state: The security of the connection used to fetch this + * request. Has one of following string values: + * * "insecure": the connection was not secure (only http) + * * "weak": the connection has minor security issues + * * "broken": secure connection failed (e.g. expired cert) + * * "secure": the connection was properly secured. + * If state == broken: + * - errorMessage: full error message from + * nsITransportSecurityInfo. + * If state == secure: + * - protocolVersion: one of TLSv1, TLSv1.1, TLSv1.2, TLSv1.3. + * - cipherSuite: the cipher suite used in this connection. + * - cert: information about certificate used in this connection. + * See parseCertificateInfo for the contents. + * - hsts: true if host uses Strict Transport Security, + * false otherwise + * - hpkp: true if host uses Public Key Pinning, false otherwise + * If state == weak: Same as state == secure and + * - weaknessReasons: list of reasons that cause the request to be + * considered weak. See getReasonsForWeakness. + */ + parseSecurityInfo: function (securityInfo, httpActivity) { + const info = { + state: "insecure", + }; + + // The request did not contain any security info. + if (!securityInfo) { + return info; + } + + /** + * Different scenarios to consider here and how they are handled: + * - request is HTTP, the connection is not secure + * => securityInfo is null + * => state === "insecure" + * + * - request is HTTPS, the connection is secure + * => .securityState has STATE_IS_SECURE flag + * => state === "secure" + * + * - request is HTTPS, the connection has security issues + * => .securityState has STATE_IS_INSECURE flag + * => .errorCode is an NSS error code. + * => state === "broken" + * + * - request is HTTPS, the connection was terminated before the security + * could be validated + * => .securityState has STATE_IS_INSECURE flag + * => .errorCode is NOT an NSS error code. + * => .errorMessage is not available. + * => state === "insecure" + * + * - request is HTTPS but it uses a weak cipher or old protocol, see + * http://hg.mozilla.org/mozilla-central/annotate/def6ed9d1c1a/ + * security/manager/ssl/nsNSSCallbacks.cpp#l1233 + * - request is mixed content (which makes no sense whatsoever) + * => .securityState has STATE_IS_BROKEN flag + * => .errorCode is NOT an NSS error code + * => .errorMessage is not available + * => state === "weak" + */ + + securityInfo.QueryInterface(Ci.nsITransportSecurityInfo); + securityInfo.QueryInterface(Ci.nsISSLStatusProvider); + + const wpl = Ci.nsIWebProgressListener; + const NSSErrorsService = Cc["@mozilla.org/nss_errors_service;1"] + .getService(Ci.nsINSSErrorsService); + const SSLStatus = securityInfo.SSLStatus; + if (!NSSErrorsService.isNSSErrorCode(securityInfo.errorCode)) { + const state = securityInfo.securityState; + + let uri = null; + if (httpActivity.channel && httpActivity.channel.URI) { + uri = httpActivity.channel.URI; + } + if (uri && !uri.schemeIs("https") && !uri.schemeIs("wss")) { + // it is not enough to look at the transport security info - + // schemes other than https and wss are subject to + // downgrade/etc at the scheme level and should always be + // considered insecure + info.state = "insecure"; + } else if (state & wpl.STATE_IS_SECURE) { + // The connection is secure if the scheme is sufficient + info.state = "secure"; + } else if (state & wpl.STATE_IS_BROKEN) { + // The connection is not secure, there was no error but there's some + // minor security issues. + info.state = "weak"; + info.weaknessReasons = this.getReasonsForWeakness(state); + } else if (state & wpl.STATE_IS_INSECURE) { + // This was most likely an https request that was aborted before + // validation. Return info as info.state = insecure. + return info; + } else { + DevToolsUtils.reportException("NetworkHelper.parseSecurityInfo", + "Security state " + state + " has no known STATE_IS_* flags."); + return info; + } + + // Cipher suite. + info.cipherSuite = SSLStatus.cipherName; + + // Protocol version. + info.protocolVersion = + this.formatSecurityProtocol(SSLStatus.protocolVersion); + + // Certificate. + info.cert = this.parseCertificateInfo(SSLStatus.serverCert); + + // HSTS and HPKP if available. + if (httpActivity.hostname) { + const sss = Cc["@mozilla.org/ssservice;1"] + .getService(Ci.nsISiteSecurityService); + + // SiteSecurityService uses different storage if the channel is + // private. Thus we must give isSecureHost correct flags or we + // might get incorrect results. + let flags = (httpActivity.private) ? + Ci.nsISocketProvider.NO_PERMANENT_STORAGE : 0; + + let host = httpActivity.hostname; + + info.hsts = sss.isSecureHost(sss.HEADER_HSTS, host, flags); + info.hpkp = sss.isSecureHost(sss.HEADER_HPKP, host, flags); + } else { + DevToolsUtils.reportException("NetworkHelper.parseSecurityInfo", + "Could not get HSTS/HPKP status as hostname is not available."); + info.hsts = false; + info.hpkp = false; + } + } else { + // The connection failed. + info.state = "broken"; + info.errorMessage = securityInfo.errorMessage; + } + + return info; + }, + + /** + * Takes an nsIX509Cert and returns an object with certificate information. + * + * @param nsIX509Cert cert + * The certificate to extract the information from. + * @return object + * An object with following format: + * { + * subject: { commonName, organization, organizationalUnit }, + * issuer: { commonName, organization, organizationUnit }, + * validity: { start, end }, + * fingerprint: { sha1, sha256 } + * } + */ + parseCertificateInfo: function (cert) { + let info = {}; + if (cert) { + info.subject = { + commonName: cert.commonName, + organization: cert.organization, + organizationalUnit: cert.organizationalUnit, + }; + + info.issuer = { + commonName: cert.issuerCommonName, + organization: cert.issuerOrganization, + organizationUnit: cert.issuerOrganizationUnit, + }; + + info.validity = { + start: cert.validity.notBeforeLocalDay, + end: cert.validity.notAfterLocalDay, + }; + + info.fingerprint = { + sha1: cert.sha1Fingerprint, + sha256: cert.sha256Fingerprint, + }; + } else { + DevToolsUtils.reportException("NetworkHelper.parseCertificateInfo", + "Secure connection established without certificate."); + } + + return info; + }, + + /** + * Takes protocolVersion of SSLStatus object and returns human readable + * description. + * + * @param Number version + * One of nsISSLStatus version constants. + * @return string + * One of TLSv1, TLSv1.1, TLSv1.2, TLSv1.3 if @param version + * is valid, Unknown otherwise. + */ + formatSecurityProtocol: function (version) { + switch (version) { + case Ci.nsISSLStatus.TLS_VERSION_1: + return "TLSv1"; + case Ci.nsISSLStatus.TLS_VERSION_1_1: + return "TLSv1.1"; + case Ci.nsISSLStatus.TLS_VERSION_1_2: + return "TLSv1.2"; + case Ci.nsISSLStatus.TLS_VERSION_1_3: + return "TLSv1.3"; + default: + DevToolsUtils.reportException("NetworkHelper.formatSecurityProtocol", + "protocolVersion " + version + " is unknown."); + return "Unknown"; + } + }, + + /** + * Takes the securityState bitfield and returns reasons for weak connection + * as an array of strings. + * + * @param Number state + * nsITransportSecurityInfo.securityState. + * + * @return Array[String] + * List of weakness reasons. A subset of { cipher } where + * * cipher: The cipher suite is consireded to be weak (RC4). + */ + getReasonsForWeakness: function (state) { + const wpl = Ci.nsIWebProgressListener; + + // If there's non-fatal security issues the request has STATE_IS_BROKEN + // flag set. See http://hg.mozilla.org/mozilla-central/file/44344099d119 + // /security/manager/ssl/nsNSSCallbacks.cpp#l1233 + let reasons = []; + + if (state & wpl.STATE_IS_BROKEN) { + let isCipher = state & wpl.STATE_USES_WEAK_CRYPTO; + + if (isCipher) { + reasons.push("cipher"); + } + + if (!isCipher) { + DevToolsUtils.reportException("NetworkHelper.getReasonsForWeakness", + "STATE_IS_BROKEN without a known reason. Full state was: " + state); + } + } + + return reasons; + }, + + /** + * Parse a url's query string into its components + * + * @param string queryString + * The query part of a url + * @return array + * Array of query params {name, value} + */ + parseQueryString: function (queryString) { + // Make sure there's at least one param available. + // Be careful here, params don't necessarily need to have values, so + // no need to verify the existence of a "=". + if (!queryString) { + return null; + } + + // Turn the params string into an array containing { name: value } tuples. + let paramsArray = queryString.replace(/^[?&]/, "").split("&").map(e => { + let param = e.split("="); + return { + name: param[0] ? + NetworkHelper.convertToUnicode(unescape(param[0])) : "", + value: param[1] ? + NetworkHelper.convertToUnicode(unescape(param[1])) : "" + }; + }); + + return paramsArray; + }, + + /** + * Helper for getting an nsIURL instance out of a string. + */ + nsIURL: function (url, store = gNSURLStore) { + if (store.has(url)) { + return store.get(url); + } + + let uri = Services.io.newURI(url, null, null).QueryInterface(Ci.nsIURL); + store.set(url, uri); + return uri; + } +}; + +for (let prop of Object.getOwnPropertyNames(NetworkHelper)) { + exports[prop] = NetworkHelper[prop]; +} diff --git a/devtools/shared/webconsole/network-monitor.js b/devtools/shared/webconsole/network-monitor.js new file mode 100644 index 000000000..084493432 --- /dev/null +++ b/devtools/shared/webconsole/network-monitor.js @@ -0,0 +1,2044 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set ft= javascript ts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const {Cc, Ci, Cm, Cu, Cr, components} = require("chrome"); +const Services = require("Services"); +const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm"); + +loader.lazyRequireGetter(this, "NetworkHelper", + "devtools/shared/webconsole/network-helper"); +loader.lazyRequireGetter(this, "DevToolsUtils", + "devtools/shared/DevToolsUtils"); +loader.lazyRequireGetter(this, "flags", + "devtools/shared/flags"); +loader.lazyRequireGetter(this, "DebuggerServer", + "devtools/server/main", true); +loader.lazyImporter(this, "NetUtil", "resource://gre/modules/NetUtil.jsm"); +loader.lazyServiceGetter(this, "gActivityDistributor", + "@mozilla.org/network/http-activity-distributor;1", + "nsIHttpActivityDistributor"); +const {NetworkThrottleManager} = require("devtools/shared/webconsole/throttle"); + +// Network logging + +// The maximum uint32 value. +const PR_UINT32_MAX = 4294967295; + +// HTTP status codes. +const HTTP_MOVED_PERMANENTLY = 301; +const HTTP_FOUND = 302; +const HTTP_SEE_OTHER = 303; +const HTTP_TEMPORARY_REDIRECT = 307; + +// The maximum number of bytes a NetworkResponseListener can hold: 1 MB +const RESPONSE_BODY_LIMIT = 1048576; +// Exported for testing. +exports.RESPONSE_BODY_LIMIT = RESPONSE_BODY_LIMIT; + +/** + * Check if a given network request should be logged by a network monitor + * based on the specified filters. + * + * @param nsIHttpChannel channel + * Request to check. + * @param filters + * NetworkMonitor filters to match against. + * @return boolean + * True if the network request should be logged, false otherwise. + */ +function matchRequest(channel, filters) { + // Log everything if no filter is specified + if (!filters.outerWindowID && !filters.window && !filters.appId) { + return true; + } + + // Ignore requests from chrome or add-on code when we are monitoring + // content. + // TODO: one particular test (browser_styleeditor_fetch-from-cache.js) needs + // the flags.testing check. We will move to a better way to serve + // its needs in bug 1167188, where this check should be removed. + if (!flags.testing && channel.loadInfo && + channel.loadInfo.loadingDocument === null && + channel.loadInfo.loadingPrincipal === + Services.scriptSecurityManager.getSystemPrincipal()) { + return false; + } + + if (filters.window) { + // Since frames support, this.window may not be the top level content + // frame, so that we can't only compare with win.top. + let win = NetworkHelper.getWindowForRequest(channel); + while (win) { + if (win == filters.window) { + return true; + } + if (win.parent == win) { + break; + } + win = win.parent; + } + } + + if (filters.outerWindowID) { + let topFrame = NetworkHelper.getTopFrameForRequest(channel); + if (topFrame && topFrame.outerWindowID && + topFrame.outerWindowID == filters.outerWindowID) { + return true; + } + } + + if (filters.appId) { + let appId = NetworkHelper.getAppIdForRequest(channel); + if (appId && appId == filters.appId) { + return true; + } + } + + return false; +} + +/** + * This is a nsIChannelEventSink implementation that monitors channel redirects and + * informs the registered StackTraceCollector about the old and new channels. + */ +const SINK_CLASS_DESCRIPTION = "NetworkMonitor Channel Event Sink"; +const SINK_CLASS_ID = components.ID("{e89fa076-c845-48a8-8c45-2604729eba1d}"); +const SINK_CONTRACT_ID = "@mozilla.org/network/monitor/channeleventsink;1"; +const SINK_CATEGORY_NAME = "net-channel-event-sinks"; + +function ChannelEventSink() { + this.wrappedJSObject = this; + this.collectors = new Set(); +} + +ChannelEventSink.prototype = { + QueryInterface: XPCOMUtils.generateQI([Ci.nsIChannelEventSink]), + + registerCollector(collector) { + this.collectors.add(collector); + }, + + unregisterCollector(collector) { + this.collectors.delete(collector); + + if (this.collectors.size == 0) { + ChannelEventSinkFactory.unregister(); + } + }, + + asyncOnChannelRedirect(oldChannel, newChannel, flags, callback) { + for (let collector of this.collectors) { + try { + collector.onChannelRedirect(oldChannel, newChannel, flags); + } catch (ex) { + console.error("StackTraceCollector.onChannelRedirect threw an exception", ex); + } + } + callback.onRedirectVerifyCallback(Cr.NS_OK); + } +}; + +const ChannelEventSinkFactory = XPCOMUtils.generateSingletonFactory(ChannelEventSink); + +ChannelEventSinkFactory.register = function () { + const registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar); + if (registrar.isCIDRegistered(SINK_CLASS_ID)) { + return; + } + + registrar.registerFactory(SINK_CLASS_ID, + SINK_CLASS_DESCRIPTION, + SINK_CONTRACT_ID, + ChannelEventSinkFactory); + + XPCOMUtils.categoryManager.addCategoryEntry(SINK_CATEGORY_NAME, SINK_CONTRACT_ID, + SINK_CONTRACT_ID, false, true); +}; + +ChannelEventSinkFactory.unregister = function () { + const registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar); + registrar.unregisterFactory(SINK_CLASS_ID, ChannelEventSinkFactory); + + XPCOMUtils.categoryManager.deleteCategoryEntry(SINK_CATEGORY_NAME, SINK_CONTRACT_ID, + false); +}; + +ChannelEventSinkFactory.getService = function () { + // Make sure the ChannelEventSink service is registered before accessing it + ChannelEventSinkFactory.register(); + + return Cc[SINK_CONTRACT_ID].getService(Ci.nsIChannelEventSink).wrappedJSObject; +}; + +function StackTraceCollector(filters) { + this.filters = filters; + this.stacktracesById = new Map(); +} + +StackTraceCollector.prototype = { + init() { + Services.obs.addObserver(this, "http-on-opening-request", false); + ChannelEventSinkFactory.getService().registerCollector(this); + }, + + destroy() { + Services.obs.removeObserver(this, "http-on-opening-request"); + ChannelEventSinkFactory.getService().unregisterCollector(this); + }, + + _saveStackTrace(channel, stacktrace) { + this.stacktracesById.set(channel.channelId, stacktrace); + }, + + observe(subject) { + let channel = subject.QueryInterface(Ci.nsIHttpChannel); + + if (!matchRequest(channel, this.filters)) { + return; + } + + // Convert the nsIStackFrame XPCOM objects to a nice JSON that can be + // passed around through message managers etc. + let frame = components.stack; + let stacktrace = []; + if (frame && frame.caller) { + frame = frame.caller; + while (frame) { + stacktrace.push({ + filename: frame.filename, + lineNumber: frame.lineNumber, + columnNumber: frame.columnNumber, + functionName: frame.name, + asyncCause: frame.asyncCause, + }); + frame = frame.caller || frame.asyncCaller; + } + } + + this._saveStackTrace(channel, stacktrace); + }, + + onChannelRedirect(oldChannel, newChannel, flags) { + // We can be called with any nsIChannel, but are interested only in HTTP channels + try { + oldChannel.QueryInterface(Ci.nsIHttpChannel); + newChannel.QueryInterface(Ci.nsIHttpChannel); + } catch (ex) { + return; + } + + let oldId = oldChannel.channelId; + let stacktrace = this.stacktracesById.get(oldId); + if (stacktrace) { + this.stacktracesById.delete(oldId); + this._saveStackTrace(newChannel, stacktrace); + } + }, + + getStackTrace(channelId) { + let trace = this.stacktracesById.get(channelId); + this.stacktracesById.delete(channelId); + return trace; + } +}; + +exports.StackTraceCollector = StackTraceCollector; + +/** + * The network response listener implements the nsIStreamListener and + * nsIRequestObserver interfaces. This is used within the NetworkMonitor feature + * to get the response body of the request. + * + * The code is mostly based on code listings from: + * + * http://www.softwareishard.com/blog/firebug/ + * nsitraceablechannel-intercept-http-traffic/ + * + * @constructor + * @param object owner + * The response listener owner. This object needs to hold the + * |openResponses| object. + * @param object httpActivity + * HttpActivity object associated with this request. See NetworkMonitor + * for more information. + */ +function NetworkResponseListener(owner, httpActivity) { + this.owner = owner; + this.receivedData = ""; + this.httpActivity = httpActivity; + this.bodySize = 0; + // Note that this is really only needed for the non-e10s case. + // See bug 1309523. + let channel = this.httpActivity.channel; + this._wrappedNotificationCallbacks = channel.notificationCallbacks; + channel.notificationCallbacks = this; +} + +NetworkResponseListener.prototype = { + QueryInterface: + XPCOMUtils.generateQI([Ci.nsIStreamListener, Ci.nsIInputStreamCallback, + Ci.nsIRequestObserver, Ci.nsIInterfaceRequestor, + Ci.nsISupports]), + + // nsIInterfaceRequestor implementation + + /** + * This object implements nsIProgressEventSink, but also needs to forward + * interface requests to the notification callbacks of other objects. + */ + getInterface(iid) { + if (iid.equals(Ci.nsIProgressEventSink)) { + return this; + } + if (this._wrappedNotificationCallbacks) { + return this._wrappedNotificationCallbacks.getInterface(iid); + } + throw Cr.NS_ERROR_NO_INTERFACE; + }, + + /** + * Forward notifications for interfaces this object implements, in case other + * objects also implemented them. + */ + _forwardNotification(iid, method, args) { + if (!this._wrappedNotificationCallbacks) { + return; + } + try { + let impl = this._wrappedNotificationCallbacks.getInterface(iid); + impl[method].apply(impl, args); + } catch (e) { + if (e.result != Cr.NS_ERROR_NO_INTERFACE) { + throw e; + } + } + }, + + /** + * This NetworkResponseListener tracks the NetworkMonitor.openResponses object + * to find the associated uncached headers. + * @private + */ + _foundOpenResponse: false, + + /** + * If the channel already had notificationCallbacks, hold them here internally + * so that we can forward getInterface requests to that object. + */ + _wrappedNotificationCallbacks: null, + + /** + * The response listener owner. + */ + owner: null, + + /** + * The response will be written into the outputStream of this nsIPipe. + * Both ends of the pipe must be blocking. + */ + sink: null, + + /** + * The HttpActivity object associated with this response. + */ + httpActivity: null, + + /** + * Stores the received data as a string. + */ + receivedData: null, + + /** + * The uncompressed, decoded response body size. + */ + bodySize: null, + + /** + * Response body size on the wire, potentially compressed / encoded. + */ + transferredSize: null, + + /** + * The nsIRequest we are started for. + */ + request: null, + + /** + * Set the async listener for the given nsIAsyncInputStream. This allows us to + * wait asynchronously for any data coming from the stream. + * + * @param nsIAsyncInputStream stream + * The input stream from where we are waiting for data to come in. + * @param nsIInputStreamCallback listener + * The input stream callback you want. This is an object that must have + * the onInputStreamReady() method. If the argument is null, then the + * current callback is removed. + * @return void + */ + setAsyncListener: function (stream, listener) { + // Asynchronously wait for the stream to be readable or closed. + stream.asyncWait(listener, 0, 0, Services.tm.mainThread); + }, + + /** + * Stores the received data, if request/response body logging is enabled. It + * also does limit the number of stored bytes, based on the + * RESPONSE_BODY_LIMIT constant. + * + * Learn more about nsIStreamListener at: + * https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIStreamListener + * + * @param nsIRequest request + * @param nsISupports context + * @param nsIInputStream inputStream + * @param unsigned long offset + * @param unsigned long count + */ + onDataAvailable: function (request, context, inputStream, offset, count) { + this._findOpenResponse(); + let data = NetUtil.readInputStreamToString(inputStream, count); + + this.bodySize += count; + + if (!this.httpActivity.discardResponseBody && + this.receivedData.length < RESPONSE_BODY_LIMIT) { + this.receivedData += + NetworkHelper.convertToUnicode(data, request.contentCharset); + } + }, + + /** + * See documentation at + * https://developer.mozilla.org/En/NsIRequestObserver + * + * @param nsIRequest request + * @param nsISupports context + */ + onStartRequest: function (request) { + // Converter will call this again, we should just ignore that. + if (this.request) { + return; + } + + this.request = request; + this._getSecurityInfo(); + this._findOpenResponse(); + // We need to track the offset for the onDataAvailable calls where + // we pass the data from our pipe to the converter. + this.offset = 0; + + // In the multi-process mode, the conversion happens on the child + // side while we can only monitor the channel on the parent + // side. If the content is gzipped, we have to unzip it + // ourself. For that we use the stream converter services. Do not + // do that for Service workers as they are run in the child + // process. + let channel = this.request; + if (!this.httpActivity.fromServiceWorker && + channel instanceof Ci.nsIEncodedChannel && + channel.contentEncodings && + !channel.applyConversion) { + let encodingHeader = channel.getResponseHeader("Content-Encoding"); + let scs = Cc["@mozilla.org/streamConverters;1"] + .getService(Ci.nsIStreamConverterService); + let encodings = encodingHeader.split(/\s*\t*,\s*\t*/); + let nextListener = this; + let acceptedEncodings = ["gzip", "deflate", "br", "x-gzip", "x-deflate"]; + for (let i in encodings) { + // There can be multiple conversions applied + let enc = encodings[i].toLowerCase(); + if (acceptedEncodings.indexOf(enc) > -1) { + this.converter = scs.asyncConvertData(enc, "uncompressed", + nextListener, null); + nextListener = this.converter; + } + } + if (this.converter) { + this.converter.onStartRequest(this.request, null); + } + } + // Asynchronously wait for the data coming from the request. + this.setAsyncListener(this.sink.inputStream, this); + }, + + /** + * Parse security state of this request and report it to the client. + */ + _getSecurityInfo: DevToolsUtils.makeInfallible(function () { + // Many properties of the securityInfo (e.g., the server certificate or HPKP + // status) are not available in the content process and can't be even touched safely, + // because their C++ getters trigger assertions. This function is called in content + // process for synthesized responses from service workers, in the parent otherwise. + if (Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT) { + return; + } + + // Take the security information from the original nsIHTTPChannel instead of + // the nsIRequest received in onStartRequest. If response to this request + // was a redirect from http to https, the request object seems to contain + // security info for the https request after redirect. + let secinfo = this.httpActivity.channel.securityInfo; + let info = NetworkHelper.parseSecurityInfo(secinfo, this.httpActivity); + + this.httpActivity.owner.addSecurityInfo(info); + }), + + /** + * Handle the onStopRequest by closing the sink output stream. + * + * For more documentation about nsIRequestObserver go to: + * https://developer.mozilla.org/En/NsIRequestObserver + */ + onStopRequest: function () { + this._findOpenResponse(); + this.sink.outputStream.close(); + }, + + // nsIProgressEventSink implementation + + /** + * Handle progress event as data is transferred. This is used to record the + * size on the wire, which may be compressed / encoded. + */ + onProgress: function (request, context, progress, progressMax) { + this.transferredSize = progress; + // Need to forward as well to keep things like Download Manager's progress + // bar working properly. + this._forwardNotification(Ci.nsIProgressEventSink, "onProgress", arguments); + }, + + onStatus: function () { + this._forwardNotification(Ci.nsIProgressEventSink, "onStatus", arguments); + }, + + /** + * Find the open response object associated to the current request. The + * NetworkMonitor._httpResponseExaminer() method saves the response headers in + * NetworkMonitor.openResponses. This method takes the data from the open + * response object and puts it into the HTTP activity object, then sends it to + * the remote Web Console instance. + * + * @private + */ + _findOpenResponse: function () { + if (!this.owner || this._foundOpenResponse) { + return; + } + + let openResponse = null; + + for (let id in this.owner.openResponses) { + let item = this.owner.openResponses[id]; + if (item.channel === this.httpActivity.channel) { + openResponse = item; + break; + } + } + + if (!openResponse) { + return; + } + this._foundOpenResponse = true; + + delete this.owner.openResponses[openResponse.id]; + + this.httpActivity.owner.addResponseHeaders(openResponse.headers); + this.httpActivity.owner.addResponseCookies(openResponse.cookies); + }, + + /** + * Clean up the response listener once the response input stream is closed. + * This is called from onStopRequest() or from onInputStreamReady() when the + * stream is closed. + * @return void + */ + onStreamClose: function () { + if (!this.httpActivity) { + return; + } + // Remove our listener from the request input stream. + this.setAsyncListener(this.sink.inputStream, null); + + this._findOpenResponse(); + + if (!this.httpActivity.discardResponseBody && this.receivedData.length) { + this._onComplete(this.receivedData); + } else if (!this.httpActivity.discardResponseBody && + this.httpActivity.responseStatus == 304) { + // Response is cached, so we load it from cache. + let charset = this.request.contentCharset || this.httpActivity.charset; + NetworkHelper.loadFromCache(this.httpActivity.url, charset, + this._onComplete.bind(this)); + } else { + this._onComplete(); + } + }, + + /** + * Handler for when the response completes. This function cleans up the + * response listener. + * + * @param string [data] + * Optional, the received data coming from the response listener or + * from the cache. + */ + _onComplete: function (data) { + let response = { + mimeType: "", + text: data || "", + }; + + response.size = this.bodySize; + response.transferredSize = this.transferredSize; + + try { + response.mimeType = this.request.contentType; + } catch (ex) { + // Ignore. + } + + if (!response.mimeType || + !NetworkHelper.isTextMimeType(response.mimeType)) { + response.encoding = "base64"; + try { + response.text = btoa(response.text); + } catch (err) { + // Ignore. + } + } + + if (response.mimeType && this.request.contentCharset) { + response.mimeType += "; charset=" + this.request.contentCharset; + } + + this.receivedData = ""; + + this.httpActivity.owner.addResponseContent( + response, + this.httpActivity.discardResponseBody + ); + + this._wrappedNotificationCallbacks = null; + this.httpActivity = null; + this.sink = null; + this.inputStream = null; + this.converter = null; + this.request = null; + this.owner = null; + }, + + /** + * The nsIInputStreamCallback for when the request input stream is ready - + * either it has more data or it is closed. + * + * @param nsIAsyncInputStream stream + * The sink input stream from which data is coming. + * @returns void + */ + onInputStreamReady: function (stream) { + if (!(stream instanceof Ci.nsIAsyncInputStream) || !this.httpActivity) { + return; + } + + let available = -1; + try { + // This may throw if the stream is closed normally or due to an error. + available = stream.available(); + } catch (ex) { + // Ignore. + } + + if (available != -1) { + if (available != 0) { + if (this.converter) { + this.converter.onDataAvailable(this.request, null, stream, + this.offset, available); + } else { + this.onDataAvailable(this.request, null, stream, this.offset, + available); + } + } + this.offset += available; + this.setAsyncListener(stream, this); + } else { + this.onStreamClose(); + this.offset = 0; + } + }, +}; + +/** + * The network monitor uses the nsIHttpActivityDistributor to monitor network + * requests. The nsIObserverService is also used for monitoring + * http-on-examine-response notifications. All network request information is + * routed to the remote Web Console. + * + * @constructor + * @param object filters + * Object with the filters to use for network requests: + * - window (nsIDOMWindow): filter network requests by the associated + * window object. + * - appId (number): filter requests by the appId. + * - outerWindowID (number): filter requests by their top frame's outerWindowID. + * Filters are optional. If any of these filters match the request is + * logged (OR is applied). If no filter is provided then all requests are + * logged. + * @param object owner + * The network monitor owner. This object needs to hold: + * - onNetworkEvent(requestInfo) + * This method is invoked once for every new network request and it is + * given the initial network request information as an argument. + * onNetworkEvent() must return an object which holds several add*() + * methods which are used to add further network request/response information. + * - stackTraceCollector + * If the owner has this optional property, it will be used as a + * StackTraceCollector by the NetworkMonitor. + */ +function NetworkMonitor(filters, owner) { + this.filters = filters; + this.owner = owner; + this.openRequests = {}; + this.openResponses = {}; + this._httpResponseExaminer = + DevToolsUtils.makeInfallible(this._httpResponseExaminer).bind(this); + this._httpModifyExaminer = + DevToolsUtils.makeInfallible(this._httpModifyExaminer).bind(this); + this._serviceWorkerRequest = this._serviceWorkerRequest.bind(this); + this._throttleData = null; + this._throttler = null; +} + +exports.NetworkMonitor = NetworkMonitor; + +NetworkMonitor.prototype = { + filters: null, + + httpTransactionCodes: { + 0x5001: "REQUEST_HEADER", + 0x5002: "REQUEST_BODY_SENT", + 0x5003: "RESPONSE_START", + 0x5004: "RESPONSE_HEADER", + 0x5005: "RESPONSE_COMPLETE", + 0x5006: "TRANSACTION_CLOSE", + + 0x804b0003: "STATUS_RESOLVING", + 0x804b000b: "STATUS_RESOLVED", + 0x804b0007: "STATUS_CONNECTING_TO", + 0x804b0004: "STATUS_CONNECTED_TO", + 0x804b0005: "STATUS_SENDING_TO", + 0x804b000a: "STATUS_WAITING_FOR", + 0x804b0006: "STATUS_RECEIVING_FROM" + }, + + httpDownloadActivities: [ + gActivityDistributor.ACTIVITY_SUBTYPE_RESPONSE_START, + gActivityDistributor.ACTIVITY_SUBTYPE_RESPONSE_HEADER, + gActivityDistributor.ACTIVITY_SUBTYPE_RESPONSE_COMPLETE, + gActivityDistributor.ACTIVITY_SUBTYPE_TRANSACTION_CLOSE + ], + + // Network response bodies are piped through a buffer of the given size (in + // bytes). + responsePipeSegmentSize: null, + + owner: null, + + /** + * Whether to save the bodies of network requests and responses. + * @type boolean + */ + saveRequestAndResponseBodies: true, + + /** + * Object that holds the HTTP activity objects for ongoing requests. + */ + openRequests: null, + + /** + * Object that holds response headers coming from this._httpResponseExaminer. + */ + openResponses: null, + + /** + * The network monitor initializer. + */ + init: function () { + this.responsePipeSegmentSize = Services.prefs + .getIntPref("network.buffer.cache.size"); + this.interceptedChannels = new Set(); + + if (Services.appinfo.processType != Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT) { + gActivityDistributor.addObserver(this); + Services.obs.addObserver(this._httpResponseExaminer, + "http-on-examine-response", false); + Services.obs.addObserver(this._httpResponseExaminer, + "http-on-examine-cached-response", false); + Services.obs.addObserver(this._httpModifyExaminer, + "http-on-modify-request", false); + } + // In child processes, only watch for service worker requests + // everything else only happens in the parent process + Services.obs.addObserver(this._serviceWorkerRequest, + "service-worker-synthesized-response", false); + }, + + get throttleData() { + return this._throttleData; + }, + + set throttleData(value) { + this._throttleData = value; + // Clear out any existing throttlers + this._throttler = null; + }, + + _getThrottler: function () { + if (this.throttleData !== null && this._throttler === null) { + this._throttler = new NetworkThrottleManager(this.throttleData); + } + return this._throttler; + }, + + _serviceWorkerRequest: function (subject, topic, data) { + let channel = subject.QueryInterface(Ci.nsIHttpChannel); + + if (!matchRequest(channel, this.filters)) { + return; + } + + this.interceptedChannels.add(subject); + + // On e10s, we never receive http-on-examine-cached-response, so fake one. + if (Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT) { + this._httpResponseExaminer(channel, "http-on-examine-cached-response"); + } + }, + + /** + * Observe notifications for the http-on-examine-response topic, coming from + * the nsIObserverService. + * + * @private + * @param nsIHttpChannel subject + * @param string topic + * @returns void + */ + _httpResponseExaminer: function (subject, topic) { + // The httpResponseExaminer is used to retrieve the uncached response + // headers. The data retrieved is stored in openResponses. The + // NetworkResponseListener is responsible with updating the httpActivity + // object with the data from the new object in openResponses. + + if (!this.owner || + (topic != "http-on-examine-response" && + topic != "http-on-examine-cached-response") || + !(subject instanceof Ci.nsIHttpChannel)) { + return; + } + + let channel = subject.QueryInterface(Ci.nsIHttpChannel); + + if (!matchRequest(channel, this.filters)) { + return; + } + + let response = { + id: gSequenceId(), + channel: channel, + headers: [], + cookies: [], + }; + + let setCookieHeader = null; + + channel.visitResponseHeaders({ + visitHeader: function (name, value) { + let lowerName = name.toLowerCase(); + if (lowerName == "set-cookie") { + setCookieHeader = value; + } + response.headers.push({ name: name, value: value }); + } + }); + + if (!response.headers.length) { + // No need to continue. + return; + } + + if (setCookieHeader) { + response.cookies = NetworkHelper.parseSetCookieHeader(setCookieHeader); + } + + // Determine the HTTP version. + let httpVersionMaj = {}; + let httpVersionMin = {}; + + channel.QueryInterface(Ci.nsIHttpChannelInternal); + channel.getResponseVersion(httpVersionMaj, httpVersionMin); + + response.status = channel.responseStatus; + response.statusText = channel.responseStatusText; + response.httpVersion = "HTTP/" + httpVersionMaj.value + "." + + httpVersionMin.value; + + this.openResponses[response.id] = response; + + if (topic === "http-on-examine-cached-response") { + // Service worker requests emits cached-reponse notification on non-e10s, + // and we fake one on e10s. + let fromServiceWorker = this.interceptedChannels.has(channel); + this.interceptedChannels.delete(channel); + + // If this is a cached response, there never was a request event + // so we need to construct one here so the frontend gets all the + // expected events. + let httpActivity = this._createNetworkEvent(channel, { + fromCache: !fromServiceWorker, + fromServiceWorker: fromServiceWorker + }); + httpActivity.owner.addResponseStart({ + httpVersion: response.httpVersion, + remoteAddress: "", + remotePort: "", + status: response.status, + statusText: response.statusText, + headersSize: 0, + }, "", true); + + // There also is never any timing events, so we can fire this + // event with zeroed out values. + let timings = this._setupHarTimings(httpActivity, true); + httpActivity.owner.addEventTimings(timings.total, timings.timings); + } + }, + + /** + * Observe notifications for the http-on-modify-request topic, coming from + * the nsIObserverService. + * + * @private + * @param nsIHttpChannel aSubject + * @returns void + */ + _httpModifyExaminer: function (subject) { + let throttler = this._getThrottler(); + if (throttler) { + let channel = subject.QueryInterface(Ci.nsIHttpChannel); + if (matchRequest(channel, this.filters)) { + // Read any request body here, before it is throttled. + let httpActivity = this.createOrGetActivityObject(channel); + this._onRequestBodySent(httpActivity); + throttler.manageUpload(channel); + } + } + }, + + /** + * A helper function for observeActivity. This does whatever work + * is required by a particular http activity event. Arguments are + * the same as for observeActivity. + */ + _dispatchActivity: function (httpActivity, channel, activityType, + activitySubtype, timestamp, extraSizeData, + extraStringData) { + let transCodes = this.httpTransactionCodes; + + // Store the time information for this activity subtype. + if (activitySubtype in transCodes) { + let stage = transCodes[activitySubtype]; + if (stage in httpActivity.timings) { + httpActivity.timings[stage].last = timestamp; + } else { + httpActivity.timings[stage] = { + first: timestamp, + last: timestamp, + }; + } + } + + switch (activitySubtype) { + case gActivityDistributor.ACTIVITY_SUBTYPE_REQUEST_BODY_SENT: + this._onRequestBodySent(httpActivity); + if (httpActivity.sentBody !== null) { + httpActivity.owner.addRequestPostData({ text: httpActivity.sentBody }); + httpActivity.sentBody = null; + } + break; + case gActivityDistributor.ACTIVITY_SUBTYPE_RESPONSE_HEADER: + this._onResponseHeader(httpActivity, extraStringData); + break; + case gActivityDistributor.ACTIVITY_SUBTYPE_TRANSACTION_CLOSE: + this._onTransactionClose(httpActivity); + break; + default: + break; + } + }, + + /** + * Begin observing HTTP traffic that originates inside the current tab. + * + * @see https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIHttpActivityObserver + * + * @param nsIHttpChannel channel + * @param number activityType + * @param number activitySubtype + * @param number timestamp + * @param number extraSizeData + * @param string extraStringData + */ + observeActivity: + DevToolsUtils.makeInfallible(function (channel, activityType, activitySubtype, + timestamp, extraSizeData, + extraStringData) { + if (!this.owner || + activityType != gActivityDistributor.ACTIVITY_TYPE_HTTP_TRANSACTION && + activityType != gActivityDistributor.ACTIVITY_TYPE_SOCKET_TRANSPORT) { + return; + } + + if (!(channel instanceof Ci.nsIHttpChannel)) { + return; + } + + channel = channel.QueryInterface(Ci.nsIHttpChannel); + + if (activitySubtype == + gActivityDistributor.ACTIVITY_SUBTYPE_REQUEST_HEADER) { + this._onRequestHeader(channel, timestamp, extraStringData); + return; + } + + // Iterate over all currently ongoing requests. If channel can't + // be found within them, then exit this function. + let httpActivity = this._findActivityObject(channel); + if (!httpActivity) { + return; + } + + // If we're throttling, we must not report events as they arrive + // from platform, but instead let the throttler emit the events + // after some time has elapsed. + if (httpActivity.downloadThrottle && + this.httpDownloadActivities.indexOf(activitySubtype) >= 0) { + let callback = this._dispatchActivity.bind(this); + httpActivity.downloadThrottle + .addActivityCallback(callback, httpActivity, channel, activityType, + activitySubtype, timestamp, extraSizeData, + extraStringData); + } else { + this._dispatchActivity(httpActivity, channel, activityType, + activitySubtype, timestamp, extraSizeData, + extraStringData); + } + }), + + /** + * + */ + _createNetworkEvent: function (channel, { timestamp, extraStringData, + fromCache, fromServiceWorker }) { + let httpActivity = this.createOrGetActivityObject(channel); + + channel.QueryInterface(Ci.nsIPrivateBrowsingChannel); + httpActivity.private = channel.isChannelPrivate; + + if (timestamp) { + httpActivity.timings.REQUEST_HEADER = { + first: timestamp, + last: timestamp + }; + } + + let event = {}; + event.method = channel.requestMethod; + event.channelId = channel.channelId; + event.url = channel.URI.spec; + event.private = httpActivity.private; + event.headersSize = 0; + event.startedDateTime = + (timestamp ? new Date(Math.round(timestamp / 1000)) : new Date()) + .toISOString(); + event.fromCache = fromCache; + event.fromServiceWorker = fromServiceWorker; + httpActivity.fromServiceWorker = fromServiceWorker; + + if (extraStringData) { + event.headersSize = extraStringData.length; + } + + // Determine the cause and if this is an XHR request. + let causeType = channel.loadInfo.externalContentPolicyType; + let loadingPrincipal = channel.loadInfo.loadingPrincipal; + let causeUri = loadingPrincipal ? loadingPrincipal.URI : null; + let stacktrace; + // If this is the parent process, there is no stackTraceCollector - the stack + // trace will be added in NetworkMonitorChild._onNewEvent. + if (this.owner.stackTraceCollector) { + stacktrace = this.owner.stackTraceCollector.getStackTrace(event.channelId); + } + + event.cause = { + type: causeType, + loadingDocumentUri: causeUri ? causeUri.spec : null, + stacktrace + }; + + httpActivity.isXHR = event.isXHR = + (causeType === Ci.nsIContentPolicy.TYPE_XMLHTTPREQUEST || + causeType === Ci.nsIContentPolicy.TYPE_FETCH); + + // Determine the HTTP version. + let httpVersionMaj = {}; + let httpVersionMin = {}; + channel.QueryInterface(Ci.nsIHttpChannelInternal); + channel.getRequestVersion(httpVersionMaj, httpVersionMin); + + event.httpVersion = "HTTP/" + httpVersionMaj.value + "." + + httpVersionMin.value; + + event.discardRequestBody = !this.saveRequestAndResponseBodies; + event.discardResponseBody = !this.saveRequestAndResponseBodies; + + let headers = []; + let cookies = []; + let cookieHeader = null; + + // Copy the request header data. + channel.visitRequestHeaders({ + visitHeader: function (name, value) { + if (name == "Cookie") { + cookieHeader = value; + } + headers.push({ name: name, value: value }); + } + }); + + if (cookieHeader) { + cookies = NetworkHelper.parseCookieHeader(cookieHeader); + } + + httpActivity.owner = this.owner.onNetworkEvent(event); + + this._setupResponseListener(httpActivity, fromCache); + + httpActivity.owner.addRequestHeaders(headers, extraStringData); + httpActivity.owner.addRequestCookies(cookies); + + return httpActivity; + }, + + /** + * Handler for ACTIVITY_SUBTYPE_REQUEST_HEADER. When a request starts the + * headers are sent to the server. This method creates the |httpActivity| + * object where we store the request and response information that is + * collected through its lifetime. + * + * @private + * @param nsIHttpChannel channel + * @param number timestamp + * @param string extraStringData + * @return void + */ + _onRequestHeader: function (channel, timestamp, extraStringData) { + if (!matchRequest(channel, this.filters)) { + return; + } + + this._createNetworkEvent(channel, { timestamp, extraStringData }); + }, + + /** + * Find an HTTP activity object for the channel. + * + * @param nsIHttpChannel channel + * The HTTP channel whose activity object we want to find. + * @return object + * The HTTP activity object, or null if it is not found. + */ + _findActivityObject: function (channel) { + for (let id in this.openRequests) { + let item = this.openRequests[id]; + if (item.channel === channel) { + return item; + } + } + return null; + }, + + /** + * Find an existing HTTP activity object, or create a new one. This + * object is used for storing all the request and response + * information. + * + * This is a HAR-like object. Conformance to the spec is not guaranteed at + * this point. + * + * @see http://www.softwareishard.com/blog/har-12-spec + * @param nsIHttpChannel channel + * The HTTP channel for which the HTTP activity object is created. + * @return object + * The new HTTP activity object. + */ + createOrGetActivityObject: function (channel) { + let httpActivity = this._findActivityObject(channel); + if (!httpActivity) { + let win = NetworkHelper.getWindowForRequest(channel); + let charset = win ? win.document.characterSet : null; + + httpActivity = { + id: gSequenceId(), + channel: channel, + // see _onRequestBodySent() + charset: charset, + sentBody: null, + url: channel.URI.spec, + // needed for host specific security info + hostname: channel.URI.host, + discardRequestBody: !this.saveRequestAndResponseBodies, + discardResponseBody: !this.saveRequestAndResponseBodies, + // internal timing information, see observeActivity() + timings: {}, + // see _onResponseHeader() + responseStatus: null, + // the activity owner which is notified when changes happen + owner: null, + }; + + this.openRequests[httpActivity.id] = httpActivity; + } + + return httpActivity; + }, + + /** + * Setup the network response listener for the given HTTP activity. The + * NetworkResponseListener is responsible for storing the response body. + * + * @private + * @param object httpActivity + * The HTTP activity object we are tracking. + */ + _setupResponseListener: function (httpActivity, fromCache) { + let channel = httpActivity.channel; + channel.QueryInterface(Ci.nsITraceableChannel); + + if (!fromCache) { + let throttler = this._getThrottler(); + if (throttler) { + httpActivity.downloadThrottle = throttler.manage(channel); + } + } + + // The response will be written into the outputStream of this pipe. + // This allows us to buffer the data we are receiving and read it + // asynchronously. + // Both ends of the pipe must be blocking. + let sink = Cc["@mozilla.org/pipe;1"].createInstance(Ci.nsIPipe); + + // The streams need to be blocking because this is required by the + // stream tee. + sink.init(false, false, this.responsePipeSegmentSize, PR_UINT32_MAX, null); + + // Add listener for the response body. + let newListener = new NetworkResponseListener(this, httpActivity); + + // Remember the input stream, so it isn't released by GC. + newListener.inputStream = sink.inputStream; + newListener.sink = sink; + + let tee = Cc["@mozilla.org/network/stream-listener-tee;1"] + .createInstance(Ci.nsIStreamListenerTee); + + let originalListener = channel.setNewListener(tee); + + tee.init(originalListener, sink.outputStream, newListener); + }, + + /** + * Handler for ACTIVITY_SUBTYPE_REQUEST_BODY_SENT. The request body is logged + * here. + * + * @private + * @param object httpActivity + * The HTTP activity object we are working with. + */ + _onRequestBodySent: function (httpActivity) { + // Return early if we don't need the request body, or if we've + // already found it. + if (httpActivity.discardRequestBody || httpActivity.sentBody !== null) { + return; + } + + let sentBody = NetworkHelper.readPostTextFromRequest(httpActivity.channel, + httpActivity.charset); + + if (sentBody !== null && this.window && + httpActivity.url == this.window.location.href) { + // If the request URL is the same as the current page URL, then + // we can try to get the posted text from the page directly. + // This check is necessary as otherwise the + // NetworkHelper.readPostTextFromPageViaWebNav() + // function is called for image requests as well but these + // are not web pages and as such don't store the posted text + // in the cache of the webpage. + let webNav = this.window.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIWebNavigation); + sentBody = NetworkHelper + .readPostTextFromPageViaWebNav(webNav, httpActivity.charset); + } + + if (sentBody !== null) { + httpActivity.sentBody = sentBody; + } + }, + + /** + * Handler for ACTIVITY_SUBTYPE_RESPONSE_HEADER. This method stores + * information about the response headers. + * + * @private + * @param object httpActivity + * The HTTP activity object we are working with. + * @param string extraStringData + * The uncached response headers. + */ + _onResponseHeader: function (httpActivity, extraStringData) { + // extraStringData contains the uncached response headers. The first line + // contains the response status (e.g. HTTP/1.1 200 OK). + // + // Note: The response header is not saved here. Calling the + // channel.visitResponseHeaders() method at this point sometimes causes an + // NS_ERROR_NOT_AVAILABLE exception. + // + // We could parse extraStringData to get the headers and their values, but + // that is not trivial to do in an accurate manner. Hence, we save the + // response headers in this._httpResponseExaminer(). + + let headers = extraStringData.split(/\r\n|\n|\r/); + let statusLine = headers.shift(); + let statusLineArray = statusLine.split(" "); + + let response = {}; + response.httpVersion = statusLineArray.shift(); + response.remoteAddress = httpActivity.channel.remoteAddress; + response.remotePort = httpActivity.channel.remotePort; + response.status = statusLineArray.shift(); + response.statusText = statusLineArray.join(" "); + response.headersSize = extraStringData.length; + + httpActivity.responseStatus = response.status; + + // Discard the response body for known response statuses. + switch (parseInt(response.status, 10)) { + case HTTP_MOVED_PERMANENTLY: + case HTTP_FOUND: + case HTTP_SEE_OTHER: + case HTTP_TEMPORARY_REDIRECT: + httpActivity.discardResponseBody = true; + break; + } + + response.discardResponseBody = httpActivity.discardResponseBody; + + httpActivity.owner.addResponseStart(response, extraStringData); + }, + + /** + * Handler for ACTIVITY_SUBTYPE_TRANSACTION_CLOSE. This method updates the HAR + * timing information on the HTTP activity object and clears the request + * from the list of known open requests. + * + * @private + * @param object httpActivity + * The HTTP activity object we work with. + */ + _onTransactionClose: function (httpActivity) { + let result = this._setupHarTimings(httpActivity); + httpActivity.owner.addEventTimings(result.total, result.timings); + delete this.openRequests[httpActivity.id]; + }, + + /** + * Update the HTTP activity object to include timing information as in the HAR + * spec. The HTTP activity object holds the raw timing information in + * |timings| - these are timings stored for each activity notification. The + * HAR timing information is constructed based on these lower level + * data. + * + * @param object httpActivity + * The HTTP activity object we are working with. + * @param boolean fromCache + * Indicates that the result was returned from the browser cache + * @return object + * This object holds two properties: + * - total - the total time for all of the request and response. + * - timings - the HAR timings object. + */ + _setupHarTimings: function (httpActivity, fromCache) { + if (fromCache) { + // If it came from the browser cache, we have no timing + // information and these should all be 0 + return { + total: 0, + timings: { + blocked: 0, + dns: 0, + connect: 0, + send: 0, + wait: 0, + receive: 0 + } + }; + } + + let timings = httpActivity.timings; + let harTimings = {}; + + if (timings.STATUS_RESOLVING && timings.STATUS_CONNECTING_TO) { + harTimings.blocked = timings.STATUS_RESOLVING.first - + timings.REQUEST_HEADER.first; + } else if (timings.STATUS_SENDING_TO) { + harTimings.blocked = timings.STATUS_SENDING_TO.first - + timings.REQUEST_HEADER.first; + } else { + harTimings.blocked = -1; + } + + // DNS timing information is available only in when the DNS record is not + // cached. + harTimings.dns = timings.STATUS_RESOLVING && timings.STATUS_RESOLVED ? + timings.STATUS_RESOLVED.last - + timings.STATUS_RESOLVING.first : -1; + + if (timings.STATUS_CONNECTING_TO && timings.STATUS_CONNECTED_TO) { + harTimings.connect = timings.STATUS_CONNECTED_TO.last - + timings.STATUS_CONNECTING_TO.first; + } else { + harTimings.connect = -1; + } + + if (timings.STATUS_SENDING_TO) { + harTimings.send = timings.STATUS_SENDING_TO.last - timings.STATUS_SENDING_TO.first; + } else if (timings.REQUEST_HEADER && timings.REQUEST_BODY_SENT) { + harTimings.send = timings.REQUEST_BODY_SENT.last - timings.REQUEST_HEADER.first; + } else { + harTimings.send = -1; + } + + if (timings.RESPONSE_START) { + harTimings.wait = timings.RESPONSE_START.first - + (timings.REQUEST_BODY_SENT || + timings.STATUS_SENDING_TO).last; + } else { + harTimings.wait = -1; + } + + if (timings.RESPONSE_START && timings.RESPONSE_COMPLETE) { + harTimings.receive = timings.RESPONSE_COMPLETE.last - + timings.RESPONSE_START.first; + } else { + harTimings.receive = -1; + } + + let totalTime = 0; + for (let timing in harTimings) { + let time = Math.max(Math.round(harTimings[timing] / 1000), -1); + harTimings[timing] = time; + if (time > -1) { + totalTime += time; + } + } + + return { + total: totalTime, + timings: harTimings, + }; + }, + + /** + * Suspend Web Console activity. This is called when all Web Consoles are + * closed. + */ + destroy: function () { + if (Services.appinfo.processType != Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT) { + gActivityDistributor.removeObserver(this); + Services.obs.removeObserver(this._httpResponseExaminer, + "http-on-examine-response"); + Services.obs.removeObserver(this._httpResponseExaminer, + "http-on-examine-cached-response"); + Services.obs.removeObserver(this._httpModifyExaminer, + "http-on-modify-request", false); + } + + Services.obs.removeObserver(this._serviceWorkerRequest, + "service-worker-synthesized-response"); + + this.interceptedChannels.clear(); + this.openRequests = {}; + this.openResponses = {}; + this.owner = null; + this.filters = null; + this._throttler = null; + }, +}; + +/** + * The NetworkMonitorChild is used to proxy all of the network activity of the + * child app process from the main process. The child WebConsoleActor creates an + * instance of this object. + * + * Network requests for apps happen in the main process. As such, + * a NetworkMonitor instance is used by the WebappsActor in the main process to + * log the network requests for this child process. + * + * The main process creates NetworkEventActorProxy instances per request. These + * send the data to this object using the nsIMessageManager. Here we proxy the + * data to the WebConsoleActor or to a NetworkEventActor. + * + * @constructor + * @param number appId + * The web appId of the child process. + * @param number outerWindowID + * The outerWindowID of the TabActor's main window. + * @param nsIMessageManager messageManager + * The nsIMessageManager to use to communicate with the parent process. + * @param object DebuggerServerConnection + * The RDP connection to the client. + * @param object owner + * The WebConsoleActor that is listening for the network requests. + */ +function NetworkMonitorChild(appId, outerWindowID, messageManager, conn, owner) { + this.appId = appId; + this.outerWindowID = outerWindowID; + this.conn = conn; + this.owner = owner; + this._messageManager = messageManager; + this._onNewEvent = this._onNewEvent.bind(this); + this._onUpdateEvent = this._onUpdateEvent.bind(this); + this._netEvents = new Map(); + this._msgName = `debug:${this.conn.prefix}netmonitor`; +} + +exports.NetworkMonitorChild = NetworkMonitorChild; + +NetworkMonitorChild.prototype = { + appId: null, + owner: null, + _netEvents: null, + _saveRequestAndResponseBodies: true, + _throttleData: null, + + get saveRequestAndResponseBodies() { + return this._saveRequestAndResponseBodies; + }, + + set saveRequestAndResponseBodies(val) { + this._saveRequestAndResponseBodies = val; + + this._messageManager.sendAsyncMessage(this._msgName, { + action: "setPreferences", + preferences: { + saveRequestAndResponseBodies: this._saveRequestAndResponseBodies, + }, + }); + }, + + get throttleData() { + return this._throttleData; + }, + + set throttleData(val) { + this._throttleData = val; + + this._messageManager.sendAsyncMessage(this._msgName, { + action: "setPreferences", + preferences: { + throttleData: this._throttleData, + }, + }); + }, + + init: function () { + this.conn.setupInParent({ + module: "devtools/shared/webconsole/network-monitor", + setupParent: "setupParentProcess" + }); + + let mm = this._messageManager; + mm.addMessageListener(`${this._msgName}:newEvent`, this._onNewEvent); + mm.addMessageListener(`${this._msgName}:updateEvent`, this._onUpdateEvent); + mm.sendAsyncMessage(this._msgName, { + appId: this.appId, + outerWindowID: this.outerWindowID, + action: "start", + }); + }, + + _onNewEvent: DevToolsUtils.makeInfallible(function _onNewEvent(msg) { + let {id, event} = msg.data; + + // Try to add stack trace to the event data received from parent + if (this.owner.stackTraceCollector) { + event.cause.stacktrace = + this.owner.stackTraceCollector.getStackTrace(event.channelId); + } + + let actor = this.owner.onNetworkEvent(event); + this._netEvents.set(id, Cu.getWeakReference(actor)); + }), + + _onUpdateEvent: DevToolsUtils.makeInfallible(function _onUpdateEvent(msg) { + let {id, method, args} = msg.data; + let weakActor = this._netEvents.get(id); + let actor = weakActor ? weakActor.get() : null; + if (!actor) { + console.error(`Received ${this._msgName}:updateEvent for unknown event ID: ${id}`); + return; + } + if (!(method in actor)) { + console.error(`Received ${this._msgName}:updateEvent unsupported ` + + `method: ${method}`); + return; + } + actor[method].apply(actor, args); + }), + + destroy: function () { + let mm = this._messageManager; + try { + mm.removeMessageListener(`${this._msgName}:newEvent`, this._onNewEvent); + mm.removeMessageListener(`${this._msgName}:updateEvent`, this._onUpdateEvent); + } catch (e) { + // On b2g, when registered to a new root docshell, + // all message manager functions throw when trying to call them during + // message-manager-disconnect event. + // As there is no attribute/method on message manager to know + // if they are still usable or not, we can only catch the exception... + } + this._netEvents.clear(); + this._messageManager = null; + this.conn = null; + this.owner = null; + }, +}; + +/** + * The NetworkEventActorProxy is used to send network request information from + * the main process to the child app process. One proxy is used per request. + * Similarly, one NetworkEventActor in the child app process is used per + * request. The client receives all network logs from the child actors. + * + * The child process has a NetworkMonitorChild instance that is listening for + * all network logging from the main process. The net monitor shim is used to + * proxy the data to the WebConsoleActor instance of the child process. + * + * @constructor + * @param nsIMessageManager messageManager + * The message manager for the child app process. This is used for + * communication with the NetworkMonitorChild instance of the process. + * @param string msgName + * The message name to be used for this connection. + */ +function NetworkEventActorProxy(messageManager, msgName) { + this.id = gSequenceId(); + this.messageManager = messageManager; + this._msgName = msgName; +} +exports.NetworkEventActorProxy = NetworkEventActorProxy; + +NetworkEventActorProxy.methodFactory = function (method) { + return DevToolsUtils.makeInfallible(function () { + let args = Array.slice(arguments); + let mm = this.messageManager; + mm.sendAsyncMessage(`${this._msgName}:updateEvent`, { + id: this.id, + method: method, + args: args, + }); + }, "NetworkEventActorProxy." + method); +}; + +NetworkEventActorProxy.prototype = { + /** + * Initialize the network event. This method sends the network request event + * to the content process. + * + * @param object event + * Object describing the network request. + * @return object + * This object. + */ + init: DevToolsUtils.makeInfallible(function (event) { + let mm = this.messageManager; + mm.sendAsyncMessage(`${this._msgName}:newEvent`, { + id: this.id, + event: event, + }); + return this; + }), +}; + +(function () { + // Listeners for new network event data coming from the NetworkMonitor. + let methods = ["addRequestHeaders", "addRequestCookies", "addRequestPostData", + "addResponseStart", "addSecurityInfo", "addResponseHeaders", + "addResponseCookies", "addResponseContent", "addEventTimings"]; + let factory = NetworkEventActorProxy.methodFactory; + for (let method of methods) { + NetworkEventActorProxy.prototype[method] = factory(method); + } +})(); + +/** + * This is triggered by the child calling `setupInParent` when the child's network monitor + * is starting up. This initializes the parent process side of the monitoring. + */ +function setupParentProcess({ mm, prefix }) { + let networkMonitor = new NetworkMonitorParent(mm, prefix); + return { + onBrowserSwap: newMM => networkMonitor.setMessageManager(newMM), + onDisconnected: () => { + networkMonitor.destroy(); + networkMonitor = null; + } + }; +} + +exports.setupParentProcess = setupParentProcess; + +/** + * The NetworkMonitorParent runs in the parent process and uses the message manager to + * listen for requests from the child process to start/stop the network monitor. Most + * request data is only available from the parent process, so that's why the network + * monitor needs to run there when debugging tabs that are in the child. + * + * @param nsIMessageManager mm + * The message manager for the browser we're filtering on. + * @param string prefix + * The RDP connection prefix that uniquely identifies the connection. + */ +function NetworkMonitorParent(mm, prefix) { + this._msgName = `debug:${prefix}netmonitor`; + this.onNetMonitorMessage = this.onNetMonitorMessage.bind(this); + this.onNetworkEvent = this.onNetworkEvent.bind(this); + this.setMessageManager(mm); +} + +NetworkMonitorParent.prototype = { + netMonitor: null, + messageManager: null, + + setMessageManager(mm) { + if (this.messageManager) { + let oldMM = this.messageManager; + oldMM.removeMessageListener(this._msgName, this.onNetMonitorMessage); + } + this.messageManager = mm; + if (mm) { + mm.addMessageListener(this._msgName, this.onNetMonitorMessage); + } + }, + + /** + * Handler for `debug:${prefix}netmonitor` messages received through the message manager + * from the content process. + * + * @param object msg + * Message from the content. + */ + onNetMonitorMessage: DevToolsUtils.makeInfallible(function (msg) { + let {action} = msg.json; + // Pipe network monitor data from parent to child via the message manager. + switch (action) { + case "start": + if (!this.netMonitor) { + let {appId, outerWindowID} = msg.json; + this.netMonitor = new NetworkMonitor({ + outerWindowID, + appId, + }, this); + this.netMonitor.init(); + } + break; + case "setPreferences": { + let {preferences} = msg.json; + for (let key of Object.keys(preferences)) { + if ((key == "saveRequestAndResponseBodies" || + key == "throttleData") && this.netMonitor) { + this.netMonitor[key] = preferences[key]; + } + } + break; + } + + case "stop": + if (this.netMonitor) { + this.netMonitor.destroy(); + this.netMonitor = null; + } + break; + + case "disconnect": + this.destroy(); + break; + } + }), + + /** + * Handler for new network requests. This method is invoked by the current + * NetworkMonitor instance. + * + * @param object event + * Object describing the network request. + * @return object + * A NetworkEventActorProxy instance which is notified when further + * data about the request is available. + */ + onNetworkEvent: DevToolsUtils.makeInfallible(function (event) { + return new NetworkEventActorProxy(this.messageManager, this._msgName).init(event); + }), + + destroy: function () { + this.setMessageManager(null); + + if (this.netMonitor) { + this.netMonitor.destroy(); + this.netMonitor = null; + } + }, +}; + +/** + * A WebProgressListener that listens for location changes. + * + * This progress listener is used to track file loads and other kinds of + * location changes. + * + * @constructor + * @param object window + * The window for which we need to track location changes. + * @param object owner + * The listener owner which needs to implement two methods: + * - onFileActivity(aFileURI) + * - onLocationChange(aState, aTabURI, aPageTitle) + */ +function ConsoleProgressListener(window, owner) { + this.window = window; + this.owner = owner; +} +exports.ConsoleProgressListener = ConsoleProgressListener; + +ConsoleProgressListener.prototype = { + /** + * Constant used for startMonitor()/stopMonitor() that tells you want to + * monitor file loads. + */ + MONITOR_FILE_ACTIVITY: 1, + + /** + * Constant used for startMonitor()/stopMonitor() that tells you want to + * monitor page location changes. + */ + MONITOR_LOCATION_CHANGE: 2, + + /** + * Tells if you want to monitor file activity. + * @private + * @type boolean + */ + _fileActivity: false, + + /** + * Tells if you want to monitor location changes. + * @private + * @type boolean + */ + _locationChange: false, + + /** + * Tells if the console progress listener is initialized or not. + * @private + * @type boolean + */ + _initialized: false, + + _webProgress: null, + + QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener, + Ci.nsISupportsWeakReference]), + + /** + * Initialize the ConsoleProgressListener. + * @private + */ + _init: function () { + if (this._initialized) { + return; + } + + this._webProgress = this.window.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIWebNavigation) + .QueryInterface(Ci.nsIWebProgress); + this._webProgress.addProgressListener(this, + Ci.nsIWebProgress.NOTIFY_STATE_ALL); + + this._initialized = true; + }, + + /** + * Start a monitor/tracker related to the current nsIWebProgressListener + * instance. + * + * @param number monitor + * Tells what you want to track. Available constants: + * - this.MONITOR_FILE_ACTIVITY + * Track file loads. + * - this.MONITOR_LOCATION_CHANGE + * Track location changes for the top window. + */ + startMonitor: function (monitor) { + switch (monitor) { + case this.MONITOR_FILE_ACTIVITY: + this._fileActivity = true; + break; + case this.MONITOR_LOCATION_CHANGE: + this._locationChange = true; + break; + default: + throw new Error("ConsoleProgressListener: unknown monitor type " + + monitor + "!"); + } + this._init(); + }, + + /** + * Stop a monitor. + * + * @param number monitor + * Tells what you want to stop tracking. See this.startMonitor() for + * the list of constants. + */ + stopMonitor: function (monitor) { + switch (monitor) { + case this.MONITOR_FILE_ACTIVITY: + this._fileActivity = false; + break; + case this.MONITOR_LOCATION_CHANGE: + this._locationChange = false; + break; + default: + throw new Error("ConsoleProgressListener: unknown monitor type " + + monitor + "!"); + } + + if (!this._fileActivity && !this._locationChange) { + this.destroy(); + } + }, + + onStateChange: function (progress, request, state, status) { + if (!this.owner) { + return; + } + + if (this._fileActivity) { + this._checkFileActivity(progress, request, state, status); + } + + if (this._locationChange) { + this._checkLocationChange(progress, request, state, status); + } + }, + + /** + * Check if there is any file load, given the arguments of + * nsIWebProgressListener.onStateChange. If the state change tells that a file + * URI has been loaded, then the remote Web Console instance is notified. + * @private + */ + _checkFileActivity: function (progress, request, state, status) { + if (!(state & Ci.nsIWebProgressListener.STATE_START)) { + return; + } + + let uri = null; + if (request instanceof Ci.imgIRequest) { + let imgIRequest = request.QueryInterface(Ci.imgIRequest); + uri = imgIRequest.URI; + } else if (request instanceof Ci.nsIChannel) { + let nsIChannel = request.QueryInterface(Ci.nsIChannel); + uri = nsIChannel.URI; + } + + if (!uri || !uri.schemeIs("file") && !uri.schemeIs("ftp")) { + return; + } + + this.owner.onFileActivity(uri.spec); + }, + + /** + * Check if the current window.top location is changing, given the arguments + * of nsIWebProgressListener.onStateChange. If that is the case, the remote + * Web Console instance is notified. + * @private + */ + _checkLocationChange: function (progress, request, state) { + let isStart = state & Ci.nsIWebProgressListener.STATE_START; + let isStop = state & Ci.nsIWebProgressListener.STATE_STOP; + let isNetwork = state & Ci.nsIWebProgressListener.STATE_IS_NETWORK; + let isWindow = state & Ci.nsIWebProgressListener.STATE_IS_WINDOW; + + // Skip non-interesting states. + if (!isNetwork || !isWindow || progress.DOMWindow != this.window) { + return; + } + + if (isStart && request instanceof Ci.nsIChannel) { + this.owner.onLocationChange("start", request.URI.spec, ""); + } else if (isStop) { + this.owner.onLocationChange("stop", this.window.location.href, + this.window.document.title); + } + }, + + onLocationChange: function () {}, + onStatusChange: function () {}, + onProgressChange: function () {}, + onSecurityChange: function () {}, + + /** + * Destroy the ConsoleProgressListener. + */ + destroy: function () { + if (!this._initialized) { + return; + } + + this._initialized = false; + this._fileActivity = false; + this._locationChange = false; + + try { + this._webProgress.removeProgressListener(this); + } catch (ex) { + // This can throw during browser shutdown. + } + + this._webProgress = null; + this.window = null; + this.owner = null; + }, +}; + +function gSequenceId() { + return gSequenceId.n++; +} +gSequenceId.n = 1; diff --git a/devtools/shared/webconsole/server-logger-monitor.js b/devtools/shared/webconsole/server-logger-monitor.js new file mode 100644 index 000000000..9cc2682ea --- /dev/null +++ b/devtools/shared/webconsole/server-logger-monitor.js @@ -0,0 +1,191 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set ft= javascript ts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const {Ci} = require("chrome"); +const Services = require("Services"); + +const {makeInfallible} = require("devtools/shared/DevToolsUtils"); + +loader.lazyGetter(this, "NetworkHelper", () => require("devtools/shared/webconsole/network-helper")); + +// Helper tracer. Should be generic sharable by other modules (bug 1171927) +const trace = { + log: function (...args) { + } +}; + +const acceptableHeaders = ["x-chromelogger-data"]; + +/** + * This object represents HTTP events observer. It's intended to be + * used in e10s enabled browser only. + * + * Since child processes can't register HTTP event observer they use + * this module to do the observing in the parent process. This monitor + * is loaded through DebuggerServerConnection.setupInParent() that is + * executed from within the child process. The execution is done by + * {@ServerLoggingListener}. The monitor listens to HTTP events and + * forwards it into the right child process. + * + * Read more about the architecture: + * https://github.com/mozilla/gecko-dev/blob/fx-team/devtools/server/docs/actor-e10s-handling.md + */ +var ServerLoggerMonitor = { + // Initialization + + initialize: function () { + this.onChildMessage = this.onChildMessage.bind(this); + this.onExamineResponse = this.onExamineResponse.bind(this); + + // Set of registered child frames (loggers). + this.targets = new Set(); + }, + + // Parent Child Relationship + + attach: makeInfallible(function ({ mm, prefix }) { + trace.log("ServerLoggerMonitor.attach; ", arguments); + + let setMessageManager = newMM => { + if (mm) { + mm.removeMessageListener("debug:server-logger", this.onChildMessage); + } + mm = newMM; + if (mm) { + mm.addMessageListener("debug:server-logger", this.onChildMessage); + } + }; + + // Start listening for messages from the {@ServerLogger} actor + // living in the child process. + setMessageManager(mm); + + return { + onBrowserSwap: setMessageManager, + onDisconnected: () => { + trace.log("ServerLoggerMonitor.onDisconnectChild; ", arguments); + setMessageManager(null); + } + }; + }), + + // Child Message Handling + + onChildMessage: function (msg) { + let method = msg.data.method; + + trace.log("ServerLoggerMonitor.onChildMessage; ", method, msg); + + switch (method) { + case "attachChild": + return this.onAttachChild(msg); + case "detachChild": + return this.onDetachChild(msg); + default: + trace.log("Unknown method name: ", method); + return undefined; + } + }, + + onAttachChild: function (event) { + let target = event.target; + let size = this.targets.size; + + trace.log("ServerLoggerMonitor.onAttachChild; size: ", size, target); + + // If this is the first child attached, register global HTTP observer. + if (!size) { + trace.log("ServerLoggerMonitor.onAttatchChild; Add HTTP Observer"); + Services.obs.addObserver(this.onExamineResponse, + "http-on-examine-response", false); + } + + // Collect child loggers. The frame element where the + // window/document lives. + this.targets.add(target); + }, + + onDetachChild: function (event) { + let target = event.target; + this.targets.delete(target); + + let size = this.targets.size; + trace.log("ServerLoggerMonitor.onDetachChild; size: ", size, target); + + // If this is the last child process attached, unregister + // the global HTTP observer. + if (!size) { + trace.log("ServerLoggerMonitor.onDetachChild; Remove HTTP Observer"); + Services.obs.removeObserver(this.onExamineResponse, + "http-on-examine-response", false); + } + }, + + // HTTP Observer + + onExamineResponse: makeInfallible(function (subject, topic) { + let httpChannel = subject.QueryInterface(Ci.nsIHttpChannel); + + trace.log("ServerLoggerMonitor.onExamineResponse; ", httpChannel.name, + this.targets); + + // Ignore requests from chrome or add-on code when we are monitoring + // content. + if (!httpChannel.loadInfo && + httpChannel.loadInfo.loadingDocument === null && + httpChannel.loadInfo.loadingPrincipal === + Services.scriptSecurityManager.getSystemPrincipal()) { + return; + } + + let requestFrame = NetworkHelper.getTopFrameForRequest(httpChannel); + if (!requestFrame) { + return; + } + + // Ignore requests from parent frames that aren't registered. + if (!this.targets.has(requestFrame)) { + return; + } + + let headers = []; + + httpChannel.visitResponseHeaders((header, value) => { + header = header.toLowerCase(); + if (acceptableHeaders.indexOf(header) !== -1) { + headers.push({header: header, value: value}); + } + }); + + if (!headers.length) { + return; + } + + let { messageManager } = requestFrame; + messageManager.sendAsyncMessage("debug:server-logger", { + method: "examineHeaders", + headers: headers, + }); + + trace.log("ServerLoggerMonitor.onExamineResponse; headers ", + headers.length, ", ", headers); + }), +}; + +/** + * Executed automatically by the framework. + */ +function setupParentProcess(event) { + return ServerLoggerMonitor.attach(event); +} + +// Monitor initialization. +ServerLoggerMonitor.initialize(); + +// Exports from this module +exports.setupParentProcess = setupParentProcess; diff --git a/devtools/shared/webconsole/server-logger.js b/devtools/shared/webconsole/server-logger.js new file mode 100644 index 000000000..58a2f216a --- /dev/null +++ b/devtools/shared/webconsole/server-logger.js @@ -0,0 +1,514 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set ft= javascript ts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const {Ci} = require("chrome"); +const {Class} = require("sdk/core/heritage"); +const Services = require("Services"); + +const {DebuggerServer} = require("devtools/server/main"); +const DevToolsUtils = require("devtools/shared/DevToolsUtils"); + +loader.lazyGetter(this, "NetworkHelper", () => require("devtools/shared/webconsole/network-helper")); + +// Helper tracer. Should be generic sharable by other modules (bug 1171927) +const trace = { + log: function () { + } +}; + +// Constants +const makeInfallible = DevToolsUtils.makeInfallible; +const acceptableHeaders = ["x-chromelogger-data"]; + +/** + * The listener is responsible for detecting server side logs + * within HTTP headers and sending them to the client. + * + * The logic is based on "http-on-examine-response" event that is + * sent when a response from the server is received. Consequently HTTP + * headers are parsed to find server side logs. + * + * A listeners for "http-on-examine-response" is registered when + * the listener starts and removed when destroy is executed. + */ +var ServerLoggingListener = Class({ + /** + * Initialization of the listener. The main step during the initialization + * process is registering a listener for "http-on-examine-response" event. + * + * @param {Object} win (nsIDOMWindow): + * filter network requests by the associated window object. + * If null (i.e. in the browser context) log everything + * @param {Object} owner + * The {@WebConsoleActor} instance + */ + initialize: function (win, owner) { + trace.log("ServerLoggingListener.initialize; ", owner.actorID, + ", child process: ", DebuggerServer.isInChildProcess); + + this.owner = owner; + this.window = win; + + this.onExamineResponse = this.onExamineResponse.bind(this); + this.onExamineHeaders = this.onExamineHeaders.bind(this); + this.onParentMessage = this.onParentMessage.bind(this); + + this.attach(); + }, + + /** + * The destroy is called by the parent WebConsoleActor actor. + */ + destroy: function () { + trace.log("ServerLoggingListener.destroy; ", this.owner.actorID, + ", child process: ", DebuggerServer.isInChildProcess); + + this.detach(); + }, + + /** + * The main responsibility of this method is registering a listener for + * "http-on-examine-response" events. + */ + attach: makeInfallible(function () { + trace.log("ServerLoggingListener.attach; child process: ", + DebuggerServer.isInChildProcess); + + // Setup the child <-> parent communication if this actor module + // is running in a child process. If e10s is disabled (this actor + // running in the same process as everything else) register observer + // listener just like in good old pre e10s days. + if (DebuggerServer.isInChildProcess) { + this.attachParentProcess(); + } else { + Services.obs.addObserver(this.onExamineResponse, + "http-on-examine-response", false); + } + }), + + /** + * Remove the "http-on-examine-response" listener. + */ + detach: makeInfallible(function () { + trace.log("ServerLoggingListener.detach; ", this.owner.actorID); + + if (DebuggerServer.isInChildProcess) { + this.detachParentProcess(); + } else { + Services.obs.removeObserver(this.onExamineResponse, + "http-on-examine-response", false); + } + }), + + // Parent Child Relationship + + attachParentProcess: function () { + trace.log("ServerLoggingListener.attachParentProcess;"); + + this.owner.conn.setupInParent({ + module: "devtools/shared/webconsole/server-logger-monitor", + setupParent: "setupParentProcess" + }); + + let mm = this.owner.conn.parentMessageManager; + let { addMessageListener, sendSyncMessage } = mm; + + // It isn't possible to register HTTP-* event observer inside + // a child process (in case of e10s), so listen for messages + // coming from the {@ServerLoggerMonitor} that lives inside + // the parent process. + addMessageListener("debug:server-logger", this.onParentMessage); + + // Attach to the {@ServerLoggerMonitor} object to subscribe events. + sendSyncMessage("debug:server-logger", { + method: "attachChild" + }); + }, + + detachParentProcess: makeInfallible(function () { + trace.log("ServerLoggingListener.detachParentProcess;"); + + let mm = this.owner.conn.parentMessageManager; + let { removeMessageListener, sendSyncMessage } = mm; + + sendSyncMessage("debug:server-logger", { + method: "detachChild", + }); + + removeMessageListener("debug:server-logger", this.onParentMessage); + }), + + onParentMessage: makeInfallible(function (msg) { + if (!msg.data) { + return; + } + + let method = msg.data.method; + trace.log("ServerLogger.onParentMessage; ", method, msg.data); + + switch (method) { + case "examineHeaders": + this.onExamineHeaders(msg); + break; + default: + trace.log("Unknown method name: ", method); + } + }), + + // HTTP Observer + + onExamineHeaders: function (event) { + let headers = event.data.headers; + + trace.log("ServerLoggingListener.onExamineHeaders;", headers); + + let parsedMessages = []; + + for (let item of headers) { + let header = item.header; + let value = item.value; + + let messages = this.parse(header, value); + if (messages) { + parsedMessages.push(...messages); + } + } + + if (!parsedMessages.length) { + return; + } + + for (let message of parsedMessages) { + this.sendMessage(message); + } + }, + + onExamineResponse: makeInfallible(function (subject) { + let httpChannel = subject.QueryInterface(Ci.nsIHttpChannel); + + trace.log("ServerLoggingListener.onExamineResponse; ", httpChannel.name, + ", ", this.owner.actorID, httpChannel); + + if (!this._matchRequest(httpChannel)) { + trace.log("ServerLoggerMonitor.onExamineResponse; No matching request!"); + return; + } + + let headers = []; + + httpChannel.visitResponseHeaders((header, value) => { + header = header.toLowerCase(); + if (acceptableHeaders.indexOf(header) !== -1) { + headers.push({header: header, value: value}); + } + }); + + this.onExamineHeaders({ + data: { + headers: headers, + } + }); + }), + + /** + * Check if a given network request should be logged by this network monitor + * instance based on the current filters. + * + * @private + * @param nsIHttpChannel channel + * Request to check. + * @return boolean + * True if the network request should be logged, false otherwise. + */ + _matchRequest: function (channel) { + trace.log("_matchRequest ", this.window, ", ", this.topFrame); + + // Log everything if the window is null (it's null in the browser context) + if (!this.window) { + return true; + } + + // Ignore requests from chrome or add-on code when we are monitoring + // content. + if (!channel.loadInfo && + channel.loadInfo.loadingDocument === null && + channel.loadInfo.loadingPrincipal === + Services.scriptSecurityManager.getSystemPrincipal()) { + return false; + } + + // Since frames support, this.window may not be the top level content + // frame, so that we can't only compare with win.top. + let win = NetworkHelper.getWindowForRequest(channel); + while (win) { + if (win == this.window) { + return true; + } + if (win.parent == win) { + break; + } + win = win.parent; + } + + return false; + }, + + // Server Logs + + /** + * Search through HTTP headers to catch all server side logs. + * Learn more about the data structure: + * https://craig.is/writing/chrome-logger/techspecs + */ + parse: function (header, value) { + let data; + + try { + let result = decodeURIComponent(escape(atob(value))); + data = JSON.parse(result); + } catch (err) { + console.error("Failed to parse HTTP log data! " + err); + return null; + } + + let parsedMessage = []; + let columnMap = this.getColumnMap(data); + + trace.log("ServerLoggingListener.parse; ColumnMap", columnMap); + trace.log("ServerLoggingListener.parse; data", data); + + let lastLocation; + + for (let row of data.rows) { + let backtrace = row[columnMap.get("backtrace")]; + let rawLogs = row[columnMap.get("log")]; + let type = row[columnMap.get("type")] || "log"; + + // Old version of the protocol includes a label. + // If this is the old version do some converting. + if (data.columns.indexOf("label") != -1) { + let label = row[columnMap.get("label")]; + let showLabel = label && typeof label === "string"; + + rawLogs = [rawLogs]; + + if (showLabel) { + rawLogs.unshift(label); + } + } + + // If multiple logs come from the same line only the first log + // has info about the backtrace. So, remember the last valid + // location and use it for those that not set. + let location = this.parseBacktrace(backtrace); + if (location) { + lastLocation = location; + } else { + location = lastLocation; + } + + parsedMessage.push({ + logs: rawLogs, + location: location, + type: type + }); + } + + return parsedMessage; + }, + + parseBacktrace: function (backtrace) { + if (!backtrace) { + return null; + } + + let result = backtrace.match(/\s*(\d+)$/); + if (!result || result.length < 2) { + return backtrace; + } + + return { + url: backtrace.slice(0, -result[0].length), + line: result[1] + }; + }, + + getColumnMap: function (data) { + let columnMap = new Map(); + let columnName; + + for (let key in data.columns) { + columnName = data.columns[key]; + columnMap.set(columnName, key); + } + + return columnMap; + }, + + sendMessage: function (msg) { + trace.log("ServerLoggingListener.sendMessage; message", msg); + + let formatted = format(msg); + trace.log("ServerLoggingListener.sendMessage; formatted", formatted); + + let win = this.window; + let innerID = win ? getInnerId(win) : null; + let location = msg.location; + + let message = { + category: "server", + innerID: innerID, + level: msg.type, + filename: location ? location.url : null, + lineNumber: location ? location.line : null, + columnNumber: 0, + private: false, + timeStamp: Date.now(), + arguments: formatted ? formatted.logs : null, + styles: formatted ? formatted.styles : null, + }; + + // Make sure to set the group name. + if (msg.type == "group" && formatted && formatted.logs) { + message.groupName = formatted ? formatted.logs[0] : null; + } + + // A message for console.table() method (passed in as the first + // argument) isn't supported. But, it's passed in by some server + // side libraries that implement console.* API - let's just remove it. + let args = message.arguments; + if (msg.type == "table" && args) { + if (typeof args[0] == "string") { + args.shift(); + } + } + + trace.log("ServerLoggingListener.sendMessage; raw: ", + msg.logs.join(", "), message); + + this.owner.onServerLogCall(message); + }, +}); + +// Helpers + +/** + * Parse printf-like specifiers ("%f", "%d", ...) and + * format the logs according to them. + */ +function format(msg) { + if (!msg.logs || !msg.logs[0]) { + return null; + } + + // Initialize the styles array (used for the "%c" specifier). + msg.styles = []; + + // Remove and get the first log (in which the specifiers are). + // Note that the first string doesn't have to be specified. + // An example of a log on the server side: + // ChromePhp::log("server info: ", $_SERVER); + // ChromePhp::log($_SERVER); + let firstString = ""; + if (typeof msg.logs[0] == "string") { + firstString = msg.logs.shift(); + } + + // All the specifiers present in the first string. + let splitLogRegExp = /(.*?)(%[oOcsdif]|$)/g; + let splitLogRegExpRes; + let concatString = ""; + let pushConcatString = () => { + if (concatString) { + rebuiltLogArray.push(concatString); + } + concatString = ""; + }; + + // This array represents the string of the log, in which the specifiers + // are replaced. It alternates strings and objects (%o;%O). + let rebuiltLogArray = []; + + // Get the strings before the specifiers (or the last chunk before the end + // of the string). + while ((splitLogRegExpRes = splitLogRegExp.exec(firstString)) !== null) { + let [, log, specifier] = splitLogRegExpRes; + + // We may start with a specifier or add consecutively several ones. In such + // a case, there is no log. + // Example: "%ctest" => first iteration: log = "", specifier = "%c". + // => second iteration: log = "test", specifier = "". + if (log) { + concatString += log; + } + + // Break now if there is no specifier anymore + // (means that we have reached the end of the string). + if (!specifier) { + break; + } + + let argument = msg.logs.shift(); + switch (specifier) { + case "%i": + case "%d": + // Parse into integer. + concatString += (argument | 0); + break; + case "%f": + // Parse into float. + concatString += (+argument); + break; + case "%o": + case "%O": + // Push the concatenated string and reinitialize concatString. + pushConcatString(); + // Push the object. + rebuiltLogArray.push(argument); + break; + case "%s": + concatString += argument; + break; + case "%c": + pushConcatString(); + let fillNullArrayLength = rebuiltLogArray.length - msg.styles.length; + let fillNullArray = Array(fillNullArrayLength).fill(null); + msg.styles.push(...fillNullArray, argument); + break; + } + } + + if (concatString) { + rebuiltLogArray.push(concatString); + } + + // Append the rest of arguments that don't have corresponding + // specifiers to the message logs. + msg.logs.unshift(...rebuiltLogArray); + + // Remove special ___class_name property that isn't supported + // by the current implementation. This property represents object class + // allowing custom rendering in the console panel. + for (let log of msg.logs) { + if (typeof log == "object") { + delete log.___class_name; + } + } + + return msg; +} + +// These helper are cloned from SDK to avoid loading to +// much SDK modules just because of two functions. +function getInnerId(win) { + return win.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID; +} + +// Exports from this module +exports.ServerLoggingListener = ServerLoggingListener; diff --git a/devtools/shared/webconsole/test/chrome.ini b/devtools/shared/webconsole/test/chrome.ini new file mode 100644 index 000000000..ae867b821 --- /dev/null +++ b/devtools/shared/webconsole/test/chrome.ini @@ -0,0 +1,41 @@ +[DEFAULT] +tags = devtools +support-files = + common.js + data.json + data.json^headers^ + helper_serviceworker.js + network_requests_iframe.html + sandboxed_iframe.html + console-test-worker.js + !/browser/base/content/test/general/browser_star_hsts.sjs + !/browser/base/content/test/general/pinning_headers.sjs + +[test_basics.html] +[test_bug819670_getter_throws.html] +[test_cached_messages.html] +[test_commands_other.html] +[test_commands_registration.html] +[test_consoleapi.html] +[test_consoleapi_innerID.html] +[test_console_serviceworker.html] +[test_console_serviceworker_cached.html] +[test_console_styling.html] +[test_file_uri.html] +[test_reflow.html] +[test_jsterm.html] +[test_jsterm_autocomplete.html] +[test_jsterm_cd_iframe.html] +[test_jsterm_last_result.html] +[test_jsterm_queryselector.html] +[test_network_get.html] +[test_network_longstring.html] +[test_network_post.html] +[test_network_security-hpkp.html] +[test_network_security-hsts.html] +[test_nsiconsolemessage.html] +[test_object_actor.html] +[test_object_actor_native_getters.html] +[test_object_actor_native_getters_lenient_this.html] +[test_page_errors.html] +[test_throw.html] diff --git a/devtools/shared/webconsole/test/common.js b/devtools/shared/webconsole/test/common.js new file mode 100644 index 000000000..b6649bc44 --- /dev/null +++ b/devtools/shared/webconsole/test/common.js @@ -0,0 +1,345 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set ft= javascript ts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +var {classes: Cc, interfaces: Ci, utils: Cu} = Components; + +const XHTML_NS = "http://www.w3.org/1999/xhtml"; + +// This gives logging to stdout for tests +var {console} = Cu.import("resource://gre/modules/Console.jsm", {}); + +var {require} = Cu.import("resource://devtools/shared/Loader.jsm", {}); +var Services = require("Services"); +var WebConsoleUtils = require("devtools/client/webconsole/utils").Utils; +var {Task} = require("devtools/shared/task"); + +var ConsoleAPIStorage = Cc["@mozilla.org/consoleAPI-storage;1"] + .getService(Ci.nsIConsoleAPIStorage); +var {DebuggerServer} = require("devtools/server/main"); +var {DebuggerClient, ObjectClient} = require("devtools/shared/client/main"); + +var {ConsoleServiceListener, ConsoleAPIListener} = + require("devtools/server/actors/utils/webconsole-utils"); + +function initCommon() +{ + // Services.prefs.setBoolPref("devtools.debugger.log", true); +} + +function initDebuggerServer() +{ + if (!DebuggerServer.initialized) { + DebuggerServer.init(); + DebuggerServer.addBrowserActors(); + } + DebuggerServer.allowChromeProcess = true; +} + +function connectToDebugger(aCallback) +{ + initCommon(); + initDebuggerServer(); + + let transport = DebuggerServer.connectPipe(); + let client = new DebuggerClient(transport); + + let dbgState = { dbgClient: client }; + client.connect().then(response => aCallback(dbgState, response)); +} + +function attachConsole(aListeners, aCallback) { + _attachConsole(aListeners, aCallback); +} +function attachConsoleToTab(aListeners, aCallback) { + _attachConsole(aListeners, aCallback, true); +} +function attachConsoleToWorker(aListeners, aCallback) { + _attachConsole(aListeners, aCallback, true, true); +} + +function _attachConsole(aListeners, aCallback, aAttachToTab, aAttachToWorker) +{ + function _onAttachConsole(aState, aResponse, aWebConsoleClient) + { + if (aResponse.error) { + console.error("attachConsole failed: " + aResponse.error + " " + + aResponse.message); + } + + aState.client = aWebConsoleClient; + + aCallback(aState, aResponse); + } + + connectToDebugger(function _onConnect(aState, aResponse) { + if (aResponse.error) { + console.error("client.connect() failed: " + aResponse.error + " " + + aResponse.message); + aCallback(aState, aResponse); + return; + } + + if (aAttachToTab) { + aState.dbgClient.listTabs(function _onListTabs(aResponse) { + if (aResponse.error) { + console.error("listTabs failed: " + aResponse.error + " " + + aResponse.message); + aCallback(aState, aResponse); + return; + } + let tab = aResponse.tabs[aResponse.selected]; + aState.dbgClient.attachTab(tab.actor, function (response, tabClient) { + if (aAttachToWorker) { + let workerName = "console-test-worker.js#" + new Date().getTime(); + var worker = new Worker(workerName); + // Keep a strong reference to the Worker to avoid it being + // GCd during the test (bug 1237492). + aState._worker_ref = worker; + worker.addEventListener("message", function listener() { + worker.removeEventListener("message", listener); + tabClient.listWorkers(function (response) { + let worker = response.workers.filter(w => w.url == workerName)[0]; + if (!worker) { + console.error("listWorkers failed. Unable to find the " + + "worker actor\n"); + return; + } + tabClient.attachWorker(worker.actor, function (response, workerClient) { + if (!workerClient || response.error) { + console.error("attachWorker failed. No worker client or " + + " error: " + response.error); + return; + } + workerClient.attachThread({}, function (aResponse) { + aState.actor = workerClient.consoleActor; + aState.dbgClient.attachConsole(workerClient.consoleActor, aListeners, + _onAttachConsole.bind(null, aState)); + }); + }); + }); + }); + } else { + aState.actor = tab.consoleActor; + aState.dbgClient.attachConsole(tab.consoleActor, aListeners, + _onAttachConsole.bind(null, aState)); + } + }); + }); + } else { + aState.dbgClient.getProcess().then(response => { + aState.dbgClient.attachTab(response.form.actor, function () { + let consoleActor = response.form.consoleActor; + aState.actor = consoleActor; + aState.dbgClient.attachConsole(consoleActor, aListeners, + _onAttachConsole.bind(null, aState)); + }); + }); + } + }); +} + +function closeDebugger(aState, aCallback) +{ + aState.dbgClient.close().then(aCallback); + aState.dbgClient = null; + aState.client = null; +} + +function checkConsoleAPICalls(consoleCalls, expectedConsoleCalls) +{ + is(consoleCalls.length, expectedConsoleCalls.length, + "received correct number of console calls"); + expectedConsoleCalls.forEach(function (aMessage, aIndex) { + info("checking received console call #" + aIndex); + checkConsoleAPICall(consoleCalls[aIndex], expectedConsoleCalls[aIndex]); + }); +} + +function checkConsoleAPICall(aCall, aExpected) +{ + if (aExpected.level != "trace" && aExpected.arguments) { + is(aCall.arguments.length, aExpected.arguments.length, + "number of arguments"); + } + + checkObject(aCall, aExpected); +} + +function checkObject(aObject, aExpected) +{ + for (let name of Object.keys(aExpected)) + { + let expected = aExpected[name]; + let value = aObject[name]; + checkValue(name, value, expected); + } +} + +function checkValue(aName, aValue, aExpected) +{ + if (aExpected === null) { + ok(!aValue, "'" + aName + "' is null"); + } + else if (aValue === undefined) { + ok(false, "'" + aName + "' is undefined"); + } + else if (aValue === null) { + ok(false, "'" + aName + "' is null"); + } + else if (typeof aExpected == "string" || typeof aExpected == "number" || + typeof aExpected == "boolean") { + is(aValue, aExpected, "property '" + aName + "'"); + } + else if (aExpected instanceof RegExp) { + ok(aExpected.test(aValue), aName + ": " + aExpected + " matched " + aValue); + } + else if (Array.isArray(aExpected)) { + info("checking array for property '" + aName + "'"); + checkObject(aValue, aExpected); + } + else if (typeof aExpected == "object") { + info("checking object for property '" + aName + "'"); + checkObject(aValue, aExpected); + } +} + +function checkHeadersOrCookies(aArray, aExpected) +{ + let foundHeaders = {}; + + for (let elem of aArray) { + if (!(elem.name in aExpected)) { + continue; + } + foundHeaders[elem.name] = true; + info("checking value of header " + elem.name); + checkValue(elem.name, elem.value, aExpected[elem.name]); + } + + for (let header in aExpected) { + if (!(header in foundHeaders)) { + ok(false, header + " was not found"); + } + } +} + +function checkRawHeaders(aText, aExpected) +{ + let headers = aText.split(/\r\n|\n|\r/); + let arr = []; + for (let header of headers) { + let index = header.indexOf(": "); + if (index < 0) { + continue; + } + arr.push({ + name: header.substr(0, index), + value: header.substr(index + 2) + }); + } + + checkHeadersOrCookies(arr, aExpected); +} + +var gTestState = {}; + +function runTests(aTests, aEndCallback) +{ + function* driver() + { + let lastResult, sendToNext; + for (let i = 0; i < aTests.length; i++) { + gTestState.index = i; + let fn = aTests[i]; + info("will run test #" + i + ": " + fn.name); + lastResult = fn(sendToNext, lastResult); + sendToNext = yield lastResult; + } + yield aEndCallback(sendToNext, lastResult); + } + gTestState.driver = driver(); + return gTestState.driver.next(); +} + +function nextTest(aMessage) +{ + return gTestState.driver.next(aMessage); +} + +function withFrame(url) { + return new Promise(resolve => { + let iframe = document.createElement("iframe"); + iframe.onload = function () { + resolve(iframe); + }; + iframe.src = url; + document.body.appendChild(iframe); + }); +} + +function navigateFrame(iframe, url) { + return new Promise(resolve => { + iframe.onload = function () { + resolve(iframe); + }; + iframe.src = url; + }); +} + +function forceReloadFrame(iframe) { + return new Promise(resolve => { + iframe.onload = function () { + resolve(iframe); + }; + iframe.contentWindow.location.reload(true); + }); +} + +function withActiveServiceWorker(win, url, scope) { + let opts = {}; + if (scope) { + opts.scope = scope; + } + return win.navigator.serviceWorker.register(url, opts).then(swr => { + if (swr.active) { + return swr; + } + + // Unfortunately we can't just use navigator.serviceWorker.ready promise + // here. If the service worker is for a scope that does not cover the window + // then the ready promise will never resolve. Instead monitor the service + // workers state change events to determine when its activated. + return new Promise(resolve => { + let sw = swr.waiting || swr.installing; + sw.addEventListener("statechange", function stateHandler(evt) { + if (sw.state === "activated") { + sw.removeEventListener("statechange", stateHandler); + resolve(swr); + } + }); + }); + }); +} + +function messageServiceWorker(win, scope, message) { + return win.navigator.serviceWorker.getRegistration(scope).then(swr => { + return new Promise(resolve => { + win.navigator.serviceWorker.onmessage = evt => { + resolve(); + }; + let sw = swr.active || swr.waiting || swr.installing; + sw.postMessage({ type: "PING", message: message }); + }); + }); +} + +function unregisterServiceWorker(win) { + return win.navigator.serviceWorker.ready.then(swr => { + return swr.unregister(); + }); +} diff --git a/devtools/shared/webconsole/test/console-test-worker.js b/devtools/shared/webconsole/test/console-test-worker.js new file mode 100644 index 000000000..881eab0b8 --- /dev/null +++ b/devtools/shared/webconsole/test/console-test-worker.js @@ -0,0 +1,16 @@ +"use strict"; + +function f() { + var a = 1; + var b = 2; + var c = 3; +} + +self.onmessage = function (event) { + if (event.data == "ping") { + f(); + postMessage("pong"); + } +}; + +postMessage("load"); diff --git a/devtools/shared/webconsole/test/data.json b/devtools/shared/webconsole/test/data.json new file mode 100644 index 000000000..d46085c12 --- /dev/null +++ b/devtools/shared/webconsole/test/data.json @@ -0,0 +1,3 @@ +{ id: "test JSON data", myArray: [ "foo", "bar", "baz", "biff" ], + veryLong: "foo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo barfoo bar" +} diff --git a/devtools/shared/webconsole/test/data.json^headers^ b/devtools/shared/webconsole/test/data.json^headers^ new file mode 100644 index 000000000..bb6b45500 --- /dev/null +++ b/devtools/shared/webconsole/test/data.json^headers^ @@ -0,0 +1,3 @@ +Content-Type: application/json +x-very-long: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse a ipsum massa. Phasellus at elit dictum libero laoreet sagittis. Phasellus condimentum ultricies imperdiet. Nam eu ligula justo, ut tincidunt quam. Etiam sollicitudin, tortor sed egestas blandit, sapien sem tincidunt nulla, eu luctus libero odio quis leo. Nam elit massa, mattis quis blandit ac, facilisis vitae arcu. Donec vitae dictum neque. Proin ornare nisl at lectus commodo iaculis eget eget est. Quisque scelerisque vestibulum quam sed interdum. +x-very-short: hello world diff --git a/devtools/shared/webconsole/test/helper_serviceworker.js b/devtools/shared/webconsole/test/helper_serviceworker.js new file mode 100644 index 000000000..633f3e09b --- /dev/null +++ b/devtools/shared/webconsole/test/helper_serviceworker.js @@ -0,0 +1,19 @@ +console.log("script evaluation"); + +addEventListener("install", function (evt) { + console.log("install event"); +}); + +addEventListener("activate", function (evt) { + console.log("activate event"); +}); + +addEventListener("fetch", function (evt) { + console.log("fetch event: " + evt.request.url); + evt.respondWith(new Response("Hello world")); +}); + +addEventListener("message", function (evt) { + console.log("message event: " + evt.data.message); + evt.source.postMessage({ type: "PONG" }); +}); diff --git a/devtools/shared/webconsole/test/network_requests_iframe.html b/devtools/shared/webconsole/test/network_requests_iframe.html new file mode 100644 index 000000000..9147b6720 --- /dev/null +++ b/devtools/shared/webconsole/test/network_requests_iframe.html @@ -0,0 +1,61 @@ + + + + + Console HTTP test page + + + + +

Web Console HTTP Logging Testpage

+

This page is used to test the HTTP logging.

+ +
+
+
+
+ + diff --git a/devtools/shared/webconsole/test/sandboxed_iframe.html b/devtools/shared/webconsole/test/sandboxed_iframe.html new file mode 100644 index 000000000..55a6224b5 --- /dev/null +++ b/devtools/shared/webconsole/test/sandboxed_iframe.html @@ -0,0 +1,8 @@ + +Sandboxed iframe + + + + diff --git a/devtools/shared/webconsole/test/test_basics.html b/devtools/shared/webconsole/test/test_basics.html new file mode 100644 index 000000000..fa54557ae --- /dev/null +++ b/devtools/shared/webconsole/test/test_basics.html @@ -0,0 +1,80 @@ + + + + + Basic Web Console Actor tests + + + + + +

Basic Web Console Actor tests

+ + + + diff --git a/devtools/shared/webconsole/test/test_bug819670_getter_throws.html b/devtools/shared/webconsole/test/test_bug819670_getter_throws.html new file mode 100644 index 000000000..1b45c2d88 --- /dev/null +++ b/devtools/shared/webconsole/test/test_bug819670_getter_throws.html @@ -0,0 +1,76 @@ + + + + + Test for Bug 819670 - Web console object inspection does not handle native getters throwing very well + + + + + +

Test for Bug 819670 - Web console object inspection does not handle native getters throwing very well

+ + + + diff --git a/devtools/shared/webconsole/test/test_cached_messages.html b/devtools/shared/webconsole/test/test_cached_messages.html new file mode 100644 index 000000000..210543ca3 --- /dev/null +++ b/devtools/shared/webconsole/test/test_cached_messages.html @@ -0,0 +1,230 @@ + + + + + Test for cached messages + + + + + +

Test for cached messages

+ + + + + + diff --git a/devtools/shared/webconsole/test/test_commands_other.html b/devtools/shared/webconsole/test/test_commands_other.html new file mode 100644 index 000000000..47d1142c9 --- /dev/null +++ b/devtools/shared/webconsole/test/test_commands_other.html @@ -0,0 +1,83 @@ + + + + + Test for the other command helpers + + + + + +

Test for the querySelector / querySelectorAll helpers

+ + + + diff --git a/devtools/shared/webconsole/test/test_commands_registration.html b/devtools/shared/webconsole/test/test_commands_registration.html new file mode 100644 index 000000000..2a68f7cdc --- /dev/null +++ b/devtools/shared/webconsole/test/test_commands_registration.html @@ -0,0 +1,191 @@ + + + + + Test for Web Console commands registration. + + + + + +

Test for Web Console commands registration.

+

+ + + + + diff --git a/devtools/shared/webconsole/test/test_console_serviceworker.html b/devtools/shared/webconsole/test/test_console_serviceworker.html new file mode 100644 index 000000000..83d728d92 --- /dev/null +++ b/devtools/shared/webconsole/test/test_console_serviceworker.html @@ -0,0 +1,157 @@ + + + + + Test for the Console API and Service Workers + + + + + +

Test for the Console API and Service Workers

+ + + + diff --git a/devtools/shared/webconsole/test/test_console_serviceworker_cached.html b/devtools/shared/webconsole/test/test_console_serviceworker_cached.html new file mode 100644 index 000000000..5aab64d7f --- /dev/null +++ b/devtools/shared/webconsole/test/test_console_serviceworker_cached.html @@ -0,0 +1,117 @@ + + + + + Test for getCachedMessages and Service Workers + + + + + +

Test for getCachedMessages and Service Workers

+ + + + diff --git a/devtools/shared/webconsole/test/test_console_styling.html b/devtools/shared/webconsole/test/test_console_styling.html new file mode 100644 index 000000000..97d21bcb9 --- /dev/null +++ b/devtools/shared/webconsole/test/test_console_styling.html @@ -0,0 +1,126 @@ + + + + + Test for console.log styling with %c + + + + + +

Test for console.log styling with %c

+ + + + diff --git a/devtools/shared/webconsole/test/test_consoleapi.html b/devtools/shared/webconsole/test/test_consoleapi.html new file mode 100644 index 000000000..848db9cb6 --- /dev/null +++ b/devtools/shared/webconsole/test/test_consoleapi.html @@ -0,0 +1,233 @@ + + + + + Test for the Console API + + + + + +

Test for the Console API

+ + + + diff --git a/devtools/shared/webconsole/test/test_consoleapi_innerID.html b/devtools/shared/webconsole/test/test_consoleapi_innerID.html new file mode 100644 index 000000000..b477a36be --- /dev/null +++ b/devtools/shared/webconsole/test/test_consoleapi_innerID.html @@ -0,0 +1,164 @@ + + + + + Test for the innerID property of the Console API + + + + + +

Test for the Console API

+ + + + diff --git a/devtools/shared/webconsole/test/test_file_uri.html b/devtools/shared/webconsole/test/test_file_uri.html new file mode 100644 index 000000000..f5aada5b1 --- /dev/null +++ b/devtools/shared/webconsole/test/test_file_uri.html @@ -0,0 +1,106 @@ + + + + + Test for file activity tracking + + + + + +

Test for file activity tracking

+ + + + diff --git a/devtools/shared/webconsole/test/test_jsterm.html b/devtools/shared/webconsole/test/test_jsterm.html new file mode 100644 index 000000000..b6eefad4b --- /dev/null +++ b/devtools/shared/webconsole/test/test_jsterm.html @@ -0,0 +1,309 @@ + + + + + Test for JavaScript terminal functionality + + + + + +

Test for JavaScript terminal functionality

+ + + + + + diff --git a/devtools/shared/webconsole/test/test_jsterm_autocomplete.html b/devtools/shared/webconsole/test/test_jsterm_autocomplete.html new file mode 100644 index 000000000..0e32e1a63 --- /dev/null +++ b/devtools/shared/webconsole/test/test_jsterm_autocomplete.html @@ -0,0 +1,183 @@ + + + + + Test for JavaScript terminal functionality + + + + + +

Test for JavaScript terminal autocomplete functionality

+ + + + diff --git a/devtools/shared/webconsole/test/test_jsterm_cd_iframe.html b/devtools/shared/webconsole/test/test_jsterm_cd_iframe.html new file mode 100644 index 000000000..7207a00a1 --- /dev/null +++ b/devtools/shared/webconsole/test/test_jsterm_cd_iframe.html @@ -0,0 +1,223 @@ + + + + + Test for the cd() function + + + + + +

Test for the cd() function

+ + + + + + diff --git a/devtools/shared/webconsole/test/test_jsterm_last_result.html b/devtools/shared/webconsole/test/test_jsterm_last_result.html new file mode 100644 index 000000000..e90ce14ed --- /dev/null +++ b/devtools/shared/webconsole/test/test_jsterm_last_result.html @@ -0,0 +1,130 @@ + + + + + Test for the $_ getter + + + + + +

Test for the $_ getter

+ + + + + + diff --git a/devtools/shared/webconsole/test/test_jsterm_queryselector.html b/devtools/shared/webconsole/test/test_jsterm_queryselector.html new file mode 100644 index 000000000..b75ee399c --- /dev/null +++ b/devtools/shared/webconsole/test/test_jsterm_queryselector.html @@ -0,0 +1,134 @@ + + + + + Test for the querySelector / querySelectorAll helpers + + + + + +

Test for the querySelector / querySelectorAll helpers

+ + + + diff --git a/devtools/shared/webconsole/test/test_network_get.html b/devtools/shared/webconsole/test/test_network_get.html new file mode 100644 index 000000000..710c9b0d7 --- /dev/null +++ b/devtools/shared/webconsole/test/test_network_get.html @@ -0,0 +1,260 @@ + + + + + Test for the network actor (GET request) + + + + + +

Test for the network actor (GET request)

+ + + + + + diff --git a/devtools/shared/webconsole/test/test_network_longstring.html b/devtools/shared/webconsole/test/test_network_longstring.html new file mode 100644 index 000000000..d55136896 --- /dev/null +++ b/devtools/shared/webconsole/test/test_network_longstring.html @@ -0,0 +1,293 @@ + + + + + Test that the network actor uses the LongStringActor + + + + + +

Test that the network actor uses the LongStringActor

+ + + + + + diff --git a/devtools/shared/webconsole/test/test_network_post.html b/devtools/shared/webconsole/test/test_network_post.html new file mode 100644 index 000000000..d96b9b0b7 --- /dev/null +++ b/devtools/shared/webconsole/test/test_network_post.html @@ -0,0 +1,272 @@ + + + + + Test for the network actor (POST request) + + + + + +

Test for the network actor (POST request)

+ + + + + + diff --git a/devtools/shared/webconsole/test/test_network_security-hpkp.html b/devtools/shared/webconsole/test/test_network_security-hpkp.html new file mode 100644 index 000000000..55e2621a8 --- /dev/null +++ b/devtools/shared/webconsole/test/test_network_security-hpkp.html @@ -0,0 +1,108 @@ + + + + + Test for the network actor (HPKP detection) + + + + + +

Test for the network actor (HPKP detection)

+ + + + + + diff --git a/devtools/shared/webconsole/test/test_network_security-hsts.html b/devtools/shared/webconsole/test/test_network_security-hsts.html new file mode 100644 index 000000000..f69244d8d --- /dev/null +++ b/devtools/shared/webconsole/test/test_network_security-hsts.html @@ -0,0 +1,100 @@ + + + + + Test for the network actor (HSTS detection) + + + + + +

Test for the network actor (HSTS detection)

+ + + + + + diff --git a/devtools/shared/webconsole/test/test_nsiconsolemessage.html b/devtools/shared/webconsole/test/test_nsiconsolemessage.html new file mode 100644 index 000000000..ef8b8067e --- /dev/null +++ b/devtools/shared/webconsole/test/test_nsiconsolemessage.html @@ -0,0 +1,74 @@ + + + + + Test for nsIConsoleMessages + + + + + +

Make sure that nsIConsoleMessages are logged. See bug 859756.

+ + + + diff --git a/devtools/shared/webconsole/test/test_object_actor.html b/devtools/shared/webconsole/test/test_object_actor.html new file mode 100644 index 000000000..09176a5aa --- /dev/null +++ b/devtools/shared/webconsole/test/test_object_actor.html @@ -0,0 +1,178 @@ + + + + + Test for the object actor + + + + + +

Test for the object actor

+ + + + diff --git a/devtools/shared/webconsole/test/test_object_actor_native_getters.html b/devtools/shared/webconsole/test/test_object_actor_native_getters.html new file mode 100644 index 000000000..e22eb8cd5 --- /dev/null +++ b/devtools/shared/webconsole/test/test_object_actor_native_getters.html @@ -0,0 +1,106 @@ + + + + + Test for the native getters in object actors + + + + + +

Test for the native getters in object actors

+ + + + diff --git a/devtools/shared/webconsole/test/test_object_actor_native_getters_lenient_this.html b/devtools/shared/webconsole/test/test_object_actor_native_getters_lenient_this.html new file mode 100644 index 000000000..c4197a5b8 --- /dev/null +++ b/devtools/shared/webconsole/test/test_object_actor_native_getters_lenient_this.html @@ -0,0 +1,79 @@ + + + + + Test that WebIDL attributes with the LenientThis extended attribute + do not appear in the wrong objects + + + + + +

Test for the native getters in object actors

+ + + + diff --git a/devtools/shared/webconsole/test/test_page_errors.html b/devtools/shared/webconsole/test/test_page_errors.html new file mode 100644 index 000000000..19e5ba4b4 --- /dev/null +++ b/devtools/shared/webconsole/test/test_page_errors.html @@ -0,0 +1,186 @@ + + + + + Test for page errors + + + + + +

Test for page errors

+ + + + diff --git a/devtools/shared/webconsole/test/test_reflow.html b/devtools/shared/webconsole/test/test_reflow.html new file mode 100644 index 000000000..2ac2ca509 --- /dev/null +++ b/devtools/shared/webconsole/test/test_reflow.html @@ -0,0 +1,94 @@ + + + + + Test for the Reflow Activity + + + + + +

Test for reflow events

+ + + + diff --git a/devtools/shared/webconsole/test/test_throw.html b/devtools/shared/webconsole/test/test_throw.html new file mode 100644 index 000000000..7d7ea7b31 --- /dev/null +++ b/devtools/shared/webconsole/test/test_throw.html @@ -0,0 +1,93 @@ + + + + + Web Console throw tests + + + + + +

Web Console throw tests

+ + + + diff --git a/devtools/shared/webconsole/test/unit/.eslintrc.js b/devtools/shared/webconsole/test/unit/.eslintrc.js new file mode 100644 index 000000000..59adf410a --- /dev/null +++ b/devtools/shared/webconsole/test/unit/.eslintrc.js @@ -0,0 +1,6 @@ +"use strict"; + +module.exports = { + // Extend from the common devtools xpcshell eslintrc config. + "extends": "../../../../.eslintrc.xpcshell.js" +}; diff --git a/devtools/shared/webconsole/test/unit/test_js_property_provider.js b/devtools/shared/webconsole/test/unit/test_js_property_provider.js new file mode 100644 index 000000000..c360cf96d --- /dev/null +++ b/devtools/shared/webconsole/test/unit/test_js_property_provider.js @@ -0,0 +1,170 @@ +/* -*- js-indent-level: 2; indent-tabs-mode: nil -*- */ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/publicdomain/zero/1.0/ + +"use strict"; +const { require } = Components.utils.import("resource://devtools/shared/Loader.jsm", {}); +const { FallibleJSPropertyProvider: JSPropertyProvider } = + require("devtools/shared/webconsole/js-property-provider"); + +Components.utils.import("resource://gre/modules/jsdebugger.jsm"); +addDebuggerToGlobal(this); + +function run_test() { + const testArray = `var testArray = [ + {propA: "A"}, + { + propB: "B", + propC: [ + "D" + ] + }, + [ + {propE: "E"} + ] + ]`; + + const testObject = 'var testObject = {"propA": [{"propB": "B"}]}'; + const testHyphenated = 'var testHyphenated = {"prop-A": "res-A"}'; + const testLet = "let foobar = {a: ''}; const blargh = {a: 1};"; + + let sandbox = Components.utils.Sandbox("http://example.com"); + let dbg = new Debugger; + let dbgObject = dbg.addDebuggee(sandbox); + let dbgEnv = dbgObject.asEnvironment(); + Components.utils.evalInSandbox(testArray, sandbox); + Components.utils.evalInSandbox(testObject, sandbox); + Components.utils.evalInSandbox(testHyphenated, sandbox); + Components.utils.evalInSandbox(testLet, sandbox); + + do_print("Running tests with dbgObject"); + runChecks(dbgObject, null); + + do_print("Running tests with dbgEnv"); + runChecks(null, dbgEnv); + +} + +function runChecks(dbgObject, dbgEnv) { + do_print("Test that suggestions are given for 'this'"); + let results = JSPropertyProvider(dbgObject, dbgEnv, "t"); + test_has_result(results, "this"); + + if (dbgObject != null) { + do_print("Test that suggestions are given for 'this.'"); + results = JSPropertyProvider(dbgObject, dbgEnv, "this."); + test_has_result(results, "testObject"); + + do_print("Test that no suggestions are given for 'this.this'"); + results = JSPropertyProvider(dbgObject, dbgEnv, "this.this"); + test_has_no_results(results); + } + + do_print("Testing lexical scope issues (Bug 1207868)"); + results = JSPropertyProvider(dbgObject, dbgEnv, "foobar"); + test_has_result(results, "foobar"); + + results = JSPropertyProvider(dbgObject, dbgEnv, "foobar."); + test_has_result(results, "a"); + + results = JSPropertyProvider(dbgObject, dbgEnv, "blargh"); + test_has_result(results, "blargh"); + + results = JSPropertyProvider(dbgObject, dbgEnv, "blargh."); + test_has_result(results, "a"); + + do_print("Test that suggestions are given for 'foo[n]' where n is an integer."); + results = JSPropertyProvider(dbgObject, dbgEnv, "testArray[0]."); + test_has_result(results, "propA"); + + do_print("Test that suggestions are given for multidimensional arrays."); + results = JSPropertyProvider(dbgObject, dbgEnv, "testArray[2][0]."); + test_has_result(results, "propE"); + + do_print("Test that suggestions are given for nested arrays."); + results = JSPropertyProvider(dbgObject, dbgEnv, "testArray[1].propC[0]."); + test_has_result(results, "indexOf"); + + do_print("Test that suggestions are given for literal arrays."); + results = JSPropertyProvider(dbgObject, dbgEnv, "[1,2,3]."); + test_has_result(results, "indexOf"); + + do_print("Test that suggestions are given for literal arrays with newlines."); + results = JSPropertyProvider(dbgObject, dbgEnv, "[1,2,3,\n4\n]."); + test_has_result(results, "indexOf"); + + do_print("Test that suggestions are given for literal strings."); + results = JSPropertyProvider(dbgObject, dbgEnv, "'foo'."); + test_has_result(results, "charAt"); + results = JSPropertyProvider(dbgObject, dbgEnv, '"foo".'); + test_has_result(results, "charAt"); + results = JSPropertyProvider(dbgObject, dbgEnv, "`foo`."); + test_has_result(results, "charAt"); + results = JSPropertyProvider(dbgObject, dbgEnv, "'[1,2,3]'."); + test_has_result(results, "charAt"); + + do_print("Test that suggestions are not given for syntax errors."); + results = JSPropertyProvider(dbgObject, dbgEnv, "'foo\""); + do_check_null(results); + results = JSPropertyProvider(dbgObject, dbgEnv, "[1,',2]"); + do_check_null(results); + results = JSPropertyProvider(dbgObject, dbgEnv, "'[1,2]."); + do_check_null(results); + results = JSPropertyProvider(dbgObject, dbgEnv, "'foo'.."); + do_check_null(results); + + do_print("Test that suggestions are not given without a dot."); + results = JSPropertyProvider(dbgObject, dbgEnv, "'foo'"); + test_has_no_results(results); + results = JSPropertyProvider(dbgObject, dbgEnv, "[1,2,3]"); + test_has_no_results(results); + results = JSPropertyProvider(dbgObject, dbgEnv, "[1,2,3].\n'foo'"); + test_has_no_results(results); + + do_print("Test that suggestions are not given for numeric literals."); + results = JSPropertyProvider(dbgObject, dbgEnv, "1."); + do_check_null(results); + + do_print("Test that suggestions are not given for index that's out of bounds."); + results = JSPropertyProvider(dbgObject, dbgEnv, "testArray[10]."); + do_check_null(results); + + do_print("Test that no suggestions are given if an index is not numerical somewhere in the chain."); + results = JSPropertyProvider(dbgObject, dbgEnv, "testArray[0]['propC'][0]."); + do_check_null(results); + + results = JSPropertyProvider(dbgObject, dbgEnv, "testObject['propA'][0]."); + do_check_null(results); + + results = JSPropertyProvider(dbgObject, dbgEnv, "testArray[0]['propC']."); + do_check_null(results); + + results = JSPropertyProvider(dbgObject, dbgEnv, "testArray[][1]."); + do_check_null(results); + + do_print("Test that suggestions are not given if there is an hyphen in the chain."); + results = JSPropertyProvider(dbgObject, dbgEnv, "testHyphenated['prop-A']."); + do_check_null(results); +} + +/** + * A helper that ensures an empty array of results were found. + * @param Object aResults + * The results returned by JSPropertyProvider. + */ +function test_has_no_results(aResults) { + do_check_neq(aResults, null); + do_check_eq(aResults.matches.length, 0); +} +/** + * A helper that ensures (required) results were found. + * @param Object aResults + * The results returned by JSPropertyProvider. + * @param String aRequiredSuggestion + * A suggestion that must be found from the results. + */ +function test_has_result(aResults, aRequiredSuggestion) { + do_check_neq(aResults, null); + do_check_true(aResults.matches.length > 0); + do_check_true(aResults.matches.indexOf(aRequiredSuggestion) !== -1); +} diff --git a/devtools/shared/webconsole/test/unit/test_network_helper.js b/devtools/shared/webconsole/test/unit/test_network_helper.js new file mode 100644 index 000000000..3a43ff432 --- /dev/null +++ b/devtools/shared/webconsole/test/unit/test_network_helper.js @@ -0,0 +1,47 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; +var Cu = Components.utils; +const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {}); + +Object.defineProperty(this, "NetworkHelper", { + get: function () { + return require("devtools/shared/webconsole/network-helper"); + }, + configurable: true, + writeable: false, + enumerable: true +}); + +function run_test() { + test_isTextMimeType(); +} + +function test_isTextMimeType() { + do_check_eq(NetworkHelper.isTextMimeType("text/plain"), true); + do_check_eq(NetworkHelper.isTextMimeType("application/javascript"), true); + do_check_eq(NetworkHelper.isTextMimeType("application/json"), true); + do_check_eq(NetworkHelper.isTextMimeType("text/css"), true); + do_check_eq(NetworkHelper.isTextMimeType("text/html"), true); + do_check_eq(NetworkHelper.isTextMimeType("image/svg+xml"), true); + do_check_eq(NetworkHelper.isTextMimeType("application/xml"), true); + + // Test custom JSON subtype + do_check_eq(NetworkHelper.isTextMimeType("application/vnd.tent.posts-feed.v0+json"), true); + do_check_eq(NetworkHelper.isTextMimeType("application/vnd.tent.posts-feed.v0-json"), true); + // Test custom XML subtype + do_check_eq(NetworkHelper.isTextMimeType("application/vnd.tent.posts-feed.v0+xml"), true); + do_check_eq(NetworkHelper.isTextMimeType("application/vnd.tent.posts-feed.v0-xml"), false); + // Test case-insensitive + do_check_eq(NetworkHelper.isTextMimeType("application/vnd.BIG-CORP+json"), true); + // Test non-text type + do_check_eq(NetworkHelper.isTextMimeType("image/png"), false); + // Test invalid types + do_check_eq(NetworkHelper.isTextMimeType("application/foo-+json"), false); + do_check_eq(NetworkHelper.isTextMimeType("application/-foo+json"), false); + do_check_eq(NetworkHelper.isTextMimeType("application/foo--bar+json"), false); + + // Test we do not cause internal errors with unoptimized regex. Bug 961097 + do_check_eq(NetworkHelper.isTextMimeType("application/vnd.google.safebrowsing-chunk"), false); +} diff --git a/devtools/shared/webconsole/test/unit/test_security-info-certificate.js b/devtools/shared/webconsole/test/unit/test_security-info-certificate.js new file mode 100644 index 000000000..be223d87e --- /dev/null +++ b/devtools/shared/webconsole/test/unit/test_security-info-certificate.js @@ -0,0 +1,68 @@ +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +// Tests that NetworkHelper.parseCertificateInfo parses certificate information +// correctly. + +const { require } = Components.utils.import("resource://devtools/shared/Loader.jsm", {}); + +Object.defineProperty(this, "NetworkHelper", { + get: function () { + return require("devtools/shared/webconsole/network-helper"); + }, + configurable: true, + writeable: false, + enumerable: true +}); + +var Ci = Components.interfaces; +const DUMMY_CERT = { + commonName: "cn", + organization: "o", + organizationalUnit: "ou", + issuerCommonName: "issuerCN", + issuerOrganization: "issuerO", + issuerOrganizationUnit: "issuerOU", + sha256Fingerprint: "qwertyuiopoiuytrewq", + sha1Fingerprint: "qwertyuiop", + validity: { + notBeforeLocalDay: "yesterday", + notAfterLocalDay: "tomorrow", + } +}; + +function run_test() { + do_print("Testing NetworkHelper.parseCertificateInfo."); + + let result = NetworkHelper.parseCertificateInfo(DUMMY_CERT); + + // Subject + equal(result.subject.commonName, DUMMY_CERT.commonName, + "Common name is correct."); + equal(result.subject.organization, DUMMY_CERT.organization, + "Organization is correct."); + equal(result.subject.organizationUnit, DUMMY_CERT.organizationUnit, + "Organizational unit is correct."); + + // Issuer + equal(result.issuer.commonName, DUMMY_CERT.issuerCommonName, + "Common name of the issuer is correct."); + equal(result.issuer.organization, DUMMY_CERT.issuerOrganization, + "Organization of the issuer is correct."); + equal(result.issuer.organizationUnit, DUMMY_CERT.issuerOrganizationUnit, + "Organizational unit of the issuer is correct."); + + // Validity + equal(result.validity.start, DUMMY_CERT.validity.notBeforeLocalDay, + "Start of the validity period is correct."); + equal(result.validity.end, DUMMY_CERT.validity.notAfterLocalDay, + "End of the validity period is correct."); + + // Fingerprints + equal(result.fingerprint.sha1, DUMMY_CERT.sha1Fingerprint, + "Certificate SHA1 fingerprint is correct."); + equal(result.fingerprint.sha256, DUMMY_CERT.sha256Fingerprint, + "Certificate SHA256 fingerprint is correct."); +} diff --git a/devtools/shared/webconsole/test/unit/test_security-info-parser.js b/devtools/shared/webconsole/test/unit/test_security-info-parser.js new file mode 100644 index 000000000..a5682e209 --- /dev/null +++ b/devtools/shared/webconsole/test/unit/test_security-info-parser.js @@ -0,0 +1,64 @@ +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +// Test that NetworkHelper.parseSecurityInfo returns correctly formatted object. + +const { require } = Components.utils.import("resource://devtools/shared/Loader.jsm", {}); +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); + +Object.defineProperty(this, "NetworkHelper", { + get: function () { + return require("devtools/shared/webconsole/network-helper"); + }, + configurable: true, + writeable: false, + enumerable: true +}); + +var Ci = Components.interfaces; +const wpl = Ci.nsIWebProgressListener; +const MockCertificate = { + commonName: "cn", + organization: "o", + organizationalUnit: "ou", + issuerCommonName: "issuerCN", + issuerOrganization: "issuerO", + issuerOrganizationUnit: "issuerOU", + sha256Fingerprint: "qwertyuiopoiuytrewq", + sha1Fingerprint: "qwertyuiop", + validity: { + notBeforeLocalDay: "yesterday", + notAfterLocalDay: "tomorrow", + } +}; + +const MockSecurityInfo = { + QueryInterface: XPCOMUtils.generateQI([Ci.nsITransportSecurityInfo, + Ci.nsISSLStatusProvider]), + securityState: wpl.STATE_IS_SECURE, + errorCode: 0, + SSLStatus: { + cipherSuite: "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256", + protocolVersion: 3, // TLS_VERSION_1_2 + serverCert: MockCertificate, + } +}; + +function run_test() { + let result = NetworkHelper.parseSecurityInfo(MockSecurityInfo, {}); + + equal(result.state, "secure", "State is correct."); + + equal(result.cipherSuite, MockSecurityInfo.cipherSuite, + "Cipher suite is correct."); + + equal(result.protocolVersion, "TLSv1.2", "Protocol version is correct."); + + deepEqual(result.cert, NetworkHelper.parseCertificateInfo(MockCertificate), + "Certificate information is correct."); + + equal(result.hpkp, false, "HPKP is false when URI is not available."); + equal(result.hsts, false, "HSTS is false when URI is not available."); +} diff --git a/devtools/shared/webconsole/test/unit/test_security-info-protocol-version.js b/devtools/shared/webconsole/test/unit/test_security-info-protocol-version.js new file mode 100644 index 000000000..b84002131 --- /dev/null +++ b/devtools/shared/webconsole/test/unit/test_security-info-protocol-version.js @@ -0,0 +1,54 @@ +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +// Tests that NetworkHelper.formatSecurityProtocol returns correct +// protocol version strings. + +const { require } = Components.utils.import("resource://devtools/shared/Loader.jsm", {}); + +Object.defineProperty(this, "NetworkHelper", { + get: function () { + return require("devtools/shared/webconsole/network-helper"); + }, + configurable: true, + writeable: false, + enumerable: true +}); + +var Ci = Components.interfaces; +const TEST_CASES = [ + { + description: "TLS_VERSION_1", + input: 1, + expected: "TLSv1" + }, { + description: "TLS_VERSION_1.1", + input: 2, + expected: "TLSv1.1" + }, { + description: "TLS_VERSION_1.2", + input: 3, + expected: "TLSv1.2" + }, { + description: "TLS_VERSION_1.3", + input: 4, + expected: "TLSv1.3" + }, { + description: "invalid version", + input: -1, + expected: "Unknown" + }, +]; + +function run_test() { + do_print("Testing NetworkHelper.formatSecurityProtocol."); + + for (let {description, input, expected} of TEST_CASES) { + do_print("Testing " + description); + + equal(NetworkHelper.formatSecurityProtocol(input), expected, + "Got the expected protocol string."); + } +} diff --git a/devtools/shared/webconsole/test/unit/test_security-info-state.js b/devtools/shared/webconsole/test/unit/test_security-info-state.js new file mode 100644 index 000000000..efa493a95 --- /dev/null +++ b/devtools/shared/webconsole/test/unit/test_security-info-state.js @@ -0,0 +1,100 @@ +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +// Tests that security info parser gives correct general security state for +// different cases. + +const { require } = Components.utils.import("resource://devtools/shared/Loader.jsm", {}); +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); + +Object.defineProperty(this, "NetworkHelper", { + get: function () { + return require("devtools/shared/webconsole/network-helper"); + }, + configurable: true, + writeable: false, + enumerable: true +}); + +var Ci = Components.interfaces; +const wpl = Ci.nsIWebProgressListener; +const MockSecurityInfo = { + QueryInterface: XPCOMUtils.generateQI([Ci.nsITransportSecurityInfo, + Ci.nsISSLStatusProvider]), + securityState: wpl.STATE_IS_BROKEN, + errorCode: 0, + SSLStatus: { + protocolVersion: 3, // nsISSLStatus.TLS_VERSION_1_2 + cipherSuite: "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256", + } +}; + +function run_test() { + test_nullSecurityInfo(); + test_insecureSecurityInfoWithNSSError(); + test_insecureSecurityInfoWithoutNSSError(); + test_brokenSecurityInfo(); + test_secureSecurityInfo(); +} + +/** + * Test that undefined security information is returns "insecure". + */ +function test_nullSecurityInfo() { + let result = NetworkHelper.parseSecurityInfo(null, {}); + equal(result.state, "insecure", + "state == 'insecure' when securityInfo was undefined"); +} + +/** + * Test that STATE_IS_INSECURE with NSSError returns "broken" + */ +function test_insecureSecurityInfoWithNSSError() { + MockSecurityInfo.securityState = wpl.STATE_IS_INSECURE; + + // Taken from security/manager/ssl/tests/unit/head_psm.js. + MockSecurityInfo.errorCode = -8180; + + let result = NetworkHelper.parseSecurityInfo(MockSecurityInfo, {}); + equal(result.state, "broken", + "state == 'broken' if securityState contains STATE_IS_INSECURE flag AND " + + "errorCode is NSS error."); + + MockSecurityInfo.errorCode = 0; +} + +/** + * Test that STATE_IS_INSECURE without NSSError returns "insecure" + */ +function test_insecureSecurityInfoWithoutNSSError() { + MockSecurityInfo.securityState = wpl.STATE_IS_INSECURE; + + let result = NetworkHelper.parseSecurityInfo(MockSecurityInfo, {}); + equal(result.state, "insecure", + "state == 'insecure' if securityState contains STATE_IS_INSECURE flag BUT " + + "errorCode is not NSS error."); +} + +/** + * Test that STATE_IS_SECURE returns "secure" + */ +function test_secureSecurityInfo() { + MockSecurityInfo.securityState = wpl.STATE_IS_SECURE; + + let result = NetworkHelper.parseSecurityInfo(MockSecurityInfo, {}); + equal(result.state, "secure", + "state == 'secure' if securityState contains STATE_IS_SECURE flag"); +} + +/** + * Test that STATE_IS_BROKEN returns "weak" + */ +function test_brokenSecurityInfo() { + MockSecurityInfo.securityState = wpl.STATE_IS_BROKEN; + + let result = NetworkHelper.parseSecurityInfo(MockSecurityInfo, {}); + equal(result.state, "weak", + "state == 'weak' if securityState contains STATE_IS_BROKEN flag"); +} diff --git a/devtools/shared/webconsole/test/unit/test_security-info-static-hpkp.js b/devtools/shared/webconsole/test/unit/test_security-info-static-hpkp.js new file mode 100644 index 000000000..b76fa141a --- /dev/null +++ b/devtools/shared/webconsole/test/unit/test_security-info-static-hpkp.js @@ -0,0 +1,47 @@ +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +// Test that NetworkHelper.parseSecurityInfo correctly detects static hpkp pins + +const { require } = Components.utils.import("resource://devtools/shared/Loader.jsm", {}); +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); +const Services = require("Services"); + +Object.defineProperty(this, "NetworkHelper", { + get: function () { + return require("devtools/shared/webconsole/network-helper"); + }, + configurable: true, + writeable: false, + enumerable: true +}); + +var Ci = Components.interfaces; +const wpl = Ci.nsIWebProgressListener; + +const MockSecurityInfo = { + QueryInterface: XPCOMUtils.generateQI([Ci.nsITransportSecurityInfo, + Ci.nsISSLStatusProvider]), + securityState: wpl.STATE_IS_SECURE, + errorCode: 0, + SSLStatus: { + cipherSuite: "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256", + protocolVersion: 3, // TLS_VERSION_1_2 + serverCert: { + validity: {} + }, + } +}; + +const MockHttpInfo = { + hostname: "include-subdomains.pinning.example.com", + private: false, +}; + +function run_test() { + Services.prefs.setIntPref("security.cert_pinning.enforcement_level", 1); + let result = NetworkHelper.parseSecurityInfo(MockSecurityInfo, MockHttpInfo); + equal(result.hpkp, true, "Static HPKP detected."); +} diff --git a/devtools/shared/webconsole/test/unit/test_security-info-weakness-reasons.js b/devtools/shared/webconsole/test/unit/test_security-info-weakness-reasons.js new file mode 100644 index 000000000..f91d8049e --- /dev/null +++ b/devtools/shared/webconsole/test/unit/test_security-info-weakness-reasons.js @@ -0,0 +1,47 @@ +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +// Tests that NetworkHelper.getReasonsForWeakness returns correct reasons for +// weak requests. + +const { require } = Components.utils.import("resource://devtools/shared/Loader.jsm", {}); + +Object.defineProperty(this, "NetworkHelper", { + get: function () { + return require("devtools/shared/webconsole/network-helper"); + }, + configurable: true, + writeable: false, + enumerable: true +}); + +var Ci = Components.interfaces; +const wpl = Ci.nsIWebProgressListener; +const TEST_CASES = [ + { + description: "weak cipher", + input: wpl.STATE_IS_BROKEN | wpl.STATE_USES_WEAK_CRYPTO, + expected: ["cipher"] + }, { + description: "only STATE_IS_BROKEN flag", + input: wpl.STATE_IS_BROKEN, + expected: [] + }, { + description: "only STATE_IS_SECURE flag", + input: wpl.STATE_IS_SECURE, + expected: [] + }, +]; + +function run_test() { + do_print("Testing NetworkHelper.getReasonsForWeakness."); + + for (let {description, input, expected} of TEST_CASES) { + do_print("Testing " + description); + + deepEqual(NetworkHelper.getReasonsForWeakness(input), expected, + "Got the expected reasons for weakness."); + } +} diff --git a/devtools/shared/webconsole/test/unit/test_throttle.js b/devtools/shared/webconsole/test/unit/test_throttle.js new file mode 100644 index 000000000..fa8b26b61 --- /dev/null +++ b/devtools/shared/webconsole/test/unit/test_throttle.js @@ -0,0 +1,140 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const Cu = Components.utils; +const Cc = Components.classes; +const Ci = Components.interfaces; +const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {}); +const promise = require("promise"); +const { NetworkThrottleManager } = + require("devtools/shared/webconsole/throttle"); +const nsIScriptableInputStream = Ci.nsIScriptableInputStream; + +function TestStreamListener() { + this.state = "initial"; +} +TestStreamListener.prototype = { + onStartRequest: function() { + this.setState("start"); + }, + + onStopRequest: function() { + this.setState("stop"); + }, + + onDataAvailable: function(request, context, inputStream, offset, count) { + const sin = Components.classes["@mozilla.org/scriptableinputstream;1"] + .createInstance(nsIScriptableInputStream); + sin.init(inputStream); + this.data = sin.read(count); + this.setState("data"); + }, + + setState: function(state) { + this.state = state; + if (this._deferred) { + this._deferred.resolve(state); + this._deferred = null; + } + }, + + onStateChanged: function() { + if (!this._deferred) { + this._deferred = promise.defer(); + } + return this._deferred.promise; + } +}; + +function TestChannel() { + this.state = "initial"; + this.testListener = new TestStreamListener(); + this._throttleQueue = null; +} +TestChannel.prototype = { + QueryInterface: function() { + return this; + }, + + get throttleQueue() { + return this._throttleQueue; + }, + + set throttleQueue(q) { + this._throttleQueue = q; + this.state = "throttled"; + }, + + setNewListener: function(listener) { + this.listener = listener; + this.state = "listener"; + return this.testListener; + }, +}; + +add_task(function*() { + let throttler = new NetworkThrottleManager({ + roundTripTimeMean: 1, + roundTripTimeMax: 1, + downloadBPSMean: 500, + downloadBPSMax: 500, + uploadBPSMean: 500, + uploadBPSMax: 500, + }); + + let uploadChannel = new TestChannel(); + throttler.manageUpload(uploadChannel); + equal(uploadChannel.state, "throttled", + "NetworkThrottleManager set throttleQueue"); + + let downloadChannel = new TestChannel(); + let testListener = downloadChannel.testListener; + + let listener = throttler.manage(downloadChannel); + equal(downloadChannel.state, "listener", + "NetworkThrottleManager called setNewListener"); + + equal(testListener.state, "initial", "test listener in initial state"); + + // This method must be passed through immediately. + listener.onStartRequest(null, null); + equal(testListener.state, "start", "test listener started"); + + const TEST_INPUT = "hi bob"; + + let testStream = Cc["@mozilla.org/storagestream;1"] + .createInstance(Ci.nsIStorageStream); + testStream.init(512, 512); + let out = testStream.getOutputStream(0); + out.write(TEST_INPUT, TEST_INPUT.length); + out.close(); + let testInputStream = testStream.newInputStream(0); + + let activityDistributor = + Cc["@mozilla.org/network/http-activity-distributor;1"] + .getService(Ci.nsIHttpActivityDistributor); + let activitySeen = false; + listener.addActivityCallback(() => activitySeen = true, null, null, null, + activityDistributor + .ACTIVITY_SUBTYPE_RESPONSE_COMPLETE, + null, TEST_INPUT.length, null); + + // onDataAvailable is required to immediately read the data. + listener.onDataAvailable(null, null, testInputStream, 0, 6); + equal(testInputStream.available(), 0, "no more data should be available"); + equal(testListener.state, "start", + "test listener should not have received data"); + equal(activitySeen, false, "activity not distributed yet"); + + let newState = yield testListener.onStateChanged(); + equal(newState, "data", "test listener received data"); + equal(testListener.data, TEST_INPUT, "test listener received all the data"); + equal(activitySeen, true, "activity has been distributed"); + + let onChange = testListener.onStateChanged(); + listener.onStopRequest(null, null, null); + newState = yield onChange; + equal(newState, "stop", "onStateChanged reported"); +}); diff --git a/devtools/shared/webconsole/test/unit/xpcshell.ini b/devtools/shared/webconsole/test/unit/xpcshell.ini new file mode 100644 index 000000000..083950834 --- /dev/null +++ b/devtools/shared/webconsole/test/unit/xpcshell.ini @@ -0,0 +1,17 @@ +[DEFAULT] +tags = devtools +head = +tail = +firefox-appdir = browser +skip-if = toolkit == 'android' +support-files = + +[test_js_property_provider.js] +[test_network_helper.js] +[test_security-info-certificate.js] +[test_security-info-parser.js] +[test_security-info-protocol-version.js] +[test_security-info-state.js] +[test_security-info-static-hpkp.js] +[test_security-info-weakness-reasons.js] +[test_throttle.js] diff --git a/devtools/shared/webconsole/throttle.js b/devtools/shared/webconsole/throttle.js new file mode 100644 index 000000000..3a875ee24 --- /dev/null +++ b/devtools/shared/webconsole/throttle.js @@ -0,0 +1,418 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set ft= javascript ts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const {CC, Ci, Cu, Cc} = require("chrome"); + +const ArrayBufferInputStream = CC("@mozilla.org/io/arraybuffer-input-stream;1", + "nsIArrayBufferInputStream"); +const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1", + "nsIBinaryInputStream", "setInputStream"); + +loader.lazyServiceGetter(this, "gActivityDistributor", + "@mozilla.org/network/http-activity-distributor;1", + "nsIHttpActivityDistributor"); + +const {XPCOMUtils} = require("resource://gre/modules/XPCOMUtils.jsm"); +const {setTimeout} = Cu.import("resource://gre/modules/Timer.jsm", {}); + +/** + * Construct a new nsIStreamListener that buffers data and provides a + * method to notify another listener when data is available. This is + * used to throttle network data on a per-channel basis. + * + * After construction, @see setOriginalListener must be called on the + * new object. + * + * @param {NetworkThrottleQueue} queue the NetworkThrottleQueue to + * which status changes should be reported + */ +function NetworkThrottleListener(queue) { + this.queue = queue; + this.pendingData = []; + this.pendingException = null; + this.offset = 0; + this.responseStarted = false; + this.activities = {}; +} + +NetworkThrottleListener.prototype = { + QueryInterface: + XPCOMUtils.generateQI([Ci.nsIStreamListener, Ci.nsIInterfaceRequestor, + Ci.nsISupports]), + + /** + * Set the original listener for this object. The original listener + * will receive requests from this object when the queue allows data + * through. + * + * @param {nsIStreamListener} originalListener the original listener + * for the channel, to which all requests will be sent + */ + setOriginalListener: function (originalListener) { + this.originalListener = originalListener; + }, + + /** + * @see nsIStreamListener.onStartRequest. + */ + onStartRequest: function (request, context) { + this.originalListener.onStartRequest(request, context); + this.queue.start(this); + }, + + /** + * @see nsIStreamListener.onStopRequest. + */ + onStopRequest: function (request, context, statusCode) { + this.pendingData.push({request, context, statusCode}); + this.queue.dataAvailable(this); + }, + + /** + * @see nsIStreamListener.onDataAvailable. + */ + onDataAvailable: function (request, context, inputStream, offset, count) { + if (this.pendingException) { + throw this.pendingException; + } + + const bin = new BinaryInputStream(inputStream); + const bytes = new ArrayBuffer(count); + bin.readArrayBuffer(count, bytes); + + const stream = new ArrayBufferInputStream(); + stream.setData(bytes, 0, count); + + this.pendingData.push({request, context, stream, count}); + this.queue.dataAvailable(this); + }, + + /** + * Allow some buffered data from this object to be forwarded to this + * object's originalListener. + * + * @param {Number} bytesPermitted The maximum number of bytes + * permitted to be sent. + * @return {Object} an object of the form {length, done}, where + * |length| is the number of bytes actually forwarded, and + * |done| is a boolean indicating whether this particular + * request has been completed. (A NetworkThrottleListener + * may be queued multiple times, so this does not mean that + * all available data has been sent.) + */ + sendSomeData: function (bytesPermitted) { + if (this.pendingData.length === 0) { + // Shouldn't happen. + return {length: 0, done: true}; + } + + const {request, context, stream, count, statusCode} = this.pendingData[0]; + + if (statusCode !== undefined) { + this.pendingData.shift(); + this.originalListener.onStopRequest(request, context, statusCode); + return {length: 0, done: true}; + } + + if (bytesPermitted > count) { + bytesPermitted = count; + } + + try { + this.originalListener.onDataAvailable(request, context, stream, + this.offset, bytesPermitted); + } catch (e) { + this.pendingException = e; + } + + let done = false; + if (bytesPermitted === count) { + this.pendingData.shift(); + done = true; + } else { + this.pendingData[0].count -= bytesPermitted; + } + + this.offset += bytesPermitted; + // Maybe our state has changed enough to emit an event. + this.maybeEmitEvents(); + + return {length: bytesPermitted, done}; + }, + + /** + * Return the number of pending data requests available for this + * listener. + */ + pendingCount: function () { + return this.pendingData.length; + }, + + /** + * This is called when an http activity event is delivered. This + * object delays the event until the appropriate moment. + */ + addActivityCallback: function (callback, httpActivity, channel, activityType, + activitySubtype, timestamp, extraSizeData, + extraStringData) { + let datum = {callback, httpActivity, channel, activityType, + activitySubtype, extraSizeData, + extraStringData}; + this.activities[activitySubtype] = datum; + + if (activitySubtype === + gActivityDistributor.ACTIVITY_SUBTYPE_RESPONSE_COMPLETE) { + this.totalSize = extraSizeData; + } + + this.maybeEmitEvents(); + }, + + /** + * This is called for a download throttler when the latency timeout + * has ended. + */ + responseStart: function () { + this.responseStarted = true; + this.maybeEmitEvents(); + }, + + /** + * Check our internal state and emit any http activity events as + * needed. Note that we wait until both our internal state has + * changed and we've received the real http activity event from + * platform. This approach ensures we can both pass on the correct + * data from the original event, and update the reported time to be + * consistent with the delay we're introducing. + */ + maybeEmitEvents: function () { + if (this.responseStarted) { + this.maybeEmit(gActivityDistributor.ACTIVITY_SUBTYPE_RESPONSE_START); + this.maybeEmit(gActivityDistributor.ACTIVITY_SUBTYPE_RESPONSE_HEADER); + } + + if (this.totalSize !== undefined && this.offset >= this.totalSize) { + this.maybeEmit(gActivityDistributor.ACTIVITY_SUBTYPE_RESPONSE_COMPLETE); + this.maybeEmit(gActivityDistributor.ACTIVITY_SUBTYPE_TRANSACTION_CLOSE); + } + }, + + /** + * Emit an event for |code|, if the appropriate entry in + * |activities| is defined. + */ + maybeEmit: function (code) { + if (this.activities[code] !== undefined) { + let {callback, httpActivity, channel, activityType, + activitySubtype, extraSizeData, + extraStringData} = this.activities[code]; + let now = Date.now() * 1000; + callback(httpActivity, channel, activityType, activitySubtype, + now, extraSizeData, extraStringData); + this.activities[code] = undefined; + } + }, +}; + +/** + * Construct a new queue that can be used to throttle the network for + * a group of related network requests. + * + * meanBPS {Number} Mean bytes per second. + * maxBPS {Number} Maximum bytes per second. + * roundTripTimeMean {Number} Mean round trip time in milliseconds. + * roundTripTimeMax {Number} Maximum round trip time in milliseconds. + */ +function NetworkThrottleQueue(meanBPS, maxBPS, + roundTripTimeMean, roundTripTimeMax) { + this.meanBPS = meanBPS; + this.maxBPS = maxBPS; + this.roundTripTimeMean = roundTripTimeMean; + this.roundTripTimeMax = roundTripTimeMax; + + this.pendingRequests = new Set(); + this.downloadQueue = []; + this.previousReads = []; + + this.pumping = false; +} + +NetworkThrottleQueue.prototype = { + /** + * A helper function that, given a mean and a maximum, returns a + * random integer between (mean - (max - mean)) and max. + */ + random: function (mean, max) { + return mean - (max - mean) + Math.floor(2 * (max - mean) * Math.random()); + }, + + /** + * A helper function that lets the indicating listener start sending + * data. This is called after the initial round trip time for the + * listener has elapsed. + */ + allowDataFrom: function (throttleListener) { + throttleListener.responseStart(); + this.pendingRequests.delete(throttleListener); + const count = throttleListener.pendingCount(); + for (let i = 0; i < count; ++i) { + this.downloadQueue.push(throttleListener); + } + this.pump(); + }, + + /** + * Notice a new listener object. This is called by the + * NetworkThrottleListener when the request has started. Initially + * a new listener object is put into a "pending" state, until the + * round-trip time has elapsed. This is used to simulate latency. + * + * @param {NetworkThrottleListener} throttleListener the new listener + */ + start: function (throttleListener) { + this.pendingRequests.add(throttleListener); + let delay = this.random(this.roundTripTimeMean, this.roundTripTimeMax); + if (delay > 0) { + setTimeout(() => this.allowDataFrom(throttleListener), delay); + } else { + this.allowDataFrom(throttleListener); + } + }, + + /** + * Note that new data is available for a given listener. Each time + * data is available, the listener will be re-queued. + * + * @param {NetworkThrottleListener} throttleListener the listener + * which has data available. + */ + dataAvailable: function (throttleListener) { + if (!this.pendingRequests.has(throttleListener)) { + this.downloadQueue.push(throttleListener); + this.pump(); + } + }, + + /** + * An internal function that permits individual listeners to send + * data. + */ + pump: function () { + // A redirect will cause two NetworkThrottleListeners to be on a + // listener chain. In this case, we might recursively call into + // this method. Avoid infinite recursion here. + if (this.pumping) { + return; + } + this.pumping = true; + + const now = Date.now(); + const oneSecondAgo = now - 1000; + + while (this.previousReads.length && + this.previousReads[0].when < oneSecondAgo) { + this.previousReads.shift(); + } + + const totalBytes = this.previousReads.reduce((sum, elt) => { + return sum + elt.numBytes; + }, 0); + + let thisSliceBytes = this.random(this.meanBPS, this.maxBPS); + if (totalBytes < thisSliceBytes) { + thisSliceBytes -= totalBytes; + let readThisTime = 0; + while (thisSliceBytes > 0 && this.downloadQueue.length) { + let {length, done} = this.downloadQueue[0].sendSomeData(thisSliceBytes); + thisSliceBytes -= length; + readThisTime += length; + if (done) { + this.downloadQueue.shift(); + } + } + this.previousReads.push({when: now, numBytes: readThisTime}); + } + + // If there is more data to download, then schedule ourselves for + // one second after the oldest previous read. + if (this.downloadQueue.length) { + const when = this.previousReads[0].when + 1000; + setTimeout(this.pump.bind(this), when - now); + } + + this.pumping = false; + }, +}; + +/** + * Construct a new object that can be used to throttle the network for + * a group of related network requests. + * + * @param {Object} An object with the following attributes: + * roundTripTimeMean {Number} Mean round trip time in milliseconds. + * roundTripTimeMax {Number} Maximum round trip time in milliseconds. + * downloadBPSMean {Number} Mean bytes per second for downloads. + * downloadBPSMax {Number} Maximum bytes per second for downloads. + * uploadBPSMean {Number} Mean bytes per second for uploads. + * uploadBPSMax {Number} Maximum bytes per second for uploads. + * + * Download throttling will not be done if downloadBPSMean and + * downloadBPSMax are <= 0. Upload throttling will not be done if + * uploadBPSMean and uploadBPSMax are <= 0. + */ +function NetworkThrottleManager({roundTripTimeMean, roundTripTimeMax, + downloadBPSMean, downloadBPSMax, + uploadBPSMean, uploadBPSMax}) { + if (downloadBPSMax <= 0 && downloadBPSMean <= 0) { + this.downloadQueue = null; + } else { + this.downloadQueue = + new NetworkThrottleQueue(downloadBPSMean, downloadBPSMax, + roundTripTimeMean, roundTripTimeMax); + } + if (uploadBPSMax <= 0 && uploadBPSMean <= 0) { + this.uploadQueue = null; + } else { + this.uploadQueue = Cc["@mozilla.org/network/throttlequeue;1"] + .createInstance(Ci.nsIInputChannelThrottleQueue); + this.uploadQueue.init(uploadBPSMean, uploadBPSMax); + } +} +exports.NetworkThrottleManager = NetworkThrottleManager; + +NetworkThrottleManager.prototype = { + /** + * Create a new NetworkThrottleListener for a given channel and + * install it using |setNewListener|. + * + * @param {nsITraceableChannel} channel the channel to manage + * @return {NetworkThrottleListener} the new listener, or null if + * download throttling is not being done. + */ + manage: function (channel) { + if (this.downloadQueue) { + let listener = new NetworkThrottleListener(this.downloadQueue); + let originalListener = channel.setNewListener(listener); + listener.setOriginalListener(originalListener); + return listener; + } + return null; + }, + + /** + * Throttle uploads taking place on the given channel. + * + * @param {nsITraceableChannel} channel the channel to manage + */ + manageUpload: function (channel) { + if (this.uploadQueue) { + channel = channel.QueryInterface(Ci.nsIThrottledInputChannel); + channel.throttleQueue = this.uploadQueue; + } + }, +}; diff --git a/devtools/shared/worker/helper.js b/devtools/shared/worker/helper.js new file mode 100644 index 000000000..69512550b --- /dev/null +++ b/devtools/shared/worker/helper.js @@ -0,0 +1,133 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +(function (root, factory) { + "use strict"; + + if (typeof define === "function" && define.amd) { + define(factory); + } else if (typeof exports === "object") { + module.exports = factory(); + } else { + root.workerHelper = factory(); + } +}(this, function () { + "use strict"; + + /** + * This file is to only be included by ChromeWorkers. This exposes + * a `createTask` function to workers to register tasks for communication + * back to `devtools/shared/worker`. + * + * Tasks can be send their responses via a return value, either a primitive + * or a promise. + * + * createTask(self, "average", function (data) { + * return data.reduce((sum, val) => sum + val, 0) / data.length; + * }); + * + * createTask(self, "average", function (data) { + * return new Promise((resolve, reject) => { + * resolve(data.reduce((sum, val) => sum + val, 0) / data.length); + * }); + * }); + * + * + * Errors: + * + * Returning an Error value, or if the returned promise is rejected, this + * propagates to the DevToolsWorker as a rejected promise. If an error is + * thrown in a synchronous function, that error is also propagated. + */ + + /** + * Takes a worker's `self` object, a task name, and a function to + * be called when that task is called. The task is called with the + * passed in data as the first argument + * + * @param {object} self + * @param {string} name + * @param {function} fn + */ + function createTask(self, name, fn) { + // Store a hash of task name to function on the Worker + if (!self._tasks) { + self._tasks = {}; + } + + // Create the onmessage handler if not yet created. + if (!self.onmessage) { + self.onmessage = createHandler(self); + } + + // Store the task on the worker. + self._tasks[name] = fn; + } + + /** + * Creates the `self.onmessage` handler for a Worker. + * + * @param {object} self + * @return {function} + */ + function createHandler(self) { + return function (e) { + let { id, task, data } = e.data; + let taskFn = self._tasks[task]; + + if (!taskFn) { + self.postMessage({ id, error: `Task "${task}" not found in worker.` }); + return; + } + + try { + let results; + handleResponse(taskFn(data)); + } catch (e) { + handleError(e); + } + + function handleResponse(response) { + // If a promise + if (response && typeof response.then === "function") { + response.then(val => self.postMessage({ id, response: val }), handleError); + } + // If an error object + else if (response instanceof Error) { + handleError(response); + } + // If anything else + else { + self.postMessage({ id, response }); + } + } + + function handleError(error = "Error") { + try { + // First, try and structured clone the error across directly. + self.postMessage({ id, error }); + } catch (_) { + // We could not clone whatever error value was given. Do our best to + // stringify it. + let errorString = `Error while performing task "${task}": `; + + try { + errorString += error.toString(); + } catch (_) { + errorString += ""; + } + + if ("stack" in error) { + try { + errorString += "\n" + error.stack; + } catch (_) { } + } + + self.postMessage({ id, error: errorString }); + } + } + }; + } + + return { createTask: createTask }; +}.bind(this))); diff --git a/devtools/shared/worker/loader.js b/devtools/shared/worker/loader.js new file mode 100644 index 000000000..1de72963d --- /dev/null +++ b/devtools/shared/worker/loader.js @@ -0,0 +1,517 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +// A CommonJS module loader that is designed to run inside a worker debugger. +// We can't simply use the SDK module loader, because it relies heavily on +// Components, which isn't available in workers. +// +// In principle, the standard instance of the worker loader should provide the +// same built-in modules as its devtools counterpart, so that both loaders are +// interchangable on the main thread, making them easier to test. +// +// On the worker thread, some of these modules, in particular those that rely on +// the use of Components, and for which the worker debugger doesn't provide an +// alternative API, will be replaced by vacuous objects. Consequently, they can +// still be required, but any attempts to use them will lead to an exception. + +this.EXPORTED_SYMBOLS = ["WorkerDebuggerLoader", "worker"]; + +// Some notes on module ids and URLs: +// +// An id is either a relative id or an absolute id. An id is relative if and +// only if it starts with a dot. An absolute id is a normalized id if and only +// if it contains no redundant components. +// +// Every normalized id is a URL. A URL is either an absolute URL or a relative +// URL. A URL is absolute if and only if it starts with a scheme name followed +// by a colon and 2 or 3 slashes. + +/** + * Convert the given relative id to an absolute id. + * + * @param String id + * The relative id to be resolved. + * @param String baseId + * The absolute base id to resolve the relative id against. + * + * @return String + * An absolute id + */ +function resolveId(id, baseId) { + return baseId + "/../" + id; +} + +/** + * Convert the given absolute id to a normalized id. + * + * @param String id + * The absolute id to be normalized. + * + * @return String + * A normalized id. + */ +function normalizeId(id) { + // An id consists of an optional root and a path. A root consists of either + // a scheme name followed by 2 or 3 slashes, or a single slash. Slashes in the + // root are not used as separators, so only normalize the path. + let [_, root, path] = id.match(/^(\w+:\/\/\/?|\/)?(.*)/); + + let stack = []; + path.split("/").forEach(function (component) { + switch (component) { + case "": + case ".": + break; + case "..": + if (stack.length === 0) { + if (root !== undefined) { + throw new Error("Can't normalize absolute id '" + id + "'!"); + } else { + stack.push(".."); + } + } else { + if (stack[stack.length - 1] == "..") { + stack.push(".."); + } else { + stack.pop(); + } + } + break; + default: + stack.push(component); + break; + } + }); + + return (root ? root : "") + stack.join("/"); +} + +/** + * Create a module object with the given normalized id. + * + * @param String + * The normalized id of the module to be created. + * + * @return Object + * A module with the given id. + */ +function createModule(id) { + return Object.create(null, { + // CommonJS specifies the id property to be non-configurable and + // non-writable. + id: { + configurable: false, + enumerable: true, + value: id, + writable: false + }, + + // CommonJS does not specify an exports property, so follow the NodeJS + // convention, which is to make it non-configurable and writable. + exports: { + configurable: false, + enumerable: true, + value: Object.create(null), + writable: true + } + }); +} + +/** + * Create a CommonJS loader with the following options: + * - createSandbox: + * A function that will be used to create sandboxes. It should take the name + * and prototype of the sandbox to be created, and return the newly created + * sandbox as result. This option is required. + * - globals: + * A map of names to built-in globals that will be exposed to every module. + * Defaults to the empty map. + * - loadSubScript: + * A function that will be used to load scripts in sandboxes. It should take + * the URL from and the sandbox in which the script is to be loaded, and not + * return a result. This option is required. + * - modules: + * A map from normalized ids to built-in modules that will be added to the + * module cache. Defaults to the empty map. + * - paths: + * A map of paths to base URLs that will be used to resolve relative URLs to + * absolute URLS. Defaults to the empty map. + * - resolve: + * A function that will be used to resolve relative ids to absolute ids. It + * should take the relative id of a module to be required and the absolute + * id of the requiring module as arguments, and return the absolute id of + * the module to be required as result. Defaults to resolveId above. + */ +function WorkerDebuggerLoader(options) { + /** + * Convert the given relative URL to an absolute URL, using the map of paths + * given below. + * + * @param String url + * The relative URL to be resolved. + * + * @return String + * An absolute URL. + */ + function resolveURL(url) { + let found = false; + for (let [path, baseURL] of paths) { + if (url.startsWith(path)) { + found = true; + url = url.replace(path, baseURL); + break; + } + } + if (!found) { + throw new Error("Can't resolve relative URL '" + url + "'!"); + } + + // If the url has no extension, use ".js" by default. + return url.endsWith(".js") ? url : url + ".js"; + } + + /** + * Load the given module with the given url. + * + * @param Object module + * The module object to be loaded. + * @param String url + * The URL to load the module from. + */ + function loadModule(module, url) { + // CommonJS specifies 3 free variables: require, exports, and module. These + // must be exposed to every module, so define these as properties on the + // sandbox prototype. Additional built-in globals are exposed by making + // the map of built-in globals the prototype of the sandbox prototype. + let prototype = Object.create(globals); + prototype.Components = {}; + prototype.require = createRequire(module); + prototype.exports = module.exports; + prototype.module = module; + + let sandbox = createSandbox(url, prototype); + try { + loadSubScript(url, sandbox); + } catch (error) { + if (/^Error opening input stream/.test(String(error))) { + throw new Error("Can't load module '" + module.id + "' with url '" + + url + "'!"); + } + throw error; + } + + // The value of exports may have been changed by the module script, so + // freeze it if and only if it is still an object. + if (typeof module.exports === "object" && module.exports !== null) { + Object.freeze(module.exports); + } + } + + /** + * Create a require function for the given module. If no module is given, + * create a require function for the top-level module instead. + * + * @param Object requirer + * The module for which the require function is to be created. + * + * @return Function + * A require function for the given module. + */ + function createRequire(requirer) { + return function require(id) { + // Make sure an id was passed. + if (id === undefined) { + throw new Error("Can't require module without id!"); + } + + // Built-in modules are cached by id rather than URL, so try to find the + // module to be required by id first. + let module = modules[id]; + if (module === undefined) { + // Failed to find the module to be required by id, so convert the id to + // a URL and try again. + + // If the id is relative, convert it to an absolute id. + if (id.startsWith(".")) { + if (requirer === undefined) { + throw new Error("Can't require top-level module with relative id " + + "'" + id + "'!"); + } + id = resolve(id, requirer.id); + } + + // Convert the absolute id to a normalized id. + id = normalizeId(id); + + // Convert the normalized id to a URL. + let url = id; + + // If the URL is relative, resolve it to an absolute URL. + if (url.match(/^\w+:\/\//) === null) { + url = resolveURL(id); + } + + // Try to find the module to be required by URL. + module = modules[url]; + if (module === undefined) { + // Failed to find the module to be required in the cache, so create + // a new module, load it from the given URL, and add it to the cache. + + // Add modules to the cache early so that any recursive calls to + // require for the same module will return the partially-loaded module + // from the cache instead of triggering a new load. + module = modules[url] = createModule(id); + + try { + loadModule(module, url); + } catch (error) { + // If the module failed to load, remove it from the cache so that + // subsequent calls to require for the same module will trigger a + // new load, instead of returning a partially-loaded module from + // the cache. + delete modules[url]; + throw error; + } + + Object.freeze(module); + } + } + + return module.exports; + }; + } + + let createSandbox = options.createSandbox; + let globals = options.globals || Object.create(null); + let loadSubScript = options.loadSubScript; + + // Create the module cache, by converting each entry in the map from + // normalized ids to built-in modules to a module object, with the exports + // property of each module set to a frozen version of the original entry. + let modules = options.modules || {}; + for (let id in modules) { + let module = createModule(id); + module.exports = Object.freeze(modules[id]); + modules[id] = module; + } + + // Convert the map of paths to base URLs into an array for use by resolveURL. + // The array is sorted from longest to shortest path to ensure that the + // longest path is always the first to be found. + let paths = options.paths || Object.create(null); + paths = Object.keys(paths) + .sort((a, b) => b.length - a.length) + .map(path => [path, paths[path]]); + + let resolve = options.resolve || resolveId; + + this.require = createRequire(); +} + +this.WorkerDebuggerLoader = WorkerDebuggerLoader; + +// The following APIs rely on the use of Components, and the worker debugger +// does not provide alternative definitions for them. Consequently, they are +// stubbed out both on the main thread and worker threads. + +var chrome = { + CC: undefined, + Cc: undefined, + ChromeWorker: undefined, + Cm: undefined, + Ci: undefined, + Cu: undefined, + Cr: undefined, + components: undefined +}; + +var loader = { + lazyGetter: function (object, name, lambda) { + Object.defineProperty(object, name, { + get: function () { + delete object[name]; + return object[name] = lambda.apply(object); + }, + configurable: true, + enumerable: true + }); + }, + lazyImporter: function () { + throw new Error("Can't import JSM from worker thread!"); + }, + lazyServiceGetter: function () { + throw new Error("Can't import XPCOM service from worker thread!"); + }, + lazyRequireGetter: function (obj, property, module, destructure) { + Object.defineProperty(obj, property, { + get: () => destructure ? worker.require(module)[property] + : worker.require(module || property) + }); + } +}; + +// The following APIs are defined differently depending on whether we are on the +// main thread or a worker thread. On the main thread, we use the Components +// object to implement them. On worker threads, we use the APIs provided by +// the worker debugger. + +var { + Debugger, + URL, + createSandbox, + dump, + rpc, + loadSubScript, + reportError, + setImmediate, + xpcInspector +} = (function () { + if (typeof Components === "object") { // Main thread + let { + Constructor: CC, + classes: Cc, + manager: Cm, + interfaces: Ci, + results: Cr, + utils: Cu + } = Components; + + let principal = CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")(); + + // To ensure that the this passed to addDebuggerToGlobal is a global, the + // Debugger object needs to be defined in a sandbox. + let sandbox = Cu.Sandbox(principal, {}); + Cu.evalInSandbox( + "Components.utils.import('resource://gre/modules/jsdebugger.jsm');" + + "addDebuggerToGlobal(this);", + sandbox + ); + let Debugger = sandbox.Debugger; + + let createSandbox = function (name, prototype) { + return Cu.Sandbox(principal, { + invisibleToDebugger: true, + sandboxName: name, + sandboxPrototype: prototype, + wantComponents: false, + wantXrays: false + }); + }; + + let rpc = undefined; + + let subScriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"]. + getService(Ci.mozIJSSubScriptLoader); + + let loadSubScript = function (url, sandbox) { + subScriptLoader.loadSubScript(url, sandbox, "UTF-8"); + }; + + let reportError = Cu.reportError; + + let Timer = Cu.import("resource://gre/modules/Timer.jsm", {}); + + let setImmediate = function (callback) { + Timer.setTimeout(callback, 0); + }; + + let xpcInspector = Cc["@mozilla.org/jsinspector;1"]. + getService(Ci.nsIJSInspector); + + return { + Debugger, + URL: this.URL, + createSandbox, + dump: this.dump, + rpc, + loadSubScript, + reportError, + setImmediate, + xpcInspector + }; + } else { // Worker thread + let requestors = []; + + let scope = this; + + let xpcInspector = { + get eventLoopNestLevel() { + return requestors.length; + }, + + get lastNestRequestor() { + return requestors.length === 0 ? null : requestors[requestors.length - 1]; + }, + + enterNestedEventLoop: function (requestor) { + requestors.push(requestor); + scope.enterEventLoop(); + return requestors.length; + }, + + exitNestedEventLoop: function () { + requestors.pop(); + scope.leaveEventLoop(); + return requestors.length; + } + }; + + return { + Debugger: this.Debugger, + URL: this.URL, + createSandbox: this.createSandbox, + dump: this.dump, + rpc: this.rpc, + loadSubScript: this.loadSubScript, + reportError: this.reportError, + setImmediate: this.setImmediate, + xpcInspector: xpcInspector + }; + } +}).call(this); + +// Create the default instance of the worker loader, using the APIs we defined +// above. + +this.worker = new WorkerDebuggerLoader({ + createSandbox: createSandbox, + globals: { + "isWorker": true, + "dump": dump, + "loader": loader, + "reportError": reportError, + "rpc": rpc, + "setImmediate": setImmediate, + "URL": URL, + }, + loadSubScript: loadSubScript, + modules: { + "Debugger": Debugger, + "Services": Object.create(null), + "chrome": chrome, + "xpcInspector": xpcInspector + }, + paths: { + // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ + "": "resource://gre/modules/commonjs/", + // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ + // Modules here are intended to have one implementation for + // chrome, and a separate implementation for content. Here we + // map the directory to the chrome subdirectory, but the content + // loader will map to the content subdirectory. See the + // README.md in devtools/shared/platform. + "devtools/shared/platform": "resource://devtools/shared/platform/chrome", + // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ + "devtools": "resource://devtools", + // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ + "promise": "resource://gre/modules/Promise-backend.js", + // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ + "source-map": "resource://devtools/shared/sourcemap/source-map.js", + // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ + "xpcshell-test": "resource://test" + // ⚠ DISCUSSION ON DEV-DEVELOPER-TOOLS REQUIRED BEFORE MODIFYING ⚠ + } +}); diff --git a/devtools/shared/worker/moz.build b/devtools/shared/worker/moz.build new file mode 100644 index 000000000..28b26c0a7 --- /dev/null +++ b/devtools/shared/worker/moz.build @@ -0,0 +1,13 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +BROWSER_CHROME_MANIFESTS += ['tests/browser/browser.ini'] + +DevToolsModules( + 'helper.js', + 'loader.js', + 'worker.js', +) diff --git a/devtools/shared/worker/tests/browser/.eslintrc.js b/devtools/shared/worker/tests/browser/.eslintrc.js new file mode 100644 index 000000000..698ae9181 --- /dev/null +++ b/devtools/shared/worker/tests/browser/.eslintrc.js @@ -0,0 +1,6 @@ +"use strict"; + +module.exports = { + // Extend from the shared list of defined globals for mochitests. + "extends": "../../../../.eslintrc.mochitests.js" +}; diff --git a/devtools/shared/worker/tests/browser/browser.ini b/devtools/shared/worker/tests/browser/browser.ini new file mode 100644 index 000000000..a64916dff --- /dev/null +++ b/devtools/shared/worker/tests/browser/browser.ini @@ -0,0 +1,9 @@ +[DEFAULT] +tags = devtools +subsuite = devtools +support-files = + ../../../../server/tests/browser/head.js + +[browser_worker-01.js] +[browser_worker-02.js] +[browser_worker-03.js] diff --git a/devtools/shared/worker/tests/browser/browser_worker-01.js b/devtools/shared/worker/tests/browser/browser_worker-01.js new file mode 100644 index 000000000..7679e4166 --- /dev/null +++ b/devtools/shared/worker/tests/browser/browser_worker-01.js @@ -0,0 +1,45 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Tests that the devtools/shared/worker communicates properly +// as both CommonJS module and as a JSM. + +const WORKER_URL = + "resource://devtools/client/shared/widgets/GraphsWorker.js"; + +const count = 100000; +const WORKER_DATA = (function () { + let timestamps = []; + for (let i = 0; i < count; i++) { + timestamps.push(i); + } + return timestamps; +})(); +const INTERVAL = 100; +const DURATION = 1000; + +add_task(function* () { + // Test both CJS and JSM versions + + yield testWorker("JSM", () => Cu.import("resource://devtools/shared/worker/worker.js", {})); + yield testWorker("CommonJS", () => require("devtools/shared/worker/worker")); +}); + +function* testWorker(context, workerFactory) { + let { DevToolsWorker, workerify } = workerFactory(); + let worker = new DevToolsWorker(WORKER_URL); + let results = yield worker.performTask("plotTimestampsGraph", { + timestamps: WORKER_DATA, + interval: INTERVAL, + duration: DURATION + }); + + ok(results.plottedData.length, + `worker should have returned an object with array properties in ${context}`); + + let fn = workerify(function (x) { return x * x; }); + is((yield fn(5)), 25, `workerify works in ${context}`); + fn.destroy(); + + worker.destroy(); +} diff --git a/devtools/shared/worker/tests/browser/browser_worker-02.js b/devtools/shared/worker/tests/browser/browser_worker-02.js new file mode 100644 index 000000000..e6a9a54cf --- /dev/null +++ b/devtools/shared/worker/tests/browser/browser_worker-02.js @@ -0,0 +1,46 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Tests errors are handled properly by the DevToolsWorker. + +const { DevToolsWorker } = require("devtools/shared/worker/worker"); +const WORKER_URL = + "resource://devtools/client/shared/widgets/GraphsWorker.js"; + +add_task(function* () { + try { + let workerNotFound = new DevToolsWorker("resource://i/dont/exist.js"); + ok(false, "Creating a DevToolsWorker with an invalid URL throws"); + } catch (e) { + ok(true, "Creating a DevToolsWorker with an invalid URL throws"); + } + + let worker = new DevToolsWorker(WORKER_URL); + try { + // plotTimestampsGraph requires timestamp, interval an duration props on the object + // passed in so there should be an error thrown in the worker + let results = yield worker.performTask("plotTimestampsGraph", {}); + ok(false, "DevToolsWorker returns a rejected promise when an error occurs in the worker"); + } catch (e) { + ok(true, "DevToolsWorker returns a rejected promise when an error occurs in the worker"); + } + + try { + let results = yield worker.performTask("not a real task"); + ok(false, "DevToolsWorker returns a rejected promise when task does not exist"); + } catch (e) { + ok(true, "DevToolsWorker returns a rejected promise when task does not exist"); + } + + worker.destroy(); + try { + let results = yield worker.performTask("plotTimestampsGraph", { + timestamps: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], + interval: 1, + duration: 1 + }); + ok(false, "DevToolsWorker rejects when performing a task on a destroyed worker"); + } catch (e) { + ok(true, "DevToolsWorker rejects when performing a task on a destroyed worker"); + } +}); diff --git a/devtools/shared/worker/tests/browser/browser_worker-03.js b/devtools/shared/worker/tests/browser/browser_worker-03.js new file mode 100644 index 000000000..053e381b9 --- /dev/null +++ b/devtools/shared/worker/tests/browser/browser_worker-03.js @@ -0,0 +1,52 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Tests that the devtools/shared/worker can handle: +// returned primitives (or promise or Error) +// +// And tests `workerify` by doing so. + +const { DevToolsWorker, workerify } = require("devtools/shared/worker/worker"); +function square(x) { + return x * x; +} + +function squarePromise(x) { + return new Promise((resolve) => resolve(x * x)); +} + +function squareError(x) { + return new Error("Nope"); +} + +function squarePromiseReject(x) { + return new Promise((_, reject) => reject("Nope")); +} + +add_task(function* () { + let fn = workerify(square); + is((yield fn(5)), 25, "return primitives successful"); + fn.destroy(); + + fn = workerify(squarePromise); + is((yield fn(5)), 25, "promise primitives successful"); + fn.destroy(); + + fn = workerify(squareError); + try { + yield fn(5); + ok(false, "return error should reject"); + } catch (e) { + ok(true, "return error should reject"); + } + fn.destroy(); + + fn = workerify(squarePromiseReject); + try { + yield fn(5); + ok(false, "returned rejected promise rejects"); + } catch (e) { + ok(true, "returned rejected promise rejects"); + } + fn.destroy(); +}); diff --git a/devtools/shared/worker/worker.js b/devtools/shared/worker/worker.js new file mode 100644 index 000000000..9ed9afa27 --- /dev/null +++ b/devtools/shared/worker/worker.js @@ -0,0 +1,171 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/* global ChromeWorker */ + +(function (factory) { + if (this.module && module.id.indexOf("worker") >= 0) { + // require + const { Cc, Ci, Cu, ChromeWorker } = require("chrome"); + const dumpn = require("devtools/shared/DevToolsUtils").dumpn; + factory.call(this, require, exports, module, { Cc, Ci, Cu }, ChromeWorker, dumpn); + } else { + // Cu.import + const { classes: Cc, interfaces: Ci, utils: Cu } = Components; + const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {}); + this.isWorker = false; + this.Promise = Cu.import("resource://gre/modules/Promise.jsm", {}).Promise; + this.console = Cu.import("resource://gre/modules/Console.jsm", {}).console; + factory.call( + this, require, this, { exports: this }, + { Cc, Ci, Cu }, ChromeWorker, null + ); + this.EXPORTED_SYMBOLS = ["DevToolsWorker"]; + } +}).call(this, function (require, exports, module, { Ci, Cc }, ChromeWorker, dumpn) { + let MESSAGE_COUNTER = 0; + + /** + * Creates a wrapper around a ChromeWorker, providing easy + * communication to offload demanding tasks. The corresponding URL + * must implement the interface provided by `devtools/shared/worker/helper`. + * + * @see `./devtools/client/shared/widgets/GraphsWorker.js` + * + * @param {string} url + * The URL of the worker. + * @param Object opts + * An option with the following optional fields: + * - name: a name that will be printed with logs + * - verbose: log incoming and outgoing messages + */ + function DevToolsWorker(url, opts) { + opts = opts || {}; + this._worker = new ChromeWorker(url); + this._verbose = opts.verbose; + this._name = opts.name; + + this._worker.addEventListener("error", this.onError, false); + } + exports.DevToolsWorker = DevToolsWorker; + + /** + * Performs the given task in a chrome worker, passing in data. + * Returns a promise that resolves when the task is completed, resulting in + * the return value of the task. + * + * @param {string} task + * The name of the task to execute in the worker. + * @param {any} data + * Data to be passed into the task implemented by the worker. + * @return {Promise} + */ + DevToolsWorker.prototype.performTask = function (task, data) { + if (this._destroyed) { + return Promise.reject("Cannot call performTask on a destroyed DevToolsWorker"); + } + let worker = this._worker; + let id = ++MESSAGE_COUNTER; + let payload = { task, id, data }; + + if (this._verbose && dumpn) { + dumpn("Sending message to worker" + + (this._name ? (" (" + this._name + ")") : "") + + ": " + + JSON.stringify(payload, null, 2)); + } + worker.postMessage(payload); + + return new Promise((resolve, reject) => { + let listener = ({ data: result }) => { + if (this._verbose && dumpn) { + dumpn("Received message from worker" + + (this._name ? (" (" + this._name + ")") : "") + + ": " + + JSON.stringify(result, null, 2)); + } + + if (result.id !== id) { + return; + } + worker.removeEventListener("message", listener); + if (result.error) { + reject(result.error); + } else { + resolve(result.response); + } + }; + + worker.addEventListener("message", listener); + }); + }; + + /** + * Terminates the underlying worker. Use when no longer needing the worker. + */ + DevToolsWorker.prototype.destroy = function () { + this._worker.terminate(); + this._worker = null; + this._destroyed = true; + }; + + DevToolsWorker.prototype.onError = function ({ message, filename, lineno }) { + dump(new Error(message + " @ " + filename + ":" + lineno) + "\n"); + }; + + /** + * Takes a function and returns a Worker-wrapped version of the same function. + * Returns a promise upon resolution. + * @see `./devtools/shared/shared/tests/browser/browser_devtools-worker-03.js + * + * ⚠ This should only be used for tests or A/B testing performance ⚠ + * + * The original function must: + * + * Be a pure function, that is, not use any variables not declared within the + * function, or its arguments. + * + * Return a value or a promise. + * + * Note any state change in the worker will not affect the callee's context. + * + * @param {function} fn + * @return {function} + */ + function workerify(fn) { + console.warn("`workerify` should only be used in tests or measuring performance. " + + "This creates an object URL on the browser window, and should not be " + + "used in production."); + // Fetch via window/utils here as we don't want to include + // this module normally. + let { getMostRecentBrowserWindow } = require("sdk/window/utils"); + let { URL, Blob } = getMostRecentBrowserWindow(); + let stringifiedFn = createWorkerString(fn); + let blob = new Blob([stringifiedFn]); + let url = URL.createObjectURL(blob); + let worker = new DevToolsWorker(url); + + let wrapperFn = data => worker.performTask("workerifiedTask", data); + + wrapperFn.destroy = function () { + URL.revokeObjectURL(url); + worker.destroy(); + }; + + return wrapperFn; + } + exports.workerify = workerify; + + /** + * Takes a function, and stringifies it, attaching the worker-helper.js + * boilerplate hooks. + */ + function createWorkerString(fn) { + return `importScripts("resource://gre/modules/workers/require.js"); + const { createTask } = require("resource://devtools/shared/worker/helper.js"); + createTask(self, "workerifiedTask", ${fn.toString()});`; + } +}); -- cgit v1.2.3