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

Side by Side Diff: third_party/WebKit/Source/core/geometry/DOMMatrixReadOnly.cpp

Issue 2846523002: Update the stringifier behavior for DOMMatrixReadOnly (Closed)
Patch Set: Update the stringifier behavior for DOMMatrixReadOnly Created 3 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/geometry/DOMMatrixReadOnly.h" 5 #include "core/geometry/DOMMatrixReadOnly.h"
6 6
7 #include "bindings/core/v8/V8ObjectBuilder.h" 7 #include "bindings/core/v8/V8ObjectBuilder.h"
8 #include "core/css/CSSIdentifierValue.h" 8 #include "core/css/CSSIdentifierValue.h"
9 #include "core/css/CSSToLengthConversionData.h" 9 #include "core/css/CSSToLengthConversionData.h"
10 #include "core/css/CSSValueList.h" 10 #include "core/css/CSSValueList.h"
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 NotShared<DOMFloat64Array> DOMMatrixReadOnly::toFloat64Array() const { 315 NotShared<DOMFloat64Array> DOMMatrixReadOnly::toFloat64Array() const {
316 double array[] = { 316 double array[] = {
317 matrix_->M11(), matrix_->M12(), matrix_->M13(), matrix_->M14(), 317 matrix_->M11(), matrix_->M12(), matrix_->M13(), matrix_->M14(),
318 matrix_->M21(), matrix_->M22(), matrix_->M23(), matrix_->M24(), 318 matrix_->M21(), matrix_->M22(), matrix_->M23(), matrix_->M24(),
319 matrix_->M31(), matrix_->M32(), matrix_->M33(), matrix_->M34(), 319 matrix_->M31(), matrix_->M32(), matrix_->M33(), matrix_->M34(),
320 matrix_->M41(), matrix_->M42(), matrix_->M43(), matrix_->M44()}; 320 matrix_->M41(), matrix_->M42(), matrix_->M43(), matrix_->M44()};
321 321
322 return NotShared<DOMFloat64Array>(DOMFloat64Array::Create(array, 16)); 322 return NotShared<DOMFloat64Array>(DOMFloat64Array::Create(array, 16));
323 } 323 }
324 324
325 const String DOMMatrixReadOnly::toString() const { 325 const String DOMMatrixReadOnly::toString(
326 std::stringstream stream; 326 ExceptionState& exception_state) const {
327 const char* kComma = ", ";
328 String result;
329
327 if (is2D()) { 330 if (is2D()) {
328 stream << "matrix(" << a() << ", " << b() << ", " << c() << ", " << d() 331 if (!std::isfinite(a()) || !std::isfinite(b()) || !std::isfinite(c()) ||
329 << ", " << e() << ", " << f(); 332 !std::isfinite(d()) || !std::isfinite(e()) || !std::isfinite(f())) {
330 } else { 333 exception_state.ThrowDOMException(
331 stream << "matrix3d(" << m11() << ", " << m12() << ", " << m13() << ", " 334 kInvalidStateError,
332 << m14() << ", " << m21() << ", " << m22() << ", " << m23() << ", " 335 "DOMMatrix cannot be serialized with NaN or Infinity values.");
333 << m24() << ", " << m31() << ", " << m32() << ", " << m33() << ", " 336 return String();
334 << m34() << ", " << m41() << ", " << m42() << ", " << m43() << ", " 337 }
335 << m44(); 338
339 result.append("matrix(");
340 result.append(String::NumberToStringECMAScript(a()));
341 result.append(kComma);
342 result.append(String::NumberToStringECMAScript(b()));
343 result.append(kComma);
344 result.append(String::NumberToStringECMAScript(c()));
345 result.append(kComma);
346 result.append(String::NumberToStringECMAScript(d()));
347 result.append(kComma);
348 result.append(String::NumberToStringECMAScript(e()));
349 result.append(kComma);
350 result.append(String::NumberToStringECMAScript(f()));
351 result.append(")");
352 return result;
336 } 353 }
337 stream << ")";
338 354
339 return String(stream.str().c_str()); 355 if (!std::isfinite(m11()) || !std::isfinite(m12()) || !std::isfinite(m13()) ||
356 !std::isfinite(m14()) || !std::isfinite(m21()) || !std::isfinite(m22()) ||
357 !std::isfinite(m23()) || !std::isfinite(m24()) || !std::isfinite(m31()) ||
358 !std::isfinite(m32()) || !std::isfinite(m33()) || !std::isfinite(m34()) ||
359 !std::isfinite(m41()) || !std::isfinite(m42()) || !std::isfinite(m43()) ||
360 !std::isfinite(m44())) {
361 exception_state.ThrowDOMException(
362 kInvalidStateError,
363 "DOMMatrix cannot be serialized with NaN or Infinity values.");
364 return String();
365 }
366
367 result.append("matrix3d(");
368 result.append(String::NumberToStringECMAScript(m11()));
369 result.append(kComma);
370 result.append(String::NumberToStringECMAScript(m12()));
371 result.append(kComma);
372 result.append(String::NumberToStringECMAScript(m13()));
373 result.append(kComma);
374 result.append(String::NumberToStringECMAScript(m14()));
375 result.append(kComma);
376 result.append(String::NumberToStringECMAScript(m21()));
377 result.append(kComma);
378 result.append(String::NumberToStringECMAScript(m22()));
379 result.append(kComma);
380 result.append(String::NumberToStringECMAScript(m23()));
381 result.append(kComma);
382 result.append(String::NumberToStringECMAScript(m24()));
383 result.append(kComma);
384 result.append(String::NumberToStringECMAScript(m31()));
385 result.append(kComma);
386 result.append(String::NumberToStringECMAScript(m32()));
387 result.append(kComma);
388 result.append(String::NumberToStringECMAScript(m33()));
389 result.append(kComma);
390 result.append(String::NumberToStringECMAScript(m34()));
391 result.append(kComma);
392 result.append(String::NumberToStringECMAScript(m41()));
393 result.append(kComma);
394 result.append(String::NumberToStringECMAScript(m42()));
395 result.append(kComma);
396 result.append(String::NumberToStringECMAScript(m43()));
397 result.append(kComma);
398 result.append(String::NumberToStringECMAScript(m44()));
399 result.append(")");
400
401 return result;
340 } 402 }
341 403
342 ScriptValue DOMMatrixReadOnly::toJSONForBinding( 404 ScriptValue DOMMatrixReadOnly::toJSONForBinding(
343 ScriptState* script_state) const { 405 ScriptState* script_state) const {
344 V8ObjectBuilder result(script_state); 406 V8ObjectBuilder result(script_state);
345 result.AddNumber("a", a()); 407 result.AddNumber("a", a());
346 result.AddNumber("b", b()); 408 result.AddNumber("b", b());
347 result.AddNumber("c", c()); 409 result.AddNumber("c", c());
348 result.AddNumber("d", d()); 410 result.AddNumber("d", d());
349 result.AddNumber("e", e()); 411 result.AddNumber("e", e());
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 474
413 matrix_->MakeIdentity(); 475 matrix_->MakeIdentity();
414 operations.Apply(FloatSize(0, 0), *matrix_); 476 operations.Apply(FloatSize(0, 0), *matrix_);
415 477
416 is2d_ = !operations.Has3DOperation(); 478 is2d_ = !operations.Has3DOperation();
417 479
418 return; 480 return;
419 } 481 }
420 482
421 } // namespace blink 483 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698