<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[203037] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/203037">203037</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-07-10 01:24:18 -0700 (Sun, 10 Jul 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>ECMAScript 2016: %TypedArray%.prototype.includes implementation
https://bugs.webkit.org/show_bug.cgi?id=159385
Patch by Caio Lima <ticaiolima@gmail.com> on 2016-07-10
Reviewed by Benjamin Poulain.
Source/JavaScriptCore:
This patch implements the ECMAScript 2016:
%TypedArray%.prototype.includes
following spec 22.2.3.14
https://tc39.github.io/ecma262/2016/#sec-%typedarray%.prototype.includes
* runtime/JSGenericTypedArrayViewPrototypeFunctions.h:
(JSC::genericTypedArrayViewProtoFuncIncludes):
* runtime/JSTypedArrayViewPrototype.cpp:
(JSC::typedArrayViewProtoFuncIncludes):
(JSC::JSTypedArrayViewPrototype::finishCreation):
LayoutTests:
This patch implements test case to ECMAScript 2016:
%TypedArray%.prototype.includes implementation
following spec 22.2.3.14
https://tc39.github.io/ecma262/2016/#sec-%typedarray%.prototype.includes
* js/regress/script-tests/typed-array-includes.js: Added.
(assertProperError):
(testIntTypedArray):
(testFloatTypedArray):
* js/typed-array-includes-expected.txt: Added.
* js/typed-array-includes.html: Added.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSGenericTypedArrayViewh">trunk/Source/JavaScriptCore/runtime/JSGenericTypedArrayView.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSGenericTypedArrayViewPrototypeFunctionsh">trunk/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSTypedArrayViewPrototypecpp">trunk/Source/JavaScriptCore/runtime/JSTypedArrayViewPrototype.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeToNativeFromValueh">trunk/Source/JavaScriptCore/runtime/ToNativeFromValue.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeTypedArrayAdaptorsh">trunk/Source/JavaScriptCore/runtime/TypedArrayAdaptors.h</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsjsscriptteststypedarrayincludesjs">trunk/LayoutTests/js/script-tests/typed-array-includes.js</a></li>
<li><a href="#trunkLayoutTestsjstypedarrayincludesexpectedtxt">trunk/LayoutTests/js/typed-array-includes-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjstypedarrayincludeshtml">trunk/LayoutTests/js/typed-array-includes.html</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (203036 => 203037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-07-10 08:03:36 UTC (rev 203036)
+++ trunk/LayoutTests/ChangeLog        2016-07-10 08:24:18 UTC (rev 203037)
</span><span class="lines">@@ -1,3 +1,22 @@
</span><ins>+2016-07-10 Caio Lima <ticaiolima@gmail.com>
+
+ ECMAScript 2016: %TypedArray%.prototype.includes implementation
+ https://bugs.webkit.org/show_bug.cgi?id=159385
+
+ Reviewed by Benjamin Poulain.
+
+ This patch implements test case to ECMAScript 2016:
+ %TypedArray%.prototype.includes implementation
+ following spec 22.2.3.14
+ https://tc39.github.io/ecma262/2016/#sec-%typedarray%.prototype.includes
+
+ * js/regress/script-tests/typed-array-includes.js: Added.
+ (assertProperError):
+ (testIntTypedArray):
+ (testFloatTypedArray):
+ * js/typed-array-includes-expected.txt: Added.
+ * js/typed-array-includes.html: Added.
+
</ins><span class="cx"> 2016-07-10 Yusuke Suzuki <utatane.tea@gmail.com>
</span><span class="cx">
</span><span class="cx"> [GTK] Crash on https://diafygi.github.io/webcrypto-examples with ENABLE_SUBTLE_CRYPTO
</span></span></pre></div>
<a id="trunkLayoutTestsjsscriptteststypedarrayincludesjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/script-tests/typed-array-includes.js (0 => 203037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/script-tests/typed-array-includes.js         (rev 0)
+++ trunk/LayoutTests/js/script-tests/typed-array-includes.js        2016-07-10 08:24:18 UTC (rev 203037)
</span><span class="lines">@@ -0,0 +1,228 @@
</span><ins>+function assertProperError(e) {
+ if ((!(e instanceof TypeError)) || e.message.indexOf("Receiver should be a typed array view but was not an object") === -1)
+ shouldBeTrue("false");
+}
+
+var tArray;
+
+function testIntTypedArray(TypedArray) {
+
+ tArray = new TypedArray([0,2,3]);
+ shouldBeTrue("tArray.includes(2)");
+ shouldBeTrue("!tArray.includes(4)");
+ shouldBeTrue("!tArray.includes(3, 3)");
+ shouldBeTrue("tArray.includes(3, -1)");
+ shouldBeTrue("tArray.includes(3, {valueOf: () => -1})");
+
+ // Test non-array-native values
+ shouldBeTrue("tArray.includes(2.0)");
+ shouldBeTrue("!tArray.includes(2.5)");
+ shouldBeTrue("!tArray.includes(\"abc\")");
+ shouldBeTrue("!tArray.includes(null)");
+ shouldBeTrue("!tArray.includes(undefined)");
+ shouldBeTrue("!tArray.includes({1: ''})");
+ shouldBeTrue("!tArray.includes(\"\")");
+
+ // Testing TypeError handling
+ try {
+ tArray = new TypedArray([0, 1, 2]);
+ tArray.includes.call(null, 2);
+ } catch(e) {
+ assertProperError(e);
+ }
+
+ try {
+ tArray = new TypedArray([0, 1, 2]);
+ tArray.includes.call(undefined, 2);
+ } catch(e) {
+ assertProperError(e);
+ }
+
+}
+
+testIntTypedArray(Uint8Array);
+testIntTypedArray(Int8Array);
+testIntTypedArray(Uint8ClampedArray);
+testIntTypedArray(Uint16Array);
+testIntTypedArray(Int16Array);
+testIntTypedArray(Uint32Array);
+testIntTypedArray(Int32Array);
+
+var fArray;
+
+function testFloatTypedArray(TypedArray) {
+
+ fArray = new TypedArray([1.0, 2.0 , 3.0]);
+ shouldBeTrue("fArray.includes(2.0)");
+ shouldBeTrue("!fArray.includes(4.0)");
+ shouldBeTrue("!fArray.includes(3.0, 3)");
+ shouldBeTrue("fArray.includes(3, -1)");
+
+ fArray = new TypedArray([NaN]);
+ shouldBeTrue("!fArray.includes(\"abc\")");
+ shouldBeTrue("!fArray.includes(null)");
+ shouldBeTrue("!fArray.includes(undefined)");
+ shouldBeTrue("!fArray.includes({1: ''})");
+ shouldBeTrue("!fArray.includes(\"\")");
+
+ // Testing TypeError handling
+ try {
+ fArray = new TypedArray([0, 1, 2]);
+ fArray.includes.call(null, 2);
+ } catch(e) {
+ assertProperError(e);
+ }
+
+ try {
+ fArray = new TypedArray([0, 1, 2]);
+ fArray.includes.call(undefined, 2);
+ } catch(e) {
+ assertProperError(e);
+ }
+
+}
+
+// NaN handling (only true for Float32 and Float64)
+shouldBeTrue("!(new Uint8Array([NaN]).includes(NaN))");
+shouldBeTrue("new Float32Array([NaN]).includes(NaN)");
+shouldBeTrue("new Float64Array([NaN]).includes(NaN)");
+
+var descriptor;
+var gTypedArray;
+
+function testDescriptor(TypedArray) {
+ gTypedArray = TypedArray;
+ descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(TypedArray.prototype), "includes");
+
+ shouldBeTrue("descriptor.configurable");
+ shouldBeTrue("descriptor.writable");
+ shouldBeTrue("!descriptor.enumerable");
+ shouldBeTrue("descriptor.get === undefined");
+ shouldBeTrue("descriptor.set === undefined");
+
+ shouldBeTrue("Object.getPrototypeOf(gTypedArray.prototype).includes.name === \"includes\"");
+ shouldBeTrue("Object.getPrototypeOf(gTypedArray.prototype).includes.length === 1");
+}
+
+testDescriptor(Uint8Array);
+testDescriptor(Int8Array);
+testDescriptor(Uint8ClampedArray);
+testDescriptor(Uint16Array);
+testDescriptor(Int16Array);
+testDescriptor(Uint32Array);
+testDescriptor(Int32Array);
+testDescriptor(Float32Array);
+testDescriptor(Float64Array);
+
+// Testing boundaries
+
+var arr = new Uint8Array([0, 254]);
+shouldBeTrue("arr.includes(0)");
+shouldBeTrue("arr.includes(254)");
+shouldBeTrue("!arr.includes(255)");
+shouldBeTrue("!arr.includes(-1)");
+
+arr = new Int8Array([-128, 127]);
+shouldBeTrue("arr.includes(-128)");
+shouldBeTrue("arr.includes(127)");
+shouldBeTrue("!arr.includes(128)");
+shouldBeTrue("!arr.includes(-129)");
+
+arr = new Uint8ClampedArray([-128, 256]);
+shouldBeTrue("arr.includes(255)");
+shouldBeTrue("arr.includes(0)");
+shouldBeTrue("!arr.includes(-128)");
+shouldBeTrue("!arr.includes(-256)");
+
+arr = new Uint16Array([0, 65535]);
+shouldBeTrue("arr.includes(0)");
+shouldBeTrue("arr.includes(65535)");
+shouldBeTrue("!arr.includes(65536)");
+shouldBeTrue("!arr.includes(-1)");
+
+arr = new Int16Array([-32768, 32767]);
+shouldBeTrue("arr.includes(-32768)");
+shouldBeTrue("arr.includes(32767)");
+shouldBeTrue("!arr.includes(32768)");
+shouldBeTrue("!arr.includes(-32769)");
+
+arr = new Uint32Array([0, 4294967295]);
+shouldBeTrue("arr.includes(0)");
+shouldBeTrue("arr.includes(4294967295)");
+shouldBeTrue("!arr.includes(4294967296)");
+shouldBeTrue("!arr.includes(-1)");
+
+arr = new Int32Array([-2147483648, 2147483647]);
+shouldBeTrue("arr.includes(-2147483648)");
+shouldBeTrue("arr.includes(2147483647)");
+shouldBeTrue("!arr.includes(2147483648)");
+shouldBeTrue("!arr.includes(-2147483649)");
+
+arr = new Float32Array([-3.402820018375656e+38, 3.402820018375656e+38]);
+shouldBeTrue("arr.includes(-3.402820018375656e+38)");
+shouldBeTrue("arr.includes(3.402820018375656e+38)");
+shouldBeTrue("!arr.includes(3.50282e+38)");
+shouldBeTrue("!arr.includes(-3.50282e+38)");
+
+arr = new Float64Array([-1.79769e+308, 1.79769e+308]);
+shouldBeTrue("arr.includes(-1.79769e+308)");
+shouldBeTrue("arr.includes(1.79769e+308)");
+shouldBeTrue("!arr.includes(-1.89769e+308)");
+shouldBeTrue("!arr.includes(1.89769e+308)");
+
+// Testing Infinity
+
+function testInfinity(TypedArray) {
+ arr = new TypedArray([Infinity]);
+ shouldBeTrue("arr.includes(Infinity)");
+ shouldBeTrue("!arr.includes(-Infinity)");
+ shouldBeTrue("!arr.includes(NaN)");
+
+ arr = new TypedArray([-Infinity]);
+ shouldBeTrue("arr.includes(-Infinity)");
+ shouldBeTrue("!arr.includes(Infinity)");
+ shouldBeTrue("!arr.includes(NaN)");
+}
+
+testInfinity(Float32Array);
+testInfinity(Float64Array);
+
+// Test float->double precision
+
+shouldBeTrue("!(new Float32Array([2.40282e+38]).includes(2.40282e+38))");
+
+// Checking spec
+var funcCallCount;
+
+function checkingValueOfCall(TypedArray) {
+ tArray = new TypedArray([0, 1, 2]);
+ funcCallCount = {callCount: 0, valueOf: function() {this.callCount++; return 0;}};
+
+ tArray.includes(0, funcCallCount);
+ shouldBeTrue("funcCallCount.callCount === 1");
+
+ tArray.includes("abc", funcCallCount);
+ shouldBeTrue("funcCallCount.callCount === 2");
+
+ tArray.includes(null, funcCallCount);
+ shouldBeTrue("funcCallCount.callCount === 3");
+
+ tArray.includes(undefined, funcCallCount);
+ shouldBeTrue("funcCallCount.callCount === 4");
+
+ tArray.includes({1: ''}, funcCallCount);
+ shouldBeTrue("funcCallCount.callCount === 5");
+
+ tArray.includes("", funcCallCount);
+ shouldBeTrue("funcCallCount.callCount === 6");
+}
+
+checkingValueOfCall(Uint8Array);
+checkingValueOfCall(Int8Array);
+checkingValueOfCall(Uint8ClampedArray);
+checkingValueOfCall(Uint16Array);
+checkingValueOfCall(Int16Array);
+checkingValueOfCall(Uint32Array);
+checkingValueOfCall(Int32Array);
+checkingValueOfCall(Float32Array);
+checkingValueOfCall(Float64Array);
</ins></span></pre></div>
<a id="trunkLayoutTestsjstypedarrayincludesexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/typed-array-includes-expected.txt (0 => 203037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/typed-array-includes-expected.txt         (rev 0)
+++ trunk/LayoutTests/js/typed-array-includes-expected.txt        2016-07-10 08:24:18 UTC (rev 203037)
</span><span class="lines">@@ -0,0 +1,263 @@
</span><ins>+JSRegress/typed-array-includes
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS tArray.includes(2) is true
+PASS !tArray.includes(4) is true
+PASS !tArray.includes(3, 3) is true
+PASS tArray.includes(3, -1) is true
+PASS tArray.includes(3, {valueOf: () => -1}) is true
+PASS tArray.includes(2.0) is true
+PASS !tArray.includes(2.5) is true
+PASS !tArray.includes("abc") is true
+PASS !tArray.includes(null) is true
+PASS !tArray.includes(undefined) is true
+PASS !tArray.includes({1: ''}) is true
+PASS !tArray.includes("") is true
+PASS tArray.includes(2) is true
+PASS !tArray.includes(4) is true
+PASS !tArray.includes(3, 3) is true
+PASS tArray.includes(3, -1) is true
+PASS tArray.includes(3, {valueOf: () => -1}) is true
+PASS tArray.includes(2.0) is true
+PASS !tArray.includes(2.5) is true
+PASS !tArray.includes("abc") is true
+PASS !tArray.includes(null) is true
+PASS !tArray.includes(undefined) is true
+PASS !tArray.includes({1: ''}) is true
+PASS !tArray.includes("") is true
+PASS tArray.includes(2) is true
+PASS !tArray.includes(4) is true
+PASS !tArray.includes(3, 3) is true
+PASS tArray.includes(3, -1) is true
+PASS tArray.includes(3, {valueOf: () => -1}) is true
+PASS tArray.includes(2.0) is true
+PASS !tArray.includes(2.5) is true
+PASS !tArray.includes("abc") is true
+PASS !tArray.includes(null) is true
+PASS !tArray.includes(undefined) is true
+PASS !tArray.includes({1: ''}) is true
+PASS !tArray.includes("") is true
+PASS tArray.includes(2) is true
+PASS !tArray.includes(4) is true
+PASS !tArray.includes(3, 3) is true
+PASS tArray.includes(3, -1) is true
+PASS tArray.includes(3, {valueOf: () => -1}) is true
+PASS tArray.includes(2.0) is true
+PASS !tArray.includes(2.5) is true
+PASS !tArray.includes("abc") is true
+PASS !tArray.includes(null) is true
+PASS !tArray.includes(undefined) is true
+PASS !tArray.includes({1: ''}) is true
+PASS !tArray.includes("") is true
+PASS tArray.includes(2) is true
+PASS !tArray.includes(4) is true
+PASS !tArray.includes(3, 3) is true
+PASS tArray.includes(3, -1) is true
+PASS tArray.includes(3, {valueOf: () => -1}) is true
+PASS tArray.includes(2.0) is true
+PASS !tArray.includes(2.5) is true
+PASS !tArray.includes("abc") is true
+PASS !tArray.includes(null) is true
+PASS !tArray.includes(undefined) is true
+PASS !tArray.includes({1: ''}) is true
+PASS !tArray.includes("") is true
+PASS tArray.includes(2) is true
+PASS !tArray.includes(4) is true
+PASS !tArray.includes(3, 3) is true
+PASS tArray.includes(3, -1) is true
+PASS tArray.includes(3, {valueOf: () => -1}) is true
+PASS tArray.includes(2.0) is true
+PASS !tArray.includes(2.5) is true
+PASS !tArray.includes("abc") is true
+PASS !tArray.includes(null) is true
+PASS !tArray.includes(undefined) is true
+PASS !tArray.includes({1: ''}) is true
+PASS !tArray.includes("") is true
+PASS tArray.includes(2) is true
+PASS !tArray.includes(4) is true
+PASS !tArray.includes(3, 3) is true
+PASS tArray.includes(3, -1) is true
+PASS tArray.includes(3, {valueOf: () => -1}) is true
+PASS tArray.includes(2.0) is true
+PASS !tArray.includes(2.5) is true
+PASS !tArray.includes("abc") is true
+PASS !tArray.includes(null) is true
+PASS !tArray.includes(undefined) is true
+PASS !tArray.includes({1: ''}) is true
+PASS !tArray.includes("") is true
+PASS !(new Uint8Array([NaN]).includes(NaN)) is true
+PASS new Float32Array([NaN]).includes(NaN) is true
+PASS new Float64Array([NaN]).includes(NaN) is true
+PASS descriptor.configurable is true
+PASS descriptor.writable is true
+PASS !descriptor.enumerable is true
+PASS descriptor.get === undefined is true
+PASS descriptor.set === undefined is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.name === "includes" is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.length === 1 is true
+PASS descriptor.configurable is true
+PASS descriptor.writable is true
+PASS !descriptor.enumerable is true
+PASS descriptor.get === undefined is true
+PASS descriptor.set === undefined is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.name === "includes" is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.length === 1 is true
+PASS descriptor.configurable is true
+PASS descriptor.writable is true
+PASS !descriptor.enumerable is true
+PASS descriptor.get === undefined is true
+PASS descriptor.set === undefined is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.name === "includes" is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.length === 1 is true
+PASS descriptor.configurable is true
+PASS descriptor.writable is true
+PASS !descriptor.enumerable is true
+PASS descriptor.get === undefined is true
+PASS descriptor.set === undefined is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.name === "includes" is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.length === 1 is true
+PASS descriptor.configurable is true
+PASS descriptor.writable is true
+PASS !descriptor.enumerable is true
+PASS descriptor.get === undefined is true
+PASS descriptor.set === undefined is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.name === "includes" is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.length === 1 is true
+PASS descriptor.configurable is true
+PASS descriptor.writable is true
+PASS !descriptor.enumerable is true
+PASS descriptor.get === undefined is true
+PASS descriptor.set === undefined is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.name === "includes" is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.length === 1 is true
+PASS descriptor.configurable is true
+PASS descriptor.writable is true
+PASS !descriptor.enumerable is true
+PASS descriptor.get === undefined is true
+PASS descriptor.set === undefined is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.name === "includes" is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.length === 1 is true
+PASS descriptor.configurable is true
+PASS descriptor.writable is true
+PASS !descriptor.enumerable is true
+PASS descriptor.get === undefined is true
+PASS descriptor.set === undefined is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.name === "includes" is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.length === 1 is true
+PASS descriptor.configurable is true
+PASS descriptor.writable is true
+PASS !descriptor.enumerable is true
+PASS descriptor.get === undefined is true
+PASS descriptor.set === undefined is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.name === "includes" is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.length === 1 is true
+PASS arr.includes(0) is true
+PASS arr.includes(254) is true
+PASS !arr.includes(255) is true
+PASS !arr.includes(-1) is true
+PASS arr.includes(-128) is true
+PASS arr.includes(127) is true
+PASS !arr.includes(128) is true
+PASS !arr.includes(-129) is true
+PASS arr.includes(255) is true
+PASS arr.includes(0) is true
+PASS !arr.includes(-128) is true
+PASS !arr.includes(-256) is true
+PASS arr.includes(0) is true
+PASS arr.includes(65535) is true
+PASS !arr.includes(65536) is true
+PASS !arr.includes(-1) is true
+PASS arr.includes(-32768) is true
+PASS arr.includes(32767) is true
+PASS !arr.includes(32768) is true
+PASS !arr.includes(-32769) is true
+PASS arr.includes(0) is true
+PASS arr.includes(4294967295) is true
+PASS !arr.includes(4294967296) is true
+PASS !arr.includes(-1) is true
+PASS arr.includes(-2147483648) is true
+PASS arr.includes(2147483647) is true
+PASS !arr.includes(2147483648) is true
+PASS !arr.includes(-2147483649) is true
+PASS arr.includes(-3.402820018375656e+38) is true
+PASS arr.includes(3.402820018375656e+38) is true
+PASS !arr.includes(3.50282e+38) is true
+PASS !arr.includes(-3.50282e+38) is true
+PASS arr.includes(-1.79769e+308) is true
+PASS arr.includes(1.79769e+308) is true
+PASS !arr.includes(-1.89769e+308) is true
+PASS !arr.includes(1.89769e+308) is true
+PASS arr.includes(Infinity) is true
+PASS !arr.includes(-Infinity) is true
+PASS !arr.includes(NaN) is true
+PASS arr.includes(-Infinity) is true
+PASS !arr.includes(Infinity) is true
+PASS !arr.includes(NaN) is true
+PASS arr.includes(Infinity) is true
+PASS !arr.includes(-Infinity) is true
+PASS !arr.includes(NaN) is true
+PASS arr.includes(-Infinity) is true
+PASS !arr.includes(Infinity) is true
+PASS !arr.includes(NaN) is true
+PASS !(new Float32Array([2.40282e+38]).includes(2.40282e+38)) is true
+PASS funcCallCount.callCount === 1 is true
+PASS funcCallCount.callCount === 2 is true
+PASS funcCallCount.callCount === 3 is true
+PASS funcCallCount.callCount === 4 is true
+PASS funcCallCount.callCount === 5 is true
+PASS funcCallCount.callCount === 6 is true
+PASS funcCallCount.callCount === 1 is true
+PASS funcCallCount.callCount === 2 is true
+PASS funcCallCount.callCount === 3 is true
+PASS funcCallCount.callCount === 4 is true
+PASS funcCallCount.callCount === 5 is true
+PASS funcCallCount.callCount === 6 is true
+PASS funcCallCount.callCount === 1 is true
+PASS funcCallCount.callCount === 2 is true
+PASS funcCallCount.callCount === 3 is true
+PASS funcCallCount.callCount === 4 is true
+PASS funcCallCount.callCount === 5 is true
+PASS funcCallCount.callCount === 6 is true
+PASS funcCallCount.callCount === 1 is true
+PASS funcCallCount.callCount === 2 is true
+PASS funcCallCount.callCount === 3 is true
+PASS funcCallCount.callCount === 4 is true
+PASS funcCallCount.callCount === 5 is true
+PASS funcCallCount.callCount === 6 is true
+PASS funcCallCount.callCount === 1 is true
+PASS funcCallCount.callCount === 2 is true
+PASS funcCallCount.callCount === 3 is true
+PASS funcCallCount.callCount === 4 is true
+PASS funcCallCount.callCount === 5 is true
+PASS funcCallCount.callCount === 6 is true
+PASS funcCallCount.callCount === 1 is true
+PASS funcCallCount.callCount === 2 is true
+PASS funcCallCount.callCount === 3 is true
+PASS funcCallCount.callCount === 4 is true
+PASS funcCallCount.callCount === 5 is true
+PASS funcCallCount.callCount === 6 is true
+PASS funcCallCount.callCount === 1 is true
+PASS funcCallCount.callCount === 2 is true
+PASS funcCallCount.callCount === 3 is true
+PASS funcCallCount.callCount === 4 is true
+PASS funcCallCount.callCount === 5 is true
+PASS funcCallCount.callCount === 6 is true
+PASS funcCallCount.callCount === 1 is true
+PASS funcCallCount.callCount === 2 is true
+PASS funcCallCount.callCount === 3 is true
+PASS funcCallCount.callCount === 4 is true
+PASS funcCallCount.callCount === 5 is true
+PASS funcCallCount.callCount === 6 is true
+PASS funcCallCount.callCount === 1 is true
+PASS funcCallCount.callCount === 2 is true
+PASS funcCallCount.callCount === 3 is true
+PASS funcCallCount.callCount === 4 is true
+PASS funcCallCount.callCount === 5 is true
+PASS funcCallCount.callCount === 6 is true
+PASS no exception thrown
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsjstypedarrayincludeshtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/typed-array-includes.html (0 => 203037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/typed-array-includes.html         (rev 0)
+++ trunk/LayoutTests/js/typed-array-includes.html        2016-07-10 08:24:18 UTC (rev 203037)
</span><span class="lines">@@ -0,0 +1,13 @@
</span><ins>+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+ <head>
+ <script src="../resources/js-test-pre.js"></script>
+ </head>
+ <body>
+ <script src="../resources/regress-pre.js"></script>
+ <script src="script-tests/typed-array-includes.js"></script>
+ <script src="../resources/regress-post.js"></script>
+ <script src="../resources/js-test-post.js"></script>
+ </body>
+</html>
+
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (203036 => 203037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2016-07-10 08:03:36 UTC (rev 203036)
+++ trunk/Source/JavaScriptCore/ChangeLog        2016-07-10 08:24:18 UTC (rev 203037)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2016-07-10 Caio Lima <ticaiolima@gmail.com>
+
+ ECMAScript 2016: %TypedArray%.prototype.includes implementation
+ https://bugs.webkit.org/show_bug.cgi?id=159385
+
+ Reviewed by Benjamin Poulain.
+
+ This patch implements the ECMAScript 2016:
+ %TypedArray%.prototype.includes
+ following spec 22.2.3.14
+ https://tc39.github.io/ecma262/2016/#sec-%typedarray%.prototype.includes
+
+ * runtime/JSGenericTypedArrayViewPrototypeFunctions.h:
+ (JSC::genericTypedArrayViewProtoFuncIncludes):
+ * runtime/JSTypedArrayViewPrototype.cpp:
+ (JSC::typedArrayViewProtoFuncIncludes):
+ (JSC::JSTypedArrayViewPrototype::finishCreation):
+
</ins><span class="cx"> 2016-07-09 Filip Pizlo <fpizlo@apple.com>
</span><span class="cx">
</span><span class="cx"> REGRESSION(201900): validation failure for GetByOffset/PutByOffset in VALIDATE((node), node->child1().node() == node->child2().node() || node->child1()->result() == NodeResultStorage)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSGenericTypedArrayViewh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSGenericTypedArrayView.h (203036 => 203037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSGenericTypedArrayView.h        2016-07-10 08:03:36 UTC (rev 203036)
+++ trunk/Source/JavaScriptCore/runtime/JSGenericTypedArrayView.h        2016-07-10 08:24:18 UTC (rev 203037)
</span><span class="lines">@@ -178,6 +178,8 @@
</span><span class="cx">
</span><span class="cx"> static ElementType toAdaptorNativeFromValue(ExecState* exec, JSValue jsValue) { return toNativeFromValue<Adaptor>(exec, jsValue); }
</span><span class="cx">
</span><ins>+ static bool toAdaptorNativeFromValue(ExecState* exec, JSValue jsValue, ElementType& result) { return toNativeFromValue<Adaptor>(exec, jsValue, result); }
+
</ins><span class="cx"> bool setRangeToValue(ExecState* exec, unsigned start, unsigned end, JSValue jsValue)
</span><span class="cx"> {
</span><span class="cx"> ASSERT(0 <= start && start <= end && end <= m_length);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSGenericTypedArrayViewPrototypeFunctionsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h (203036 => 203037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h        2016-07-10 08:03:36 UTC (rev 203036)
+++ trunk/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h        2016-07-10 08:24:18 UTC (rev 203037)
</span><span class="lines">@@ -202,6 +202,48 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> template<typename ViewClass>
</span><ins>+EncodedJSValue JSC_HOST_CALL genericTypedArrayViewProtoFuncIncludes(ExecState* exec)
+{
+ ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue());
+ if (thisObject->isNeutered())
+ return throwVMTypeError(exec, typedArrayBufferHasBeenDetachedErrorMessage);
+
+ unsigned length = thisObject->length();
+
+ if (!length)
+ return JSValue::encode(jsBoolean(false));
+
+ JSValue valueToFind = exec->argument(0);
+
+ unsigned index = argumentClampedIndexFromStartOrEnd(exec, 1, length);
+
+ if (!valueToFind.isNumber())
+ return JSValue::encode(jsBoolean(false));
+
+ typename ViewClass::ElementType* array = thisObject->typedVector();
+ typename ViewClass::ElementType target;
+ if (!ViewClass::toAdaptorNativeFromValue(exec, valueToFind, target))
+ return JSValue::encode(jsBoolean(false));
+
+ if (exec->hadException())
+ return JSValue::encode(jsUndefined());
+
+ if (std::isnan(static_cast<double>(target))) {
+ for (; index < length; ++index) {
+ if (std::isnan(static_cast<double>(array[index])))
+ return JSValue::encode(jsBoolean(true));
+ }
+ } else {
+ for (; index < length; ++index) {
+ if (array[index] == target)
+ return JSValue::encode(jsBoolean(true));
+ }
+ }
+
+ return JSValue::encode(jsBoolean(false));
+}
+
+template<typename ViewClass>
</ins><span class="cx"> EncodedJSValue JSC_HOST_CALL genericTypedArrayViewProtoFuncIndexOf(ExecState* exec)
</span><span class="cx"> {
</span><span class="cx"> // 22.2.3.13
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSTypedArrayViewPrototypecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSTypedArrayViewPrototype.cpp (203036 => 203037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSTypedArrayViewPrototype.cpp        2016-07-10 08:03:36 UTC (rev 203036)
+++ trunk/Source/JavaScriptCore/runtime/JSTypedArrayViewPrototype.cpp        2016-07-10 08:24:18 UTC (rev 203037)
</span><span class="lines">@@ -123,6 +123,14 @@
</span><span class="cx"> CALL_GENERIC_TYPEDARRAY_PROTOTYPE_FUNCTION(genericTypedArrayViewProtoFuncFill);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+static EncodedJSValue JSC_HOST_CALL typedArrayViewProtoFuncIncludes(ExecState* exec)
+{
+ JSValue thisValue = exec->thisValue();
+ if (!thisValue.isObject())
+ return throwVMError(exec, createTypeError(exec, "Receiver should be a typed array view but was not an object"));
+ CALL_GENERIC_TYPEDARRAY_PROTOTYPE_FUNCTION(genericTypedArrayViewProtoFuncIncludes);
+}
+
</ins><span class="cx"> static EncodedJSValue JSC_HOST_CALL typedArrayViewProtoFuncLastIndexOf(ExecState* exec)
</span><span class="cx"> {
</span><span class="cx"> JSValue thisValue = exec->thisValue();
</span><span class="lines">@@ -261,6 +269,7 @@
</span><span class="cx"> JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION("sort", typedArrayPrototypeSortCodeGenerator, DontEnum);
</span><span class="cx"> JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().entriesPublicName(), typedArrayPrototypeEntriesCodeGenerator, DontEnum);
</span><span class="cx"> JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("fill", typedArrayViewProtoFuncFill, DontEnum, 1);
</span><ins>+ JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("includes", typedArrayViewProtoFuncIncludes, DontEnum, 1);
</ins><span class="cx"> JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION("find", typedArrayPrototypeFindCodeGenerator, DontEnum);
</span><span class="cx"> JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION("findIndex", typedArrayPrototypeFindIndexCodeGenerator, DontEnum);
</span><span class="cx"> JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->forEach, typedArrayPrototypeForEachCodeGenerator, DontEnum);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeToNativeFromValueh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/ToNativeFromValue.h (203036 => 203037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/ToNativeFromValue.h        2016-07-10 08:03:36 UTC (rev 203036)
+++ trunk/Source/JavaScriptCore/runtime/ToNativeFromValue.h        2016-07-10 08:24:18 UTC (rev 203037)
</span><span class="lines">@@ -48,6 +48,16 @@
</span><span class="cx"> return Adaptor::toNativeFromDouble(value.toNumber(exec));
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+template<typename Adaptor>
+bool toNativeFromValue(ExecState* exec, JSValue value, typename Adaptor::Type& result)
+{
+ if (value.isInt32())
+ return Adaptor::toNativeFromInt32(value.asInt32(), result);
+ if (value.isNumber())
+ return Adaptor::toNativeFromDouble(value.asDouble(), result);
+ return Adaptor::toNativeFromDouble(value.toNumber(exec), result);
+}
+
</ins><span class="cx"> } // namespace JSC
</span><span class="cx">
</span><span class="cx"> #endif // ToNativeFromValue_h
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeTypedArrayAdaptorsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/TypedArrayAdaptors.h (203036 => 203037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/TypedArrayAdaptors.h        2016-07-10 08:03:36 UTC (rev 203036)
+++ trunk/Source/JavaScriptCore/runtime/TypedArrayAdaptors.h        2016-07-10 08:24:18 UTC (rev 203037)
</span><span class="lines">@@ -40,6 +40,8 @@
</span><span class="cx"> typedef ViewTypeArg ViewType;
</span><span class="cx"> typedef JSViewTypeArg JSViewType;
</span><span class="cx"> static const TypedArrayType typeValue = typeValueArg;
</span><ins>+ constexpr static const TypeArg minValue = std::numeric_limits<TypeArg>::lowest();
+ constexpr static const TypeArg maxValue = std::numeric_limits<TypeArg>::max();
</ins><span class="cx">
</span><span class="cx"> static JSValue toJSValue(Type value)
</span><span class="cx"> {
</span><span class="lines">@@ -76,6 +78,38 @@
</span><span class="cx"> return OtherAdaptor::toNativeFromUint32(value);
</span><span class="cx"> return OtherAdaptor::toNativeFromInt32(value);
</span><span class="cx"> }
</span><ins>+
+ static bool toNativeFromInt32(int32_t value, Type& result)
+ {
+ if ((value >= 0 && static_cast<uint32_t>(value) > static_cast<uint32_t>(maxValue)) || value < static_cast<int32_t>(minValue))
+ return false;
+
+ result = static_cast<Type>(value);
+
+ return true;
+ }
+
+ static bool toNativeFromUint32(uint32_t value, Type& result)
+ {
+ if (value > static_cast<uint32_t>(maxValue))
+ return false;
+
+ result = static_cast<Type>(value);
+
+ return true;
+ }
+
+ static bool toNativeFromDouble(double value, Type& result)
+ {
+ Type integer = static_cast<Type>(value);
+ if (static_cast<double>(integer) != value)
+ return false;
+
+ if (value < 0)
+ return toNativeFromInt32(static_cast<int32_t>(value), result);
+
+ return toNativeFromUint32(static_cast<uint32_t>(value), result);
+ }
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> template<
</span><span class="lines">@@ -86,12 +120,14 @@
</span><span class="cx"> typedef ViewTypeArg ViewType;
</span><span class="cx"> typedef JSViewTypeArg JSViewType;
</span><span class="cx"> static const TypedArrayType typeValue = typeValueArg;
</span><del>-
</del><ins>+ constexpr static const TypeArg minValue = std::numeric_limits<TypeArg>::lowest();
+ constexpr static const TypeArg maxValue = std::numeric_limits<TypeArg>::max();
+
</ins><span class="cx"> static JSValue toJSValue(Type value)
</span><span class="cx"> {
</span><span class="cx"> return jsDoubleNumber(purifyNaN(value));
</span><span class="cx"> }
</span><del>-
</del><ins>+
</ins><span class="cx"> static double toDouble(Type value)
</span><span class="cx"> {
</span><span class="cx"> return static_cast<double>(value);
</span><span class="lines">@@ -101,22 +137,47 @@
</span><span class="cx"> {
</span><span class="cx"> return static_cast<Type>(value);
</span><span class="cx"> }
</span><del>-
</del><ins>+
</ins><span class="cx"> static Type toNativeFromUint32(uint32_t value)
</span><span class="cx"> {
</span><span class="cx"> return static_cast<Type>(value);
</span><span class="cx"> }
</span><del>-
</del><ins>+
</ins><span class="cx"> static Type toNativeFromDouble(double value)
</span><span class="cx"> {
</span><del>- return value;
</del><ins>+ return static_cast<Type>(value);
</ins><span class="cx"> }
</span><del>-
</del><ins>+
</ins><span class="cx"> template<typename OtherAdaptor>
</span><span class="cx"> static typename OtherAdaptor::Type convertTo(Type value)
</span><span class="cx"> {
</span><span class="cx"> return OtherAdaptor::toNativeFromDouble(value);
</span><span class="cx"> }
</span><ins>+
+ static bool toNativeFromInt32(int32_t value, Type& result)
+ {
+ result = static_cast<Type>(value);
+ return true;
+ }
+
+ static Type toNativeFromDouble(double value, Type& result)
+ {
+ if (std::isnan(value) || std::isinf(value)) {
+ result = static_cast<Type>(value);
+ return true;
+ }
+
+ Type valueResult = static_cast<Type>(value);
+
+ if (static_cast<double>(valueResult) != value)
+ return false;
+
+ if (value < minValue || value > maxValue)
+ return false;
+
+ result = valueResult;
+ return true;
+ }
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> struct Int8Adaptor;
</span><span class="lines">@@ -165,27 +226,29 @@
</span><span class="cx"> typedef Uint8ClampedArray ViewType;
</span><span class="cx"> typedef JSUint8ClampedArray JSViewType;
</span><span class="cx"> static const TypedArrayType typeValue = TypeUint8Clamped;
</span><del>-
</del><ins>+ constexpr static const uint8_t minValue = std::numeric_limits<uint8_t>::lowest();
+ constexpr static const uint8_t maxValue = std::numeric_limits<uint8_t>::max();
+
</ins><span class="cx"> static JSValue toJSValue(uint8_t value)
</span><span class="cx"> {
</span><span class="cx"> return jsNumber(value);
</span><span class="cx"> }
</span><del>-
</del><ins>+
</ins><span class="cx"> static double toDouble(uint8_t value)
</span><span class="cx"> {
</span><span class="cx"> return static_cast<double>(value);
</span><span class="cx"> }
</span><del>-
</del><ins>+
</ins><span class="cx"> static Type toNativeFromInt32(int32_t value)
</span><span class="cx"> {
</span><span class="cx"> return clamp(value);
</span><span class="cx"> }
</span><del>-
</del><ins>+
</ins><span class="cx"> static Type toNativeFromUint32(uint32_t value)
</span><span class="cx"> {
</span><span class="cx"> return std::min(static_cast<uint32_t>(255), value);
</span><span class="cx"> }
</span><del>-
</del><ins>+
</ins><span class="cx"> static Type toNativeFromDouble(double value)
</span><span class="cx"> {
</span><span class="cx"> if (std::isnan(value) || value < 0)
</span><span class="lines">@@ -194,7 +257,7 @@
</span><span class="cx"> return 255;
</span><span class="cx"> return static_cast<uint8_t>(lrint(value));
</span><span class="cx"> }
</span><del>-
</del><ins>+
</ins><span class="cx"> template<typename OtherAdaptor>
</span><span class="cx"> static typename OtherAdaptor::Type convertTo(uint8_t value)
</span><span class="cx"> {
</span><span class="lines">@@ -201,6 +264,26 @@
</span><span class="cx"> return OtherAdaptor::toNativeFromInt32(value);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ static bool toNativeFromInt32(int32_t value, Type& result)
+ {
+ if (value > maxValue || value < minValue)
+ return false;
+
+ result = static_cast<Type>(value);
+
+ return true;
+ }
+
+ static bool toNativeFromDouble(double value, uint8_t& result)
+ {
+ uint8_t integer = static_cast<uint8_t>(value);
+ if (static_cast<double>(integer) != value)
+ return false;
+
+ result = integer;
+ return true;
+ }
+
</ins><span class="cx"> private:
</span><span class="cx"> static uint8_t clamp(int32_t value)
</span><span class="cx"> {
</span></span></pre>
</div>
</div>
</body>
</html>