Changeset 147861 in webkit


Ignore:
Timestamp:
Apr 6, 2013 4:48:05 PM (11 years ago)
Author:
timothy@apple.com
Message:

Remove InjectedScriptHost.evaluateReturnsEvalFunction.

https://webkit.org/b/114099

Source/WebCore:

  • inspector/InjectedScriptHost.h:

(InjectedScriptHost):

  • inspector/InjectedScriptHost.idl:
  • inspector/InjectedScriptSource.js:

(InjectedScript.prototype._evaluateOn):

LayoutTests:

Reviewed by Joseph Pecoraro.

  • inspector/console/command-line-api-expected.txt:
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r147850 r147861  
     12013-04-06  Timothy Hatcher  <timothy@apple.com>
     2
     3        Remove InjectedScriptHost.evaluateReturnsEvalFunction.
     4
     5        https://webkit.org/b/114099
     6
     7        Reviewed by Joseph Pecoraro.
     8
     9        * inspector/console/command-line-api-expected.txt:
     10
    1112013-04-06  Robert Hogan  <robert@webkit.org>
    212
  • trunk/LayoutTests/inspector/console/command-line-api-expected.txt

    r147221 r147861  
    1 CONSOLE MESSAGE: line 1222: The console function $() has changed from $=getElementById(id) to $=querySelector(selector). You might try $("#%s")
     1CONSOLE MESSAGE: line 1200: The console function $() has changed from $=getElementById(id) to $=querySelector(selector). You might try $("#%s")
    22Tests that command line api works.
    33
  • trunk/Source/WebCore/ChangeLog

    r147860 r147861  
     12013-04-06  Timothy Hatcher  <timothy@apple.com>
     2
     3        Remove InjectedScriptHost.evaluateReturnsEvalFunction.
     4
     5        https://webkit.org/b/114099
     6
     7        * inspector/InjectedScriptHost.h:
     8        (InjectedScriptHost):
     9        * inspector/InjectedScriptHost.idl:
     10        * inspector/InjectedScriptSource.js:
     11        (InjectedScript.prototype._evaluateOn):
     12
    1132013-04-06  Benjamin Poulain  <bpoulain@apple.com>
    214
  • trunk/Source/WebCore/inspector/InjectedScriptHost.h

    r147795 r147861  
    105105    void getEventListenersImpl(Node*, Vector<EventListenerInfo>& listenersArray);
    106106
    107     // FIXME: Remove evaluateReturnsEvalFunction once InjectedScriptHost returns eval in evaluate on V8. https://webkit.org/b/113134
    108     bool evaluateReturnsEvalFunction() { return true; }
    109 
    110107    void clearConsoleMessages();
    111108    void copyText(const String& text);
  • trunk/Source/WebCore/inspector/InjectedScriptHost.idl

    r147857 r147861  
    4747    [Custom] Array getEventListeners(in Node node);
    4848
    49     // FIXME: Remove evaluateReturnsEvalFunction once InjectedScriptHost returns eval in evaluate on V8. https://webkit.org/b/113134
    50     readonly attribute boolean evaluateReturnsEvalFunction;
    51 
    5249    [Custom] readonly attribute any evaluate;
    5350
  • trunk/Source/WebCore/inspector/InjectedScriptSource.js

    r147356 r147861  
    551551    _evaluateOn: function(evalFunction, object, objectGroup, expression, isEvalOnCallFrame, injectCommandLineAPI)
    552552    {
    553         if (InjectedScriptHost.evaluateReturnsEvalFunction) {
    554             // We can only use this approach if the evaluate function is the true 'eval'. That allows us to use it with
    555             // the 'eval' identifier when calling it. Using 'eval' grants access to the local scope of the closure we
    556             // create that provides the command line APIs.
    557 
    558             var parameters = [InjectedScriptHost.evaluate, expression];
    559             var expressionFunctionBody = "var __originalEval = window.eval; window.eval = __eval; try { return eval(__currentExpression); } finally { window.eval = __originalEval; }";
    560 
    561             if (injectCommandLineAPI) {
    562                 // To avoid using a 'with' statement (which fails in strict mode and requires injecting the API object)
    563                 // we instead create a closure where we evaluate the expression. The command line APIs are passed as
    564                 // parameters to the closure so they are in scope but not injected. This allows the code evaluated in
    565                 // the console to stay in strict mode (if is was already set), or to get strict mode by prefixing
    566                 // expressions with 'use strict';.
    567 
    568                 var commandLineAPI = new CommandLineAPI(this._commandLineAPIImpl, isEvalOnCallFrame ? object : null);
    569                 var parameterNames = Object.getOwnPropertyNames(commandLineAPI);
    570                 for (var i = 0; i < parameterNames.length; ++i)
    571                     parameters.push(commandLineAPI[parameterNames[i]]);
    572 
    573                 var expressionFunctionString = "(function(__eval, __currentExpression, " + parameterNames.join(", ") + ") { " + expressionFunctionBody + " })";
    574             } else {
    575                 // Use a closure in this case too to keep the same behavior of 'var' being captured by the closure instead
    576                 // of leaking out into the calling scope.
    577                 var expressionFunctionString = "(function(__eval, __currentExpression) { " + expressionFunctionBody + " })";
    578             }
    579 
    580             // Bind 'this' to the function expression using another closure instead of Function.prototype.bind. This ensures things will work if the page replaces bind.
    581             var boundExpressionFunctionString = "(function(__function, __thisObject) { return function() { return __function.apply(__thisObject, arguments) }; })(" + expressionFunctionString + ", this)";
    582             var expressionFunction = evalFunction.call(object, boundExpressionFunctionString);
    583             var result = expressionFunction.apply(null, parameters);
    584 
    585             if (objectGroup === "console")
    586                 this._lastResult = result;
    587 
    588             return result;
    589         }
    590 
    591         // FIXME: This code path should be removed once V8 also returns 'eval' as the evaluate function. See: https://webkit.org/b/113134
    592 
    593         // Only install command line api object for the time of evaluation.
    594         // Surround the expression in with statements to inject our command line API so that
    595         // the window object properties still take more precedent than our API functions.
    596 
    597         try {
    598             if (injectCommandLineAPI && inspectedWindow.console) {
    599                 inspectedWindow.console._commandLineAPI = new CommandLineAPI(this._commandLineAPIImpl, isEvalOnCallFrame ? object : null);
    600                 expression = "with ((window && window.console && window.console._commandLineAPI) || {}) {\n" + expression + "\n}";
    601             }
    602             var result = evalFunction.call(object, expression);
    603             if (objectGroup === "console")
    604                 this._lastResult = result;
    605             return result;
    606         } finally {
    607             if (injectCommandLineAPI && inspectedWindow.console)
    608                 delete inspectedWindow.console._commandLineAPI;
    609         }
     553        // We can only use this approach if the evaluate function is the true 'eval'. That allows us to use it with
     554        // the 'eval' identifier when calling it. Using 'eval' grants access to the local scope of the closure we
     555        // create that provides the command line APIs.
     556
     557        var parameters = [InjectedScriptHost.evaluate, expression];
     558        var expressionFunctionBody = "var __originalEval = window.eval; window.eval = __eval; try { return eval(__currentExpression); } finally { window.eval = __originalEval; }";
     559
     560        if (injectCommandLineAPI) {
     561            // To avoid using a 'with' statement (which fails in strict mode and requires injecting the API object)
     562            // we instead create a closure where we evaluate the expression. The command line APIs are passed as
     563            // parameters to the closure so they are in scope but not injected. This allows the code evaluated in
     564            // the console to stay in strict mode (if is was already set), or to get strict mode by prefixing
     565            // expressions with 'use strict';.
     566
     567            var commandLineAPI = new CommandLineAPI(this._commandLineAPIImpl, isEvalOnCallFrame ? object : null);
     568            var parameterNames = Object.getOwnPropertyNames(commandLineAPI);
     569            for (var i = 0; i < parameterNames.length; ++i)
     570                parameters.push(commandLineAPI[parameterNames[i]]);
     571
     572            var expressionFunctionString = "(function(__eval, __currentExpression, " + parameterNames.join(", ") + ") { " + expressionFunctionBody + " })";
     573        } else {
     574            // Use a closure in this case too to keep the same behavior of 'var' being captured by the closure instead
     575            // of leaking out into the calling scope.
     576            var expressionFunctionString = "(function(__eval, __currentExpression) { " + expressionFunctionBody + " })";
     577        }
     578
     579        // Bind 'this' to the function expression using another closure instead of Function.prototype.bind. This ensures things will work if the page replaces bind.
     580        var boundExpressionFunctionString = "(function(__function, __thisObject) { return function() { return __function.apply(__thisObject, arguments) }; })(" + expressionFunctionString + ", this)";
     581        var expressionFunction = evalFunction.call(object, boundExpressionFunctionString);
     582        var result = expressionFunction.apply(null, parameters);
     583
     584        if (objectGroup === "console")
     585            this._lastResult = result;
     586
     587        return result;
    610588    },
    611589
Note: See TracChangeset for help on using the changeset viewer.