/* * 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. */ WI.FormattedValue = {}; WI.FormattedValue.MaxPreviewStringLength = 140; WI.FormattedValue.isSimpleString = function(string) { return string.length <= WI.FormattedValue.MaxPreviewStringLength && !string.slice(0, WI.FormattedValue.MaxPreviewStringLength).includes("\n"); }; WI.FormattedValue.hasSimpleDisplay = function(object) { switch (object.type) { case "boolean": case "number": case "symbol": case "bigint": case "undefined": return true; case "string": return WI.FormattedValue.isSimpleString(object.description); case "function": return false; case "object": var subtype = object.subtype; return subtype === "null" || subtype === "regexp" || subtype === "date"; } console.assert(false, "All RemoteObject types should be handled above"); return false; }; WI.FormattedValue.classNameForTypes = function(type, subtype) { return "formatted-" + (subtype ? subtype : type); }; WI.FormattedValue.classNameForObject = function(object) { return WI.FormattedValue.classNameForTypes(object.type, object.subtype); }; WI.FormattedValue.createLinkifiedElementString = function(string) { var span = document.createElement("span"); span.className = "formatted-string"; span.append("\"", WI.linkifyStringAsFragment(string.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")), "\""); return span; }; WI.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 WI.DOMTreeOutline; treeOutline.setVisible(true); treeOutline.rootDOMNode = WI.domManager.nodeForId(nodeId); if (!treeOutline.children[0].hasChildren) treeOutline.element.classList.add("single-node"); span.appendChild(treeOutline.element); }); return span; }; WI.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 = WI.ErrorObjectView.makeSourceLinkWithPrefix(preview.sourceURL, preview.line, preview.column); span.append(sourceLinkWithPrefix); return span; }; WI.FormattedValue.createElementForNodePreview = function(preview, {remoteObjectAccessor} = {}) { var value = preview.value || preview.description; var span = document.createElement("span"); span.className = "formatted-node-preview syntax-highlighted"; if (remoteObjectAccessor) { let domNode = null; span.addEventListener("mouseenter", (event) => { if (domNode) { domNode.highlight(); return; } remoteObjectAccessor((remoteObject) => { remoteObject.pushNodeToFrontend((nodeId) => { domNode = WI.domManager.nodeForId(nodeId); if (domNode) domNode.highlight(); }); }); }); span.addEventListener("mouseleave", (event) => { WI.domManager.hideDOMNodeHighlight(); }); span.addEventListener("contextmenu", (event) => { if (!domNode) return; let contextMenu = WI.ContextMenu.createFromEvent(event); WI.appendContextMenuItemsForDOMNode(contextMenu, domNode); }); } // Comment node preview. if (value.startsWith("