Changeset 209939 in webkit


Ignore:
Timestamp:
Dec 16, 2016 2:29:19 PM (7 years ago)
Author:
weinig@apple.com
Message:

[Bindings] Remove use of Dictionary/ArrayValue in CDMSessionClearKey
https://bugs.webkit.org/show_bug.cgi?id=165961

Reviewed by Darin Adler.

  • CMakeLists.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/JSBindingsAllInOne.cpp:

Remove ArrayValue.h/cpp

  • bindings/js/ArrayValue.cpp: Removed.
  • bindings/js/ArrayValue.h: Removed.
  • bindings/js/Dictionary.cpp:
  • bindings/js/Dictionary.h:

Remove support for ArrayValue.

  • Modules/encryptedmedia/legacy/LegacyCDMSessionClearKey.cpp:

(WebCore::CDMSessionClearKey::update):
Replace use of Dictionary/ArrayValue with direct JSObject functions. This
should really be replaced with a JSON parser that does not require round
tripping through JavaScript objects.

Location:
trunk/Source/WebCore
Files:
2 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/CMakeLists.txt

    r209883 r209939  
    10721072    bindings/generic/RuntimeEnabledFeatures.cpp
    10731073
    1074     bindings/js/ArrayValue.cpp
    10751074    bindings/js/CachedModuleScript.cpp
    10761075    bindings/js/CachedModuleScriptLoader.cpp
  • trunk/Source/WebCore/ChangeLog

    r209936 r209939  
     12016-12-16  Sam Weinig  <sam@webkit.org>
     2
     3        [Bindings] Remove use of Dictionary/ArrayValue in CDMSessionClearKey
     4        https://bugs.webkit.org/show_bug.cgi?id=165961
     5
     6        Reviewed by Darin Adler.
     7
     8        * CMakeLists.txt:
     9        * WebCore.xcodeproj/project.pbxproj:
     10        * bindings/js/JSBindingsAllInOne.cpp:
     11        Remove ArrayValue.h/cpp
     12
     13        * bindings/js/ArrayValue.cpp: Removed.
     14        * bindings/js/ArrayValue.h: Removed.
     15
     16        * bindings/js/Dictionary.cpp:
     17        * bindings/js/Dictionary.h:
     18        Remove support for ArrayValue.
     19
     20        * Modules/encryptedmedia/legacy/LegacyCDMSessionClearKey.cpp:
     21        (WebCore::CDMSessionClearKey::update):
     22        Replace use of Dictionary/ArrayValue with direct JSObject functions. This
     23        should really be replaced with a JSON parser that does not require round
     24        tripping through JavaScript objects.
     25
    1262016-12-13  Jer Noble  <jer.noble@apple.com>
    227
  • trunk/Source/WebCore/Modules/encryptedmedia/legacy/LegacyCDMSessionClearKey.cpp

    r209936 r209939  
    2727#include "LegacyCDMSessionClearKey.h"
    2828
    29 #include "ArrayValue.h"
    30 #include "Dictionary.h"
    3129#include "JSMainThreadExecState.h"
    3230#include "Logging.h"
     
    10098
    10199    do {
    102         String rawKeysString = String::fromUTF8(rawKeysData->data(), rawKeysData->length());
     100        auto rawKeysString = String::fromUTF8(rawKeysData->data(), rawKeysData->length());
    103101        if (rawKeysString.isEmpty())  {
    104102            LOG(Media, "CDMSessionClearKey::update(%p) - failed: empty message", this);
     
    106104        }
    107105
    108         VM& vm = clearKeyVM();
     106        auto& vm = clearKeyVM();
    109107        JSLockHolder lock(vm);
    110108        auto scope = DECLARE_THROW_SCOPE(vm);
    111         JSGlobalObject* globalObject = JSGlobalObject::create(vm, JSGlobalObject::createStructure(vm, jsNull()));
    112         ExecState* exec = globalObject->globalExec();
    113 
    114         JSLockHolder locker(clearKeyVM());
    115         JSValue keysDataObject = JSONParse(exec, rawKeysString);
    116         if (scope.exception() || !keysDataObject) {
     109        auto* globalObject = JSGlobalObject::create(vm, JSGlobalObject::createStructure(vm, jsNull()));
     110        auto& state = *globalObject->globalExec();
     111
     112        auto keysDataValue = JSONParse(&state, rawKeysString);
     113        if (scope.exception() || !keysDataValue.isObject()) {
    117114            LOG(Media, "CDMSessionClearKey::update(%p) - failed: invalid JSON", this);
    118115            break;
    119116        }
    120         Dictionary keysDataDictionary(exec, keysDataObject);
    121         ArrayValue keysArray;
    122         size_t length;
    123         if (!keysDataDictionary.get("keys", keysArray) || keysArray.isUndefinedOrNull() || !keysArray.length(length) || !length) {
     117
     118        auto keysArrayValue = asObject(keysDataValue)->get(&state, Identifier::fromString(&state, "keys"));
     119        if (scope.exception() || !isJSArray(keysArrayValue)) {
    124120            LOG(Media, "CDMSessionClearKey::update(%p) - failed: keys array missing or empty", this);
    125121            break;
    126122        }
    127123
     124        auto keysArray = asArray(keysArrayValue);
     125        auto length = keysArray->length();
     126        if (!length) {
     127            LOG(Media, "CDMSessionClearKey::update(%p) - failed: keys array missing or empty", this);
     128            break;
     129        }
     130
    128131        bool foundValidKey = false;
    129         for (size_t i = 0; i < length; ++i) {
    130             Dictionary keyDictionary;
    131             if (!keysArray.get(i, keyDictionary) || keyDictionary.isUndefinedOrNull()) {
     132        for (unsigned i = 0; i < length; ++i) {
     133            auto keyValue = keysArray->getIndex(&state, i);
     134
     135            if (scope.exception() || !keyValue.isObject()) {
    132136                LOG(Media, "CDMSessionClearKey::update(%p) - failed: null keyDictionary", this);
    133137                continue;
    134138            }
    135139
    136             String algorithm;
    137             if (!keyDictionary.get("alg", algorithm) || !equalLettersIgnoringASCIICase(algorithm, "a128kw")) {
     140            auto keyObject = asObject(keyValue);
     141
     142            auto getStringProperty = [&scope, &state, &keyObject](const char* name) -> String {
     143                auto value = keyObject->get(&state, Identifier::fromString(&state, name));
     144                if (scope.exception() || !value.isString())
     145                    return { };
     146
     147                auto string = asString(value)->value(&state);
     148                if (scope.exception())
     149                    return { };
     150               
     151                return string;
     152            };
     153
     154            auto algorithm = getStringProperty("alg");
     155            if (!equalLettersIgnoringASCIICase(algorithm, "a128kw")) {
    138156                LOG(Media, "CDMSessionClearKey::update(%p) - failed: algorithm unsupported", this);
    139157                continue;
    140158            }
    141159
    142             String keyType;
    143             if (!keyDictionary.get("kty", keyType) || !equalLettersIgnoringASCIICase(keyType, "oct")) {
     160            auto keyType = getStringProperty("kty");
     161            if (!equalLettersIgnoringASCIICase(keyType, "oct")) {
    144162                LOG(Media, "CDMSessionClearKey::update(%p) - failed: keyType unsupported", this);
    145163                continue;
    146164            }
    147165
    148             String keyId;
    149             if (!keyDictionary.get("kid", keyId) || keyId.isEmpty()) {
     166            auto keyId = getStringProperty("kid");
     167            if (keyId.isEmpty()) {
    150168                LOG(Media, "CDMSessionClearKey::update(%p) - failed: keyId missing or empty", this);
    151169                continue;
    152170            }
    153171
    154             String rawKeyData;
    155             if (!keyDictionary.get("k", rawKeyData) || rawKeyData.isEmpty())  {
     172            auto rawKeyData = getStringProperty("k");
     173            if (rawKeyData.isEmpty())  {
    156174                LOG(Media, "CDMSessionClearKey::update(%p) - failed: key missing or empty", this);
    157175                continue;
     
    159177
    160178            Vector<uint8_t> keyData;
    161             if (!base64Decode(rawKeyData, keyData) ||  keyData.isEmpty()) {
     179            if (!base64Decode(rawKeyData, keyData) || keyData.isEmpty()) {
    162180                LOG(Media, "CDMSessionClearKey::update(%p) - failed: unable to base64 decode key", this);
    163181                continue;
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r209936 r209939  
    18181818                49AF2D6914435D050016A784 /* DisplayRefreshMonitor.h in Headers */ = {isa = PBXBuildFile; fileRef = 49AF2D6814435D050016A784 /* DisplayRefreshMonitor.h */; settings = {ATTRIBUTES = (Private, ); }; };
    18191819                49AF2D6C14435D210016A784 /* DisplayRefreshMonitorMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49AF2D6B14435D210016A784 /* DisplayRefreshMonitorMac.cpp */; };
    1820                 49B3760C15C6C6840059131D /* ArrayValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49B3760A15C6C6840059131D /* ArrayValue.cpp */; };
    1821                 49B3760D15C6C6840059131D /* ArrayValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 49B3760B15C6C6840059131D /* ArrayValue.h */; };
    18221820                49C7B9931042D2D30009D447 /* JSWebGLBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49C7B9801042D2D30009D447 /* JSWebGLBuffer.cpp */; };
    18231821                49C7B9941042D2D30009D447 /* JSWebGLBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 49C7B9811042D2D30009D447 /* JSWebGLBuffer.h */; };
     
    90169014                49AF2D6814435D050016A784 /* DisplayRefreshMonitor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DisplayRefreshMonitor.h; sourceTree = "<group>"; };
    90179015                49AF2D6B14435D210016A784 /* DisplayRefreshMonitorMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DisplayRefreshMonitorMac.cpp; sourceTree = "<group>"; };
    9018                 49B3760A15C6C6840059131D /* ArrayValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ArrayValue.cpp; sourceTree = "<group>"; };
    9019                 49B3760B15C6C6840059131D /* ArrayValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArrayValue.h; sourceTree = "<group>"; };
    90209016                49C7B9801042D2D30009D447 /* JSWebGLBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWebGLBuffer.cpp; sourceTree = "<group>"; };
    90219017                49C7B9811042D2D30009D447 /* JSWebGLBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWebGLBuffer.h; sourceTree = "<group>"; };
     
    2193121927                                BC4EDEF70C08F414007EDD49 /* Custom */,
    2193221928                                14DFB33F0A7DF7630018F769 /* Derived Sources */,
    21933                                 49B3760A15C6C6840059131D /* ArrayValue.cpp */,
    21934                                 49B3760B15C6C6840059131D /* ArrayValue.h */,
    2193521929                                2DFA488E1DB541C200362B99 /* BufferSource.h */,
    2193621930                                E307DEC91D81E46E00141CAF /* CachedModuleScript.cpp */,
     
    2486524859                                512DD8FC0D91E6AF000F89EE /* ArchiveResource.h in Headers */,
    2486624860                                512DD8F80D91E6AF000F89EE /* ArchiveResourceCollection.h in Headers */,
    24867                                 49B3760D15C6C6840059131D /* ArrayValue.h in Headers */,
    2486824861                                FD5686CA13AC180200B69C68 /* AsyncAudioDecoder.h in Headers */,
    2486924862                                E1CDE9221501916900862CC5 /* AsyncFileStream.h in Headers */,
     
    2875328746                                512DD8FB0D91E6AF000F89EE /* ArchiveResource.cpp in Sources */,
    2875428747                                512DD8F70D91E6AF000F89EE /* ArchiveResourceCollection.cpp in Sources */,
    28755                                 49B3760C15C6C6840059131D /* ArrayValue.cpp in Sources */,
    2875628748                                FD5686C913AC180200B69C68 /* AsyncAudioDecoder.cpp in Sources */,
    2875728749                                E1CDE92015018ED000862CC5 /* AsyncFileStream.cpp in Sources */,
  • trunk/Source/WebCore/bindings/js/Dictionary.cpp

    r209674 r209939  
    2727#include "Dictionary.h"
    2828
    29 #include "ArrayValue.h"
    3029#include "JSDOMConvert.h"
    3130
     
    126125}
    127126
    128 void Dictionary::convertValue(ExecState& state, JSValue value, ArrayValue& result)
    129 {
    130     if (value.isUndefinedOrNull())
    131         return;
    132     result = ArrayValue(&state, value);
    133127}
    134 
    135 }
  • trunk/Source/WebCore/bindings/js/Dictionary.h

    r209674 r209939  
    4343namespace WebCore {
    4444
    45 class ArrayValue;
    46 
    4745class Dictionary {
    4846public:
     
    8684    static void convertValue(JSC::ExecState&, JSC::JSValue, Vector<String>& result);
    8785    static void convertValue(JSC::ExecState&, JSC::JSValue, Dictionary& result);
    88     static void convertValue(JSC::ExecState&, JSC::JSValue, ArrayValue& result);
    8986
    9087    JSC::ExecState* m_state { nullptr };
  • trunk/Source/WebCore/bindings/js/JSBindingsAllInOne.cpp

    r209864 r209939  
    2626// This all-in-one cpp file cuts down on template bloat to allow us to build our Windows release build.
    2727
    28 #include "ArrayValue.cpp"
    2928#include "CachedModuleScript.cpp"
    3029#include "CachedModuleScriptLoader.cpp"
Note: See TracChangeset for help on using the changeset viewer.