HELLO·Android
系统源代码
IT资讯
技术文章
我的收藏
注册
登录
-
我收藏的文章
创建代码块
我的代码块
我的账号
Jelly Bean MR2
|
4.3_r1
下载
查看原文件
收藏
根目录
external
chromium-trace
trace-viewer
src
base.js
// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. 'use strict'; /** * The global object. * @type {!Object} * @const */ var global = this; /** Platform, package, object property, and Event support. */ this.base = (function() { /** * Base path for modules. Used to form URLs for module 'require' requests. */ var moduleBasePath = '.'; function setModuleBasePath(path) { if (path[path.length - 1] == '/') path = path.substring(0, path.length - 1); moduleBasePath = path; } function mLog(text, opt_indentLevel) { if (true) return; var spacing = ''; var indentLevel = opt_indentLevel || 0; for (var i = 0; i < indentLevel; i++) spacing += ' '; console.log(spacing + text); } /** * Builds an object structure for the provided namespace path, * ensuring that names that already exist are not overwritten. For * example: * 'a.b.c' -> a = {};a.b={};a.b.c={}; * @param {string} name Name of the object that this file defines. * @param {*=} opt_object The object to expose at the end of the path. * @param {Object=} opt_objectToExportTo The object to add the path to; * default is {@code global}. * @private */ function exportPath(name, opt_object, opt_objectToExportTo) { var parts = name.split('.'); var cur = opt_objectToExportTo || global; for (var part; parts.length && (part = parts.shift());) { if (!parts.length && opt_object !== undefined) { // last part and we have an object; use it cur[part] = opt_object; } else if (part in cur) { cur = cur[part]; } else { cur = cur[part] = {}; } } return cur; }; var didLoadModules = false; var moduleDependencies = {}; var moduleStylesheets = {}; var moduleRawScripts = {}; function addModuleDependency(moduleName, dependentModuleName) { if (!moduleDependencies[moduleName]) moduleDependencies[moduleName] = []; var dependentModules = moduleDependencies[moduleName]; var found = false; for (var i = 0; i < dependentModules.length; i++) if (dependentModules[i] == dependentModuleName) found = true; if (!found) dependentModules.push(dependentModuleName); } function addModuleRawScriptDependency(moduleName, rawScriptName) { if (!moduleRawScripts[moduleName]) moduleRawScripts[moduleName] = []; var dependentRawScripts = moduleRawScripts[moduleName]; var found = false; for (var i = 0; i < moduleRawScripts.length; i++) if (dependentRawScripts[i] == rawScriptName) found = true; if (!found) dependentRawScripts.push(rawScriptName); } function addModuleStylesheet(moduleName, stylesheetName) { if (!moduleStylesheets[moduleName]) moduleStylesheets[moduleName] = []; var stylesheets = moduleStylesheets[moduleName]; var found = false; for (var i = 0; i < stylesheets.length; i++) if (stylesheets[i] == stylesheetName) found = true; if (!found) stylesheets.push(stylesheetName); } function ensureDepsLoaded() { if (didLoadModules) return; didLoadModules = true; var req = new XMLHttpRequest(); var src = moduleBasePath + '/' + 'deps.js'; req.open('GET', src, false); req.send(null); if (req.status != 200) throw new Error('Could not find ' + src + '. Run calcdeps.py and try again.'); base.addModuleDependency = addModuleDependency; base.addModuleRawScriptDependency = addModuleRawScriptDependency; base.addModuleStylesheet = addModuleStylesheet; try { // By construction, the deps file should call addModuleDependency. eval(req.responseText); } catch (e) { throw new Error('When loading deps, got ' + e.stack ? e.stack : e); } delete base.addModuleStylesheet; delete base.addModuleRawScriptDependency; delete base.addModuleDependency; } var moduleLoadStatus = {}; var rawScriptLoadStatus = {}; function require(dependentModuleName, opt_indentLevel) { var indentLevel = opt_indentLevel || 0; if (window.FLATTENED) { if (!window.FLATTENED[dependentModuleName]) { throw new Error('Somehow, module ' + dependentModuleName + ' didn\'t get stored in the flattened js file! ' + 'You may need to rerun build/calcdeps.py'); } return; } ensureDepsLoaded(); mLog('require(' + dependentModuleName + ')', indentLevel); if (moduleLoadStatus[dependentModuleName] == 'APPENDED') return; if (moduleLoadStatus[dependentModuleName] == 'RESOLVING') throw new Error('Circular dependency betwen modules. Cannot continue!'); moduleLoadStatus[dependentModuleName] = 'RESOLVING'; // Load the module stylesheet first. var stylesheets = moduleStylesheets[dependentModuleName] || []; for (var i = 0; i < stylesheets.length; i++) requireStylesheet(stylesheets[i]); // Load the module raw scripts next var rawScripts = moduleRawScripts[dependentModuleName] || []; for (var i = 0; i < rawScripts.length; i++) { var rawScriptName = rawScripts[i]; if (rawScriptLoadStatus[rawScriptName]) continue; mLog('load(' + rawScriptName + ')', indentLevel); var src = moduleBasePath + '/' + rawScriptName; var text = '
登录后可以享受更多权益
您还没有登录,登录后您可以:
收藏Android系统代码
收藏喜欢的文章
多个平台共享账号
去登录
首次使用?从这里
注册