Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | const TAB_URL = EXAMPLE_URL + "doc_closures.html"; |
michael@0 | 5 | |
michael@0 | 6 | // Test that inspecting a closure works as expected. |
michael@0 | 7 | |
michael@0 | 8 | function test() { |
michael@0 | 9 | let gPanel, gTab, gDebuggee, gDebugger; |
michael@0 | 10 | |
michael@0 | 11 | initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
michael@0 | 12 | gTab = aTab; |
michael@0 | 13 | gDebuggee = aDebuggee; |
michael@0 | 14 | gPanel = aPanel; |
michael@0 | 15 | gDebugger = gPanel.panelWin; |
michael@0 | 16 | gDebuggee.gRecurseLimit = 2; |
michael@0 | 17 | |
michael@0 | 18 | waitForSourceShown(gPanel, ".html") |
michael@0 | 19 | .then(testClosure) |
michael@0 | 20 | .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) |
michael@0 | 21 | .then(null, aError => { |
michael@0 | 22 | ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
michael@0 | 23 | }); |
michael@0 | 24 | }); |
michael@0 | 25 | |
michael@0 | 26 | function testClosure() { |
michael@0 | 27 | // Spin the event loop before causing the debuggee to pause, to allow |
michael@0 | 28 | // this function to return first. |
michael@0 | 29 | executeSoon(() => { |
michael@0 | 30 | EventUtils.sendMouseEvent({ type: "click" }, |
michael@0 | 31 | gDebuggee.document.querySelector("button"), |
michael@0 | 32 | gDebuggee); |
michael@0 | 33 | }); |
michael@0 | 34 | |
michael@0 | 35 | return waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES).then(() => { |
michael@0 | 36 | let gVars = gDebugger.DebuggerView.Variables; |
michael@0 | 37 | let localScope = gVars.getScopeAtIndex(0); |
michael@0 | 38 | let localNodes = localScope.target.querySelector(".variables-view-element-details").childNodes; |
michael@0 | 39 | |
michael@0 | 40 | is(localNodes[4].querySelector(".name").getAttribute("value"), "person", |
michael@0 | 41 | "Should have the right property name for |person|."); |
michael@0 | 42 | is(localNodes[4].querySelector(".value").getAttribute("value"), "Object", |
michael@0 | 43 | "Should have the right property value for |person|."); |
michael@0 | 44 | |
michael@0 | 45 | // Expand the 'person' tree node. This causes its properties to be |
michael@0 | 46 | // retrieved and displayed. |
michael@0 | 47 | let personNode = gVars.getItemForNode(localNodes[4]); |
michael@0 | 48 | let personFetched = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES); |
michael@0 | 49 | personNode.expand(); |
michael@0 | 50 | |
michael@0 | 51 | return personFetched.then(() => { |
michael@0 | 52 | is(personNode.expanded, true, |
michael@0 | 53 | "|person| should be expanded at this point."); |
michael@0 | 54 | |
michael@0 | 55 | is(personNode.get("getName").target.querySelector(".name") |
michael@0 | 56 | .getAttribute("value"), "getName", |
michael@0 | 57 | "Should have the right property name for 'getName' in person."); |
michael@0 | 58 | is(personNode.get("getName").target.querySelector(".value") |
michael@0 | 59 | .getAttribute("value"), "_pfactory/<.getName()", |
michael@0 | 60 | "'getName' in person should have the right value."); |
michael@0 | 61 | is(personNode.get("getFoo").target.querySelector(".name") |
michael@0 | 62 | .getAttribute("value"), "getFoo", |
michael@0 | 63 | "Should have the right property name for 'getFoo' in person."); |
michael@0 | 64 | is(personNode.get("getFoo").target.querySelector(".value") |
michael@0 | 65 | .getAttribute("value"), "_pfactory/<.getFoo()", |
michael@0 | 66 | "'getFoo' in person should have the right value."); |
michael@0 | 67 | |
michael@0 | 68 | // Expand the function nodes. This causes their properties to be |
michael@0 | 69 | // retrieved and displayed. |
michael@0 | 70 | let getFooNode = personNode.get("getFoo"); |
michael@0 | 71 | let getNameNode = personNode.get("getName"); |
michael@0 | 72 | let funcsFetched = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 2); |
michael@0 | 73 | let funcClosuresFetched = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES, 2); |
michael@0 | 74 | getFooNode.expand(); |
michael@0 | 75 | getNameNode.expand(); |
michael@0 | 76 | |
michael@0 | 77 | return funcsFetched.then(() => { |
michael@0 | 78 | is(getFooNode.expanded, true, |
michael@0 | 79 | "|person.getFoo| should be expanded at this point."); |
michael@0 | 80 | is(getNameNode.expanded, true, |
michael@0 | 81 | "|person.getName| should be expanded at this point."); |
michael@0 | 82 | |
michael@0 | 83 | is(getFooNode.get("<Closure>").target.querySelector(".name") |
michael@0 | 84 | .getAttribute("value"), "<Closure>", |
michael@0 | 85 | "Found the closure node for getFoo."); |
michael@0 | 86 | is(getFooNode.get("<Closure>").target.querySelector(".value") |
michael@0 | 87 | .getAttribute("value"), "", |
michael@0 | 88 | "The closure node has no value for getFoo."); |
michael@0 | 89 | is(getNameNode.get("<Closure>").target.querySelector(".name") |
michael@0 | 90 | .getAttribute("value"), "<Closure>", |
michael@0 | 91 | "Found the closure node for getName."); |
michael@0 | 92 | is(getNameNode.get("<Closure>").target.querySelector(".value") |
michael@0 | 93 | .getAttribute("value"), "", |
michael@0 | 94 | "The closure node has no value for getName."); |
michael@0 | 95 | |
michael@0 | 96 | // Expand the closure nodes. This causes their environments to be |
michael@0 | 97 | // retrieved and displayed. |
michael@0 | 98 | let getFooClosure = getFooNode.get("<Closure>"); |
michael@0 | 99 | let getNameClosure = getNameNode.get("<Closure>"); |
michael@0 | 100 | getFooClosure.expand(); |
michael@0 | 101 | getNameClosure.expand(); |
michael@0 | 102 | |
michael@0 | 103 | return funcClosuresFetched.then(() => { |
michael@0 | 104 | is(getFooClosure.expanded, true, |
michael@0 | 105 | "|person.getFoo| closure should be expanded at this point."); |
michael@0 | 106 | is(getNameClosure.expanded, true, |
michael@0 | 107 | "|person.getName| closure should be expanded at this point."); |
michael@0 | 108 | |
michael@0 | 109 | is(getFooClosure.get("Function scope [_pfactory]").target.querySelector(".name") |
michael@0 | 110 | .getAttribute("value"), "Function scope [_pfactory]", |
michael@0 | 111 | "Found the function scope node for the getFoo closure."); |
michael@0 | 112 | is(getFooClosure.get("Function scope [_pfactory]").target.querySelector(".value") |
michael@0 | 113 | .getAttribute("value"), "", |
michael@0 | 114 | "The function scope node has no value for the getFoo closure."); |
michael@0 | 115 | is(getNameClosure.get("Function scope [_pfactory]").target.querySelector(".name") |
michael@0 | 116 | .getAttribute("value"), "Function scope [_pfactory]", |
michael@0 | 117 | "Found the function scope node for the getName closure."); |
michael@0 | 118 | is(getNameClosure.get("Function scope [_pfactory]").target.querySelector(".value") |
michael@0 | 119 | .getAttribute("value"), "", |
michael@0 | 120 | "The function scope node has no value for the getName closure."); |
michael@0 | 121 | |
michael@0 | 122 | // Expand the scope nodes. |
michael@0 | 123 | let getFooInnerScope = getFooClosure.get("Function scope [_pfactory]"); |
michael@0 | 124 | let getNameInnerScope = getNameClosure.get("Function scope [_pfactory]"); |
michael@0 | 125 | let innerFuncsFetched = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 2); |
michael@0 | 126 | getFooInnerScope.expand(); |
michael@0 | 127 | getNameInnerScope.expand(); |
michael@0 | 128 | |
michael@0 | 129 | return funcsFetched.then(() => { |
michael@0 | 130 | is(getFooInnerScope.expanded, true, |
michael@0 | 131 | "|person.getFoo| inner scope should be expanded at this point."); |
michael@0 | 132 | is(getNameInnerScope.expanded, true, |
michael@0 | 133 | "|person.getName| inner scope should be expanded at this point."); |
michael@0 | 134 | |
michael@0 | 135 | // Only test that each function closes over the necessary variable. |
michael@0 | 136 | // We wouldn't want future SpiderMonkey closure space |
michael@0 | 137 | // optimizations to break this test. |
michael@0 | 138 | is(getFooInnerScope.get("foo").target.querySelector(".name") |
michael@0 | 139 | .getAttribute("value"), "foo", |
michael@0 | 140 | "Found the foo node for the getFoo inner scope."); |
michael@0 | 141 | is(getFooInnerScope.get("foo").target.querySelector(".value") |
michael@0 | 142 | .getAttribute("value"), "10", |
michael@0 | 143 | "The foo node has the expected value."); |
michael@0 | 144 | is(getNameInnerScope.get("name").target.querySelector(".name") |
michael@0 | 145 | .getAttribute("value"), "name", |
michael@0 | 146 | "Found the name node for the getName inner scope."); |
michael@0 | 147 | is(getNameInnerScope.get("name").target.querySelector(".value") |
michael@0 | 148 | .getAttribute("value"), '"Bob"', |
michael@0 | 149 | "The name node has the expected value."); |
michael@0 | 150 | }); |
michael@0 | 151 | }); |
michael@0 | 152 | }); |
michael@0 | 153 | }); |
michael@0 | 154 | }); |
michael@0 | 155 | } |
michael@0 | 156 | } |