Changeset 86837 in webkit


Ignore:
Timestamp:
May 19, 2011 4:47:02 AM (13 years ago)
Author:
yurys@chromium.org
Message:

2011-05-18 Yury Semikhatsky <yurys@chromium.org>

Reviewed by Pavel Feldman.

InjectedScriptSource.js - "Don't be eval()."
https://bugs.webkit.org/show_bug.cgi?id=60800

  • inspector/console/console-eval-blocked-expected.txt: Added.
  • inspector/console/console-eval-blocked.html: Added.

2011-05-18 Yury Semikhatsky <yurys@chromium.org>

Reviewed by Pavel Feldman.

InjectedScriptSource.js - "Don't be eval()."
https://bugs.webkit.org/show_bug.cgi?id=60800

Thanks to Adam Barth for providing JSC implementation!

InjectedScriptHost.evaluate is used to perform script evaluations for
inspector needs. This method is not affected by CSP and should fix inspector
on pages with CSP restrictions.

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

  • bindings/js/JSInjectedScriptHostCustom.cpp: (WebCore::JSInjectedScriptHost::evaluate):
  • bindings/v8/custom/V8InjectedScriptHostCustom.cpp: (WebCore::V8InjectedScriptHost::evaluateCallback): (WebCore::V8InjectedScriptHost::inspectedNodeCallback):
  • inspector/InjectedScriptHost.idl:
  • inspector/InjectedScriptSource.js: (.):
