/* 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 . */ // @flow import type { Why } from "../../../types"; import type { NamedValue } from "./types"; export function getFramePopVariables(why: Why, path: string): NamedValue[] { const vars: Array = []; if (why && why.frameFinished) { const frameFinished = why.frameFinished; // Always display a `throw` property if present, even if it is falsy. if (Object.prototype.hasOwnProperty.call(frameFinished, "throw")) { vars.push({ name: "", path: `${path}/`, contents: { value: frameFinished.throw } }); } if (Object.prototype.hasOwnProperty.call(frameFinished, "return")) { const returned = frameFinished.return; // Do not display undefined. Do display falsy values like 0 and false. The // protocol grip for undefined is a JSON object: { type: "undefined" }. if (typeof returned !== "object" || returned.type !== "undefined") { vars.push({ name: "", path: `${path}/`, contents: { value: returned } }); } } } return vars; } export function getThisVariable(this_: any, path: string): ?NamedValue { if (!this_) { return null; } return { name: "", path: `${path}/`, contents: { value: this_ } }; }