Changeset 178796 in webkit


Ignore:
Timestamp:
Jan 20, 2015 8:22:24 PM (9 years ago)
Author:
commit-queue@webkit.org
Message:

Web Inspector: Clean up InjectedScriptSource.js
https://bugs.webkit.org/show_bug.cgi?id=140709

Patch by Joseph Pecoraro <Joseph Pecoraro> on 2015-01-20
Reviewed by Timothy Hatcher.

This patch includes some relevant Blink patches and small changes.

Patch by <aandrey@chromium.org>
DevTools: Remove console last result $_ on console clear.
https://src.chromium.org/viewvc/blink?revision=179179&view=revision

Patch by <eustas@chromium.org>
[Inspect DOM properties] incorrect CSS Selector Syntax
https://src.chromium.org/viewvc/blink?revision=156903&view=revision

  • inspector/InjectedScriptSource.js:
Location:
trunk/Source/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r178791 r178796  
     12015-01-20  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        Web Inspector: Clean up InjectedScriptSource.js
     4        https://bugs.webkit.org/show_bug.cgi?id=140709
     5
     6        Reviewed by Timothy Hatcher.
     7
     8        This patch includes some relevant Blink patches and small changes.
     9       
     10        Patch by <aandrey@chromium.org>
     11        DevTools: Remove console last result $_ on console clear.
     12        https://src.chromium.org/viewvc/blink?revision=179179&view=revision
     13
     14        Patch by <eustas@chromium.org>
     15        [Inspect DOM properties] incorrect CSS Selector Syntax
     16        https://src.chromium.org/viewvc/blink?revision=156903&view=revision
     17
     18        * inspector/InjectedScriptSource.js:
     19
    1202015-01-20  Joseph Pecoraro  <pecoraro@apple.com>
    221
  • trunk/Source/JavaScriptCore/inspector/InjectedScriptSource.js

    r178768 r178796  
    2929//# sourceURL=__WebInspectorInjectedScript__
    3030
    31 /**
    32  * @param {InjectedScriptHost} InjectedScriptHost
    33  * @param {GlobalObject} inspectedGlobalObject
    34  * @param {number} injectedScriptId
    35  */
    3631(function (InjectedScriptHost, inspectedGlobalObject, injectedScriptId) {
    3732
     
    3934var Object = {}.constructor;
    4035
    41 /**
    42  * @constructor
    43  */
    4436var InjectedScript = function()
    4537{
     
    5143}
    5244
    53 /**
    54  * @type {Object.<string, boolean>}
    55  * @const
    56  */
    5745InjectedScript.primitiveTypes = {
    5846    undefined: true,
     
    6351
    6452InjectedScript.prototype = {
    65     /**
    66      * @param {*} object
    67      * @return {boolean}
    68      */
    6953    isPrimitiveValue: function(object)
    7054    {
     
    7357    },
    7458
    75     /**
    76      * @param {*} object
    77      * @param {string} groupName
    78      * @param {boolean} canAccessInspectedGlobalObject
    79      * @param {boolean} generatePreview
    80      * @return {!RuntimeAgent.RemoteObject}
    81      */
    8259    wrapObject: function(object, groupName, canAccessInspectedGlobalObject, generatePreview)
    8360    {
     
    9774    },
    9875
    99     /**
    100      * @param {*} object
    101      * @return {!RuntimeAgent.RemoteObject}
    102      */
    10376    _fallbackWrapper: function(object)
    10477    {
     
    10982        else
    11083            result.description = this._toString(object);
    111         return /** @type {!RuntimeAgent.RemoteObject} */ (result);
    112     },
    113 
    114     /**
    115      * @param {boolean} canAccessInspectedGlobalObject
    116      * @param {Object} table
    117      * @param {Array.<string>|string|boolean} columns
    118      * @return {!RuntimeAgent.RemoteObject}
    119      */
     84        return result;
     85    },
     86
    12087    wrapTable: function(canAccessInspectedGlobalObject, table, columns)
    12188    {
     
    12592        if (typeof columns === "string")
    12693            columns = [columns];
    127         if (InjectedScriptHost.type(columns) == "array") {
     94        if (InjectedScriptHost.type(columns) === "array") {
    12895            columnNames = [];
    12996            for (var i = 0; i < columns.length; ++i)
     
    133100    },
    134101
    135     /**
    136      * @param {*} object
    137      */
    138102    inspectObject: function(object)
    139103    {
     
    142106    },
    143107
    144     /**
    145      * This method cannot throw.
    146      * @param {*} object
    147      * @param {string=} objectGroupName
    148      * @param {boolean=} forceValueType
    149      * @param {boolean=} generatePreview
    150      * @param {?Array.<string>=} columnNames
    151      * @return {!RuntimeAgent.RemoteObject}
    152      * @suppress {checkTypes}
    153      */
    154108    _wrapObject: function(object, objectGroupName, forceValueType, generatePreview, columnNames)
    155109    {
     
    166120    },
    167121
    168     /**
    169      * @param {*} object
    170      * @param {string=} objectGroupName
    171      * @return {string}
    172      */
    173122    _bind: function(object, objectGroupName)
    174123    {
     
    188137    },
    189138
    190     /**
    191      * @param {string} objectId
    192      * @return {Object}
    193      */
    194139    _parseObjectId: function(objectId)
    195140    {
     
    197142    },
    198143
    199     /**
    200      * @param {string} objectGroupName
    201      */
    202144    releaseObjectGroup: function(objectGroupName)
    203145    {
     146        if (objectGroupName === "console")
     147            delete this._lastResult;
    204148        var group = this._objectGroups[objectGroupName];
    205149        if (!group)
     
    210154    },
    211155
    212     /**
    213      * @param {string} methodName
    214      * @param {string} args
    215      * @return {*}
    216      */
    217156    dispatch: function(methodName, args)
    218157    {
     
    256195    },
    257196
    258     /**
    259      * @param {string} objectId
    260      * @return {Array.<Object>|boolean}
    261      */
    262197    getInternalProperties: function(objectId, ownProperties)
    263198    {
     
    267202        if (!this._isDefined(object))
    268203            return false;
     204
    269205        var descriptors = [];
    270206        var internalProperties = InjectedScriptHost.getInternalProperties(object);
     
    279215            }
    280216        }
     217
    281218        return descriptors;
    282219    },
    283220
    284     /**
    285      * @param {string} functionId
    286      * @return {!DebuggerAgent.FunctionDetails|string}
    287      */
    288221    getFunctionDetails: function(functionId)
    289222    {
     
    307240    },
    308241
    309     /**
    310      * @param {string} objectId
    311      */
    312242    releaseObject: function(objectId)
    313243    {
     
    316246    },
    317247
    318     /**
    319      * @param {string} id
    320      */
    321248    _releaseObject: function(id)
    322249    {
     
    325252    },
    326253
    327     /**
    328      * @param {string} expression
    329      * @param {string} objectGroup
    330      * @param {boolean} injectCommandLineAPI
    331      * @param {boolean} returnByValue
    332      * @param {boolean} generatePreview
    333      * @return {*}
    334      */
    335254    evaluate: function(expression, objectGroup, injectCommandLineAPI, returnByValue, generatePreview)
    336255    {
     
    338257    },
    339258
    340     /**
    341      * @param {string} objectId
    342      * @param {string} expression
    343      * @param {boolean} returnByValue
    344      * @return {Object|string}
    345      */
    346259    callFunctionOn: function(objectId, expression, args, returnByValue)
    347260    {
     
    353266        if (args) {
    354267            var resolvedArgs = [];
    355             args = InjectedScriptHost.evaluate(args);
    356             for (var i = 0; i < args.length; ++i) {
    357                 var resolvedCallArgument;
     268            var callArgs = InjectedScriptHost.evaluate(args);
     269            for (var i = 0; i < callArgs.length; ++i) {
    358270                try {
    359                     resolvedCallArgument = this._resolveCallArgument(args[i]);
     271                    resolvedArgs[i] = this._resolveCallArgument(callArgs[i]);
    360272                } catch (e) {
    361273                    return String(e);
    362274                }
    363                 resolvedArgs.push(resolvedCallArgument)
    364275            }
    365276        }
     
    371282                return "Given expression does not evaluate to a function";
    372283
    373             return { wasThrown: false,
    374                      result: this._wrapObject(func.apply(object, resolvedArgs), objectGroup, returnByValue) };
     284            return {
     285                wasThrown: false,
     286                result: this._wrapObject(func.apply(object, resolvedArgs), objectGroup, returnByValue)
     287            };
    375288        } catch (e) {
    376289            return this._createThrownValue(e, objectGroup);
     
    378291    },
    379292
    380     /**
    381      * Resolves a value from CallArgument description.
    382      * @param {RuntimeAgent.CallArgument} callArgumentJson
    383      * @return {*} resolved value
    384      * @throws {string} error message
    385      */
    386293    _resolveCallArgument: function(callArgumentJson) {
    387294        var objectId = callArgumentJson.objectId;
     
    398305        } else if ("value" in callArgumentJson)
    399306            return callArgumentJson.value;
    400         else
    401             return undefined;
    402     },
    403 
    404     /**
    405      * @param {Function} evalFunction
    406      * @param {Object} object
    407      * @param {string} objectGroup
    408      * @param {boolean} isEvalOnCallFrame
    409      * @param {boolean} injectCommandLineAPI
    410      * @param {boolean} returnByValue
    411      * @param {boolean} generatePreview
    412      * @return {*}
    413      */
     307        return undefined;
     308    },
     309
    414310    _evaluateAndWrap: function(evalFunction, object, expression, objectGroup, isEvalOnCallFrame, injectCommandLineAPI, returnByValue, generatePreview)
    415311    {
    416312        try {
    417             return { wasThrown: false,
    418                      result: this._wrapObject(this._evaluateOn(evalFunction, object, objectGroup, expression, isEvalOnCallFrame, injectCommandLineAPI), objectGroup, returnByValue, generatePreview) };
     313            return {
     314                wasThrown: false,
     315                result: this._wrapObject(this._evaluateOn(evalFunction, object, objectGroup, expression, isEvalOnCallFrame, injectCommandLineAPI), objectGroup, returnByValue, generatePreview)
     316            };
    419317        } catch (e) {
    420318            return this._createThrownValue(e, objectGroup);
     
    422320    },
    423321
    424     /**
    425      * @param {*} value
    426      * @param {string} objectGroup
    427      * @return {Object}
    428      */
    429322    _createThrownValue: function(value, objectGroup)
    430323    {
     
    433326            remoteObject.description = this._toString(value);
    434327        } catch (e) {}
    435         return { wasThrown: true,
    436                  result: remoteObject };
    437     },
    438 
    439     /**
    440      * @param {Function} evalFunction
    441      * @param {Object} object
    442      * @param {string} objectGroup
    443      * @param {string} expression
    444      * @param {boolean} isEvalOnCallFrame
    445      * @param {boolean} injectCommandLineAPI
    446      * @return {*}
    447      */
     328        return {
     329            wasThrown: true,
     330            result: remoteObject
     331        };
     332    },
     333
    448334    _evaluateOn: function(evalFunction, object, objectGroup, expression, isEvalOnCallFrame, injectCommandLineAPI)
    449335    {
     
    525411    },
    526412
    527     /**
    528      * @param {Object} callFrame
    529      * @return {Array.<InjectedScript.CallFrameProxy>|boolean}
    530      */
    531413    wrapCallFrames: function(callFrame)
    532414    {
     
    543425    },
    544426
    545     /**
    546      * @param {Object} topCallFrame
    547      * @param {string} callFrameId
    548      * @param {string} expression
    549      * @param {string} objectGroup
    550      * @param {boolean} injectCommandLineAPI
    551      * @param {boolean} returnByValue
    552      * @param {boolean} generatePreview
    553      * @return {*}
    554      */
    555427    evaluateOnCallFrame: function(topCallFrame, callFrameId, expression, objectGroup, injectCommandLineAPI, returnByValue, generatePreview)
    556428    {
     
    561433    },
    562434
    563     /**
    564      * @param {Object} topCallFrame
    565      * @param {string} callFrameId
    566      * @return {Object}
    567      */
    568435    _callFrameForId: function(topCallFrame, callFrameId)
    569436    {
     
    576443    },
    577444
    578     /**
    579      * @param {Object} objectId
    580      * @return {Object}
    581      */
    582445    _objectForId: function(objectId)
    583446    {
     
    585448    },
    586449
    587     /**
    588      * @param {string} objectId
    589      * @return {Object}
    590      */
    591450    findObjectById: function(objectId)
    592451    {
     
    595454    },
    596455
    597     /**
    598      * @param {string} name
    599      * @return {Object}
    600      */
    601456    module: function(name)
    602457    {
     
    604459    },
    605460
    606     /**
    607      * @param {string} name
    608      * @param {string} source
    609      * @return {Object}
    610      */
    611461    injectModule: function(name, source, host)
    612462    {
    613463        delete this._modules[name];
     464
    614465        var moduleFunction = InjectedScriptHost.evaluate("(" + source + ")");
    615466        if (typeof moduleFunction !== "function") {
     
    618469            return null;
    619470        }
     471
    620472        var module = moduleFunction.call(inspectedGlobalObject, InjectedScriptHost, inspectedGlobalObject, injectedScriptId, this, host);
    621473        this._modules[name] = module;
     
    726578    },
    727579
    728     /**
    729      * @param {*} object
    730      * @return {boolean}
    731      */
    732580    _isDefined: function(object)
    733581    {
     
    735583    },
    736584
    737     /**
    738      * @param {*} object
    739      * @return {boolean}
    740      */
    741585    _isHTMLAllCollection: function(object)
    742586    {
     
    745589    },
    746590
    747     /**
    748      * @param {Object=} obj
    749      * @return {string?}
    750      */
    751591    _subtype: function(obj)
    752592    {
     
    777617    },
    778618
    779     /**
    780      * @param {*} obj
    781      * @return {string?}
    782      */
    783619    _describe: function(obj)
    784620    {
     
    786622            return null;
    787623
    788         obj = /** @type {Object} */ (obj);
    789 
    790         // Type is object, get subtype.
    791624        var subtype = this._subtype(obj);
    792625
     
    806639                description += obj.id ? "#" + obj.id : "";
    807640                var className = obj.className;
    808                 description += className ? "." + className : "";
     641                description += (className && typeof className === "string") ? "." + className.trim().replace(/\s+/g, ".") : "";
    809642                break;
    810643            case 10 /*Node.DOCUMENT_TYPE_NODE */:
     
    826659            return this._toString(obj);
    827660
     661        // FIXME: Can we remove this?
    828662        if (className === "Object") {
    829663            // In Chromium DOM wrapper prototypes will have Object as their constructor name,
     
    836670    },
    837671
    838     /**
    839      * @param {*} obj
    840      * @return {string}
    841      */
    842672    _toString: function(obj)
    843673    {
     
    847677}
    848678
    849 /**
    850  * @type {InjectedScript}
    851  * @const
    852  */
    853 var injectedScript = new InjectedScript();
    854 
    855 /**
    856  * @constructor
    857  * @param {*} object
    858  * @param {string=} objectGroupName
    859  * @param {boolean=} forceValueType
    860  * @param {boolean=} generatePreview
    861  * @param {?Array.<string>=} columnNames
    862  */
     679var injectedScript = new InjectedScript;
     680
     681
    863682InjectedScript.RemoteObject = function(object, objectGroupName, forceValueType, generatePreview, columnNames)
    864683{
    865684    this.type = typeof object;
     685
     686    if (this.type === "undefined" && injectedScript._isHTMLAllCollection(object))
     687        this.type = "object";
     688
    866689    if (injectedScript.isPrimitiveValue(object) || object === null || forceValueType) {
    867690        // We don't send undefined values over JSON.
    868         if (typeof object !== "undefined")
     691        if (this.type !== "undefined")
    869692            this.value = object;
    870693
     
    874697
    875698        // Provide user-friendly number values.
    876         if (typeof object === "number")
     699        if (this.type === "number")
    877700            this.description = object + "";
    878701        return;
    879702    }
    880 
    881     object = /** @type {Object} */ (object);
    882703
    883704    this.objectId = injectedScript._bind(object, objectGroupName);
     
    885706    if (subtype)
    886707        this.subtype = subtype;
     708
    887709    this.className = InjectedScriptHost.internalConstructorName(object);
    888710    this.description = injectedScript._describe(object);
     
    893715
    894716InjectedScript.RemoteObject.prototype = {
    895     /**
    896      * @param {Object} object
    897      * @param {Array.<string>=} firstLevelKeys
    898      * @param {?Array.<string>=} secondLevelKeys
    899      * @return {Object} preview
    900      */
    901717    _generatePreview: function(object, firstLevelKeys, secondLevelKeys)
    902718    {
     
    918734    },
    919735
    920     /**
    921      * @param {Object} object
    922      * @param {Object} preview
    923      * @param {Object} propertiesThreshold
    924      * @param {Array.<string>=} firstLevelKeys
    925      * @param {Array.<string>=} secondLevelKeys
    926      */
    927736    _generateProtoPreview: function(object, preview, propertiesThreshold, firstLevelKeys, secondLevelKeys)
    928737    {
    929         var propertyNames = firstLevelKeys ? firstLevelKeys : Object.keys(/** @type {!Object} */(object));
     738        var propertyNames = firstLevelKeys ? firstLevelKeys : Object.keys(object);
    930739        try {
    931740            for (var i = 0; i < propertyNames.length; ++i) {
     
    939748                    continue;
    940749
    941                 var descriptor = Object.getOwnPropertyDescriptor(/** @type {!Object} */(object), name);
     750                var descriptor = Object.getOwnPropertyDescriptor(object, name);
    942751                if (!("value" in descriptor) || !descriptor.enumerable) {
    943752                    preview.lossless = false;
     
    982791                var description = "";
    983792                if (type !== "function")
    984                     description = this._abbreviateString(/** @type {string} */ (injectedScript._describe(value)), maxLength, subtype === "regexp");
     793                    description = this._abbreviateString(injectedScript._describe(value), maxLength, subtype === "regexp");
    985794
    986795                var property = { name: name, type: type, value: description };
     
    993802    },
    994803
    995     /**
    996      * @param {Object} preview
    997      * @param {Object} property
    998      * @param {Object} propertiesThreshold
    999      */
    1000804    _appendPropertyPreview: function(preview, property, propertiesThreshold)
    1001805    {
     
    1007811    },
    1008812
    1009     /**
    1010      * @param {string} string
    1011      * @param {number} maxLength
    1012      * @param {boolean=} middle
    1013      * @returns
    1014      */
    1015813    _abbreviateString: function(string, maxLength, middle)
    1016814    {
    1017815        if (string.length <= maxLength)
    1018816            return string;
     817
    1019818        if (middle) {
    1020819            var leftHalf = maxLength >> 1;
     
    1022821            return string.substr(0, leftHalf) + "\u2026" + string.substr(string.length - rightHalf, rightHalf);
    1023822        }
     823
    1024824        return string.substr(0, maxLength) + "\u2026";
    1025825    }
    1026826}
    1027 /**
    1028  * @constructor
    1029  * @param {number} ordinal
    1030  * @param {Object} callFrame
    1031  */
     827
    1032828InjectedScript.CallFrameProxy = function(ordinal, callFrame)
    1033829{
    1034830    this.callFrameId = "{\"ordinal\":" + ordinal + ",\"injectedScriptId\":" + injectedScriptId + "}";
    1035831    this.functionName = (callFrame.type === "function" ? callFrame.functionName : "");
    1036     this.location = { scriptId: String(callFrame.sourceID), lineNumber: callFrame.line, columnNumber: callFrame.column };
     832    this.location = {scriptId: String(callFrame.sourceID), lineNumber: callFrame.line, columnNumber: callFrame.column};
    1037833    this.scopeChain = this._wrapScopeChain(callFrame);
    1038834    this.this = injectedScript._wrapObject(callFrame.thisObject, "backtrace");
     
    1040836
    1041837InjectedScript.CallFrameProxy.prototype = {
    1042     /**
    1043      * @param {Object} callFrame
    1044      * @return {!Array.<DebuggerAgent.Scope>}
    1045      */
    1046838    _wrapScopeChain: function(callFrame)
    1047839    {
    1048840        var scopeChain = callFrame.scopeChain;
    1049841        var scopeChainProxy = [];
    1050         for (var i = 0; i < scopeChain.length; i++) {
    1051             var scope = InjectedScript.CallFrameProxy._createScopeJson(callFrame.scopeType(i), scopeChain[i], "backtrace");
    1052             scopeChainProxy.push(scope);
    1053         }
     842        for (var i = 0; i < scopeChain.length; i++)
     843            scopeChainProxy[i] = InjectedScript.CallFrameProxy._createScopeJson(callFrame.scopeType(i), scopeChain[i], "backtrace");
    1054844        return scopeChainProxy;
    1055845    }
    1056846}
    1057847
    1058 /**
    1059  * @param {number} scopeTypeCode
    1060  * @param {*} scopeObject
    1061  * @param {string} groupId
    1062  * @return {!DebuggerAgent.Scope}
    1063  */
    1064 InjectedScript.CallFrameProxy._createScopeJson = function(scopeTypeCode, scopeObject, groupId) {
    1065     const GLOBAL_SCOPE = 0;
    1066     const LOCAL_SCOPE = 1;
    1067     const WITH_SCOPE = 2;
    1068     const CLOSURE_SCOPE = 3;
    1069     const CATCH_SCOPE = 4;
    1070     const FUNCTION_NAME_SCOPE = 5;
    1071 
    1072     /** @type {!Object.<number, string>} */
    1073     var scopeTypeNames = {};
    1074     scopeTypeNames[GLOBAL_SCOPE] = "global";
    1075     scopeTypeNames[LOCAL_SCOPE] = "local";
    1076     scopeTypeNames[WITH_SCOPE] = "with";
    1077     scopeTypeNames[CLOSURE_SCOPE] = "closure";
    1078     scopeTypeNames[CATCH_SCOPE] = "catch";
    1079     scopeTypeNames[FUNCTION_NAME_SCOPE] = "functionName";
    1080 
     848InjectedScript.CallFrameProxy._scopeTypeNames = {
     849    0: "global", // GLOBAL_SCOPE
     850    1: "local", // LOCAL_SCOPE
     851    2: "with", // WITH_SCOPE
     852    3: "closure", // CLOSURE_SCOPE
     853    4: "catch", // CATCH_SCOPE
     854    5: "functionName", // FUNCTION_NAME_SCOPE
     855}
     856
     857InjectedScript.CallFrameProxy._createScopeJson = function(scopeTypeCode, scopeObject, groupId)
     858{
    1081859    return {
    1082860        object: injectedScript._wrapObject(scopeObject, groupId),
    1083         type: /** @type {DebuggerAgent.ScopeType} */ (scopeTypeNames[scopeTypeCode])
     861        type: InjectedScript.CallFrameProxy._scopeTypeNames[scopeTypeCode]
    1084862    };
    1085863}
Note: See TracChangeset for help on using the changeset viewer.