Location:
trunk
Files:
2 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r86834 r86837  
     12011-05-18  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        InjectedScriptSource.js - "Don't be eval()."
     6        https://bugs.webkit.org/show_bug.cgi?id=60800
     7
     8        * inspector/console/console-eval-blocked-expected.txt: Added.
     9        * inspector/console/console-eval-blocked.html: Added.
     10
    1112011-05-19  Chang Shu  <cshu@webkit.org>
    212
  • trunk/Source/JavaScriptCore/JavaScriptCore.exp

    r86727 r86837  
    156156__ZN3JSC13StatementNode6setLocEii
    157157__ZN3JSC14JSGlobalObject10globalExecEv
    158 __ZN3JSC14JSGlobalObject11disableEvalEv
    159158__ZN3JSC14JSGlobalObject12defineGetterEPNS_9ExecStateERKNS_10IdentifierEPNS_8JSObjectEj
    160159__ZN3JSC14JSGlobalObject12defineSetterEPNS_9ExecStateERKNS_10IdentifierEPNS_8JSObjectEj
  • trunk/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def

    r86727 r86837  
    153153    ?detachThread@WTF@@YAXI@Z
    154154    ?didTimeOut@TimeoutChecker@JSC@@QAE_NPAVExecState@2@@Z
    155     ?disableEval@JSGlobalObject@JSC@@QAEXXZ
    156155    ?dtoa@WTF@@YAXQADNAA_NAAHAAI@Z
    157156    ?dumpSampleData@JSGlobalData@JSC@@QAEXPAVExecState@2@@Z
  • trunk/Source/JavaScriptCore/runtime/Executable.cpp

    r86499 r86837  
    103103    JSGlobalData* globalData = &exec->globalData();
    104104    JSGlobalObject* lexicalGlobalObject = exec->lexicalGlobalObject();
    105     if (!lexicalGlobalObject->isEvalEnabled())
     105    if (!lexicalGlobalObject->evalEnabled())
    106106        return throwError(exec, createEvalError(exec, "Eval is disabled"));
    107107    RefPtr<EvalNode> evalNode = globalData->parser->parse<EvalNode>(lexicalGlobalObject, lexicalGlobalObject->debugger(), exec, m_source, 0, isStrictMode() ? JSParseStrict : JSParseNormal, &exception);
  • trunk/Source/JavaScriptCore/runtime/FunctionConstructor.cpp

    r86100 r86837  
    7575JSObject* constructFunction(ExecState* exec, JSGlobalObject* globalObject, const ArgList& args, const Identifier& functionName, const UString& sourceURL, int lineNumber)
    7676{
    77     if (!globalObject->isEvalEnabled())
     77    if (!globalObject->evalEnabled())
    7878        return throwError(exec, createEvalError(exec, "Function constructor is disabled"));
    7979    return constructFunctionSkippingEvalEnabledCheck(exec, globalObject, args, functionName, sourceURL, lineNumber);
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp

    r86727 r86837  
    377377}
    378378
    379 void JSGlobalObject::disableEval()
    380 {
    381     ASSERT(m_isEvalEnabled);
    382     m_isEvalEnabled = false;
    383 }
    384 
    385379void JSGlobalObject::copyGlobalsFrom(RegisterFile& registerFile)
    386380{
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h

    r86785 r86837  
    120120        SymbolTable m_symbolTable;
    121121
    122         bool m_isEvalEnabled;
     122        bool m_evalEnabled;
    123123
    124124    public:
     
    130130            , m_globalScopeChain()
    131131            , m_weakRandom(static_cast<unsigned>(randomNumber() * (std::numeric_limits<unsigned>::max() + 1.0)))
    132             , m_isEvalEnabled(true)
     132            , m_evalEnabled(true)
    133133        {
    134134            COMPILE_ASSERT(JSGlobalObject::AnonymousSlotCount == 1, JSGlobalObject_has_only_a_single_slot);
     
    145145            , m_globalScopeChain()
    146146            , m_weakRandom(static_cast<unsigned>(randomNumber() * (std::numeric_limits<unsigned>::max() + 1.0)))
    147             , m_isEvalEnabled(true)
     147            , m_evalEnabled(true)
    148148        {
    149149            COMPILE_ASSERT(JSGlobalObject::AnonymousSlotCount == 1, JSGlobalObject_has_only_a_single_slot);
     
    236236        virtual bool isDynamicScope(bool& requiresDynamicChecks) const;
    237237
    238         void disableEval();
    239         bool isEvalEnabled() { return m_isEvalEnabled; }
     238        void setEvalEnabled(bool enabled) { m_evalEnabled = enabled; }
     239        bool evalEnabled() { return m_evalEnabled; }
    240240
    241241        void copyGlobalsFrom(RegisterFile&);
  • trunk/Source/WebCore/ChangeLog

    r86836 r86837  
     12011-05-18  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        InjectedScriptSource.js - "Don't be eval()."
     6        https://bugs.webkit.org/show_bug.cgi?id=60800
     7
     8        Thanks to Adam Barth for providing JSC implementation!
     9
     10        InjectedScriptHost.evaluate is used to perform script evaluations for
     11        inspector needs. This method is not affected by CSP and should fix inspector
     12        on pages with CSP restrictions.
     13
     14        Test: inspector/console/console-eval-blocked.html
     15
     16        * bindings/js/JSInjectedScriptHostCustom.cpp:
     17        (WebCore::JSInjectedScriptHost::evaluate):
     18        * bindings/v8/custom/V8InjectedScriptHostCustom.cpp:
     19        (WebCore::V8InjectedScriptHost::evaluateCallback):
     20        (WebCore::V8InjectedScriptHost::inspectedNodeCallback):
     21        * inspector/InjectedScriptHost.idl:
     22        * inspector/InjectedScriptSource.js:
     23        (.):
     24
    1252011-05-19  Pavel Feldman  <pfeldman@google.com>
    226
  • trunk/Source/WebCore/bindings/js/JSInjectedScriptHostCustom.cpp

    r85724 r86837  
    5454#endif
    5555#include <runtime/DateInstance.h>
     56#include <runtime/Error.h>
    5657#include <runtime/JSArray.h>
     58#include <runtime/JSFunction.h>
    5759#include <runtime/JSLock.h>
    5860#include <runtime/RegExpObject.h>
     
    7375    JSLock lock(SilenceAssertionsOnly);
    7476    return ScriptValue(state->globalData(), toJS(state, deprecatedGlobalObjectForPrototype(state), node));
     77}
     78
     79JSValue JSInjectedScriptHost::evaluate(ExecState* exec)
     80{
     81    JSValue expression = exec->argument(0);
     82    if (!expression.isString())
     83        return throwError(exec, createError(exec, "String argument expected."));
     84    JSGlobalObject* globalObject = exec->lexicalGlobalObject();
     85    JSFunction* evalFunction = globalObject->evalFunction();
     86    CallData callData;
     87    CallType callType = evalFunction->getCallData(callData);
     88    if (callType == CallTypeNone)
     89        return jsUndefined();
     90    MarkedArgumentBuffer args;
     91    args.append(expression);
     92
     93    bool wasEvalEnabled = globalObject->evalEnabled();
     94    globalObject->setEvalEnabled(true);
     95    JSValue result = JSC::call(exec, evalFunction, callType, callData, exec->globalThisValue(), args);
     96    globalObject->setEvalEnabled(wasEvalEnabled);
     97
     98    return result;
    7599}
    76100
  • trunk/Source/WebCore/bindings/js/ScriptController.cpp

    r85442 r86837  
    241241void ScriptController::disableEval()
    242242{
    243     windowShell(mainThreadNormalWorld())->window()->disableEval();
     243    windowShell(mainThreadNormalWorld())->window()->setEvalEnabled(false);
    244244}
    245245
  • trunk/Source/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp

    r85722 r86837  
    6666}
    6767
     68v8::Handle<v8::Value> V8InjectedScriptHost::evaluateCallback(const v8::Arguments& args)
     69{
     70    INC_STATS("InjectedScriptHost.evaluate()");
     71    if (args.Length() < 1)
     72        return v8::ThrowException(v8::Exception::Error(v8::String::New("One argument expected.")));
     73
     74    v8::Handle<v8::String> expression = args[0]->ToString();
     75    if (expression.IsEmpty())
     76        return v8::ThrowException(v8::Exception::Error(v8::String::New("The argument must be a string.")));
     77
     78    v8::Handle<v8::Script> script = v8::Script::Compile(expression);
     79    return script->Run();
     80}
     81
    6882v8::Handle<v8::Value> V8InjectedScriptHost::inspectedNodeCallback(const v8::Arguments& args)
    6983{
     
    7387
    7488    InjectedScriptHost* host = V8InjectedScriptHost::toNative(args.Holder());
    75    
     89
    7690    Node* node = host->inspectedNode(args[0]->ToInt32()->Value());
    7791    if (!node)
  • trunk/Source/WebCore/inspector/InjectedScriptHost.idl

    r85722 r86837  
    3535        void clearConsoleMessages();
    3636
     37        [Custom] DOMObject evaluate(in DOMString text);
     38
    3739        void copyText(in DOMString text);
    3840        [Custom] void inspect(in DOMObject objectId, in DOMObject hints);
  • trunk/Source/WebCore/inspector/InjectedScriptSource.js

    r86836 r86837  
    117117    _parseObjectId: function(objectId)
    118118    {
    119         return eval("(" + objectId + ")");
     119        return InjectedScriptHost.evaluate("(" + objectId + ")");
    120120    },
    121121
     
    132132    dispatch: function(methodName, args)
    133133    {
    134         var argsArray = eval("(" + args + ")");
     134        var argsArray = InjectedScriptHost.evaluate("(" + args + ")");
    135135        var result = this[methodName].apply(this, argsArray);
    136136        if (typeof result === "undefined") {
     
    200200            // not call frame while on a breakpoint.
    201201            // TODO: bring evaluation against call frame back.
    202             var result = inspectedWindow.eval("(" + expression + ")");
     202            var result = InjectedScriptHost.evaluate("(" + expression + ")");
    203203            // Store the result in the property.
    204204            object[propertyName] = result;
    205205        } catch(e) {
    206206            try {
    207                 var result = inspectedWindow.eval("\"" + expression.replace(/"/g, "\\\"") + "\"");
     207                var result = InjectedScriptHost.evaluate("\"" + expression.replace(/"/g, "\\\"") + "\"");
    208208                object[propertyName] = result;
    209209            } catch(e) {
     
    246246    evaluate: function(expression, objectGroup, injectCommandLineAPI)
    247247    {
    248         return this._evaluateAndWrap(inspectedWindow.eval, inspectedWindow, expression, objectGroup, false, injectCommandLineAPI);
     248        return this._evaluateAndWrap(InjectedScriptHost.evaluate, InjectedScriptHost, expression, objectGroup, false, injectCommandLineAPI);
    249249    },
    250250
     
    316316    _callFrameForId: function(topCallFrame, callFrameId)
    317317    {
    318         var parsedCallFrameId = eval("(" + callFrameId + ")");
     318        var parsedCallFrameId = InjectedScriptHost.evaluate("(" + callFrameId + ")");
    319319        var ordinal = parsedCallFrameId.ordinal;
    320320        var callFrame = topCallFrame;
Note: See TracChangeset for help on using the changeset viewer.