Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Unified Diff: third_party/WebKit/Source/bindings/core/v8/custom/V8DOMMatrixReadOnlyCustom.cpp

Issue 2749403002: WIP: Prototype using "dictionary schema" to do bulk read for DOMMatrixInit.
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/bindings/core/v8/custom/V8DOMMatrixReadOnlyCustom.cpp
diff --git a/third_party/WebKit/Source/bindings/core/v8/custom/V8DOMMatrixReadOnlyCustom.cpp b/third_party/WebKit/Source/bindings/core/v8/custom/V8DOMMatrixReadOnlyCustom.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..5acf7a42b7ac50e2c3cb51828040e3520bea8b8a
--- /dev/null
+++ b/third_party/WebKit/Source/bindings/core/v8/custom/V8DOMMatrixReadOnlyCustom.cpp
@@ -0,0 +1,130 @@
+// Copyright 2017 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 "bindings/core/v8/V8DOMMatrixReadOnly.h"
+
+#include "bindings/core/v8/IDLTypes.h"
+#include "bindings/core/v8/NativeValueTraitsImpl.h"
+#include "core/dom/DOMMatrixInit.h"
+
+namespace blink {
+
+void V8DOMMatrixReadOnly::multiplyMethodCustom(
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
+ ExceptionState exceptionState(info.GetIsolate(),
+ ExceptionState::ExecutionContext,
+ "DOMMatrixReadOnly", "multiply");
+
+ DOMMatrixReadOnly* impl = V8DOMMatrixReadOnly::toImpl(info.Holder());
+
+ DOMMatrixInit other;
+ if (!isUndefinedOrNull(info[0]) && !info[0]->IsObject()) {
+ exceptionState.throwTypeError("parameter 1 ('other') is not an object.");
+
+ return;
+ }
+
+ // V8DOMMatrixInit::toImpl(info.GetIsolate(), info[0], other, exceptionState);
+
+ // TODO(jbroman): Use a cache in V8PerIsolateData.
+ v8::Isolate* isolate = info.GetIsolate();
+ static v8::Eternal<v8::DictionarySchema>& s_schema =
+ *new v8::Eternal<v8::DictionarySchema>;
+ if (s_schema.IsEmpty()) {
+ static const char* const kKeys[] = {
+ "a", "b", "c", "d", "e", "f", "is2D", "m11",
+ "m12", "m13", "m14", "m21", "m22", "m23", "m24", "m31",
+ "m32", "m33", "m34", "m41", "m42", "m43", "m44",
+ };
+ v8::Local<v8::Value> keys[arraysize(kKeys)];
+ std::transform(
+ std::begin(kKeys), std::end(kKeys), std::begin(keys),
+ [isolate](const char* k) { return v8AtomicString(isolate, k); });
+ s_schema.Set(isolate, v8::DictionarySchema::New(info.GetIsolate(), keys,
+ arraysize(keys)));
+ }
+
+ {
+ v8::TryCatch block(isolate);
+ v8::Local<v8::DictionarySchema> schema = s_schema.Get(info.GetIsolate());
+ v8::Local<v8::Value> values[23];
+ int index = 0;
+ bool isDone = false;
+ do {
+ int begin = index;
+ v8::Maybe<bool> result = schema->Get(
+ info.GetIsolate()->GetCurrentContext(), info[0].As<v8::Object>(),
+ v8::DictionarySchema::kValueFilterPrimitives, values,
+ arraysize(values), &index);
+ if (!result.To(&isDone)) {
+ exceptionState.rethrowV8Exception(block.Exception());
+ return;
+ }
+
+ // fprintf(stderr, "== GO ==\n");
+ switch (begin) {
+#define DOUBLE_CASE(n, setter) \
+ case n: { \
+ v8::Local<v8::Value> aValue = values[n]; \
+ if (aValue.IsEmpty() || aValue->IsUndefined()) { \
+ /* Do nothing. */ \
+ } else { \
+ double a = NativeValueTraits<IDLUnrestrictedDouble>::nativeValue( \
+ isolate, aValue, exceptionState); \
+ if (exceptionState.hadException()) \
+ return; \
+ /*fprintf(stderr, #setter " = %f\n", a);*/ \
+ other.setter(a); \
+ } \
+ if ((n + 1) >= index) \
+ break; \
+ }
+ DOUBLE_CASE(0, setA);
+ DOUBLE_CASE(1, setB);
+ DOUBLE_CASE(2, setC);
+ DOUBLE_CASE(3, setD);
+ DOUBLE_CASE(4, setE);
+ DOUBLE_CASE(5, setF);
+ case 6: {
+ v8::Local<v8::Value> value = values[6];
+ if (value.IsEmpty() || value->IsUndefined()) {
+ // Do nothing.
+ } else {
+ bool is2D = NativeValueTraits<IDLBoolean>::nativeValue(
+ isolate, value, exceptionState);
+ if (exceptionState.hadException())
+ return;
+ other.setIs2D(is2D);
+ }
+ if ((6 + 1) >= index)
+ break;
+ }
+ DOUBLE_CASE(7, setM11);
+ DOUBLE_CASE(8, setM12);
+ DOUBLE_CASE(9, setM13);
+ DOUBLE_CASE(10, setM14);
+ DOUBLE_CASE(11, setM21);
+ DOUBLE_CASE(12, setM22);
+ DOUBLE_CASE(13, setM23);
+ DOUBLE_CASE(14, setM24);
+ DOUBLE_CASE(15, setM33);
+ DOUBLE_CASE(16, setM32);
+ DOUBLE_CASE(17, setM33);
+ DOUBLE_CASE(18, setM34);
+ DOUBLE_CASE(19, setM43);
+ DOUBLE_CASE(20, setM42);
+ DOUBLE_CASE(21, setM43);
+ DOUBLE_CASE(22, setM44);
+ }
+ } while (!isDone);
+ }
+
+ DOMMatrix* result = impl->multiply(other, exceptionState);
+ if (exceptionState.hadException()) {
+ return;
+ }
+ v8SetReturnValue(info, result);
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/bindings/bindings.gni ('k') | third_party/WebKit/Source/core/dom/DOMMatrixReadOnly.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698