Commit 76818387 authored by sigbjornf@opera.com's avatar sigbjornf@opera.com

Have SourceBuffer throw TypeError for non-finite doubles.

Switch to throwing TypeError instead of TypeMismatchError when encountering
non-finite doubles, following what WebIDL requires

 http://heycam.github.io/webidl/#es-double

R=acolwell@chromium.org
BUG=353245

Review URL: https://codereview.chromium.org/212953004

git-svn-id: svn://svn.chromium.org/blink/trunk@170098 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent d9903968
...@@ -32,15 +32,15 @@ ...@@ -32,15 +32,15 @@
assert_true(sourceBuffer != null, "New SourceBuffer returned"); assert_true(sourceBuffer != null, "New SourceBuffer returned");
sourceBuffer.appendWindowEnd = 500.0; sourceBuffer.appendWindowEnd = 500.0;
assert_throws("TypeMismatchError", assert_throws({name: "TypeError"},
function() { sourceBuffer.appendWindowStart = Number.NEGATIVE_INFINITY; }, function() { sourceBuffer.appendWindowStart = Number.NEGATIVE_INFINITY; },
"set appendWindowStart throws an exception for Number.NEGATIVE_INFINITY."); "set appendWindowStart throws an exception for Number.NEGATIVE_INFINITY.");
assert_throws("TypeMismatchError", assert_throws({name: "TypeError"},
function() { sourceBuffer.appendWindowStart = Number.POSITIVE_INFINITY; }, function() { sourceBuffer.appendWindowStart = Number.POSITIVE_INFINITY; },
"set appendWindowStart throws an exception for Number.POSITIVE_INFINITY."); "set appendWindowStart throws an exception for Number.POSITIVE_INFINITY.");
assert_throws("TypeMismatchError", assert_throws({name: "TypeError"},
function() { sourceBuffer.appendWindowStart = Number.NaN; }, function() { sourceBuffer.appendWindowStart = Number.NaN; },
"set appendWindowStart throws an exception for Number.NaN."); "set appendWindowStart throws an exception for Number.NaN.");
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
var segmentInfo = MediaSourceUtil.SEGMENT_INFO; var segmentInfo = MediaSourceUtil.SEGMENT_INFO;
var sourceBuffer = mediaSource.addSourceBuffer(segmentInfo.type); var sourceBuffer = mediaSource.addSourceBuffer(segmentInfo.type);
if (expected == 'TypeMismatchError') { if (expected == 'TypeError') {
assert_throws('TypeMismatchError', assert_throws({name: 'TypeError'},
function() { sourceBuffer.timestampOffset = value; }, function() { sourceBuffer.timestampOffset = value; },
'setting timestampOffset to ' + description + ' throws an exception.'); 'setting timestampOffset to ' + description + ' throws an exception.');
} else { } else {
...@@ -32,10 +32,10 @@ ...@@ -32,10 +32,10 @@
simpleTimestampOffsetTest(10.5, 10.5, 'a positive number'); simpleTimestampOffsetTest(10.5, 10.5, 'a positive number');
simpleTimestampOffsetTest(-10.4, -10.4, 'a negative number'); simpleTimestampOffsetTest(-10.4, -10.4, 'a negative number');
simpleTimestampOffsetTest(0, 0, 'zero'); simpleTimestampOffsetTest(0, 0, 'zero');
simpleTimestampOffsetTest(Number.POSITIVE_INFINITY, 'TypeMismatchError', 'positive infinity'); simpleTimestampOffsetTest(Number.POSITIVE_INFINITY, 'TypeError', 'positive infinity');
simpleTimestampOffsetTest(Number.NEGATIVE_INFINITY, 'TypeMismatchError', 'negative infinity'); simpleTimestampOffsetTest(Number.NEGATIVE_INFINITY, 'TypeError', 'negative infinity');
simpleTimestampOffsetTest(Number.NaN, 'TypeMismatchError', 'NaN'); simpleTimestampOffsetTest(Number.NaN, 'TypeError', 'NaN');
simpleTimestampOffsetTest(undefined, 'TypeMismatchError', 'undefined'); simpleTimestampOffsetTest(undefined, 'TypeError', 'undefined');
simpleTimestampOffsetTest(null, 0, 'null'); simpleTimestampOffsetTest(null, 0, 'null');
simpleTimestampOffsetTest(false, 0, 'false'); simpleTimestampOffsetTest(false, 0, 'false');
simpleTimestampOffsetTest(true, 1, 'true'); simpleTimestampOffsetTest(true, 1, 'true');
......
...@@ -177,7 +177,7 @@ void SourceBuffer::setTimestampOffset(double offset, ExceptionState& exceptionSt ...@@ -177,7 +177,7 @@ void SourceBuffer::setTimestampOffset(double offset, ExceptionState& exceptionSt
{ {
// Enforce throwing an exception on restricted double values. // Enforce throwing an exception on restricted double values.
if (!std::isfinite(offset)) { if (!std::isfinite(offset)) {
exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::notAFiniteNumber(offset)); exceptionState.throwTypeError(ExceptionMessages::notAFiniteNumber(offset));
return; return;
} }
...@@ -213,10 +213,8 @@ double SourceBuffer::appendWindowStart() const ...@@ -213,10 +213,8 @@ double SourceBuffer::appendWindowStart() const
void SourceBuffer::setAppendWindowStart(double start, ExceptionState& exceptionState) void SourceBuffer::setAppendWindowStart(double start, ExceptionState& exceptionState)
{ {
// Enforce throwing an exception on restricted double values. // Enforce throwing an exception on restricted double values.
if (std::isnan(start) if (!std::isfinite(start)) {
|| start == std::numeric_limits<double>::infinity() exceptionState.throwTypeError(ExceptionMessages::notAFiniteNumber(start));
|| start == -std::numeric_limits<double>::infinity()) {
exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::notAFiniteNumber(start));
return; return;
} }
......
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