Skip to content

Commit

Permalink
IndexedDB: Reduce IDBAny usage in IDBCursor
Browse files Browse the repository at this point in the history
Use IDL-generated union type 'IDBObjectStoreOrIDBIndex' instead
of IDBAny. This aligns better with the spec.

Bug: 798819
Change-Id: I2296cf1cb99dc4ed954e3d79dafa8f70d4796851
Reviewed-on: https://chromium-review.googlesource.com/861682
Reviewed-by: Victor Costan <pwnall@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Reviewed-by: Jeremy Roman <jbroman@chromium.org>
Commit-Queue: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#528988}
  • Loading branch information
Xunran Ding authored and Commit Bot committed Jan 12, 2018
1 parent 40039c0 commit b9868b8
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 28 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@ Xu Xing <xing.xu@intel.com>
Xuefei Ren <xrenishere@gmail.com>
Xueqing Huang <huangxueqing@xiaomi.com>
Xun Sun <xun.sun@intel.com>
Xunran Ding <xunran.ding@samsung.com>
Xunran Ding <dingxunran@gmail.com>
Yael Aharon <yael.aharon@intel.com>
Yair Yogev <progame@chromium.org>
Expand Down
2 changes: 2 additions & 0 deletions third_party/WebKit/Source/bindings/modules/v8/generated.gni
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ bindings_modules_generated_union_type_files = [
"$bindings_modules_v8_output_dir/float32_array_or_float64_array_or_dom_matrix.h",
"$bindings_modules_v8_output_dir/html_canvas_element_or_offscreen_canvas.cc",
"$bindings_modules_v8_output_dir/html_canvas_element_or_offscreen_canvas.h",
"$bindings_modules_v8_output_dir/idb_object_store_or_idb_index.cc",
"$bindings_modules_v8_output_dir/idb_object_store_or_idb_index.h",
"$bindings_modules_v8_output_dir/long_or_constrain_long_range.cc",
"$bindings_modules_v8_output_dir/long_or_constrain_long_range.h",
"$bindings_modules_v8_output_dir/offscreen_rendering_context.cc",
Expand Down
25 changes: 12 additions & 13 deletions third_party/WebKit/Source/modules/indexeddb/IDBCursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace blink {
IDBCursor* IDBCursor::Create(std::unique_ptr<WebIDBCursor> backend,
WebIDBCursorDirection direction,
IDBRequest* request,
IDBAny* source,
const Source& source,
IDBTransaction* transaction) {
return new IDBCursor(std::move(backend), direction, request, source,
transaction);
Expand All @@ -60,7 +60,7 @@ IDBCursor* IDBCursor::Create(std::unique_ptr<WebIDBCursor> backend,
IDBCursor::IDBCursor(std::unique_ptr<WebIDBCursor> backend,
WebIDBCursorDirection direction,
IDBRequest* request,
IDBAny* source,
const Source& source,
IDBTransaction* transaction)
: backend_(std::move(backend)),
request_(request),
Expand All @@ -69,8 +69,7 @@ IDBCursor::IDBCursor(std::unique_ptr<WebIDBCursor> backend,
transaction_(transaction) {
DCHECK(backend_);
DCHECK(request_);
DCHECK(source_->GetType() == IDBAny::kIDBObjectStoreType ||
source_->GetType() == IDBAny::kIDBIndexType);
DCHECK(!source_.IsNull());
DCHECK(transaction_);
}

Expand Down Expand Up @@ -223,7 +222,7 @@ void IDBCursor::continuePrimaryKey(ScriptState* script_state,
return;
}

if (source_->GetType() != IDBAny::kIDBIndexType) {
if (!source_.IsIDBIndex()) {
exception_state.ThrowDOMException(kInvalidAccessError,
"The cursor's source is not an index.");
return;
Expand Down Expand Up @@ -417,8 +416,8 @@ ScriptValue IDBCursor::value(ScriptState* script_state) {
return script_value;
}

ScriptValue IDBCursor::source(ScriptState* script_state) const {
return ScriptValue::From(script_state, source_);
void IDBCursor::source(Source& source) const {
source = source_;
}

void IDBCursor::SetValueReady(std::unique_ptr<IDBKey> key,
Expand Down Expand Up @@ -468,15 +467,15 @@ const IDBKey* IDBCursor::IdbPrimaryKey() const {
}

IDBObjectStore* IDBCursor::EffectiveObjectStore() const {
if (source_->GetType() == IDBAny::kIDBObjectStoreType)
return source_->IdbObjectStore();
return source_->IdbIndex()->objectStore();
if (source_.IsIDBObjectStore())
return source_.GetAsIDBObjectStore();
return source_.GetAsIDBIndex()->objectStore();
}

bool IDBCursor::IsDeleted() const {
if (source_->GetType() == IDBAny::kIDBObjectStoreType)
return source_->IdbObjectStore()->IsDeleted();
return source_->IdbIndex()->IsDeleted();
if (source_.IsIDBObjectStore())
return source_.GetAsIDBObjectStore()->IsDeleted();
return source_.GetAsIDBIndex()->IsDeleted();
}

WebIDBCursorDirection IDBCursor::StringToDirection(
Expand Down
12 changes: 7 additions & 5 deletions third_party/WebKit/Source/modules/indexeddb/IDBCursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <memory>
#include "base/memory/scoped_refptr.h"
#include "bindings/core/v8/ScriptValue.h"
#include "bindings/modules/v8/idb_object_store_or_idb_index.h"
#include "modules/indexeddb/IDBKey.h"
#include "modules/indexeddb/IDBRequest.h"
#include "modules/indexeddb/IndexedDB.h"
Expand All @@ -40,7 +41,6 @@
namespace blink {

class ExceptionState;
class IDBAny;
class IDBTransaction;
class IDBValue;
class ScriptState;
Expand All @@ -49,12 +49,14 @@ class IDBCursor : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();

public:
using Source = IDBObjectStoreOrIDBIndex;

static WebIDBCursorDirection StringToDirection(const String& mode_string);

static IDBCursor* Create(std::unique_ptr<WebIDBCursor>,
WebIDBCursorDirection,
IDBRequest*,
IDBAny* source,
const Source&,
IDBTransaction*);
virtual ~IDBCursor();
void Trace(blink::Visitor*);
Expand All @@ -70,7 +72,7 @@ class IDBCursor : public ScriptWrappable {
ScriptValue key(ScriptState*);
ScriptValue primaryKey(ScriptState*);
ScriptValue value(ScriptState*);
ScriptValue source(ScriptState*) const;
void source(Source&) const;

IDBRequest* update(ScriptState*, const ScriptValue&, ExceptionState&);
void advance(unsigned, ExceptionState&);
Expand Down Expand Up @@ -103,7 +105,7 @@ class IDBCursor : public ScriptWrappable {
IDBCursor(std::unique_ptr<WebIDBCursor>,
WebIDBCursorDirection,
IDBRequest*,
IDBAny* source,
const Source&,
IDBTransaction*);

private:
Expand All @@ -112,7 +114,7 @@ class IDBCursor : public ScriptWrappable {
std::unique_ptr<WebIDBCursor> backend_;
Member<IDBRequest> request_;
const WebIDBCursorDirection direction_;
Member<IDBAny> source_;
Source source_;
Member<IDBTransaction> transaction_;
bool got_value_ = false;
bool key_dirty_ = true;
Expand Down
2 changes: 1 addition & 1 deletion third_party/WebKit/Source/modules/indexeddb/IDBCursor.idl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ enum IDBCursorDirection {
[
Exposed=(Window,Worker)
] interface IDBCursor {
[CallWith=ScriptState] readonly attribute any source;
readonly attribute (IDBObjectStore or IDBIndex) source;
readonly attribute IDBCursorDirection direction;
[CallWith=ScriptState, CachedAttribute=isKeyDirty] readonly attribute any key;
[CallWith=ScriptState, CachedAttribute=isPrimaryKeyDirty] readonly attribute any primaryKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ IDBCursorWithValue* IDBCursorWithValue::Create(
std::unique_ptr<WebIDBCursor> backend,
WebIDBCursorDirection direction,
IDBRequest* request,
IDBAny* source,
const Source& source,
IDBTransaction* transaction) {
return new IDBCursorWithValue(std::move(backend), direction, request, source,
transaction);
Expand All @@ -45,7 +45,7 @@ IDBCursorWithValue* IDBCursorWithValue::Create(
IDBCursorWithValue::IDBCursorWithValue(std::unique_ptr<WebIDBCursor> backend,
WebIDBCursorDirection direction,
IDBRequest* request,
IDBAny* source,
const Source& source,
IDBTransaction* transaction)
: IDBCursor(std::move(backend), direction, request, source, transaction) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

namespace blink {

class IDBAny;
class IDBRequest;
class IDBTransaction;

Expand All @@ -45,7 +44,7 @@ class IDBCursorWithValue final : public IDBCursor {
static IDBCursorWithValue* Create(std::unique_ptr<WebIDBCursor>,
WebIDBCursorDirection,
IDBRequest*,
IDBAny* source,
const Source&,
IDBTransaction*);
~IDBCursorWithValue() override;

Expand All @@ -60,7 +59,7 @@ class IDBCursorWithValue final : public IDBCursor {
IDBCursorWithValue(std::unique_ptr<WebIDBCursor>,
WebIDBCursorDirection,
IDBRequest*,
IDBAny* source,
const Source&,
IDBTransaction*);
};

Expand Down
19 changes: 15 additions & 4 deletions third_party/WebKit/Source/modules/indexeddb/IDBRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,16 @@ void IDBRequest::EnqueueResponse(const Vector<String>& string_list) {
metrics_.RecordAndReset();
}

static IDBCursor::Source ToIDBCursorSource(IDBAny* any) {
if (any->GetType() == IDBAny::kIDBObjectStoreType)
return IDBCursor::Source::FromIDBObjectStore(any->IdbObjectStore());
if (any->GetType() == IDBAny::kIDBIndexType)
return IDBCursor::Source::FromIDBIndex(any->IdbIndex());

NOTREACHED();
return IDBCursor::Source();
}

void IDBRequest::EnqueueResponse(std::unique_ptr<WebIDBCursor> backend,
std::unique_ptr<IDBKey> key,
std::unique_ptr<IDBKey> primary_key,
Expand All @@ -446,12 +456,13 @@ void IDBRequest::EnqueueResponse(std::unique_ptr<WebIDBCursor> backend,
switch (cursor_type_) {
case IndexedDB::kCursorKeyOnly:
cursor = IDBCursor::Create(std::move(backend), cursor_direction_, this,
source_.Get(), transaction_.Get());
ToIDBCursorSource(source_.Get()),
transaction_.Get());
break;
case IndexedDB::kCursorKeyAndValue:
cursor =
IDBCursorWithValue::Create(std::move(backend), cursor_direction_,
this, source_.Get(), transaction_.Get());
cursor = IDBCursorWithValue::Create(
std::move(backend), cursor_direction_, this,
ToIDBCursorSource(source_.Get()), transaction_.Get());
break;
default:
NOTREACHED();
Expand Down

0 comments on commit b9868b8

Please sign in to comment.