mirror of https://github.com/lukechilds/node.git
Browse Source
Pick up latest from [1] corresponding to the Blink commit 60cd6e859b. [1]: https://github.com/pavelfeldman/v8_inspector/commit/55f21a5611 PR-URL: https://github.com/nodejs/node/pull/8150 Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>v6.x
Eugene Ostroukhov
8 years ago
committed by
Jeremiah Senkpiel
102 changed files with 1852 additions and 1598 deletions
@ -0,0 +1,66 @@ |
|||
/*
|
|||
* Copyright (C) 2013 Google 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. |
|||
*/ |
|||
|
|||
|
|||
#ifndef PlatformExport_h |
|||
#define PlatformExport_h |
|||
|
|||
#if !defined(BLINK_PLATFORM_IMPLEMENTATION) |
|||
#define BLINK_PLATFORM_IMPLEMENTATION 0 |
|||
#endif |
|||
|
|||
#if defined(COMPONENT_BUILD) |
|||
#if defined(WIN32) |
|||
#if BLINK_PLATFORM_IMPLEMENTATION |
|||
#define PLATFORM_EXPORT __declspec(dllexport) |
|||
#else |
|||
#define PLATFORM_EXPORT __declspec(dllimport) |
|||
#endif |
|||
#else // defined(WIN32)
|
|||
#define PLATFORM_EXPORT __attribute__((visibility("default"))) |
|||
#endif |
|||
#else // defined(COMPONENT_BUILD)
|
|||
#define PLATFORM_EXPORT |
|||
#endif |
|||
|
|||
#if defined(_MSC_VER) |
|||
// MSVC Compiler warning C4275:
|
|||
// non dll-interface class 'Bar' used as base for dll-interface class 'Foo'.
|
|||
// Note that this is intended to be used only when no access to the base class'
|
|||
// static data is done through derived classes or inline methods. For more info,
|
|||
// see http://msdn.microsoft.com/en-us/library/3tdb471s(VS.80).aspx
|
|||
//
|
|||
// This pragma will allow exporting a class that inherits from a non-exported
|
|||
// base class, anywhere in the Blink platform component. This is only
|
|||
// a problem when using the MSVC compiler on Windows.
|
|||
#pragma warning(suppress:4275) |
|||
#endif |
|||
|
|||
#endif // PlatformExport_h
|
@ -0,0 +1,5 @@ |
|||
// Copyright 2016 The Chromium Authors. All rights reserved. |
|||
// Use of this source code is governed by a BSD-style license that can be |
|||
// found in the LICENSE file. |
|||
|
|||
#include "{{config.lib_package}}/InspectorProtocol.h" |
@ -1,14 +0,0 @@ |
|||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
|||
// found in the LICENSE file.
|
|||
|
|||
#ifndef String16_h |
|||
#define String16_h |
|||
|
|||
#if V8_INSPECTOR_USE_STL |
|||
#include "platform/inspector_protocol/String16STL.h" |
|||
#else |
|||
#include "platform/inspector_protocol/String16WTF.h" |
|||
#endif // V8_INSPECTOR_USE_STL
|
|||
|
|||
#endif // !defined(String16_h)
|
@ -1,263 +0,0 @@ |
|||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
|||
// found in the LICENSE file.
|
|||
|
|||
#ifndef String16STL_h |
|||
#define String16STL_h |
|||
|
|||
#include <cctype> |
|||
#include <cstdlib> |
|||
#include <cstring> |
|||
#include <stdint.h> |
|||
#include <string> |
|||
#include <vector> |
|||
|
|||
using UChar = uint16_t; |
|||
using UChar32 = uint32_t; |
|||
using LChar = unsigned char; |
|||
// presubmit: allow wstring
|
|||
using wstring = std::basic_string<UChar>; |
|||
const size_t kNotFound = static_cast<size_t>(-1); |
|||
|
|||
namespace blink { |
|||
namespace protocol { |
|||
|
|||
class String16 { |
|||
public: |
|||
String16() { } |
|||
String16(const String16& other) : m_impl(other.m_impl) { } |
|||
// presubmit: allow wstring
|
|||
String16(const wstring& impl) : m_impl(impl) { } |
|||
String16(const UChar* characters) : m_impl(characters) { } |
|||
String16(const char* characters) : String16(characters, std::strlen(characters)) { } |
|||
String16(const char* characters, size_t size) |
|||
{ |
|||
m_impl.resize(size); |
|||
for (size_t i = 0; i < size; ++i) |
|||
m_impl[i] = characters[i]; |
|||
} |
|||
String16(const UChar* characters, size_t size) : m_impl(characters, size) { } |
|||
String16 isolatedCopy() const { return String16(m_impl); } |
|||
|
|||
unsigned sizeInBytes() const { return m_impl.size() * sizeof(UChar); } |
|||
const UChar* characters16() const { return m_impl.c_str(); } |
|||
std::string utf8() const; |
|||
static String16 fromUTF8(const char* stringStart, size_t length); |
|||
static String16 fromInteger(int i) { return String16(String16::intToString(i).c_str()); } |
|||
static String16 fromDouble(double d) { return String16(String16::doubleToString(d).c_str()); } |
|||
static String16 fromDoubleFixedPrecision(double d, int len) { return String16(String16::doubleToString(d).c_str()); } |
|||
|
|||
static double charactersToDouble(const UChar* characters, size_t length, bool* ok = 0) |
|||
{ |
|||
std::string str; |
|||
str.resize(length); |
|||
for (size_t i = 0; i < length; ++i) |
|||
str[i] = static_cast<char>(characters[i]); |
|||
|
|||
const char* buffer = str.c_str(); |
|||
char* endptr; |
|||
double result = strtod(buffer, &endptr); |
|||
if (ok) |
|||
*ok = buffer + length == endptr; |
|||
return result; |
|||
} |
|||
|
|||
String16 substring(unsigned pos, unsigned len = 0xFFFFFFFF) const |
|||
{ |
|||
return String16(m_impl.substr(pos, len)); |
|||
} |
|||
|
|||
String16 stripWhiteSpace() const; |
|||
|
|||
int toInt(bool* ok = 0) const |
|||
{ |
|||
size_t length = m_impl.length(); |
|||
std::string str; |
|||
str.resize(length); |
|||
for (size_t i = 0; i < length; ++i) |
|||
str[i] = static_cast<char>(m_impl[i]); |
|||
|
|||
const char* buffer = str.c_str(); |
|||
char* endptr; |
|||
int result = strtol(buffer, &endptr, 10); |
|||
if (ok) |
|||
*ok = buffer + length == endptr; |
|||
return result; |
|||
} |
|||
|
|||
size_t length() const { return m_impl.length(); } |
|||
bool isEmpty() const { return !m_impl.length(); } |
|||
UChar operator[](unsigned index) const { return m_impl[index]; } |
|||
|
|||
size_t find(UChar c, unsigned start = 0) const |
|||
{ |
|||
return m_impl.find(c, start); |
|||
} |
|||
|
|||
size_t find(const String16& str, unsigned start = 0) const |
|||
{ |
|||
return m_impl.find(str.m_impl, start); |
|||
} |
|||
|
|||
size_t reverseFind(const String16& str, unsigned start = 0xFFFFFFFF) const |
|||
{ |
|||
return m_impl.rfind(str.m_impl, start); |
|||
} |
|||
|
|||
bool startWith(const String16& s) const |
|||
{ |
|||
if (m_impl.length() < s.m_impl.length()) |
|||
return false; |
|||
return m_impl.substr(0, s.m_impl.length()) == s.m_impl; |
|||
} |
|||
|
|||
bool endsWith(UChar character) const |
|||
{ |
|||
return m_impl.length() && m_impl[m_impl.length() - 1] == character; |
|||
} |
|||
|
|||
// presubmit: allow wstring
|
|||
const wstring& impl() const { return m_impl; } |
|||
|
|||
std::size_t hash() const |
|||
{ |
|||
if (!has_hash) { |
|||
size_t hash = 0; |
|||
for (size_t i = 0; i < length(); ++i) |
|||
hash = 31 * hash + m_impl[i]; |
|||
hash_code = hash; |
|||
has_hash = true; |
|||
} |
|||
return hash_code; |
|||
} |
|||
|
|||
private: |
|||
static std::string intToString(int); |
|||
static std::string doubleToString(double); |
|||
// presubmit: allow wstring
|
|||
wstring m_impl; |
|||
mutable bool has_hash = false; |
|||
mutable std::size_t hash_code = 0; |
|||
}; |
|||
|
|||
static inline bool isSpaceOrNewline(UChar c) |
|||
{ |
|||
return std::isspace(c); // NOLINT
|
|||
} |
|||
|
|||
class String16Builder { |
|||
public: |
|||
String16Builder() { } |
|||
|
|||
void append(const String16& str) |
|||
{ |
|||
m_impl += str.impl(); |
|||
} |
|||
|
|||
void append(UChar c) |
|||
{ |
|||
m_impl += c; |
|||
} |
|||
|
|||
void append(LChar c) |
|||
{ |
|||
m_impl += c; |
|||
} |
|||
|
|||
void append(char c) |
|||
{ |
|||
m_impl += c; |
|||
} |
|||
|
|||
void appendNumber(int i) |
|||
{ |
|||
m_impl = m_impl + String16::fromInteger(i).impl(); |
|||
} |
|||
|
|||
void appendNumber(double d) |
|||
{ |
|||
m_impl = m_impl + String16::fromDoubleFixedPrecision(d, 6).impl(); |
|||
} |
|||
|
|||
void append(const UChar* c, size_t length) |
|||
{ |
|||
// presubmit: allow wstring
|
|||
m_impl += wstring(c, length); |
|||
} |
|||
|
|||
void append(const char* c, size_t length) |
|||
{ |
|||
m_impl += String16(c, length).impl(); |
|||
} |
|||
|
|||
String16 toString() |
|||
{ |
|||
return String16(m_impl); |
|||
} |
|||
|
|||
void reserveCapacity(unsigned newCapacity) |
|||
{ |
|||
} |
|||
|
|||
private: |
|||
// presubmit: allow wstring
|
|||
wstring m_impl; |
|||
}; |
|||
|
|||
inline bool operator==(const String16& a, const String16& b) { return a.impl() == b.impl(); } |
|||
inline bool operator!=(const String16& a, const String16& b) { return a.impl() != b.impl(); } |
|||
inline bool operator==(const String16& a, const char* b) { return a.impl() == String16(b).impl(); } |
|||
inline bool operator<(const String16& a, const String16& b) { return a.impl() < b.impl(); } |
|||
|
|||
inline String16 operator+(const String16& a, const char* b) |
|||
{ |
|||
return String16(a.impl() + String16(b).impl()); |
|||
} |
|||
|
|||
inline String16 operator+(const char* a, const String16& b) |
|||
{ |
|||
return String16(String16(a).impl() + b.impl()); |
|||
} |
|||
|
|||
inline String16 operator+(const String16& a, const String16& b) |
|||
{ |
|||
return String16(a.impl() + b.impl()); |
|||
} |
|||
|
|||
} // namespace protocol
|
|||
} // namespace blink
|
|||
|
|||
using String16 = blink::protocol::String16; |
|||
using String16Builder = blink::protocol::String16Builder; |
|||
|
|||
|
|||
namespace WTF { |
|||
// Interim solution for those headers that reference WTF::String for overrides.
|
|||
// It does nothing. If the code actually relies on WTF:String, it will not
|
|||
// compile!
|
|||
// TODO(eostroukhov): Eradicate
|
|||
class String { |
|||
public: |
|||
String() {}; |
|||
String(const String16& other) {}; |
|||
operator String16() const { return String16(); }; |
|||
}; |
|||
} // namespace WTF
|
|||
|
|||
#if !defined(__APPLE__) || defined(_LIBCPP_VERSION) |
|||
|
|||
namespace std { |
|||
template<> struct hash<String16> { |
|||
std::size_t operator()(const String16& string) const |
|||
{ |
|||
return string.hash(); |
|||
} |
|||
}; |
|||
|
|||
} // namespace std
|
|||
|
|||
#endif // !defined(__APPLE__) || defined(_LIBCPP_VERSION)
|
|||
|
|||
using String = WTF::String; |
|||
|
|||
#endif // !defined(String16STL_h)
|
@ -1,47 +0,0 @@ |
|||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
|||
// found in the LICENSE file.
|
|||
|
|||
#include "platform/inspector_protocol/String16WTF.h" |
|||
|
|||
namespace blink { |
|||
namespace protocol { |
|||
|
|||
String16::String16(const String16& other) : m_impl(other.m_impl) { } |
|||
|
|||
String16::String16(const UChar* u, unsigned length) : m_impl(u, length) { } |
|||
|
|||
String16::String16(const char* characters) : String16(characters, strlen(characters)) { } |
|||
|
|||
String16::String16(const WTF::String& other) |
|||
{ |
|||
if (other.isNull()) |
|||
return; |
|||
if (!other.is8Bit()) { |
|||
m_impl = other; |
|||
return; |
|||
} |
|||
|
|||
UChar* data; |
|||
const LChar* characters = other.characters8(); |
|||
size_t length = other.length(); |
|||
m_impl = String::createUninitialized(length, data); |
|||
for (size_t i = 0; i < length; ++i) |
|||
data[i] = characters[i]; |
|||
} |
|||
|
|||
String16::String16(const char* characters, size_t length) |
|||
{ |
|||
UChar* data; |
|||
m_impl = String::createUninitialized(length, data); |
|||
for (size_t i = 0; i < length; ++i) |
|||
data[i] = characters[i]; |
|||
} |
|||
|
|||
String16 String16::createUninitialized(unsigned length, UChar*& data) |
|||
{ |
|||
return String::createUninitialized(length, data); |
|||
} |
|||
|
|||
} // namespace protocol
|
|||
} // namespace blink
|
@ -1,154 +0,0 @@ |
|||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
|||
// found in the LICENSE file.
|
|||
|
|||
#ifndef String16WTF_h |
|||
#define String16WTF_h |
|||
|
|||
#include "platform/Decimal.h" |
|||
#include "public/platform/WebString.h" |
|||
#include "wtf/text/StringBuilder.h" |
|||
#include "wtf/text/StringConcatenate.h" |
|||
#include "wtf/text/StringHash.h" |
|||
#include "wtf/text/StringToNumber.h" |
|||
#include "wtf/text/StringView.h" |
|||
#include "wtf/text/WTFString.h" |
|||
|
|||
namespace blink { |
|||
namespace protocol { |
|||
|
|||
class PLATFORM_EXPORT String16 { |
|||
public: |
|||
String16() { } |
|||
String16(const String16& other); |
|||
String16(const UChar*, unsigned); |
|||
String16(const char*); |
|||
String16(const char*, size_t); |
|||
static String16 createUninitialized(unsigned length, UChar*& data); |
|||
|
|||
// WTF convenience constructors and helper methods.
|
|||
String16(const WebString& other) : String16(String(other)) { } |
|||
template<typename StringType1, typename StringType2> |
|||
String16(const WTF::StringAppend<StringType1, StringType2>& impl) : String16(String(impl)) { } |
|||
String16(const WTF::AtomicString& impl) : String16(String(impl)) { } |
|||
String16(const WTF::String& impl); |
|||
String16(WTF::HashTableDeletedValueType) : m_impl(WTF::HashTableDeletedValue) { } |
|||
bool isHashTableDeletedValue() const { return m_impl.isHashTableDeletedValue(); } |
|||
operator WTF::String() const { return m_impl; } |
|||
operator WTF::StringView() const { return StringView(m_impl); } |
|||
operator WebString() { return m_impl; } |
|||
const WTF::String& impl() const { return m_impl; } |
|||
String16 isolatedCopy() const { return String16(m_impl.isolatedCopy()); } |
|||
|
|||
~String16() { } |
|||
|
|||
static String16 fromInteger(int i) { return String::number(i); } |
|||
static String16 fromDouble(double number) { return Decimal::fromDouble(number).toString(); } |
|||
static String16 fromDoubleFixedPrecision(double number, int precision) { return String::numberToStringFixedWidth(number, precision); } |
|||
|
|||
size_t length() const { return m_impl.length(); } |
|||
bool isEmpty() const { return m_impl.isEmpty(); } |
|||
UChar operator[](unsigned index) const { return m_impl[index]; } |
|||
|
|||
unsigned sizeInBytes() const { return m_impl.sizeInBytes(); } |
|||
const UChar* characters16() const { return m_impl.isEmpty() ? nullptr : m_impl.characters16(); } |
|||
|
|||
static double charactersToDouble(const LChar* characters, size_t length, bool* ok = 0) { return ::charactersToDouble(characters, length, ok); } |
|||
static double charactersToDouble(const UChar* characters, size_t length, bool* ok = 0) { return ::charactersToDouble(characters, length, ok); } |
|||
|
|||
String16 substring(unsigned pos, unsigned len = UINT_MAX) const { return m_impl.substring(pos, len); } |
|||
String16 stripWhiteSpace() const { return m_impl.stripWhiteSpace(); } |
|||
|
|||
int toInt(bool* ok = 0) const { return m_impl.toInt(ok); } |
|||
|
|||
size_t find(UChar c, unsigned start = 0) const { return m_impl.find(c, start); } |
|||
size_t find(const String16& str, unsigned start = 0) const { return m_impl.find(str.impl(), start); } |
|||
size_t reverseFind(const String16& str, unsigned start = UINT_MAX) const { return m_impl.reverseFind(str.impl(), start); } |
|||
|
|||
bool startWith(const String16& s) const { return m_impl.startsWith(s); } |
|||
bool startWith(UChar character) const { return m_impl.startsWith(character); } |
|||
bool endsWith(const String16& s) const { return m_impl.endsWith(s); } |
|||
bool endsWith(UChar character) const { return m_impl.endsWith(character); } |
|||
|
|||
private: |
|||
WTF::String m_impl; |
|||
}; |
|||
|
|||
class String16Builder { |
|||
public: |
|||
String16Builder() { } |
|||
void append(const String16& str) { m_impl.append(str); }; |
|||
void append(UChar c) { m_impl.append(c); }; |
|||
void append(LChar c) { m_impl.append(c); }; |
|||
void append(char c) { m_impl.append(c); }; |
|||
void append(const UChar* c, size_t size) { m_impl.append(c, size); }; |
|||
void append(const char* characters, unsigned length) { m_impl.append(characters, length); } |
|||
void appendNumber(int number) { m_impl.appendNumber(number); } |
|||
void appendNumber(double number) { m_impl.appendNumber(number); } |
|||
String16 toString() { return m_impl.toString(); } |
|||
void reserveCapacity(unsigned newCapacity) { m_impl.reserveCapacity(newCapacity); } |
|||
|
|||
private: |
|||
WTF::StringBuilder m_impl; |
|||
}; |
|||
|
|||
inline bool operator==(const String16& a, const String16& b) { return a.impl() == b.impl(); } |
|||
inline bool operator!=(const String16& a, const String16& b) { return a.impl() != b.impl(); } |
|||
inline bool operator==(const String16& a, const char* b) { return a.impl() == b; } |
|||
|
|||
inline String16 operator+(const String16& a, const char* b) |
|||
{ |
|||
return String(a.impl() + b); |
|||
} |
|||
|
|||
inline String16 operator+(const char* a, const String16& b) |
|||
{ |
|||
return String(a + b.impl()); |
|||
} |
|||
|
|||
inline String16 operator+(const String16& a, const String16& b) |
|||
{ |
|||
return String(a.impl() + b.impl()); |
|||
} |
|||
|
|||
} // namespace protocol
|
|||
} // namespace blink
|
|||
|
|||
using String16 = blink::protocol::String16; |
|||
using String16Builder = blink::protocol::String16Builder; |
|||
|
|||
namespace WTF { |
|||
|
|||
struct String16Hash { |
|||
static unsigned hash(const String16& key) { return StringHash::hash(key.impl()); } |
|||
static bool equal(const String16& a, const String16& b) |
|||
{ |
|||
return StringHash::equal(a.impl(), b.impl()); |
|||
} |
|||
static const bool safeToCompareToEmptyOrDeleted = false; |
|||
}; |
|||
|
|||
template<typename T> struct DefaultHash; |
|||
template<> struct DefaultHash<String16> { |
|||
typedef String16Hash Hash; |
|||
}; |
|||
|
|||
template<> |
|||
struct HashTraits<String16> : SimpleClassHashTraits<String16> { |
|||
static const bool hasIsEmptyValueFunction = true; |
|||
static bool isEmptyValue(const String16& a) { return a.impl().isNull(); } |
|||
}; |
|||
|
|||
} // namespace WTF
|
|||
|
|||
namespace std { |
|||
template<> struct hash<String16> { |
|||
std::size_t operator()(const String16& string) const |
|||
{ |
|||
return StringHash::hash(string.impl()); |
|||
} |
|||
}; |
|||
|
|||
} // namespace std
|
|||
|
|||
#endif // !defined(String16WTF_h)
|
@ -0,0 +1,99 @@ |
|||
// Copyright 2016 The Chromium Authors. All rights reserved. |
|||
// Use of this source code is governed by a BSD-style license that can be |
|||
// found in the LICENSE file. |
|||
|
|||
#include <cstdlib> |
|||
#include <cstring> |
|||
#include <string> |
|||
|
|||
namespace blink { |
|||
namespace protocol { |
|||
|
|||
namespace internal { |
|||
|
|||
void intToStr(int number, char* buffer, size_t length) |
|||
{ |
|||
std::snprintf(buffer, length, "%d", number); |
|||
} |
|||
|
|||
void doubleToStr(double number, char* buffer, size_t length) |
|||
{ |
|||
std::snprintf(buffer, length, "%f", number); |
|||
} |
|||
|
|||
void doubleToStr3(double number, char* buffer, size_t length) |
|||
{ |
|||
std::snprintf(buffer, length, "%.3g", number); |
|||
} |
|||
|
|||
void doubleToStr6(double number, char* buffer, size_t length) |
|||
{ |
|||
std::snprintf(buffer, length, "%.6g", number); |
|||
} |
|||
|
|||
double strToDouble(const char* buffer, bool* ok) |
|||
{ |
|||
char* endptr; |
|||
double result = std::strtod(buffer, &endptr); |
|||
if (ok) |
|||
*ok = !(*endptr); |
|||
return result; |
|||
} |
|||
|
|||
int strToInt(const char* buffer, bool* ok) |
|||
{ |
|||
char* endptr; |
|||
int result = std::strtol(buffer, &endptr, 10); |
|||
if (ok) |
|||
*ok = !(*endptr); |
|||
return result; |
|||
} |
|||
|
|||
} // namespace internal |
|||
|
|||
String16Builder::String16Builder() |
|||
{ |
|||
} |
|||
|
|||
void String16Builder::append(const String16& s) |
|||
{ |
|||
m_buffer.insert(m_buffer.end(), s.characters16(), s.characters16() + s.length()); |
|||
} |
|||
|
|||
void String16Builder::append(UChar c) |
|||
{ |
|||
m_buffer.push_back(c); |
|||
} |
|||
|
|||
void String16Builder::append(char c) |
|||
{ |
|||
UChar u = c; |
|||
m_buffer.push_back(u); |
|||
} |
|||
|
|||
void String16Builder::append(const UChar* characters, size_t length) |
|||
{ |
|||
m_buffer.insert(m_buffer.end(), characters, characters + length); |
|||
} |
|||
|
|||
void String16Builder::append(const char* characters, size_t length) |
|||
{ |
|||
m_buffer.reserve(m_buffer.size() + length); |
|||
for (size_t i = 0; i < length; ++i, ++characters) { |
|||
UChar u = *characters; |
|||
m_buffer.push_back(u); |
|||
} |
|||
} |
|||
|
|||
String16 String16Builder::toString() |
|||
{ |
|||
return String16(m_buffer.data(), m_buffer.size()); |
|||
} |
|||
|
|||
void String16Builder::reserveCapacity(size_t capacity) |
|||
{ |
|||
m_buffer.reserve(capacity); |
|||
} |
|||
|
|||
} // namespace protocol |
|||
} // namespace blink |
@ -0,0 +1,181 @@ |
|||
// Copyright 2016 The Chromium Authors. All rights reserved. |
|||
// Use of this source code is governed by a BSD-style license that can be |
|||
// found in the LICENSE file. |
|||
|
|||
#ifndef String16_h |
|||
#define String16_h |
|||
|
|||
//#include "Collections.h" |
|||
//#include "Platform.h" |
|||
#include "{{config.class_export.header}}" |
|||
|
|||
#include <vector> |
|||
|
|||
namespace blink { |
|||
namespace protocol { |
|||
|
|||
namespace internal { |
|||
{{config.class_export.macro}} void intToStr(int, char*, size_t); |
|||
{{config.class_export.macro}} void doubleToStr(double, char*, size_t); |
|||
{{config.class_export.macro}} void doubleToStr3(double, char*, size_t); |
|||
{{config.class_export.macro}} void doubleToStr6(double, char*, size_t); |
|||
{{config.class_export.macro}} double strToDouble(const char*, bool*); |
|||
{{config.class_export.macro}} int strToInt(const char*, bool*); |
|||
} // namespace internal |
|||
|
|||
template <typename T, typename C> |
|||
class {{config.class_export.macro}} String16Base { |
|||
public: |
|||
static bool isASCII(C c) |
|||
{ |
|||
return !(c & ~0x7F); |
|||
} |
|||
|
|||
static bool isSpaceOrNewLine(C c) |
|||
{ |
|||
return isASCII(c) && c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9)); |
|||
} |
|||
|
|||
static T fromInteger(int number) |
|||
{ |
|||
char buffer[50]; |
|||
internal::intToStr(number, buffer, PROTOCOL_ARRAY_LENGTH(buffer)); |
|||
return T(buffer); |
|||
} |
|||
|
|||
static T fromDouble(double number) |
|||
{ |
|||
char buffer[100]; |
|||
internal::doubleToStr(number, buffer, PROTOCOL_ARRAY_LENGTH(buffer)); |
|||
return T(buffer); |
|||
} |
|||
|
|||
static T fromDoublePrecision3(double number) |
|||
{ |
|||
char buffer[100]; |
|||
internal::doubleToStr3(number, buffer, PROTOCOL_ARRAY_LENGTH(buffer)); |
|||
return T(buffer); |
|||
} |
|||
|
|||
static T fromDoublePrecision6(double number) |
|||
{ |
|||
char buffer[100]; |
|||
internal::doubleToStr6(number, buffer, PROTOCOL_ARRAY_LENGTH(buffer)); |
|||
return T(buffer); |
|||
} |
|||
|
|||
static double charactersToDouble(const C* characters, size_t length, bool* ok = nullptr) |
|||
{ |
|||
std::vector<char> buffer; |
|||
buffer.reserve(length + 1); |
|||
for (size_t i = 0; i < length; ++i) { |
|||
if (!isASCII(characters[i])) { |
|||
if (ok) |
|||
*ok = false; |
|||
return 0; |
|||
} |
|||
buffer.push_back(static_cast<char>(characters[i])); |
|||
} |
|||
buffer.push_back('\0'); |
|||
return internal::strToDouble(buffer.data(), ok); |
|||
} |
|||
|
|||
static int charactersToInteger(const C* characters, size_t length, bool* ok = nullptr) |
|||
{ |
|||
std::vector<char> buffer; |
|||
buffer.reserve(length + 1); |
|||
for (size_t i = 0; i < length; ++i) { |
|||
if (!isASCII(characters[i])) { |
|||
if (ok) |
|||
*ok = false; |
|||
return 0; |
|||
} |
|||
buffer.push_back(static_cast<char>(characters[i])); |
|||
} |
|||
buffer.push_back('\0'); |
|||
return internal::strToInt(buffer.data(), ok); |
|||
} |
|||
|
|||
double toDouble(bool* ok = nullptr) const |
|||
{ |
|||
const C* characters = static_cast<const T&>(*this).characters16(); |
|||
size_t length = static_cast<const T&>(*this).length(); |
|||
return charactersToDouble(characters, length, ok); |
|||
} |
|||
|
|||
int toInteger(bool* ok = nullptr) const |
|||
{ |
|||
const C* characters = static_cast<const T&>(*this).characters16(); |
|||
size_t length = static_cast<const T&>(*this).length(); |
|||
return charactersToInteger(characters, length, ok); |
|||
} |
|||
|
|||
T stripWhiteSpace() const |
|||
{ |
|||
size_t length = static_cast<const T&>(*this).length(); |
|||
if (!length) |
|||
return T(); |
|||
|
|||
unsigned start = 0; |
|||
unsigned end = length - 1; |
|||
const C* characters = static_cast<const T&>(*this).characters16(); |
|||
|
|||
// skip white space from start |
|||
while (start <= end && isSpaceOrNewLine(characters[start])) |
|||
++start; |
|||
|
|||
// only white space |
|||
if (start > end) |
|||
return T(); |
|||
|
|||
// skip white space from end |
|||
while (end && isSpaceOrNewLine(characters[end])) |
|||
--end; |
|||
|
|||
if (!start && end == length - 1) |
|||
return T(static_cast<const T&>(*this)); |
|||
return T(characters + start, end + 1 - start); |
|||
} |
|||
|
|||
bool startsWith(const char* prefix) const |
|||
{ |
|||
const C* characters = static_cast<const T&>(*this).characters16(); |
|||
size_t length = static_cast<const T&>(*this).length(); |
|||
for (size_t i = 0, j = 0; prefix[j] && i < length; ++i, ++j) { |
|||
if (characters[i] != prefix[j]) |
|||
return false; |
|||
} |
|||
return true; |
|||
} |
|||
}; |
|||
|
|||
} // namespace protocol |
|||
} // namespace blink |
|||
|
|||
#include "{{config.lib.string16_header}}" |
|||
|
|||
namespace blink { |
|||
namespace protocol { |
|||
|
|||
class {{config.class_export.macro}} String16Builder { |
|||
public: |
|||
String16Builder(); |
|||
void append(const String16&); |
|||
void append(UChar); |
|||
void append(char); |
|||
void append(const UChar*, size_t); |
|||
void append(const char*, size_t); |
|||
String16 toString(); |
|||
void reserveCapacity(size_t); |
|||
|
|||
private: |
|||
std::vector<UChar> m_buffer; |
|||
}; |
|||
|
|||
} // namespace protocol |
|||
} // namespace blink |
|||
|
|||
using String16 = blink::protocol::String16; |
|||
using String16Builder = blink::protocol::String16Builder; |
|||
|
|||
#endif // !defined(String16_h) |
@ -0,0 +1,34 @@ |
|||
{ |
|||
"protocol": { |
|||
"path": "protocol/sample_protocol.json", |
|||
"package": "include/generated/files/like/this", |
|||
"output": "place/generated/files/here" |
|||
}, |
|||
|
|||
"imported": { |
|||
"path": "../relative/path/imported_protocol.json", |
|||
"package": "include/imported/files/like/this" |
|||
}, |
|||
|
|||
"exported": { |
|||
"package": "include/exported/files/like/this", |
|||
"output": "place/exported/files/here" |
|||
}, |
|||
|
|||
"string": { |
|||
"class_name": "String16" |
|||
}, |
|||
|
|||
"lib": { |
|||
"output": "place/generated/lib/files/here", |
|||
"string16_header": "sting16/implementation.h", |
|||
"platform_header": "platform/implementation.h" |
|||
}, |
|||
|
|||
"lib_package": "include/lib/files/like/this", |
|||
|
|||
"class_export": { |
|||
"macro": "LIB_EXPORT", |
|||
"header": "lib/export.h" |
|||
} |
|||
} |
@ -0,0 +1,104 @@ |
|||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
|||
// found in the LICENSE file.
|
|||
|
|||
#ifndef String16STL_h |
|||
#define String16STL_h |
|||
|
|||
#include <cctype> |
|||
#include <climits> |
|||
#include <cstdlib> |
|||
#include <cstring> |
|||
#include <stdint.h> |
|||
#include <string> |
|||
#include <vector> |
|||
|
|||
using UChar = uint16_t; |
|||
|
|||
namespace blink { |
|||
namespace protocol { |
|||
|
|||
class String16 : public String16Base<String16, UChar> { |
|||
public: |
|||
static const size_t kNotFound = static_cast<size_t>(-1); |
|||
|
|||
String16() { } |
|||
String16(const String16& other) : m_impl(other.m_impl) { } |
|||
String16(const UChar* characters, size_t size) : m_impl(characters, size) { } |
|||
String16(const UChar* characters) : m_impl(characters) { } |
|||
String16(const char* characters) : String16(characters, std::strlen(characters)) { } |
|||
String16(const char* characters, size_t size) |
|||
{ |
|||
m_impl.resize(size); |
|||
for (size_t i = 0; i < size; ++i) |
|||
m_impl[i] = characters[i]; |
|||
} |
|||
|
|||
String16 isolatedCopy() const { return String16(m_impl); } |
|||
const UChar* characters16() const { return m_impl.c_str(); } |
|||
size_t length() const { return m_impl.length(); } |
|||
bool isEmpty() const { return !m_impl.length(); } |
|||
UChar operator[](unsigned index) const { return m_impl[index]; } |
|||
String16 substring(unsigned pos, unsigned len = UINT_MAX) const { return String16(m_impl.substr(pos, len)); } |
|||
size_t find(const String16& str, unsigned start = 0) const { return m_impl.find(str.m_impl, start); } |
|||
size_t reverseFind(const String16& str, unsigned start = UINT_MAX) const { return m_impl.rfind(str.m_impl, start); } |
|||
|
|||
// Convenience methods.
|
|||
std::string utf8() const; |
|||
static String16 fromUTF8(const char* stringStart, size_t length); |
|||
|
|||
const std::basic_string<UChar>& impl() const { return m_impl; } |
|||
explicit String16(const std::basic_string<UChar>& impl) : m_impl(impl) { } |
|||
|
|||
std::size_t hash() const |
|||
{ |
|||
if (!has_hash) { |
|||
size_t hash = 0; |
|||
for (size_t i = 0; i < length(); ++i) |
|||
hash = 31 * hash + m_impl[i]; |
|||
hash_code = hash; |
|||
has_hash = true; |
|||
} |
|||
return hash_code; |
|||
} |
|||
|
|||
private: |
|||
std::basic_string<UChar> m_impl; |
|||
mutable bool has_hash = false; |
|||
mutable std::size_t hash_code = 0; |
|||
}; |
|||
|
|||
inline bool operator==(const String16& a, const String16& b) { return a.impl() == b.impl(); } |
|||
inline bool operator<(const String16& a, const String16& b) { return a.impl() < b.impl(); } |
|||
inline bool operator!=(const String16& a, const String16& b) { return a.impl() != b.impl(); } |
|||
inline bool operator==(const String16& a, const char* b) { return a.impl() == String16(b).impl(); } |
|||
inline String16 operator+(const String16& a, const char* b) { return String16(a.impl() + String16(b).impl()); } |
|||
inline String16 operator+(const char* a, const String16& b) { return String16(String16(a).impl() + b.impl()); } |
|||
inline String16 operator+(const String16& a, const String16& b) { return String16(a.impl() + b.impl()); } |
|||
|
|||
} // namespace protocol
|
|||
} // namespace blink
|
|||
|
|||
#if !defined(__APPLE__) || defined(_LIBCPP_VERSION) |
|||
|
|||
namespace std { |
|||
template<> struct hash<blink::protocol::String16> { |
|||
std::size_t operator()(const blink::protocol::String16& string) const |
|||
{ |
|||
return string.hash(); |
|||
} |
|||
}; |
|||
|
|||
} // namespace std
|
|||
|
|||
#endif // !defined(__APPLE__) || defined(_LIBCPP_VERSION)
|
|||
|
|||
class InspectorProtocolConvenienceStringType { |
|||
public: |
|||
// This class should not be ever instantiated, so we don't implement constructors.
|
|||
InspectorProtocolConvenienceStringType(); |
|||
InspectorProtocolConvenienceStringType(const blink::protocol::String16& other); |
|||
operator blink::protocol::String16() const { return blink::protocol::String16(); }; |
|||
}; |
|||
|
|||
#endif // !defined(String16STL_h)
|
@ -0,0 +1,111 @@ |
|||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
|||
// found in the LICENSE file.
|
|||
|
|||
#ifndef String16WTF_h |
|||
#define String16WTF_h |
|||
|
|||
#include "platform/Decimal.h" |
|||
#include "public/platform/WebString.h" |
|||
#include "wtf/text/StringBuilder.h" |
|||
#include "wtf/text/StringConcatenate.h" |
|||
#include "wtf/text/StringHash.h" |
|||
#include "wtf/text/StringToNumber.h" |
|||
#include "wtf/text/StringView.h" |
|||
#include "wtf/text/WTFString.h" |
|||
|
|||
namespace blink { |
|||
namespace protocol { |
|||
|
|||
class PLATFORM_EXPORT String16 : public String16Base<String16, UChar> { |
|||
public: |
|||
static const size_t kNotFound = WTF::kNotFound; |
|||
|
|||
String16() { } |
|||
String16(const String16& other) : m_impl(other.m_impl) { } |
|||
String16(const UChar* characters, unsigned length) : m_impl(characters, length) { } |
|||
String16(const char* characters) : String16(characters, strlen(characters)) { } |
|||
String16(const char* characters, size_t length) |
|||
{ |
|||
UChar* data; |
|||
m_impl = WTF::String::createUninitialized(length, data); |
|||
for (size_t i = 0; i < length; ++i) |
|||
data[i] = characters[i]; |
|||
} |
|||
|
|||
~String16() { } |
|||
|
|||
String16 isolatedCopy() const { return String16(m_impl.isolatedCopy()); } |
|||
const UChar* characters16() const { return m_impl.isEmpty() ? nullptr : m_impl.characters16(); } |
|||
size_t length() const { return m_impl.length(); } |
|||
bool isEmpty() const { return m_impl.isEmpty(); } |
|||
UChar operator[](unsigned index) const { return m_impl[index]; } |
|||
String16 substring(unsigned pos, unsigned len = UINT_MAX) const { return m_impl.substring(pos, len); } |
|||
size_t find(const String16& str, unsigned start = 0) const { return m_impl.find(str.impl(), start); } |
|||
size_t reverseFind(const String16& str, unsigned start = UINT_MAX) const { return m_impl.reverseFind(str.impl(), start); } |
|||
|
|||
// WTF convenience constructors and helper methods.
|
|||
String16(const WebString& other) : String16(String(other)) { } |
|||
template<typename StringType1, typename StringType2> |
|||
String16(const WTF::StringAppend<StringType1, StringType2>& impl) : String16(String(impl)) { } |
|||
String16(const WTF::AtomicString& impl) : String16(String(impl)) { } |
|||
String16(const WTF::String& impl) : m_impl(impl) { m_impl.ensure16Bit(); } |
|||
String16(WTF::HashTableDeletedValueType) : m_impl(WTF::HashTableDeletedValue) { } |
|||
bool isHashTableDeletedValue() const { return m_impl.isHashTableDeletedValue(); } |
|||
operator WTF::String() const { return m_impl; } |
|||
operator WTF::StringView() const { return StringView(m_impl); } |
|||
operator WebString() { return m_impl; } |
|||
const WTF::String& impl() const { return m_impl; } |
|||
|
|||
private: |
|||
WTF::String m_impl; |
|||
}; |
|||
|
|||
inline bool operator==(const String16& a, const String16& b) { return a.impl() == b.impl(); } |
|||
inline bool operator!=(const String16& a, const String16& b) { return a.impl() != b.impl(); } |
|||
inline bool operator==(const String16& a, const char* b) { return a.impl() == b; } |
|||
inline String16 operator+(const String16& a, const char* b) { return String16(a.impl() + b); } |
|||
inline String16 operator+(const char* a, const String16& b) { return String16(a + b.impl()); } |
|||
inline String16 operator+(const String16& a, const String16& b) { return String16(a.impl() + b.impl()); } |
|||
|
|||
} // namespace protocol
|
|||
} // namespace blink
|
|||
|
|||
namespace std { |
|||
template<> struct hash<blink::protocol::String16> { |
|||
std::size_t operator()(const blink::protocol::String16& string) const |
|||
{ |
|||
return StringHash::hash(string.impl()); |
|||
} |
|||
}; |
|||
} // namespace std
|
|||
|
|||
using InspectorProtocolConvenienceStringType = WTF::String; |
|||
|
|||
// WTF helpers below this line.
|
|||
|
|||
namespace WTF { |
|||
|
|||
struct String16Hash { |
|||
static unsigned hash(const blink::protocol::String16& key) { return StringHash::hash(key.impl()); } |
|||
static bool equal(const blink::protocol::String16& a, const blink::protocol::String16& b) |
|||
{ |
|||
return StringHash::equal(a.impl(), b.impl()); |
|||
} |
|||
static const bool safeToCompareToEmptyOrDeleted = false; |
|||
}; |
|||
|
|||
template<typename T> struct DefaultHash; |
|||
template<> struct DefaultHash<blink::protocol::String16> { |
|||
typedef String16Hash Hash; |
|||
}; |
|||
|
|||
template<> |
|||
struct HashTraits<blink::protocol::String16> : SimpleClassHashTraits<blink::protocol::String16> { |
|||
static const bool hasIsEmptyValueFunction = true; |
|||
static bool isEmptyValue(const blink::protocol::String16& a) { return a.impl().isNull(); } |
|||
}; |
|||
|
|||
} // namespace WTF
|
|||
|
|||
#endif // !defined(String16WTF_h)
|
@ -0,0 +1,29 @@ |
|||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
|||
// found in the LICENSE file.
|
|||
|
|||
#include "platform/v8_inspector/V8SchemaAgentImpl.h" |
|||
|
|||
#include "platform/v8_inspector/V8InspectorSessionImpl.h" |
|||
|
|||
namespace v8_inspector { |
|||
|
|||
V8SchemaAgentImpl::V8SchemaAgentImpl(V8InspectorSessionImpl* session, protocol::FrontendChannel* frontendChannel, protocol::DictionaryValue* state) |
|||
: m_session(session) |
|||
, m_frontend(frontendChannel) |
|||
{ |
|||
} |
|||
|
|||
V8SchemaAgentImpl::~V8SchemaAgentImpl() |
|||
{ |
|||
} |
|||
|
|||
void V8SchemaAgentImpl::getDomains(ErrorString*, std::unique_ptr<protocol::Array<protocol::Schema::Domain>>* result) |
|||
{ |
|||
std::vector<std::unique_ptr<protocol::Schema::Domain>> domains = m_session->supportedDomainsImpl(); |
|||
*result = protocol::Array<protocol::Schema::Domain>::create(); |
|||
for (size_t i = 0; i < domains.size(); ++i) |
|||
(*result)->addItem(std::move(domains[i])); |
|||
} |
|||
|
|||
} // namespace v8_inspector
|
@ -0,0 +1,33 @@ |
|||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
|||
// found in the LICENSE file.
|
|||
|
|||
#ifndef V8SchemaAgentImpl_h |
|||
#define V8SchemaAgentImpl_h |
|||
|
|||
#include "platform/inspector_protocol/InspectorProtocol.h" |
|||
#include "platform/v8_inspector/protocol/Schema.h" |
|||
|
|||
namespace v8_inspector { |
|||
|
|||
class V8InspectorSessionImpl; |
|||
|
|||
namespace protocol = blink::protocol; |
|||
|
|||
class V8SchemaAgentImpl : public protocol::Schema::Backend { |
|||
PROTOCOL_DISALLOW_COPY(V8SchemaAgentImpl); |
|||
public: |
|||
V8SchemaAgentImpl(V8InspectorSessionImpl*, protocol::FrontendChannel*, protocol::DictionaryValue* state); |
|||
~V8SchemaAgentImpl() override; |
|||
|
|||
void getDomains(ErrorString*, std::unique_ptr<protocol::Array<protocol::Schema::Domain>>*) override; |
|||
|
|||
private: |
|||
V8InspectorSessionImpl* m_session; |
|||
protocol::Schema::Frontend m_frontend; |
|||
}; |
|||
|
|||
} // namespace v8_inspector
|
|||
|
|||
|
|||
#endif // !defined(V8SchemaAgentImpl_h)
|
@ -0,0 +1,90 @@ |
|||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
|||
// found in the LICENSE file.
|
|||
|
|||
#include "platform/v8_inspector/V8ValueCopier.h" |
|||
|
|||
namespace v8_inspector { |
|||
|
|||
namespace { |
|||
|
|||
static int kMaxDepth = 20; |
|||
static int kMaxCalls = 1000; |
|||
|
|||
class V8ValueCopier { |
|||
public: |
|||
v8::MaybeLocal<v8::Value> copy(v8::Local<v8::Value> value, int depth) |
|||
{ |
|||
if (++m_calls > kMaxCalls || depth > kMaxDepth) |
|||
return v8::MaybeLocal<v8::Value>(); |
|||
|
|||
if (value.IsEmpty()) |
|||
return v8::MaybeLocal<v8::Value>(); |
|||
if (value->IsNull() || value->IsUndefined() || value->IsBoolean() || value->IsString() || value->IsNumber()) |
|||
return value; |
|||
if (!value->IsObject()) |
|||
return v8::MaybeLocal<v8::Value>(); |
|||
v8::Local<v8::Object> object = value.As<v8::Object>(); |
|||
if (object->CreationContext() != m_from) |
|||
return value; |
|||
|
|||
if (object->IsArray()) { |
|||
v8::Local<v8::Array> array = object.As<v8::Array>(); |
|||
v8::Local<v8::Array> result = v8::Array::New(m_isolate, array->Length()); |
|||
if (!result->SetPrototype(m_to, v8::Null(m_isolate)).FromMaybe(false)) |
|||
return v8::MaybeLocal<v8::Value>(); |
|||
for (size_t i = 0; i < array->Length(); ++i) { |
|||
v8::Local<v8::Value> item; |
|||
if (!array->Get(m_from, i).ToLocal(&item)) |
|||
return v8::MaybeLocal<v8::Value>(); |
|||
v8::Local<v8::Value> copied; |
|||
if (!copy(item, depth + 1).ToLocal(&copied)) |
|||
return v8::MaybeLocal<v8::Value>(); |
|||
if (!result->Set(m_to, i, copied).FromMaybe(false)) |
|||
return v8::MaybeLocal<v8::Value>(); |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
|
|||
v8::Local<v8::Object> result = v8::Object::New(m_isolate); |
|||
if (!result->SetPrototype(m_to, v8::Null(m_isolate)).FromMaybe(false)) |
|||
return v8::MaybeLocal<v8::Value>(); |
|||
v8::Local<v8::Array> properties; |
|||
if (!object->GetOwnPropertyNames(m_from).ToLocal(&properties)) |
|||
return v8::MaybeLocal<v8::Value>(); |
|||
for (size_t i = 0; i < properties->Length(); ++i) { |
|||
v8::Local<v8::Value> name; |
|||
if (!properties->Get(m_from, i).ToLocal(&name) || !name->IsString()) |
|||
return v8::MaybeLocal<v8::Value>(); |
|||
v8::Local<v8::Value> property; |
|||
if (!object->Get(m_from, name).ToLocal(&property)) |
|||
return v8::MaybeLocal<v8::Value>(); |
|||
v8::Local<v8::Value> copied; |
|||
if (!copy(property, depth + 1).ToLocal(&copied)) |
|||
return v8::MaybeLocal<v8::Value>(); |
|||
if (!result->Set(m_to, name, copied).FromMaybe(false)) |
|||
return v8::MaybeLocal<v8::Value>(); |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
v8::Isolate* m_isolate; |
|||
v8::Local<v8::Context> m_from; |
|||
v8::Local<v8::Context> m_to; |
|||
int m_calls; |
|||
}; |
|||
|
|||
} // namespace
|
|||
|
|||
v8::MaybeLocal<v8::Value> copyValueFromDebuggerContext(v8::Isolate* isolate, v8::Local<v8::Context> debuggerContext, v8::Local<v8::Context> toContext, v8::Local<v8::Value> value) |
|||
{ |
|||
V8ValueCopier copier; |
|||
copier.m_isolate = isolate; |
|||
copier.m_from = debuggerContext; |
|||
copier.m_to = toContext; |
|||
copier.m_calls = 0; |
|||
return copier.copy(value, 0); |
|||
} |
|||
|
|||
} // namespace v8_inspector
|
@ -0,0 +1,16 @@ |
|||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
|||
// found in the LICENSE file.
|
|||
|
|||
#ifndef V8ValueCopier_h |
|||
#define V8ValueCopier_h |
|||
|
|||
#include <v8.h> |
|||
|
|||
namespace v8_inspector { |
|||
|
|||
v8::MaybeLocal<v8::Value> copyValueFromDebuggerContext(v8::Isolate*, v8::Local<v8::Context> debuggerContext, v8::Local<v8::Context> toContext, v8::Local<v8::Value>); |
|||
|
|||
} // namespace v8_inspector
|
|||
|
|||
#endif // !defined(V8ValueCopier_h)
|
@ -0,0 +1,29 @@ |
|||
{ |
|||
"protocol": { |
|||
"path": "js_protocol.json", |
|||
"package": "platform/v8_inspector/protocol", |
|||
"output": "v8_inspector/protocol" |
|||
}, |
|||
|
|||
"exported": { |
|||
"package": "platform/v8_inspector/public/protocol", |
|||
"output": "v8_inspector/public/protocol" |
|||
}, |
|||
|
|||
"string": { |
|||
"class_name": "String16" |
|||
}, |
|||
|
|||
"lib": { |
|||
"output": "inspector_protocol", |
|||
"string16_header": "platform/v8_inspector/String16WTF.h", |
|||
"platform_header": "platform/v8_inspector/PlatformWTF.h" |
|||
}, |
|||
|
|||
"lib_package": "platform/inspector_protocol", |
|||
|
|||
"class_export": { |
|||
"macro": "PLATFORM_EXPORT", |
|||
"header": "platform/PlatformExport.h" |
|||
} |
|||
} |
@ -0,0 +1,29 @@ |
|||
{ |
|||
"protocol": { |
|||
"path": "js_protocol.json", |
|||
"package": "platform/v8_inspector/protocol", |
|||
"output": "v8_inspector/protocol" |
|||
}, |
|||
|
|||
"exported": { |
|||
"package": "platform/v8_inspector/public/protocol", |
|||
"output": "v8_inspector/public/protocol" |
|||
}, |
|||
|
|||
"string": { |
|||
"class_name": "String16" |
|||
}, |
|||
|
|||
"lib": { |
|||
"output": "inspector_protocol", |
|||
"string16_header": "platform/v8_inspector/String16STL.h", |
|||
"platform_header": "platform/v8_inspector/PlatformSTL.h" |
|||
}, |
|||
|
|||
"lib_package": "platform/inspector_protocol", |
|||
|
|||
"class_export": { |
|||
"macro": "PLATFORM_EXPORT", |
|||
"header": "platform/PlatformExport.h" |
|||
} |
|||
} |
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue