Changeset 255675 in webkit


Ignore:
Timestamp:
Feb 4, 2020 7:59:42 AM (4 years ago)
Author:
Devin Rousso
Message:

Web Inspector: REGRESSION(r248287): Console: function objects saved to a $n will be invoked instead of just referenced when evaluating in the Console
https://bugs.webkit.org/show_bug.cgi?id=207180
<rdar://problem/58860268>

Reviewed by Joseph Pecoraro.

Source/JavaScriptCore:

  • inspector/InjectedScriptSource.js:

(CommandLineAPI):
Instead of deciding whether to wrap the value given for a $n getter based on if the value
is already a function, always wrap getter values in a function so that if the value being
stored in the getter is already a function, it isn't used as the callback for the getter and
therefore invoked when the getter is referenced.

LayoutTests:

  • inspector/runtime/saveResult.html:
  • inspector/runtime/saveResult-expected.txt:
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r255674 r255675  
     12020-02-04  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: REGRESSION(r248287): Console: function objects saved to a $n will be invoked instead of just referenced when evaluating in the Console
     4        https://bugs.webkit.org/show_bug.cgi?id=207180
     5        <rdar://problem/58860268>
     6
     7        Reviewed by Joseph Pecoraro.
     8
     9        * inspector/runtime/saveResult.html:
     10        * inspector/runtime/saveResult-expected.txt:
     11
    1122020-02-04  Jacob Uphoff  <jacob_uphoff@apple.com>
    213
  • trunk/LayoutTests/inspector/runtime/saveResult-expected.txt

    r189415 r255675  
    3535PASS: Evaluated result 999 should match previous value $1.
    3636
     37-- Running test case: SaveFunctionValue
     38PASS: Function should become $3.
     39PASS: Saved value should match previous value $3.
     40PASS: Evaluated function should match previous value $3.
     41PASS: Calling saved function should become $4.
     42PASS: Calling saved function should return expected value.
     43
  • trunk/LayoutTests/inspector/runtime/saveResult.html

    r236766 r255675  
    172172    });
    173173
     174    // ------
     175
     176    suite.addTestCase({
     177        name: "SaveFunctionValue",
     178        description: "Ensure that saving a function object doesn't evaluate the function object when fetching it via a $n getter.",
     179        async test() {
     180            const functionName = "testSaveFunctionValue";
     181            const functionReturn = "testSaveFunctionValue Return Value";
     182
     183            let createFunctionEvaluateResult = await RuntimeAgent.evaluate.invoke({expression: `function ${functionName}() { return "${functionReturn}"; } ${functionName}`, objectGroup: "test", includeCommandLineAPI: true, saveResult: true});
     184            InspectorTest.assert(!createFunctionEvaluateResult.error, "Should not be a protocol error.");
     185            InspectorTest.expectEqual(createFunctionEvaluateResult.savedResultIndex, 3, "Function should become $3.");
     186
     187            let getSavedValueEvaluateResult = await RuntimeAgent.evaluate.invoke({expression: `$3`, objectGroup: "test", includeCommandLineAPI: true, saveResult: true});
     188            InspectorTest.assert(!getSavedValueEvaluateResult.error, "Should not be a protocol error.");
     189            InspectorTest.expectEqual(getSavedValueEvaluateResult.savedResultIndex, 3, "Saved value should match previous value $3.");
     190            InspectorTest.expectEqual(createFunctionEvaluateResult.result.description, getSavedValueEvaluateResult.result.description, "Evaluated function should match previous value $3.");
     191
     192            let callFunctionEvaluateResult = await RuntimeAgent.evaluate.invoke({expression: functionName + "()", objectGroup: "test", includeCommandLineAPI: true, saveResult: true});
     193            InspectorTest.assert(!callFunctionEvaluateResult.error, "Should not be a protocol error.");
     194            InspectorTest.expectEqual(callFunctionEvaluateResult.savedResultIndex, 4, "Calling saved function should become $4.");
     195            InspectorTest.expectEqual(callFunctionEvaluateResult.result.value, functionReturn, "Calling saved function should return expected value.");
     196        }
     197    });
     198
    174199    suite.runTestCasesAndFinish();
    175200}
  • trunk/Source/JavaScriptCore/ChangeLog

    r255659 r255675  
     12020-02-04  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: REGRESSION(r248287): Console: function objects saved to a $n will be invoked instead of just referenced when evaluating in the Console
     4        https://bugs.webkit.org/show_bug.cgi?id=207180
     5        <rdar://problem/58860268>
     6
     7        Reviewed by Joseph Pecoraro.
     8
     9        * inspector/InjectedScriptSource.js:
     10        (CommandLineAPI):
     11        Instead of deciding whether to wrap the value given for a `$n` getter based on if the value
     12        is already a function, always wrap getter values in a function so that if the value being
     13        stored in the getter is already a function, it isn't used as the callback for the getter and
     14        therefore invoked when the getter is referenced.
     15
    1162020-02-03  Yusuke Suzuki  <ysuzuki@apple.com>
    217
  • trunk/Source/JavaScriptCore/inspector/InjectedScriptSource.js

    r252202 r255675  
    14671467    let savedResultAlias = InjectedScriptHost.savedResultAlias;
    14681468
    1469     let defineGetter = (key, value) => {
    1470         if (typeof value !== "function") {
     1469    let defineGetter = (key, value, wrap) => {
     1470        if (wrap) {
    14711471            let originalValue = value;
    14721472            value = function() { return originalValue; };
     
    14791479
    14801480    if ("_lastResult" in injectedScript)
    1481         defineGetter("_", injectedScript._lastResult);
     1481        defineGetter("_", injectedScript._lastResult, true);
    14821482
    14831483    if ("_exceptionValue" in injectedScript)
    1484         defineGetter("exception", injectedScript._exceptionValue);
     1484        defineGetter("exception", injectedScript._exceptionValue, true);
    14851485
    14861486    if ("_eventValue" in injectedScript)
    1487         defineGetter("event", injectedScript._eventValue);
     1487        defineGetter("event", injectedScript._eventValue, true);
    14881488
    14891489    // $1-$99
    14901490    for (let i = 1; i < injectedScript._savedResults.length; ++i)
    1491         defineGetter(i, injectedScript._savedResults[i]);
     1491        defineGetter(i, injectedScript._savedResults[i], true);
    14921492
    14931493    for (let name in CommandLineAPI.getters)
Note: See TracChangeset for help on using the changeset viewer.