Commit 96f45eca authored by adithyas's avatar adithyas Committed by Commit bot

Move more files to platform/bindings

Moves TraceWrapperMember, SharedPersistent, IDLDictionaryBase and ToV8 to platform/bindings. Also moves some ScriptValue functions in ToV8 to ToV8ForCore as ScriptValue is not moving to platform/bindings right now.

BUG=682322

Review-Url: https://codereview.chromium.org/2843143002
Cr-Commit-Position: refs/heads/master@{#468053}
parent fe20a56c
...@@ -28,42 +28,6 @@ ...@@ -28,42 +28,6 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef SharedPersistent_h // This file has been moved to platform/bindings/SharedPersistent.h.
#define SharedPersistent_h // TODO(adithyas): Remove this file.
#include "platform/bindings/SharedPersistent.h"
#include "bindings/core/v8/ScopedPersistent.h"
#include "platform/wtf/PassRefPtr.h"
#include "platform/wtf/RefCounted.h"
#include "v8/include/v8.h"
namespace blink {
template <typename T>
class SharedPersistent : public RefCounted<SharedPersistent<T>> {
WTF_MAKE_NONCOPYABLE(SharedPersistent);
public:
static PassRefPtr<SharedPersistent<T>> Create(v8::Local<T> value,
v8::Isolate* isolate) {
return AdoptRef(new SharedPersistent<T>(value, isolate));
}
v8::Local<T> NewLocal(v8::Isolate* isolate) const {
return value_.NewLocal(isolate);
}
bool IsEmpty() { return value_.IsEmpty(); }
bool operator==(const SharedPersistent<T>& other) {
return value_ == other.value_;
}
private:
explicit SharedPersistent(v8::Local<T> value, v8::Isolate* isolate)
: value_(isolate, value) {}
ScopedPersistent<T> value_;
};
} // namespace blink
#endif // SharedPersistent_h
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
// ToV8() provides C++ -> V8 conversion. Note that ToV8() can return an empty // ToV8() provides C++ -> V8 conversion. Note that ToV8() can return an empty
// handle. Call sites must check IsEmpty() before using return value. // handle. Call sites must check IsEmpty() before using return value.
#include "bindings/core/v8/IDLDictionaryBase.h"
#include "bindings/core/v8/ScriptValue.h"
#include "bindings/core/v8/ToV8.h" #include "bindings/core/v8/ToV8.h"
#include "bindings/core/v8/V8NodeFilterCondition.h" #include "bindings/core/v8/V8NodeFilterCondition.h"
#include "core/dom/ArrayBufferViewHelpers.h" #include "core/dom/ArrayBufferViewHelpers.h"
...@@ -52,6 +54,31 @@ inline v8::Local<v8::Value> ToV8(const V8NodeFilterCondition* value, ...@@ -52,6 +54,31 @@ inline v8::Local<v8::Value> ToV8(const V8NodeFilterCondition* value,
return value ? value->Callback(isolate) : v8::Null(isolate).As<v8::Value>(); return value ? value->Callback(isolate) : v8::Null(isolate).As<v8::Value>();
} }
// Dictionary
inline v8::Local<v8::Value> ToV8(const IDLDictionaryBase& value,
v8::Local<v8::Object> creation_context,
v8::Isolate* isolate) {
return value.ToV8Impl(creation_context, isolate);
}
// ScriptValue
inline v8::Local<v8::Value> ToV8(const ScriptValue& value,
v8::Local<v8::Object> creation_context,
v8::Isolate* isolate) {
if (value.IsEmpty())
return v8::Undefined(isolate);
return value.V8Value();
}
// Cannot define in ScriptValue because of the circular dependency between toV8
// and ScriptValue
template <typename T>
inline ScriptValue ScriptValue::From(ScriptState* script_state, T&& value) {
return ScriptValue(script_state, ToV8(std::forward<T>(value), script_state));
}
} // namespace blink } // namespace blink
#endif // ToV8ForCore_h #endif // ToV8ForCore_h
...@@ -2,146 +2,6 @@ ...@@ -2,146 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef TraceWrapperMember_h // This file has been moved to platform/bindings/TraceWrapperMember.h.
#define TraceWrapperMember_h // TODO(adithyas): Remove this file.
#include "platform/bindings/TraceWrapperMember.h"
#include "bindings/core/v8/ScriptWrappableVisitor.h"
#include "platform/heap/HeapAllocator.h"
namespace blink {
class HeapObjectHeader;
template <typename T>
class Member;
/**
* TraceWrapperMember is used for Member fields that should participate in
* wrapper tracing, i.e., strongly hold a ScriptWrappable alive. All
* TraceWrapperMember fields must be traced in the class' traceWrappers method.
*/
template <class T>
class TraceWrapperMember : public Member<T> {
DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
public:
TraceWrapperMember(void* parent, T* raw) : Member<T>(raw), parent_(parent) {
#if DCHECK_IS_ON()
if (parent_) {
HeapObjectHeader::CheckFromPayload(parent_);
}
#endif
// We don't require a write barrier here as TraceWrapperMember is used for
// the following scenarios:
// - Initial initialization: The write barrier will not fire as the parent
// is initially white.
// - Wrapping when inserting into a container: The write barrier will fire
// upon establishing the move into the container.
// - Assignment to a field: The regular assignment operator will fire the
// write barrier.
// Note that support for black allocation would require a barrier here.
}
TraceWrapperMember(WTF::HashTableDeletedValueType x)
: Member<T>(x), parent_(nullptr) {}
/**
* Copying a TraceWrapperMember means that its backpointer will also be
* copied.
*/
TraceWrapperMember(const TraceWrapperMember& other) { *this = other; }
TraceWrapperMember& operator=(const TraceWrapperMember& other) {
DCHECK(!other.raw_ || other.parent_);
parent_ = other.parent_;
Member<T>::operator=(other);
ScriptWrappableVisitor::WriteBarrier(parent_, other);
return *this;
}
TraceWrapperMember& operator=(const Member<T>& other) {
DCHECK(!TraceWrapperMemberIsNotInitialized());
Member<T>::operator=(other);
ScriptWrappableVisitor::WriteBarrier(parent_, other);
return *this;
}
TraceWrapperMember& operator=(T* other) {
DCHECK(!TraceWrapperMemberIsNotInitialized());
Member<T>::operator=(other);
ScriptWrappableVisitor::WriteBarrier(parent_, other);
return *this;
}
TraceWrapperMember& operator=(std::nullptr_t) {
// No need for a write barrier when assigning nullptr.
Member<T>::operator=(nullptr);
return *this;
}
void* Parent() { return parent_; }
private:
bool TraceWrapperMemberIsNotInitialized() { return !parent_; }
/**
* The parent object holding strongly onto the actual Member.
*/
void* parent_;
};
/**
* Swaps two HeapVectors specialized for TraceWrapperMember. The custom swap
* function is required as TraceWrapperMember contains ownership information
* which is not copyable but has to be explicitly specified.
*/
template <typename T>
void swap(HeapVector<TraceWrapperMember<T>>& a,
HeapVector<TraceWrapperMember<T>>& b,
void* parent_for_a,
void* parent_for_b) {
HeapVector<TraceWrapperMember<T>> temp;
temp.ReserveCapacity(a.size());
for (auto item : a) {
temp.push_back(TraceWrapperMember<T>(parent_for_b, item.Get()));
}
a.clear();
a.ReserveCapacity(b.size());
for (auto item : b) {
a.push_back(TraceWrapperMember<T>(parent_for_a, item.Get()));
}
b.clear();
b.ReserveCapacity(temp.size());
for (auto item : temp) {
b.push_back(TraceWrapperMember<T>(parent_for_b, item.Get()));
}
}
/**
* Swaps two HeapVectors, one containing TraceWrapperMember and one with
* regular Members. The custom swap function is required as
* TraceWrapperMember contains ownership information which is not copyable
* but has to be explicitly specified.
*/
template <typename T>
void swap(HeapVector<TraceWrapperMember<T>>& a,
HeapVector<Member<T>>& b,
void* parent_for_a) {
HeapVector<TraceWrapperMember<T>> temp;
temp.ReserveCapacity(a.size());
for (auto item : a) {
temp.push_back(TraceWrapperMember<T>(item.Parent(), item.Get()));
}
a.clear();
a.ReserveCapacity(b.size());
for (auto item : b) {
a.push_back(TraceWrapperMember<T>(parent_for_a, item.Get()));
}
b.clear();
b.ReserveCapacity(temp.size());
for (auto item : temp) {
b.push_back(item.Get());
}
}
} // namespace blink
#endif // TraceWrapperMember_h
...@@ -488,8 +488,11 @@ component("platform") { ...@@ -488,8 +488,11 @@ component("platform") {
"bindings/ScriptWrappableVisitor.cpp", "bindings/ScriptWrappableVisitor.cpp",
"bindings/ScriptWrappableVisitor.h", "bindings/ScriptWrappableVisitor.h",
"bindings/ScriptWrappableVisitorVerifier.h", "bindings/ScriptWrappableVisitorVerifier.h",
"bindings/SharedPersistent.h",
"bindings/StringResource.cpp", "bindings/StringResource.cpp",
"bindings/StringResource.h", "bindings/StringResource.h",
"bindings/ToV8.h",
"bindings/TraceWrapperMember.h",
"bindings/TraceWrapperV8Reference.h", "bindings/TraceWrapperV8Reference.h",
"bindings/V0CustomElementBinding.cpp", "bindings/V0CustomElementBinding.cpp",
"bindings/V0CustomElementBinding.h", "bindings/V0CustomElementBinding.h",
......
/*
* Copyright (C) 2009 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 SharedPersistent_h
#define SharedPersistent_h
#include "platform/bindings/ScopedPersistent.h"
#include "platform/wtf/PassRefPtr.h"
#include "platform/wtf/RefCounted.h"
#include "v8/include/v8.h"
namespace blink {
template <typename T>
class SharedPersistent : public RefCounted<SharedPersistent<T>> {
WTF_MAKE_NONCOPYABLE(SharedPersistent);
public:
static PassRefPtr<SharedPersistent<T>> Create(v8::Local<T> value,
v8::Isolate* isolate) {
return AdoptRef(new SharedPersistent<T>(value, isolate));
}
v8::Local<T> NewLocal(v8::Isolate* isolate) const {
return value_.NewLocal(isolate);
}
bool IsEmpty() { return value_.IsEmpty(); }
bool operator==(const SharedPersistent<T>& other) {
return value_ == other.value_;
}
private:
explicit SharedPersistent(v8::Local<T> value, v8::Isolate* isolate)
: value_(isolate, value) {}
ScopedPersistent<T> value_;
};
} // namespace blink
#endif // SharedPersistent_h
This diff is collapsed.
// 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 TraceWrapperMember_h
#define TraceWrapperMember_h
#include "platform/bindings/ScriptWrappableVisitor.h"
#include "platform/heap/HeapAllocator.h"
namespace blink {
class HeapObjectHeader;
template <typename T>
class Member;
/**
* TraceWrapperMember is used for Member fields that should participate in
* wrapper tracing, i.e., strongly hold a ScriptWrappable alive. All
* TraceWrapperMember fields must be traced in the class' traceWrappers method.
*/
template <class T>
class TraceWrapperMember : public Member<T> {
DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
public:
TraceWrapperMember(void* parent, T* raw) : Member<T>(raw), parent_(parent) {
#if DCHECK_IS_ON()
if (parent_) {
HeapObjectHeader::CheckFromPayload(parent_);
}
#endif
// We don't require a write barrier here as TraceWrapperMember is used for
// the following scenarios:
// - Initial initialization: The write barrier will not fire as the parent
// is initially white.
// - Wrapping when inserting into a container: The write barrier will fire
// upon establishing the move into the container.
// - Assignment to a field: The regular assignment operator will fire the
// write barrier.
// Note that support for black allocation would require a barrier here.
}
TraceWrapperMember(WTF::HashTableDeletedValueType x)
: Member<T>(x), parent_(nullptr) {}
/**
* Copying a TraceWrapperMember means that its backpointer will also be
* copied.
*/
TraceWrapperMember(const TraceWrapperMember& other) { *this = other; }
TraceWrapperMember& operator=(const TraceWrapperMember& other) {
DCHECK(!other.raw_ || other.parent_);
parent_ = other.parent_;
Member<T>::operator=(other);
ScriptWrappableVisitor::WriteBarrier(parent_, other);
return *this;
}
TraceWrapperMember& operator=(const Member<T>& other) {
DCHECK(!TraceWrapperMemberIsNotInitialized());
Member<T>::operator=(other);
ScriptWrappableVisitor::WriteBarrier(parent_, other);
return *this;
}
TraceWrapperMember& operator=(T* other) {
DCHECK(!TraceWrapperMemberIsNotInitialized());
Member<T>::operator=(other);
ScriptWrappableVisitor::WriteBarrier(parent_, other);
return *this;
}
TraceWrapperMember& operator=(std::nullptr_t) {
// No need for a write barrier when assigning nullptr.
Member<T>::operator=(nullptr);
return *this;
}
void* Parent() { return parent_; }
private:
bool TraceWrapperMemberIsNotInitialized() { return !parent_; }
/**
* The parent object holding strongly onto the actual Member.
*/
void* parent_;
};
/**
* Swaps two HeapVectors specialized for TraceWrapperMember. The custom swap
* function is required as TraceWrapperMember contains ownership information
* which is not copyable but has to be explicitly specified.
*/
template <typename T>
void swap(HeapVector<TraceWrapperMember<T>>& a,
HeapVector<TraceWrapperMember<T>>& b,
void* parent_for_a,
void* parent_for_b) {
HeapVector<TraceWrapperMember<T>> temp;
temp.ReserveCapacity(a.size());
for (auto item : a) {
temp.push_back(TraceWrapperMember<T>(parent_for_b, item.Get()));
}
a.clear();
a.ReserveCapacity(b.size());
for (auto item : b) {
a.push_back(TraceWrapperMember<T>(parent_for_a, item.Get()));
}
b.clear();
b.ReserveCapacity(temp.size());
for (auto item : temp) {
b.push_back(TraceWrapperMember<T>(parent_for_b, item.Get()));
}
}
/**
* Swaps two HeapVectors, one containing TraceWrapperMember and one with
* regular Members. The custom swap function is required as
* TraceWrapperMember contains ownership information which is not copyable
* but has to be explicitly specified.
*/
template <typename T>
void swap(HeapVector<TraceWrapperMember<T>>& a,
HeapVector<Member<T>>& b,
void* parent_for_a) {
HeapVector<TraceWrapperMember<T>> temp;
temp.ReserveCapacity(a.size());
for (auto item : a) {
temp.push_back(TraceWrapperMember<T>(item.Parent(), item.Get()));
}
a.clear();
a.ReserveCapacity(b.size());
for (auto item : b) {
a.push_back(TraceWrapperMember<T>(parent_for_a, item.Get()));
}
b.clear();
b.ReserveCapacity(temp.size());
for (auto item : temp) {
b.push_back(item.Get());
}
}
} // namespace blink
#endif // TraceWrapperMember_h
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment