Commit 9b40862b authored by hs1217.lee's avatar hs1217.lee Committed by Commit bot

Implement toString() funtion in DOMMatrixReadOnly.

add toString() funtion in DOMMatrixReadOnly.
refer to detail spec([1])

[1] = https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-stringifier

BUG=388780

Review-Url: https://codereview.chromium.org/2273663002
Cr-Commit-Position: refs/heads/master@{#414228}
parent 3c5633df
......@@ -39,6 +39,18 @@ test(function() {
assert_equals(matrix3d.m44, 16.6);
}, "DOMMatrixReadOnly constructor - 3D matrix");
test(function() {
var matrix2d = new DOMMatrixReadOnly([1, 2, 3, 3.1, 2, 1]);
assert_true(matrix2d.is2D);
assert_equals(matrix2d.toString(), "matrix(1, 2, 3, 3.1, 2, 1)");
}, "DOMMatrixReadOnly toString() - 2D matrix");
test(function() {
var matrix3d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10.1, 11, 12, 13, 14, 15, 16.6]);
assert_false(matrix3d.is2D);
assert_equals(matrix3d.toString(), "matrix3d(1, 2, 3, 4, 5, 6, 7, 8, 9, 10.1, 11, 12, 13, 14, 15, 16.6)");
}, "DOMMatrixReadOnly toString() - 3D matrix");
test(function() {
assert_throws(new TypeError(), function() { new DOMMatrixReadOnly(1, 2, 3, 4, 5, 6); },
"DOMMatrixReadOnly constructor only accepts 1 argument");
......
......@@ -1057,6 +1057,7 @@ interface DOMMatrixReadOnly
method skewY
method toFloat32Array
method toFloat64Array
method toString
method translate
interface DOMParser
attribute @@toStringTag
......
......@@ -128,4 +128,23 @@ DOMFloat64Array* DOMMatrixReadOnly::toFloat64Array() const
return DOMFloat64Array::create(array, 16);
}
const String DOMMatrixReadOnly::toString() const
{
std::stringstream stream;
if (is2D()) {
stream << "matrix("
<< a() << ", " << b() << ", " << c() << ", "
<< d() << ", " << e() << ", " << f();
} else {
stream << "matrix3d("
<< m11() << ", " << m12() << ", " << m13() << ", " << m14() << ", "
<< m21() << ", " << m22() << ", " << m23() << ", " << m24() << ", "
<< m31() << ", " << m32() << ", " << m33() << ", " << m34() << ", "
<< m41() << ", " << m42() << ", " << m43() << ", " << m44();
}
stream << ")";
return String(stream.str().c_str());
}
} // namespace blink
......@@ -63,6 +63,8 @@ public:
DOMFloat32Array* toFloat32Array() const;
DOMFloat64Array* toFloat64Array() const;
const String toString() const;
const TransformationMatrix& matrix() const { return *m_matrix; }
DEFINE_INLINE_TRACE() { }
......
......@@ -64,4 +64,5 @@
Float32Array toFloat32Array();
Float64Array toFloat64Array();
stringifier;
};
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