Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (226011 => 226012)
--- trunk/Source/_javascript_Core/ChangeLog 2017-12-17 19:35:38 UTC (rev 226011)
+++ trunk/Source/_javascript_Core/ChangeLog 2017-12-17 20:57:35 UTC (rev 226012)
@@ -1,3 +1,67 @@
+2017-12-17 Mark Lam <[email protected]>
+
+ Hollow out stub implementation of InspectorBackendDispatcher::sendResponse().
+ https://bugs.webkit.org/show_bug.cgi?id=180901
+ <rdar://problem/36087649>
+
+ Reviewed by Darin Adler.
+
+ We only need to keep a deprecated implementation of InspectorValues,
+ InspectorObjects, and InspectorBackendDispatcher::sendResponse() around so that
+ older versions of Safari can link against and run with a build of the latest code
+ in WebKit trunk. Older versions of System Safari used InspectorValues (via
+ WebInspector.framework) for two things:
+
+ 1. Augmented JSContexts SPIs (via WebInspector.framework).
+ 2. maybe WebDriver.
+
+ Neither of these are used when running SafariForWebKitDevelopment. Since neither
+ are used, we can stub out the symbols (InspectorValues, InspectorObjects,
+ InspectorBackendDispatcher::sendResponse) to do nothing, and
+ SafariForWebKitDevelopment will still continue to launch with trunk WebKit, and
+ run without any observable bad behavior.
+
+ * _javascript_Core.xcodeproj/project.pbxproj:
+ * SourcesCocoa.txt:
+ * inspector/InspectorBackendDispatcher.cpp:
+ * inspector/InspectorBackendDispatcher.h:
+ * inspector/cocoa/DeprecatedInspectorValues.cpp:
+ (Inspector::InspectorValue::null):
+ (Inspector::InspectorValue::create):
+ (Inspector::InspectorValue::asValue):
+ (Inspector::InspectorValue::asObject):
+ (Inspector::InspectorValue::asArray):
+ (Inspector::InspectorValue::parseJSON):
+ (Inspector::InspectorValue::toJSONString const):
+ (Inspector::InspectorValue::asBoolean const):
+ (Inspector::InspectorValue::asDouble const):
+ (Inspector::InspectorValue::asInteger const):
+ (Inspector::InspectorValue::asString const):
+ (Inspector::InspectorValue::writeJSON const):
+ (Inspector::InspectorValue::memoryCost const):
+ (Inspector::InspectorObjectBase::openAccessors):
+ (Inspector::InspectorObjectBase::memoryCost const):
+ (Inspector::InspectorObjectBase::getBoolean const):
+ (Inspector::InspectorObjectBase::getString const):
+ (Inspector::InspectorObjectBase::getObject const):
+ (Inspector::InspectorObjectBase::getArray const):
+ (Inspector::InspectorObjectBase::getValue const):
+ (Inspector::InspectorObjectBase::remove):
+ (Inspector::InspectorObject::create):
+ (Inspector::InspectorArrayBase::get const):
+ (Inspector::InspectorArrayBase::memoryCost const):
+ (Inspector::InspectorArray::create):
+ (Inspector::BackendDispatcher::sendResponse):
+ (Inspector::InspectorObjectBase::~InspectorObjectBase): Deleted.
+ (Inspector::InspectorObjectBase::asObject): Deleted.
+ (Inspector::InspectorObjectBase::writeJSON const): Deleted.
+ (Inspector::InspectorObjectBase::InspectorObjectBase): Deleted.
+ (Inspector::InspectorArrayBase::~InspectorArrayBase): Deleted.
+ (Inspector::InspectorArrayBase::asArray): Deleted.
+ (Inspector::InspectorArrayBase::writeJSON const): Deleted.
+ (Inspector::InspectorArrayBase::InspectorArrayBase): Deleted.
+ * inspector/cocoa/DeprecatedInspectorValues.h: Removed.
+
2017-12-17 Yusuke Suzuki <[email protected]>
[JSC][WebCore][CSSJIT] Remove VM reference in CSSJIT
Modified: trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj (226011 => 226012)
--- trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj 2017-12-17 19:35:38 UTC (rev 226011)
+++ trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj 2017-12-17 20:57:35 UTC (rev 226012)
@@ -1214,7 +1214,6 @@
978801411471AD920041B016 /* JSDateMath.h in Headers */ = {isa = PBXBuildFile; fileRef = 9788FC231471AD0C0068CE2D /* JSDateMath.h */; settings = {ATTRIBUTES = (Private, ); }; };
981ED82328234D91BAECCADE /* MachineContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 28806E21155E478A93FA7B02 /* MachineContext.h */; settings = {ATTRIBUTES = (Private, ); }; };
990DA67F1C8E316A00295159 /* generate_objc_protocol_type_conversions_implementation.py in Headers */ = {isa = PBXBuildFile; fileRef = 990DA67E1C8E311D00295159 /* generate_objc_protocol_type_conversions_implementation.py */; settings = {ATTRIBUTES = (Private, ); }; };
- 992D6A131FBD492E000245F4 /* DeprecatedInspectorValues.h in Headers */ = {isa = PBXBuildFile; fileRef = 992D6A101FBD491C000245F4 /* DeprecatedInspectorValues.h */; };
992F56B71E4E84B20035953B /* RemoteInspectorXPCConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 992F56B11E4E84790035953B /* RemoteInspectorXPCConnection.h */; settings = {ATTRIBUTES = (Private, ); }; };
9959E92B1BD17FA4001AA413 /* cssmin.py in Headers */ = {isa = PBXBuildFile; fileRef = 9959E9271BD17FA0001AA413 /* cssmin.py */; settings = {ATTRIBUTES = (Private, ); }; };
9959E92D1BD17FA4001AA413 /* jsmin.py in Headers */ = {isa = PBXBuildFile; fileRef = 9959E9291BD17FA0001AA413 /* jsmin.py */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -1715,6 +1714,7 @@
E3FF75331D9CEA1800C7E16D /* DOMJITGetterSetter.h in Headers */ = {isa = PBXBuildFile; fileRef = E3FF752F1D9CEA1200C7E16D /* DOMJITGetterSetter.h */; settings = {ATTRIBUTES = (Private, ); }; };
E49DC16C12EF294E00184A1F /* SourceProviderCache.h in Headers */ = {isa = PBXBuildFile; fileRef = E49DC15112EF272200184A1F /* SourceProviderCache.h */; settings = {ATTRIBUTES = (Private, ); }; };
E49DC16D12EF295300184A1F /* SourceProviderCacheItem.h in Headers */ = {isa = PBXBuildFile; fileRef = E49DC14912EF261A00184A1F /* SourceProviderCacheItem.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ FE05FAFD1FE4CEDA00093230 /* DeprecatedInspectorValues.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 992D6A111FBD491D000245F4 /* DeprecatedInspectorValues.cpp */; };
FE0D4A061AB8DD0A002F54BF /* ExecutionTimeLimitTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE0D4A041AB8DD0A002F54BF /* ExecutionTimeLimitTest.cpp */; };
FE0D4A091ABA2437002F54BF /* GlobalContextWithFinalizerTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE0D4A071ABA2437002F54BF /* GlobalContextWithFinalizerTest.cpp */; };
FE10AAEB1F44D528009DEDC5 /* ProbeStack.h in Headers */ = {isa = PBXBuildFile; fileRef = FE10AAEA1F44D512009DEDC5 /* ProbeStack.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -3815,7 +3815,6 @@
990DA67E1C8E311D00295159 /* generate_objc_protocol_type_conversions_implementation.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = generate_objc_protocol_type_conversions_implementation.py; sourceTree = "<group>"; };
992ABCF51BEA94CA006403A0 /* RemoteAutomationTarget.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RemoteAutomationTarget.cpp; sourceTree = "<group>"; };
992ABCF61BEA94CA006403A0 /* RemoteAutomationTarget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RemoteAutomationTarget.h; sourceTree = "<group>"; };
- 992D6A101FBD491C000245F4 /* DeprecatedInspectorValues.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DeprecatedInspectorValues.h; sourceTree = "<group>"; };
992D6A111FBD491D000245F4 /* DeprecatedInspectorValues.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DeprecatedInspectorValues.cpp; sourceTree = "<group>"; };
992F56B01E4E84790035953B /* RemoteInspectorCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RemoteInspectorCocoa.mm; sourceTree = "<group>"; };
992F56B11E4E84790035953B /* RemoteInspectorXPCConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RemoteInspectorXPCConnection.h; sourceTree = "<group>"; };
@@ -7630,7 +7629,6 @@
isa = PBXGroup;
children = (
992D6A111FBD491D000245F4 /* DeprecatedInspectorValues.cpp */,
- 992D6A101FBD491C000245F4 /* DeprecatedInspectorValues.h */,
);
path = cocoa;
sourceTree = "<group>";
@@ -8355,7 +8353,6 @@
FE5068651AE246390009DAB7 /* DeferredSourceDump.h in Headers */,
473DA4A4764C45FE871B0485 /* DefinePropertyAttributes.h in Headers */,
0FBB73BB1DEF8645002C009E /* DeleteAllCodeEffort.h in Headers */,
- 992D6A131FBD492E000245F4 /* DeprecatedInspectorValues.h in Headers */,
0F96303C1D4192CD005609D9 /* DestructionMode.h in Headers */,
A77A423E17A0BBFD00A8DB81 /* DFGAbstractHeap.h in Headers */,
A704D90317A0BAA8006BA554 /* DFGAbstractInterpreter.h in Headers */,
@@ -8869,7 +8866,7 @@
148CD1D8108CF902008163C6 /* JSContextRefPrivate.h in Headers */,
FE2B0B731FD9EF700075DA5F /* JSCPoison.h in Headers */,
FE2B0B691FD227E00075DA5F /* JSCPoisonedPtr.h in Headers */,
- A72028B81797601E0098028C /* JSCTestRunnerUtils.h in Headers */,
+ A72028B81797601E0098028C /* JSCTestRunnerUtils.h in Headers */,
72AAF7CE1D0D31B3005E60BE /* JSCustomGetterSetterFunction.h in Headers */,
0F2B66EC17B6B5AB00A7AE3F /* JSDataView.h in Headers */,
0F2B66EE17B6B5AB00A7AE3F /* JSDataViewPrototype.h in Headers */,
@@ -10106,6 +10103,7 @@
536B31411F71C5990037FC33 /* UnifiedSource94.cpp in Sources */,
536B31381F71C5990037FC33 /* UnifiedSource95.cpp in Sources */,
536B312F1F71C5990037FC33 /* UnifiedSource96.cpp in Sources */,
+ FE05FAFD1FE4CEDA00093230 /* DeprecatedInspectorValues.cpp in Sources */,
536B31361F71C5990037FC33 /* UnifiedSource97.cpp in Sources */,
536B316A1F71C5990037FC33 /* UnifiedSource98.cpp in Sources */,
536B31631F71C5990037FC33 /* UnifiedSource99.cpp in Sources */,
Modified: trunk/Source/_javascript_Core/SourcesCocoa.txt (226011 => 226012)
--- trunk/Source/_javascript_Core/SourcesCocoa.txt 2017-12-17 19:35:38 UTC (rev 226011)
+++ trunk/Source/_javascript_Core/SourcesCocoa.txt 2017-12-17 20:57:35 UTC (rev 226012)
@@ -31,8 +31,6 @@
API/JSWrapperMap.mm
API/ObjCCallbackFunction.mm
-inspector/cocoa/DeprecatedInspectorValues.cpp
-
inspector/remote/RemoteAutomationTarget.cpp
inspector/remote/RemoteControllableTarget.cpp
inspector/remote/RemoteInspectionTarget.cpp
Modified: trunk/Source/_javascript_Core/inspector/InspectorBackendDispatcher.cpp (226011 => 226012)
--- trunk/Source/_javascript_Core/inspector/InspectorBackendDispatcher.cpp 2017-12-17 19:35:38 UTC (rev 226011)
+++ trunk/Source/_javascript_Core/inspector/InspectorBackendDispatcher.cpp 2017-12-17 20:57:35 UTC (rev 226012)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013, 2015 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2013-2017 Apple Inc. All Rights Reserved.
* Copyright (C) 2011 The Chromium Authors. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -33,10 +33,6 @@
#include <wtf/text/CString.h>
#include <wtf/text/WTFString.h>
-#if PLATFORM(COCOA)
-#include "DeprecatedInspectorValues.h"
-#endif
-
namespace Inspector {
SupplementalBackendDispatcher::SupplementalBackendDispatcher(BackendDispatcher& backendDispatcher)
@@ -189,21 +185,6 @@
}
}
-#if PLATFORM(COCOA)
-// COMPATIBILITY: remove this when no longer needed by system WebInspector.framework <http://webkit.org/b/179847>.
-void BackendDispatcher::sendResponse(long requestId, RefPtr<InspectorObject>&& result)
-{
- ASSERT(!m_protocolErrors.size());
-
- // The JSON-RPC 2.0 specification requires that the "error" member have the value 'null'
- // if no error occurred during an invocation, but we do not include it at all.
- Ref<InspectorObject> responseMessage = InspectorObject::create();
- responseMessage->setObject(ASCIILiteral("result"), WTFMove(result));
- responseMessage->setInteger(ASCIILiteral("id"), requestId);
- m_frontendRouter->sendResponse(responseMessage->toJSONString());
-}
-#endif // PLATFORM(COCOA)
-
// FIXME: remove this function when legacy InspectorObject symbols are no longer needed <http://webkit.org/b/179847>.
void BackendDispatcher::sendResponse(long requestId, RefPtr<JSON::Object>&& result)
{
Modified: trunk/Source/_javascript_Core/inspector/InspectorBackendDispatcher.h (226011 => 226012)
--- trunk/Source/_javascript_Core/inspector/InspectorBackendDispatcher.h 2017-12-17 19:35:38 UTC (rev 226011)
+++ trunk/Source/_javascript_Core/inspector/InspectorBackendDispatcher.h 2017-12-17 20:57:35 UTC (rev 226012)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013, 2015 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2013-2017 Apple Inc. All Rights Reserved.
* Copyright (C) 2011 The Chromium Authors. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -38,10 +38,6 @@
class BackendDispatcher;
-#if PLATFORM(COCOA)
-class InspectorObject;
-#endif
-
typedef String ErrorString;
class JS_EXPORT_PRIVATE SupplementalBackendDispatcher : public RefCounted<SupplementalBackendDispatcher> {
@@ -93,11 +89,6 @@
// When <http://webkit.org/b/179847> is fixed or this class is renamed for the JSON::Object case,
// then this alternate method with a dummy parameter can be removed in favor of the one without it.
void sendResponse(long requestId, RefPtr<JSON::Object>&& result, bool unused);
-#if PLATFORM(COCOA)
- // COMPATIBILITY: remove this when no longer needed by system WebInspector.framework.
- void sendResponse(long requestId, RefPtr<InspectorObject>&& result);
-#endif
-
void sendResponse(long requestId, RefPtr<JSON::Object>&& result);
void sendPendingErrors();
Modified: trunk/Source/_javascript_Core/inspector/cocoa/DeprecatedInspectorValues.cpp (226011 => 226012)
--- trunk/Source/_javascript_Core/inspector/cocoa/DeprecatedInspectorValues.cpp 2017-12-17 19:35:38 UTC (rev 226011)
+++ trunk/Source/_javascript_Core/inspector/cocoa/DeprecatedInspectorValues.cpp 2017-12-17 20:57:35 UTC (rev 226012)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 Google Inc. All rights reserved.
+ * Copyright (C) 2009-2010 Google Inc. All rights reserved.
* Copyright (C) 2014 University of Washington. All rights reserved.
* Copyright (C) 2017 Apple Inc. All rights reserved.
*
@@ -31,821 +31,171 @@
*/
#include "config.h"
-#include "DeprecatedInspectorValues.h"
-#include <wtf/DecimalNumber.h>
-#include <wtf/dtoa.h>
-#include <wtf/text/StringBuilder.h>
+#include "JSExportMacros.h"
-namespace Inspector {
+namespace WTF {
-namespace {
+class StringBuilder;
-static const int stackLimit = 1000;
+class String { };
+template<typename T> class Ref { };
+template<typename T> class RefPtr { };
-enum Token {
- OBJECT_BEGIN,
- OBJECT_END,
- ARRAY_BEGIN,
- ARRAY_END,
- STRING,
- NUMBER,
- BOOL_TRUE,
- BOOL_FALSE,
- NULL_TOKEN,
- LIST_SEPARATOR,
- OBJECT_PAIR_SEPARATOR,
- INVALID_TOKEN,
-};
+} // namespace WTF
-const char* const nullString = "null";
-const char* const trueString = "true";
-const char* const falseString = "false";
+using WTF::Ref;
+using WTF::RefPtr;
+using WTF::String;
+using WTF::StringBuilder;
-bool parseConstToken(const UChar* start, const UChar* end, const UChar** tokenEnd, const char* token)
-{
- while (start < end && *token != '\0' && *start++ == *token++) { }
-
- if (*token != '\0')
- return false;
-
- *tokenEnd = start;
- return true;
+namespace Inspector {
+class InspectorArray;
+class InspectorArrayBase;
+class InspectorObject;
+class InspectorObjectBase;
+class InspectorValue;
}
-bool readInt(const UChar* start, const UChar* end, const UChar** tokenEnd, bool canHaveLeadingZeros)
-{
- if (start == end)
- return false;
+namespace Inspector {
- bool haveLeadingZero = '0' == *start;
- int length = 0;
- while (start < end && '0' <= *start && *start <= '9') {
- ++start;
- ++length;
- }
+class JS_EXPORT_PRIVATE InspectorValue {
+public:
+ virtual ~InspectorValue() { }
- if (!length)
- return false;
+ static Ref<InspectorValue> null();
+ static Ref<InspectorValue> create(bool);
+ static Ref<InspectorValue> create(int);
+ static Ref<InspectorValue> create(double);
+ static Ref<InspectorValue> create(const String&);
+ static Ref<InspectorValue> create(const char*);
- if (!canHaveLeadingZeros && length > 1 && haveLeadingZero)
- return false;
+ enum class Type {
+ Null = 0,
+ Boolean,
+ Double,
+ Integer,
+ String,
+ Object,
+ Array,
+ };
- *tokenEnd = start;
- return true;
-}
+ Type type() const { return Type::Null; }
+ bool isNull() const { return true; }
-bool parseNumberToken(const UChar* start, const UChar* end, const UChar** tokenEnd)
-{
- // We just grab the number here. We validate the size in DecodeNumber.
- // According to RFC4627, a valid number is: [minus] int [frac] [exp]
- if (start == end)
- return false;
+ bool asBoolean(bool&) const;
+ bool asInteger(int&) const;
+ bool asInteger(unsigned&) const;
+ bool asInteger(long&) const;
+ bool asInteger(long long&) const;
+ bool asInteger(unsigned long&) const;
+ bool asInteger(unsigned long long&) const;
+ bool asDouble(double&) const;
+ bool asDouble(float&) const;
+ bool asString(String&) const;
+ bool asValue(RefPtr<InspectorValue>&);
- UChar c = *start;
- if ('-' == c)
- ++start;
+ virtual bool asObject(RefPtr<InspectorObject>&);
+ virtual bool asArray(RefPtr<InspectorArray>&);
- if (!readInt(start, end, &start, false))
- return false;
+ static bool parseJSON(const String&, RefPtr<InspectorValue>&);
- if (start == end) {
- *tokenEnd = start;
- return true;
- }
+ String toJSONString() const;
+ virtual void writeJSON(StringBuilder&) const;
- // Optional fraction part
- c = *start;
- if ('.' == c) {
- ++start;
- if (!readInt(start, end, &start, true))
- return false;
- if (start == end) {
- *tokenEnd = start;
- return true;
- }
- c = *start;
- }
+ virtual size_t memoryCost() const;
+};
- // Optional exponent part
- if ('e' == c || 'E' == c) {
- ++start;
- if (start == end)
- return false;
- c = *start;
- if ('-' == c || '+' == c) {
- ++start;
- if (start == end)
- return false;
- }
- if (!readInt(start, end, &start, true))
- return false;
- }
+Ref<InspectorValue> InspectorValue::null() { return { }; }
+Ref<InspectorValue> InspectorValue::create(bool) { return { }; }
+Ref<InspectorValue> InspectorValue::create(int) { return { }; }
+Ref<InspectorValue> InspectorValue::create(double) { return { }; }
+Ref<InspectorValue> InspectorValue::create(const String&) { return { }; }
+Ref<InspectorValue> InspectorValue::create(const char*) { return { }; }
- *tokenEnd = start;
- return true;
-}
+bool InspectorValue::asValue(RefPtr<Inspector::InspectorValue> &) { return true; }
+bool InspectorValue::asObject(RefPtr<InspectorObject>&) { return false; }
+bool InspectorValue::asArray(RefPtr<InspectorArray>&) { return false; }
-bool readHexDigits(const UChar* start, const UChar* end, const UChar** tokenEnd, int digits)
-{
- if (end - start < digits)
- return false;
+bool InspectorValue::parseJSON(const String&, RefPtr<InspectorValue>&) { return false; }
+String InspectorValue::toJSONString() const { return { }; }
- for (int i = 0; i < digits; ++i) {
- if (!isASCIIHexDigit(*start++))
- return false;
- }
+bool InspectorValue::asBoolean(bool&) const { return false; }
+bool InspectorValue::asDouble(double&) const { return false; }
+bool InspectorValue::asDouble(float&) const { return false; }
- *tokenEnd = start;
- return true;
-}
+bool InspectorValue::asInteger(int&) const { return false; }
+bool InspectorValue::asInteger(unsigned&) const { return false; }
+bool InspectorValue::asInteger(long&) const { return false; }
+bool InspectorValue::asInteger(long long&) const { return false; }
+bool InspectorValue::asInteger(unsigned long&) const { return false; }
+bool InspectorValue::asInteger(unsigned long long&) const { return false; }
-bool parseStringToken(const UChar* start, const UChar* end, const UChar** tokenEnd)
-{
- while (start < end) {
- UChar c = *start++;
- if ('\\' == c) {
- c = *start++;
- // Make sure the escaped char is valid.
- switch (c) {
- case 'x':
- if (!readHexDigits(start, end, &start, 2))
- return false;
- break;
- case 'u':
- if (!readHexDigits(start, end, &start, 4))
- return false;
- break;
- case '\\':
- case '/':
- case 'b':
- case 'f':
- case 'n':
- case 'r':
- case 't':
- case 'v':
- case '"':
- break;
- default:
- return false;
- }
- } else if ('"' == c) {
- *tokenEnd = start;
- return true;
- }
- }
+bool InspectorValue::asString(String&) const { return false; }
+void InspectorValue::writeJSON(StringBuilder&) const { }
+size_t InspectorValue::memoryCost() const { return 0; }
- return false;
-}
-Token parseToken(const UChar* start, const UChar* end, const UChar** tokenStart, const UChar** tokenEnd)
-{
- while (start < end && isSpaceOrNewline(*start))
- ++start;
+class JS_EXPORT_PRIVATE InspectorObjectBase : public InspectorValue {
+public:
+ InspectorObject* openAccessors();
- if (start == end)
- return INVALID_TOKEN;
+ size_t memoryCost() const final;
- *tokenStart = start;
+ bool getBoolean(const String& name, bool& output) const;
+ bool getString(const String& name, String& output) const;
+ bool getObject(const String& name, RefPtr<InspectorObject>&) const;
+ bool getArray(const String& name, RefPtr<InspectorArray>&) const;
+ bool getValue(const String& name, RefPtr<InspectorValue>&) const;
- switch (*start) {
- case 'n':
- if (parseConstToken(start, end, tokenEnd, nullString))
- return NULL_TOKEN;
- break;
- case 't':
- if (parseConstToken(start, end, tokenEnd, trueString))
- return BOOL_TRUE;
- break;
- case 'f':
- if (parseConstToken(start, end, tokenEnd, falseString))
- return BOOL_FALSE;
- break;
- case '[':
- *tokenEnd = start + 1;
- return ARRAY_BEGIN;
- case ']':
- *tokenEnd = start + 1;
- return ARRAY_END;
- case ',':
- *tokenEnd = start + 1;
- return LIST_SEPARATOR;
- case '{':
- *tokenEnd = start + 1;
- return OBJECT_BEGIN;
- case '}':
- *tokenEnd = start + 1;
- return OBJECT_END;
- case ':':
- *tokenEnd = start + 1;
- return OBJECT_PAIR_SEPARATOR;
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- case '-':
- if (parseNumberToken(start, end, tokenEnd))
- return NUMBER;
- break;
- case '"':
- if (parseStringToken(start + 1, end, tokenEnd))
- return STRING;
- break;
- }
+ void remove(const String&);
+};
- return INVALID_TOKEN;
-}
+InspectorObject* InspectorObjectBase::openAccessors() { return nullptr; }
+size_t InspectorObjectBase::memoryCost() const { return 0; }
-bool decodeString(const UChar* start, const UChar* end, StringBuilder& output)
-{
- while (start < end) {
- UChar c = *start++;
- if ('\\' != c) {
- output.append(c);
- continue;
- }
- c = *start++;
- switch (c) {
- case '"':
- case '/':
- case '\\':
- break;
- case 'b':
- c = '\b';
- break;
- case 'f':
- c = '\f';
- break;
- case 'n':
- c = '\n';
- break;
- case 'r':
- c = '\r';
- break;
- case 't':
- c = '\t';
- break;
- case 'v':
- c = '\v';
- break;
- case 'x':
- c = toASCIIHexValue(start[0], start[1]);
- start += 2;
- break;
- case 'u':
- c = toASCIIHexValue(start[0], start[1]) << 8 | toASCIIHexValue(start[2], start[3]);
- start += 4;
- break;
- default:
- return false;
- }
- output.append(c);
- }
+bool InspectorObjectBase::getBoolean(const String&, bool&) const { return false; }
+bool InspectorObjectBase::getString(const String&, String&) const { return false; }
+bool InspectorObjectBase::getObject(const String&, RefPtr<InspectorObject>&) const { return false; }
+bool InspectorObjectBase::getArray(const String&, RefPtr<InspectorArray>&) const { return false; }
+bool InspectorObjectBase::getValue(const String&, RefPtr<InspectorValue>&) const { return false; }
+void InspectorObjectBase::remove(const String&) { }
- return true;
-}
-bool decodeString(const UChar* start, const UChar* end, String& output)
-{
- if (start == end) {
- output = emptyString();
- return true;
- }
+class InspectorObject : public InspectorObjectBase {
+public:
+ static JS_EXPORT_PRIVATE Ref<InspectorObject> create();
+};
- if (start > end)
- return false;
+Ref<InspectorObject> InspectorObject::create() { return { }; }
- StringBuilder buffer;
- buffer.reserveCapacity(end - start);
- if (!decodeString(start, end, buffer))
- return false;
- output = buffer.toString();
- return true;
-}
+class JS_EXPORT_PRIVATE InspectorArrayBase : public InspectorValue {
+public:
+ RefPtr<InspectorValue> get(size_t index) const;
-RefPtr<InspectorValue> buildValue(const UChar* start, const UChar* end, const UChar** valueTokenEnd, int depth)
-{
- if (depth > stackLimit)
- return nullptr;
+ size_t memoryCost() const final;
+};
- RefPtr<InspectorValue> result;
- const UChar* tokenStart;
- const UChar* tokenEnd;
- Token token = parseToken(start, end, &tokenStart, &tokenEnd);
- switch (token) {
- case INVALID_TOKEN:
- return nullptr;
- case NULL_TOKEN:
- result = InspectorValue::null();
- break;
- case BOOL_TRUE:
- result = InspectorValue::create(true);
- break;
- case BOOL_FALSE:
- result = InspectorValue::create(false);
- break;
- case NUMBER: {
- bool ok;
- double value = charactersToDouble(tokenStart, tokenEnd - tokenStart, &ok);
- if (!ok)
- return nullptr;
- result = InspectorValue::create(value);
- break;
- }
- case STRING: {
- String value;
- bool ok = decodeString(tokenStart + 1, tokenEnd - 1, value);
- if (!ok)
- return nullptr;
- result = InspectorValue::create(value);
- break;
- }
- case ARRAY_BEGIN: {
- Ref<InspectorArray> array = InspectorArray::create();
- start = tokenEnd;
- token = parseToken(start, end, &tokenStart, &tokenEnd);
- while (token != ARRAY_END) {
- RefPtr<InspectorValue> arrayNode = buildValue(start, end, &tokenEnd, depth + 1);
- if (!arrayNode)
- return nullptr;
- array->pushValue(WTFMove(arrayNode));
+RefPtr<InspectorValue> InspectorArrayBase::get(size_t) const { return { }; }
+size_t InspectorArrayBase::memoryCost() const { return 0; }
- // After a list value, we expect a comma or the end of the list.
- start = tokenEnd;
- token = parseToken(start, end, &tokenStart, &tokenEnd);
- if (token == LIST_SEPARATOR) {
- start = tokenEnd;
- token = parseToken(start, end, &tokenStart, &tokenEnd);
- if (token == ARRAY_END)
- return nullptr;
- } else if (token != ARRAY_END) {
- // Unexpected value after list value. Bail out.
- return nullptr;
- }
- }
- if (token != ARRAY_END)
- return nullptr;
- result = WTFMove(array);
- break;
- }
- case OBJECT_BEGIN: {
- Ref<InspectorObject> object = InspectorObject::create();
- start = tokenEnd;
- token = parseToken(start, end, &tokenStart, &tokenEnd);
- while (token != OBJECT_END) {
- if (token != STRING)
- return nullptr;
- String key;
- if (!decodeString(tokenStart + 1, tokenEnd - 1, key))
- return nullptr;
- start = tokenEnd;
- token = parseToken(start, end, &tokenStart, &tokenEnd);
- if (token != OBJECT_PAIR_SEPARATOR)
- return nullptr;
- start = tokenEnd;
+class InspectorArray : public InspectorArrayBase {
+public:
+ static JS_EXPORT_PRIVATE Ref<InspectorArray> create();
+};
- RefPtr<InspectorValue> value = buildValue(start, end, &tokenEnd, depth + 1);
- if (!value)
- return nullptr;
- object->setValue(key, WTFMove(value));
- start = tokenEnd;
+Ref<InspectorArray> InspectorArray::create() { return { }; }
- // After a key/value pair, we expect a comma or the end of the
- // object.
- token = parseToken(start, end, &tokenStart, &tokenEnd);
- if (token == LIST_SEPARATOR) {
- start = tokenEnd;
- token = parseToken(start, end, &tokenStart, &tokenEnd);
- if (token == OBJECT_END)
- return nullptr;
- } else if (token != OBJECT_END) {
- // Unexpected value after last object value. Bail out.
- return nullptr;
- }
- }
- if (token != OBJECT_END)
- return nullptr;
- result = WTFMove(object);
- break;
- }
- default:
- // We got a token that's not a value.
- return nullptr;
- }
- *valueTokenEnd = tokenEnd;
- return result;
-}
+class JS_EXPORT_PRIVATE BackendDispatcher {
+public:
+ // COMPATIBILITY: remove this when no longer needed by system WebInspector.framework.
+ void sendResponse(long requestId, RefPtr<InspectorObject>&& result);
+};
-inline bool escapeChar(UChar c, StringBuilder& dst)
-{
- switch (c) {
- case '\b': dst.appendLiteral("\\b"); break;
- case '\f': dst.appendLiteral("\\f"); break;
- case '\n': dst.appendLiteral("\\n"); break;
- case '\r': dst.appendLiteral("\\r"); break;
- case '\t': dst.appendLiteral("\\t"); break;
- case '\\': dst.appendLiteral("\\\\"); break;
- case '"': dst.appendLiteral("\\\""); break;
- default:
- return false;
- }
- return true;
-}
+// COMPATIBILITY: remove this when no longer needed by system WebInspector.framework <http://webkit.org/b/179847>.
+void BackendDispatcher::sendResponse(long, RefPtr<InspectorObject>&&) { }
-inline void doubleQuoteString(const String& str, StringBuilder& dst)
-{
- dst.append('"');
- for (unsigned i = 0; i < str.length(); ++i) {
- UChar c = str[i];
- if (!escapeChar(c, dst)) {
- if (c < 32 || c > 126 || c == '<' || c == '>') {
- // 1. Escaping <, > to prevent script execution.
- // 2. Technically, we could also pass through c > 126 as UTF8, but this
- // is also optional. It would also be a pain to implement here.
- dst.append(String::format("\\u%04X", c));
- } else
- dst.append(c);
- }
- }
- dst.append('"');
-}
-
-} // anonymous namespace
-
-Ref<InspectorValue> InspectorValue::null()
-{
- return adoptRef(*new InspectorValue);
-}
-
-Ref<InspectorValue> InspectorValue::create(bool value)
-{
- return adoptRef(*new InspectorValue(value));
-}
-
-Ref<InspectorValue> InspectorValue::create(int value)
-{
- return adoptRef(*new InspectorValue(value));
-}
-
-Ref<InspectorValue> InspectorValue::create(double value)
-{
- return adoptRef(*new InspectorValue(value));
-}
-
-Ref<InspectorValue> InspectorValue::create(const String& value)
-{
- return adoptRef(*new InspectorValue(value));
-}
-
-Ref<InspectorValue> InspectorValue::create(const char* value)
-{
- return adoptRef(*new InspectorValue(value));
-}
-
-bool InspectorValue::asValue(RefPtr<Inspector::InspectorValue> & value)
-{
- value = this;
- return true;
-}
-
-bool InspectorValue::asObject(RefPtr<InspectorObject>&)
-{
- return false;
-}
-
-bool InspectorValue::asArray(RefPtr<InspectorArray>&)
-{
- return false;
-}
-
-bool InspectorValue::parseJSON(const String& jsonInput, RefPtr<InspectorValue>& output)
-{
- // FIXME: This whole file should just use StringView instead of UChar/length and avoid upconverting.
- auto characters = StringView(jsonInput).upconvertedCharacters();
- const UChar* start = characters;
- const UChar* end = start + jsonInput.length();
- const UChar* tokenEnd;
- auto result = buildValue(start, end, &tokenEnd, 0);
- if (!result || tokenEnd != end)
- return false;
-
- output = WTFMove(result);
- return true;
-}
-
-String InspectorValue::toJSONString() const
-{
- StringBuilder result;
- result.reserveCapacity(512);
- writeJSON(result);
- return result.toString();
-}
-
-bool InspectorValue::asBoolean(bool& output) const
-{
- if (type() != Type::Boolean)
- return false;
-
- output = m_value.boolean;
- return true;
-}
-
-bool InspectorValue::asDouble(double& output) const
-{
- if (type() != Type::Double)
- return false;
-
- output = m_value.number;
- return true;
-}
-
-bool InspectorValue::asDouble(float& output) const
-{
- if (type() != Type::Double)
- return false;
-
- output = static_cast<float>(m_value.number);
- return true;
-}
-
-bool InspectorValue::asInteger(int& output) const
-{
- if (type() != Type::Integer && type() != Type::Double)
- return false;
-
- output = static_cast<int>(m_value.number);
- return true;
-}
-
-bool InspectorValue::asInteger(unsigned& output) const
-{
- if (type() != Type::Integer && type() != Type::Double)
- return false;
-
- output = static_cast<unsigned>(m_value.number);
- return true;
-}
-
-bool InspectorValue::asInteger(long& output) const
-{
- if (type() != Type::Integer && type() != Type::Double)
- return false;
-
- output = static_cast<long>(m_value.number);
- return true;
-}
-
-bool InspectorValue::asInteger(long long& output) const
-{
- if (type() != Type::Integer && type() != Type::Double)
- return false;
-
- output = static_cast<long long>(m_value.number);
- return true;
-}
-
-bool InspectorValue::asInteger(unsigned long& output) const
-{
- if (type() != Type::Integer && type() != Type::Double)
- return false;
-
- output = static_cast<unsigned long>(m_value.number);
- return true;
-}
-
-bool InspectorValue::asInteger(unsigned long long& output) const
-{
- if (type() != Type::Integer && type() != Type::Double)
- return false;
-
- output = static_cast<unsigned long long>(m_value.number);
- return true;
-}
-
-bool InspectorValue::asString(String& output) const
-{
- if (type() != Type::String)
- return false;
-
- output = m_value.string;
- return true;
-}
-
-void InspectorValue::writeJSON(StringBuilder& output) const
-{
- switch (m_type) {
- case Type::Null:
- output.appendLiteral("null");
- break;
- case Type::Boolean:
- if (m_value.boolean)
- output.appendLiteral("true");
- else
- output.appendLiteral("false");
- break;
- case Type::String:
- doubleQuoteString(m_value.string, output);
- break;
- case Type::Double:
- case Type::Integer: {
- NumberToLStringBuffer buffer;
- if (!std::isfinite(m_value.number)) {
- output.appendLiteral("null");
- return;
- }
- DecimalNumber decimal = m_value.number;
- unsigned length = 0;
- if (decimal.bufferLengthForStringDecimal() > WTF::NumberToStringBufferLength) {
- // Not enough room for decimal. Use exponential format.
- if (decimal.bufferLengthForStringExponential() > WTF::NumberToStringBufferLength) {
- // Fallback for an abnormal case if it's too little even for exponential.
- output.appendLiteral("NaN");
- return;
- }
- length = decimal.toStringExponential(buffer, WTF::NumberToStringBufferLength);
- } else
- length = decimal.toStringDecimal(buffer, WTF::NumberToStringBufferLength);
- output.append(buffer, length);
- break;
- }
- default:
- ASSERT_NOT_REACHED();
- }
-}
-
-size_t InspectorValue::memoryCost() const
-{
- size_t memoryCost = sizeof(this);
- if (m_type == Type::String && m_value.string)
- memoryCost += m_value.string->sizeInBytes();
- return memoryCost;
-}
-
-InspectorObjectBase::~InspectorObjectBase()
-{
-}
-
-bool InspectorObjectBase::asObject(RefPtr<InspectorObject>& output)
-{
- COMPILE_ASSERT(sizeof(InspectorObject) == sizeof(InspectorObjectBase), cannot_cast);
-
- output = static_cast<InspectorObject*>(this);
- return true;
-}
-
-InspectorObject* InspectorObjectBase::openAccessors()
-{
- COMPILE_ASSERT(sizeof(InspectorObject) == sizeof(InspectorObjectBase), cannot_cast);
-
- return static_cast<InspectorObject*>(this);
-}
-
-size_t InspectorObjectBase::memoryCost() const
-{
- size_t memoryCost = InspectorValue::memoryCost();
- for (const auto& entry : m_map) {
- memoryCost += entry.key.sizeInBytes();
- if (entry.value)
- memoryCost += entry.value->memoryCost();
- }
- return memoryCost;
-}
-
-bool InspectorObjectBase::getBoolean(const String& name, bool& output) const
-{
- RefPtr<InspectorValue> value;
- if (!getValue(name, value))
- return false;
-
- return value->asBoolean(output);
-}
-
-bool InspectorObjectBase::getString(const String& name, String& output) const
-{
- RefPtr<InspectorValue> value;
- if (!getValue(name, value))
- return false;
-
- return value->asString(output);
-}
-
-bool InspectorObjectBase::getObject(const String& name, RefPtr<InspectorObject>& output) const
-{
- RefPtr<InspectorValue> value;
- if (!getValue(name, value))
- return false;
-
- return value->asObject(output);
-}
-
-bool InspectorObjectBase::getArray(const String& name, RefPtr<InspectorArray>& output) const
-{
- RefPtr<InspectorValue> value;
- if (!getValue(name, value))
- return false;
-
- return value->asArray(output);
-}
-
-bool InspectorObjectBase::getValue(const String& name, RefPtr<InspectorValue>& output) const
-{
- Dictionary::const_iterator findResult = m_map.find(name);
- if (findResult == m_map.end())
- return false;
-
- output = findResult->value;
- return true;
-}
-
-void InspectorObjectBase::remove(const String& name)
-{
- m_map.remove(name);
- m_order.removeFirst(name);
-}
-
-void InspectorObjectBase::writeJSON(StringBuilder& output) const
-{
- output.append('{');
- for (size_t i = 0; i < m_order.size(); ++i) {
- auto findResult = m_map.find(m_order[i]);
- ASSERT(findResult != m_map.end());
- if (i)
- output.append(',');
- doubleQuoteString(findResult->key, output);
- output.append(':');
- findResult->value->writeJSON(output);
- }
- output.append('}');
-}
-
-InspectorObjectBase::InspectorObjectBase()
- : Inspector::InspectorValue(Type::Object)
- , m_map()
- , m_order()
-{
-}
-
-InspectorArrayBase::~InspectorArrayBase()
-{
-}
-
-bool InspectorArrayBase::asArray(RefPtr<InspectorArray>& output)
-{
- COMPILE_ASSERT(sizeof(InspectorArrayBase) == sizeof(InspectorArray), cannot_cast);
- output = static_cast<InspectorArray*>(this);
- return true;
-}
-
-void InspectorArrayBase::writeJSON(StringBuilder& output) const
-{
- output.append('[');
- for (Vector<RefPtr<InspectorValue>>::const_iterator it = m_map.begin(); it != m_map.end(); ++it) {
- if (it != m_map.begin())
- output.append(',');
- (*it)->writeJSON(output);
- }
- output.append(']');
-}
-
-InspectorArrayBase::InspectorArrayBase()
- : InspectorValue(Type::Array)
- , m_map()
-{
-}
-
-RefPtr<InspectorValue> InspectorArrayBase::get(size_t index) const
-{
- ASSERT_WITH_SECURITY_IMPLICATION(index < m_map.size());
- return m_map[index];
-}
-
-Ref<InspectorObject> InspectorObject::create()
-{
- return adoptRef(*new InspectorObject);
-}
-
-Ref<InspectorArray> InspectorArray::create()
-{
- return adoptRef(*new InspectorArray);
-}
-
-size_t InspectorArrayBase::memoryCost() const
-{
- size_t memoryCost = InspectorValue::memoryCost();
- for (const auto& item : m_map) {
- if (item)
- memoryCost += item->memoryCost();
- }
- return memoryCost;
-}
-
} // namespace Inspector
Deleted: trunk/Source/_javascript_Core/inspector/cocoa/DeprecatedInspectorValues.h (226011 => 226012)
--- trunk/Source/_javascript_Core/inspector/cocoa/DeprecatedInspectorValues.h 2017-12-17 19:35:38 UTC (rev 226011)
+++ trunk/Source/_javascript_Core/inspector/cocoa/DeprecatedInspectorValues.h 2017-12-17 20:57:35 UTC (rev 226012)
@@ -1,423 +0,0 @@
-/*
- * Copyright (C) 2009 Google Inc. All rights reserved.
- * Copyright (C) 2014 University of Washington. All rights reserved.
- * Copyright (C) 2017 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#include "JSExportMacros.h"
-#include <wtf/Assertions.h>
-#include <wtf/HashMap.h>
-#include <wtf/RefCounted.h>
-#include <wtf/Vector.h>
-#include <wtf/text/StringHash.h>
-#include <wtf/text/WTFString.h>
-
-
-namespace Inspector {
-class InspectorArray;
-class InspectorArrayBase;
-class InspectorObject;
-class InspectorObjectBase;
-class InspectorValue;
-}
-
-namespace Inspector {
-
-class JS_EXPORT_PRIVATE InspectorValue : public RefCounted<InspectorValue> {
-public:
- static const int maxDepth = 1000;
-
- virtual ~InspectorValue()
- {
- switch (m_type) {
- case Type::Null:
- case Type::Boolean:
- case Type::Double:
- case Type::Integer:
- break;
- case Type::String:
- if (m_value.string)
- m_value.string->deref();
- break;
- case Type::Object:
- case Type::Array:
- break;
- }
- }
-
- static Ref<InspectorValue> null();
- static Ref<InspectorValue> create(bool);
- static Ref<InspectorValue> create(int);
- static Ref<InspectorValue> create(double);
- static Ref<InspectorValue> create(const String&);
- static Ref<InspectorValue> create(const char*);
-
- enum class Type {
- Null = 0,
- Boolean,
- Double,
- Integer,
- String,
- Object,
- Array,
- };
-
- Type type() const { return m_type; }
- bool isNull() const { return m_type == Type::Null; }
-
- bool asBoolean(bool&) const;
- bool asInteger(int&) const;
- bool asInteger(unsigned&) const;
- bool asInteger(long&) const;
- bool asInteger(long long&) const;
- bool asInteger(unsigned long&) const;
- bool asInteger(unsigned long long&) const;
- bool asDouble(double&) const;
- bool asDouble(float&) const;
- bool asString(String&) const;
- bool asValue(RefPtr<InspectorValue>&);
-
- virtual bool asObject(RefPtr<InspectorObject>&);
- virtual bool asArray(RefPtr<InspectorArray>&);
-
- static bool parseJSON(const String& jsonInput, RefPtr<InspectorValue>& output);
-
- String toJSONString() const;
- virtual void writeJSON(StringBuilder& output) const;
-
- virtual size_t memoryCost() const;
-
-protected:
- InspectorValue()
- : m_type(Type::Null) { }
-
- explicit InspectorValue(Type type)
- : m_type(type) { }
-
- explicit InspectorValue(bool value)
- : m_type(Type::Boolean)
- {
- m_value.boolean = value;
- }
-
- explicit InspectorValue(int value)
- : m_type(Type::Integer)
- {
- m_value.number = static_cast<double>(value);
- }
-
- explicit InspectorValue(double value)
- : m_type(Type::Double)
- {
- m_value.number = value;
- }
-
- explicit InspectorValue(const String& value)
- : m_type(Type::String)
- {
- m_value.string = value.impl();
- if (m_value.string)
- m_value.string->ref();
- }
-
- explicit InspectorValue(const char* value)
- : m_type(Type::String)
- {
- String wrapper(value);
- m_value.string = wrapper.impl();
- if (m_value.string)
- m_value.string->ref();
- }
-
-private:
- Type m_type { Type::Null };
- union {
- bool boolean;
- double number;
- StringImpl* string;
- } m_value;
-};
-
-class JS_EXPORT_PRIVATE InspectorObjectBase : public InspectorValue {
-private:
- typedef HashMap<String, RefPtr<InspectorValue>> Dictionary;
-
-public:
- typedef Dictionary::iterator iterator;
- typedef Dictionary::const_iterator const_iterator;
-
- InspectorObject* openAccessors();
-
- size_t memoryCost() const final;
-
-protected:
- virtual ~InspectorObjectBase();
-
- bool asObject(RefPtr<InspectorObject>& output) override;
-
- // FIXME: use templates to reduce the amount of duplicated set*() methods.
- void setBoolean(const String& name, bool);
- void setInteger(const String& name, int);
- void setDouble(const String& name, double);
- void setString(const String& name, const String&);
- void setValue(const String& name, RefPtr<InspectorValue>&&);
- void setObject(const String& name, RefPtr<InspectorObjectBase>&&);
- void setArray(const String& name, RefPtr<InspectorArrayBase>&&);
-
- iterator find(const String& name);
- const_iterator find(const String& name) const;
-
- // FIXME: use templates to reduce the amount of duplicated get*() methods.
- bool getBoolean(const String& name, bool& output) const;
- template<class T> bool getDouble(const String& name, T& output) const
- {
- RefPtr<InspectorValue> value;
- if (!getValue(name, value))
- return false;
-
- return value->asDouble(output);
- }
- template<class T> bool getInteger(const String& name, T& output) const
- {
- RefPtr<InspectorValue> value;
- if (!getValue(name, value))
- return false;
-
- return value->asInteger(output);
- }
-
- bool getString(const String& name, String& output) const;
- bool getObject(const String& name, RefPtr<InspectorObject>&) const;
- bool getArray(const String& name, RefPtr<InspectorArray>&) const;
- bool getValue(const String& name, RefPtr<InspectorValue>&) const;
-
- void remove(const String& name);
-
- void writeJSON(StringBuilder& output) const override;
-
- iterator begin() { return m_map.begin(); }
- iterator end() { return m_map.end(); }
- const_iterator begin() const { return m_map.begin(); }
- const_iterator end() const { return m_map.end(); }
-
- int size() const { return m_map.size(); }
-
-protected:
- InspectorObjectBase();
-
-private:
- Dictionary m_map;
- Vector<String> m_order;
-};
-
-class InspectorObject : public InspectorObjectBase {
-public:
- static JS_EXPORT_PRIVATE Ref<InspectorObject> create();
-
- using InspectorObjectBase::asObject;
-
- // This class expected non-cyclic values, as we cannot serialize cycles in JSON.
- using InspectorObjectBase::setBoolean;
- using InspectorObjectBase::setInteger;
- using InspectorObjectBase::setDouble;
- using InspectorObjectBase::setString;
- using InspectorObjectBase::setValue;
- using InspectorObjectBase::setObject;
- using InspectorObjectBase::setArray;
-
- using InspectorObjectBase::find;
- using InspectorObjectBase::getBoolean;
- using InspectorObjectBase::getInteger;
- using InspectorObjectBase::getDouble;
- using InspectorObjectBase::getString;
- using InspectorObjectBase::getObject;
- using InspectorObjectBase::getArray;
- using InspectorObjectBase::getValue;
-
- using InspectorObjectBase::remove;
-
- using InspectorObjectBase::begin;
- using InspectorObjectBase::end;
-
- using InspectorObjectBase::size;
-};
-
-
-class JS_EXPORT_PRIVATE InspectorArrayBase : public InspectorValue {
-public:
- typedef Vector<RefPtr<InspectorValue>>::iterator iterator;
- typedef Vector<RefPtr<InspectorValue>>::const_iterator const_iterator;
-
- unsigned length() const { return static_cast<unsigned>(m_map.size()); }
-
- RefPtr<InspectorValue> get(size_t index) const;
-
- size_t memoryCost() const final;
-
-protected:
- virtual ~InspectorArrayBase();
-
- bool asArray(RefPtr<InspectorArray>&) override;
-
- void pushBoolean(bool);
- void pushInteger(int);
- void pushDouble(double);
- void pushString(const String&);
- void pushValue(RefPtr<InspectorValue>&&);
- void pushObject(RefPtr<InspectorObjectBase>&&);
- void pushArray(RefPtr<InspectorArrayBase>&&);
-
- void writeJSON(StringBuilder& output) const override;
-
- iterator begin() { return m_map.begin(); }
- iterator end() { return m_map.end(); }
- const_iterator begin() const { return m_map.begin(); }
- const_iterator end() const { return m_map.end(); }
-
-protected:
- InspectorArrayBase();
-
-private:
- Vector<RefPtr<InspectorValue>> m_map;
-};
-
-class InspectorArray : public InspectorArrayBase {
-public:
- static JS_EXPORT_PRIVATE Ref<InspectorArray> create();
-
- using InspectorArrayBase::asArray;
-
- // This class expected non-cyclic values, as we cannot serialize cycles in JSON.
- using InspectorArrayBase::pushBoolean;
- using InspectorArrayBase::pushInteger;
- using InspectorArrayBase::pushDouble;
- using InspectorArrayBase::pushString;
- using InspectorArrayBase::pushValue;
- using InspectorArrayBase::pushObject;
- using InspectorArrayBase::pushArray;
-
- using InspectorArrayBase::get;
-
- using InspectorArrayBase::begin;
- using InspectorArrayBase::end;
-};
-
-
-inline InspectorObjectBase::iterator InspectorObjectBase::find(const String& name)
-{
- return m_map.find(name);
-}
-
-inline InspectorObjectBase::const_iterator InspectorObjectBase::find(const String& name) const
-{
- return m_map.find(name);
-}
-
-inline void InspectorObjectBase::setBoolean(const String& name, bool value)
-{
- setValue(name, InspectorValue::create(value));
-}
-
-inline void InspectorObjectBase::setInteger(const String& name, int value)
-{
- setValue(name, InspectorValue::create(value));
-}
-
-inline void InspectorObjectBase::setDouble(const String& name, double value)
-{
- setValue(name, InspectorValue::create(value));
-}
-
-inline void InspectorObjectBase::setString(const String& name, const String& value)
-{
- setValue(name, InspectorValue::create(value));
-}
-
-inline void InspectorObjectBase::setValue(const String& name, RefPtr<InspectorValue>&& value)
-{
- ASSERT(value);
- if (m_map.set(name, WTFMove(value)).isNewEntry)
- m_order.append(name);
-}
-
-inline void InspectorObjectBase::setObject(const String& name, RefPtr<InspectorObjectBase>&& value)
-{
- ASSERT(value);
- if (m_map.set(name, WTFMove(value)).isNewEntry)
- m_order.append(name);
-}
-
-inline void InspectorObjectBase::setArray(const String& name, RefPtr<InspectorArrayBase>&& value)
-{
- ASSERT(value);
- if (m_map.set(name, WTFMove(value)).isNewEntry)
- m_order.append(name);
-}
-
-inline void InspectorArrayBase::pushBoolean(bool value)
-{
- m_map.append(InspectorValue::create(value));
-}
-
-inline void InspectorArrayBase::pushInteger(int value)
-{
- m_map.append(InspectorValue::create(value));
-}
-
-inline void InspectorArrayBase::pushDouble(double value)
-{
- m_map.append(InspectorValue::create(value));
-}
-
-inline void InspectorArrayBase::pushString(const String& value)
-{
- m_map.append(InspectorValue::create(value));
-}
-
-inline void InspectorArrayBase::pushValue(RefPtr<InspectorValue>&& value)
-{
- ASSERT(value);
- m_map.append(WTFMove(value));
-}
-
-inline void InspectorArrayBase::pushObject(RefPtr<InspectorObjectBase>&& value)
-{
- ASSERT(value);
- m_map.append(WTFMove(value));
-}
-
-inline void InspectorArrayBase::pushArray(RefPtr<InspectorArrayBase>&& value)
-{
- ASSERT(value);
- m_map.append(WTFMove(value));
-}
-
-} // namespace Inspector