Changeset 126168 in webkit


Ignore:
Timestamp:
Aug 21, 2012 10:03:12 AM (12 years ago)
Author:
pfeldman@chromium.org
Message:

Web Inspector: do not use window's eval in InjectedScript
https://bugs.webkit.org/show_bug.cgi?id=94610

Reviewed by Yury Semikhatsky.

Source/WebCore:

Otherwise, inspector does not work when eval is overriden.

Test: inspector/console/console-eval-fake.html

  • bindings/js/JSInjectedScriptHostCustom.cpp:

(WebCore::JSInjectedScriptHost::evaluate):
(WebCore):

  • bindings/v8/custom/V8InjectedScriptHostCustom.cpp:

(WebCore::V8InjectedScriptHost::evaluateCallback):
(WebCore):

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

(.):

LayoutTests:

  • inspector/console/console-eval-fake-expected.txt: Added.
  • inspector/console/console-eval-fake.html: Added.
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r126165 r126168  
     12012-08-21  Pavel Feldman  <pfeldman@chromium.org>
     2
     3        Web Inspector: do not use window's eval in InjectedScript
     4        https://bugs.webkit.org/show_bug.cgi?id=94610
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        * inspector/console/console-eval-fake-expected.txt: Added.
     9        * inspector/console/console-eval-fake.html: Added.
     10
    1112012-08-21  Adam Barth  <abarth@webkit.org>
    212
  • trunk/Source/WebCore/ChangeLog

    r126165 r126168  
     12012-08-21  Pavel Feldman  <pfeldman@chromium.org>
     2
     3        Web Inspector: do not use window's eval in InjectedScript
     4        https://bugs.webkit.org/show_bug.cgi?id=94610
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        Otherwise, inspector does not work when eval is overriden.
     9
     10        Test: inspector/console/console-eval-fake.html
     11
     12        * bindings/js/JSInjectedScriptHostCustom.cpp:
     13        (WebCore::JSInjectedScriptHost::evaluate):
     14        (WebCore):
     15        * bindings/v8/custom/V8InjectedScriptHostCustom.cpp:
     16        (WebCore::V8InjectedScriptHost::evaluateCallback):
     17        (WebCore):
     18        * inspector/InjectedScriptHost.idl:
     19        * inspector/InjectedScriptSource.js:
     20        (.):
     21
    1222012-08-21  Adam Barth  <abarth@webkit.org>
    223
  • trunk/Source/WebCore/bindings/js/JSInjectedScriptHostCustom.cpp

    r125654 r126168  
    276276}
    277277
     278JSValue JSInjectedScriptHost::evaluate(ExecState* exec)
     279{
     280    JSValue expression = exec->argument(0);
     281    if (!expression.isString())
     282        return throwError(exec, createError(exec, "String argument expected."));
     283    JSGlobalObject* globalObject = exec->lexicalGlobalObject();
     284    JSFunction* evalFunction = globalObject->evalFunction();
     285    CallData callData;
     286    CallType callType = evalFunction->methodTable()->getCallData(evalFunction, callData);
     287    if (callType == CallTypeNone)
     288        return jsUndefined();
     289    MarkedArgumentBuffer args;
     290    args.append(expression);
     291
     292    bool wasEvalEnabled = globalObject->evalEnabled();
     293    globalObject->setEvalEnabled(true);
     294    JSValue result = JSC::call(exec, evalFunction, callType, callData, exec->globalThisValue(), args);
     295    globalObject->setEvalEnabled(wasEvalEnabled);
     296
     297    return result;
     298}
     299
    278300} // namespace WebCore
    279301
  • trunk/Source/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp

    r125654 r126168  
    300300}
    301301
     302v8::Handle<v8::Value> V8InjectedScriptHost::evaluateCallback(const v8::Arguments& args)
     303{
     304    INC_STATS("InjectedScriptHost.evaluate()");
     305    if (args.Length() < 1)
     306        return v8::ThrowException(v8::Exception::Error(v8::String::New("One argument expected.")));
     307
     308    v8::Handle<v8::String> expression = args[0]->ToString();
     309    if (expression.IsEmpty())
     310        return v8::ThrowException(v8::Exception::Error(v8::String::New("The argument must be a string.")));
     311
     312    v8::Handle<v8::Script> script = v8::Script::Compile(expression);
     313    if (script.IsEmpty()) // Return immediately in case of exception to let the caller handle it.
     314        return v8::Handle<v8::Value>();
     315    return script->Run();
     316}
     317
    302318} // namespace WebCore
    303319
  • trunk/Source/WebCore/inspector/InjectedScriptHost.idl

    r123223 r126168  
    4848        [Custom] DOMString databaseId(in DOMObject database);
    4949        [Custom] DOMString storageId(in DOMObject storage);
     50        [Custom] DOMObject evaluate(in DOMString text);
    5051    };
    5152}
  • trunk/Source/WebCore/inspector/InjectedScriptSource.js

    r125186 r126168  
    175175    _parseObjectId: function(objectId)
    176176    {
    177         return eval("(" + objectId + ")");
     177        return InjectedScriptHost.evaluate("(" + objectId + ")");
    178178    },
    179179
     
    198198    dispatch: function(methodName, args)
    199199    {
    200         var argsArray = eval("(" + args + ")");
     200        var argsArray = InjectedScriptHost.evaluate("(" + args + ")");
    201201        var result = this[methodName].apply(this, argsArray);
    202202        if (typeof result === "undefined") {
     
    343343    evaluate: function(expression, objectGroup, injectCommandLineAPI, returnByValue)
    344344    {
    345         return this._evaluateAndWrap(inspectedWindow.eval, inspectedWindow, expression, objectGroup, false, injectCommandLineAPI, returnByValue);
     345        return this._evaluateAndWrap(InjectedScriptHost.evaluate, InjectedScriptHost, expression, objectGroup, false, injectCommandLineAPI, returnByValue);
    346346    },
    347347
     
    361361        if (args) {
    362362            var resolvedArgs = [];
    363             args = eval(args);
     363            args = InjectedScriptHost.evaluate(args);
    364364            for (var i = 0; i < args.length; ++i) {
    365365                objectId = args[i].objectId;
     
    383383        try {
    384384            var objectGroup = this._idToObjectGroupName[parsedObjectId.id];
    385             var func = eval("(" + expression + ")");
     385            var func = InjectedScriptHost.evaluate("(" + expression + ")");
    386386            if (typeof func !== "function")
    387387                return "Given expression does not evaluate to a function";
     
    516516    _callFrameForId: function(topCallFrame, callFrameId)
    517517    {
    518         var parsedCallFrameId = eval("(" + callFrameId + ")");
     518        var parsedCallFrameId = InjectedScriptHost.evaluate("(" + callFrameId + ")");
    519519        var ordinal = parsedCallFrameId["ordinal"];
    520520        var callFrame = topCallFrame;
     
    563563    {
    564564        delete this._modules[name];
    565         var module = eval("(" + source + ")");
     565        var module = InjectedScriptHost.evaluate("(" + source + ")");
    566566        this._modules[name] = module;
    567567        return module;
Note: See TracChangeset for help on using the changeset viewer.