/* * Copyright (C) 2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. 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. * * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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. */ WebInspector.FormattedValue = {}; WebInspector.FormattedValue.classNameForTypes = function(type, subtype) { return "formatted-" + (subtype ? subtype : type); }; WebInspector.FormattedValue.classNameForObject = function(object) { return WebInspector.FormattedValue.classNameForTypes(object.type, object.subtype); }; WebInspector.FormattedValue.createLinkifiedElementString = function(string) { var span = document.createElement("span"); span.className = "formatted-string"; span.append("\"", WebInspector.linkifyStringAsFragment(string.replace(/"/g, "\\\"")), "\""); return span; }; WebInspector.FormattedValue.createElementForNode = function(object) { var span = document.createElement("span"); span.className = "formatted-node"; object.pushNodeToFrontend(function(nodeId) { if (!nodeId) { span.textContent = object.description; return; } var treeOutline = new WebInspector.DOMTreeOutline; treeOutline.setVisible(true); treeOutline.rootDOMNode = WebInspector.domTreeManager.nodeForId(nodeId); if (!treeOutline.children[0].hasChildren) treeOutline.element.classList.add("single-node"); span.appendChild(treeOutline.element); }); return span; }; WebInspector.FormattedValue.createElementForError = function(object) { var span = document.createElement("span"); span.classList.add("formatted-error"); span.textContent = object.description; if (!object.preview) return span; function previewToObject(preview) { var result = {}; for (var property of preview.propertyPreviews) result[property.name] = property.value; return result; } var preview = previewToObject(object.preview); if (!preview.sourceURL) return span; var sourceLinkWithPrefix = WebInspector.ErrorObjectView.makeSourceLinkWithPrefix(preview.sourceURL, preview.line, preview.column); span.append(sourceLinkWithPrefix); return span; }; WebInspector.FormattedValue.createElementForNodePreview = function(preview) { var value = preview.value; var span = document.createElement("span"); span.className = "formatted-node-preview syntax-highlighted"; // Comment node preview. if (value.startsWith("