1// Copyright 2017 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import { WebInspector } from "./sourcemap.mjs";
6import {
7    ParseProcessor, ArgumentsProcessor, readFile,
8  } from "./parse-processor.mjs";
9
10function processArguments(args) {
11  const processor = new ArgumentsProcessor(args);
12  if (processor.parse()) {
13    return processor.result();
14  } else {
15    processor.printUsageAndExit();
16  }
17}
18
19function initSourceMapSupport() {
20  // Pull dev tools source maps  into our name space.
21  SourceMap = WebInspector.SourceMap;
22
23  // Overwrite the load function to load scripts synchronously.
24  SourceMap.load = function(sourceMapURL) {
25    const content = readFile(sourceMapURL);
26    const sourceMapObject = (JSON.parse(content));
27    return new SourceMap(sourceMapURL, sourceMapObject);
28  };
29}
30
31const params = processArguments(arguments);
32let sourceMap = null;
33if (params.sourceMap) {
34  initSourceMapSupport();
35  sourceMap = SourceMap.load(params.sourceMap);
36}
37const parseProcessor = new ParseProcessor();
38parseProcessor.processLogFile(params.logFileName);
39