<!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 &lt;ticaiolima@gmail.com&gt; 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  &lt;ticaiolima@gmail.com&gt;
+
+        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  &lt;utatane.tea@gmail.com&gt;
</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(&quot;Receiver should be a typed array view but was not an object&quot;) === -1)
+        shouldBeTrue(&quot;false&quot;);
+}
+
+var tArray;
+
+function testIntTypedArray(TypedArray) {
+
+    tArray = new TypedArray([0,2,3]);
+    shouldBeTrue(&quot;tArray.includes(2)&quot;);
+    shouldBeTrue(&quot;!tArray.includes(4)&quot;);
+    shouldBeTrue(&quot;!tArray.includes(3, 3)&quot;);
+    shouldBeTrue(&quot;tArray.includes(3, -1)&quot;);
+    shouldBeTrue(&quot;tArray.includes(3, {valueOf: () =&gt; -1})&quot;);
+
+    // Test non-array-native values
+    shouldBeTrue(&quot;tArray.includes(2.0)&quot;);
+    shouldBeTrue(&quot;!tArray.includes(2.5)&quot;);
+    shouldBeTrue(&quot;!tArray.includes(\&quot;abc\&quot;)&quot;);
+    shouldBeTrue(&quot;!tArray.includes(null)&quot;);
+    shouldBeTrue(&quot;!tArray.includes(undefined)&quot;);
+    shouldBeTrue(&quot;!tArray.includes({1: ''})&quot;);
+    shouldBeTrue(&quot;!tArray.includes(\&quot;\&quot;)&quot;);
+
+    // 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(&quot;fArray.includes(2.0)&quot;);
+    shouldBeTrue(&quot;!fArray.includes(4.0)&quot;);
+    shouldBeTrue(&quot;!fArray.includes(3.0, 3)&quot;);
+    shouldBeTrue(&quot;fArray.includes(3, -1)&quot;);
+
+    fArray = new TypedArray([NaN]);
+    shouldBeTrue(&quot;!fArray.includes(\&quot;abc\&quot;)&quot;);
+    shouldBeTrue(&quot;!fArray.includes(null)&quot;);
+    shouldBeTrue(&quot;!fArray.includes(undefined)&quot;);
+    shouldBeTrue(&quot;!fArray.includes({1: ''})&quot;);
+    shouldBeTrue(&quot;!fArray.includes(\&quot;\&quot;)&quot;);
+
+    // 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(&quot;!(new Uint8Array([NaN]).includes(NaN))&quot;);
+shouldBeTrue(&quot;new Float32Array([NaN]).includes(NaN)&quot;);
+shouldBeTrue(&quot;new Float64Array([NaN]).includes(NaN)&quot;);
+
+var descriptor;
+var gTypedArray;
+
+function testDescriptor(TypedArray) {
+    gTypedArray = TypedArray;
+    descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(TypedArray.prototype), &quot;includes&quot;);
+
+    shouldBeTrue(&quot;descriptor.configurable&quot;);
+    shouldBeTrue(&quot;descriptor.writable&quot;);
+    shouldBeTrue(&quot;!descriptor.enumerable&quot;);
+    shouldBeTrue(&quot;descriptor.get === undefined&quot;);
+    shouldBeTrue(&quot;descriptor.set === undefined&quot;);
+
+    shouldBeTrue(&quot;Object.getPrototypeOf(gTypedArray.prototype).includes.name === \&quot;includes\&quot;&quot;);
+    shouldBeTrue(&quot;Object.getPrototypeOf(gTypedArray.prototype).includes.length === 1&quot;);
+}
+
+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(&quot;arr.includes(0)&quot;);
+shouldBeTrue(&quot;arr.includes(254)&quot;);
+shouldBeTrue(&quot;!arr.includes(255)&quot;);
+shouldBeTrue(&quot;!arr.includes(-1)&quot;);
+
+arr = new Int8Array([-128, 127]);
+shouldBeTrue(&quot;arr.includes(-128)&quot;);
+shouldBeTrue(&quot;arr.includes(127)&quot;);
+shouldBeTrue(&quot;!arr.includes(128)&quot;);
+shouldBeTrue(&quot;!arr.includes(-129)&quot;);
+
+arr = new Uint8ClampedArray([-128, 256]);
+shouldBeTrue(&quot;arr.includes(255)&quot;);
+shouldBeTrue(&quot;arr.includes(0)&quot;);
+shouldBeTrue(&quot;!arr.includes(-128)&quot;);
+shouldBeTrue(&quot;!arr.includes(-256)&quot;);
+
+arr = new Uint16Array([0, 65535]);
+shouldBeTrue(&quot;arr.includes(0)&quot;);
+shouldBeTrue(&quot;arr.includes(65535)&quot;);
+shouldBeTrue(&quot;!arr.includes(65536)&quot;);
+shouldBeTrue(&quot;!arr.includes(-1)&quot;);
+
+arr = new Int16Array([-32768, 32767]);
+shouldBeTrue(&quot;arr.includes(-32768)&quot;);
+shouldBeTrue(&quot;arr.includes(32767)&quot;);
+shouldBeTrue(&quot;!arr.includes(32768)&quot;);
+shouldBeTrue(&quot;!arr.includes(-32769)&quot;);
+
+arr = new Uint32Array([0, 4294967295]);
+shouldBeTrue(&quot;arr.includes(0)&quot;);
+shouldBeTrue(&quot;arr.includes(4294967295)&quot;);
+shouldBeTrue(&quot;!arr.includes(4294967296)&quot;);
+shouldBeTrue(&quot;!arr.includes(-1)&quot;);
+
+arr = new Int32Array([-2147483648, 2147483647]);
+shouldBeTrue(&quot;arr.includes(-2147483648)&quot;);
+shouldBeTrue(&quot;arr.includes(2147483647)&quot;);
+shouldBeTrue(&quot;!arr.includes(2147483648)&quot;);
+shouldBeTrue(&quot;!arr.includes(-2147483649)&quot;);
+
+arr = new Float32Array([-3.402820018375656e+38, 3.402820018375656e+38]);
+shouldBeTrue(&quot;arr.includes(-3.402820018375656e+38)&quot;);
+shouldBeTrue(&quot;arr.includes(3.402820018375656e+38)&quot;);
+shouldBeTrue(&quot;!arr.includes(3.50282e+38)&quot;);
+shouldBeTrue(&quot;!arr.includes(-3.50282e+38)&quot;);
+
+arr = new Float64Array([-1.79769e+308, 1.79769e+308]);
+shouldBeTrue(&quot;arr.includes(-1.79769e+308)&quot;);
+shouldBeTrue(&quot;arr.includes(1.79769e+308)&quot;);
+shouldBeTrue(&quot;!arr.includes(-1.89769e+308)&quot;);
+shouldBeTrue(&quot;!arr.includes(1.89769e+308)&quot;);
+
+// Testing Infinity
+
+function testInfinity(TypedArray) {
+    arr = new TypedArray([Infinity]);
+    shouldBeTrue(&quot;arr.includes(Infinity)&quot;);
+    shouldBeTrue(&quot;!arr.includes(-Infinity)&quot;);
+    shouldBeTrue(&quot;!arr.includes(NaN)&quot;);
+
+    arr = new TypedArray([-Infinity]);
+    shouldBeTrue(&quot;arr.includes(-Infinity)&quot;);
+    shouldBeTrue(&quot;!arr.includes(Infinity)&quot;);
+    shouldBeTrue(&quot;!arr.includes(NaN)&quot;);
+}
+
+testInfinity(Float32Array);
+testInfinity(Float64Array);
+
+// Test float-&gt;double precision
+
+shouldBeTrue(&quot;!(new Float32Array([2.40282e+38]).includes(2.40282e+38))&quot;);
+
+// 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(&quot;funcCallCount.callCount === 1&quot;);
+
+    tArray.includes(&quot;abc&quot;, funcCallCount);
+    shouldBeTrue(&quot;funcCallCount.callCount === 2&quot;);
+
+    tArray.includes(null, funcCallCount);
+    shouldBeTrue(&quot;funcCallCount.callCount === 3&quot;);
+
+    tArray.includes(undefined, funcCallCount);
+    shouldBeTrue(&quot;funcCallCount.callCount === 4&quot;);
+
+    tArray.includes({1: ''}, funcCallCount);
+    shouldBeTrue(&quot;funcCallCount.callCount === 5&quot;);
+
+    tArray.includes(&quot;&quot;, funcCallCount);
+    shouldBeTrue(&quot;funcCallCount.callCount === 6&quot;);
+}
+
+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 &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+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: () =&gt; -1}) is true
+PASS tArray.includes(2.0) is true
+PASS !tArray.includes(2.5) is true
+PASS !tArray.includes(&quot;abc&quot;) is true
+PASS !tArray.includes(null) is true
+PASS !tArray.includes(undefined) is true
+PASS !tArray.includes({1: ''}) is true
+PASS !tArray.includes(&quot;&quot;) 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: () =&gt; -1}) is true
+PASS tArray.includes(2.0) is true
+PASS !tArray.includes(2.5) is true
+PASS !tArray.includes(&quot;abc&quot;) is true
+PASS !tArray.includes(null) is true
+PASS !tArray.includes(undefined) is true
+PASS !tArray.includes({1: ''}) is true
+PASS !tArray.includes(&quot;&quot;) 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: () =&gt; -1}) is true
+PASS tArray.includes(2.0) is true
+PASS !tArray.includes(2.5) is true
+PASS !tArray.includes(&quot;abc&quot;) is true
+PASS !tArray.includes(null) is true
+PASS !tArray.includes(undefined) is true
+PASS !tArray.includes({1: ''}) is true
+PASS !tArray.includes(&quot;&quot;) 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: () =&gt; -1}) is true
+PASS tArray.includes(2.0) is true
+PASS !tArray.includes(2.5) is true
+PASS !tArray.includes(&quot;abc&quot;) is true
+PASS !tArray.includes(null) is true
+PASS !tArray.includes(undefined) is true
+PASS !tArray.includes({1: ''}) is true
+PASS !tArray.includes(&quot;&quot;) 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: () =&gt; -1}) is true
+PASS tArray.includes(2.0) is true
+PASS !tArray.includes(2.5) is true
+PASS !tArray.includes(&quot;abc&quot;) is true
+PASS !tArray.includes(null) is true
+PASS !tArray.includes(undefined) is true
+PASS !tArray.includes({1: ''}) is true
+PASS !tArray.includes(&quot;&quot;) 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: () =&gt; -1}) is true
+PASS tArray.includes(2.0) is true
+PASS !tArray.includes(2.5) is true
+PASS !tArray.includes(&quot;abc&quot;) is true
+PASS !tArray.includes(null) is true
+PASS !tArray.includes(undefined) is true
+PASS !tArray.includes({1: ''}) is true
+PASS !tArray.includes(&quot;&quot;) 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: () =&gt; -1}) is true
+PASS tArray.includes(2.0) is true
+PASS !tArray.includes(2.5) is true
+PASS !tArray.includes(&quot;abc&quot;) is true
+PASS !tArray.includes(null) is true
+PASS !tArray.includes(undefined) is true
+PASS !tArray.includes({1: ''}) is true
+PASS !tArray.includes(&quot;&quot;) 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 === &quot;includes&quot; 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 === &quot;includes&quot; 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 === &quot;includes&quot; 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 === &quot;includes&quot; 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 === &quot;includes&quot; 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 === &quot;includes&quot; 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 === &quot;includes&quot; 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 === &quot;includes&quot; 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 === &quot;includes&quot; 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>+&lt;!DOCTYPE HTML PUBLIC &quot;-//IETF//DTD HTML//EN&quot;&gt;
+&lt;html&gt;
+    &lt;head&gt;
+        &lt;script src=&quot;../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+    &lt;/head&gt;
+    &lt;body&gt;
+        &lt;script src=&quot;../resources/regress-pre.js&quot;&gt;&lt;/script&gt;
+        &lt;script src=&quot;script-tests/typed-array-includes.js&quot;&gt;&lt;/script&gt;
+        &lt;script src=&quot;../resources/regress-post.js&quot;&gt;&lt;/script&gt;
+        &lt;script src=&quot;../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+    &lt;/body&gt;
+&lt;/html&gt;
+
</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  &lt;ticaiolima@gmail.com&gt;
+
+        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  &lt;fpizlo@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         REGRESSION(201900): validation failure for GetByOffset/PutByOffset in VALIDATE((node), node-&gt;child1().node() == node-&gt;child2().node() || node-&gt;child1()-&gt;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&lt;Adaptor&gt;(exec, jsValue); }
</span><span class="cx"> 
</span><ins>+    static bool toAdaptorNativeFromValue(ExecState* exec, JSValue jsValue, ElementType&amp; result) { return toNativeFromValue&lt;Adaptor&gt;(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 &lt;= start &amp;&amp; start &lt;= end &amp;&amp; end &lt;= 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&lt;typename ViewClass&gt;
</span><ins>+EncodedJSValue JSC_HOST_CALL genericTypedArrayViewProtoFuncIncludes(ExecState* exec)
+{
+    ViewClass* thisObject = jsCast&lt;ViewClass*&gt;(exec-&gt;thisValue());
+    if (thisObject-&gt;isNeutered())
+        return throwVMTypeError(exec, typedArrayBufferHasBeenDetachedErrorMessage);
+
+    unsigned length = thisObject-&gt;length();
+
+    if (!length)
+        return JSValue::encode(jsBoolean(false));
+
+    JSValue valueToFind = exec-&gt;argument(0);
+
+    unsigned index = argumentClampedIndexFromStartOrEnd(exec, 1, length);
+
+    if (!valueToFind.isNumber())
+        return JSValue::encode(jsBoolean(false));
+
+    typename ViewClass::ElementType* array = thisObject-&gt;typedVector();
+    typename ViewClass::ElementType target;
+    if (!ViewClass::toAdaptorNativeFromValue(exec, valueToFind, target))
+        return JSValue::encode(jsBoolean(false));
+
+    if (exec-&gt;hadException())
+        return JSValue::encode(jsUndefined());
+
+    if (std::isnan(static_cast&lt;double&gt;(target))) {
+        for (; index &lt; length; ++index) {
+            if (std::isnan(static_cast&lt;double&gt;(array[index])))
+                return JSValue::encode(jsBoolean(true));
+        }
+    } else {
+        for (; index &lt; length; ++index) {
+            if (array[index] == target)
+                return JSValue::encode(jsBoolean(true));
+        }
+    }
+
+    return JSValue::encode(jsBoolean(false));
+}
+
+template&lt;typename ViewClass&gt;
</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-&gt;thisValue();
+    if (!thisValue.isObject())
+        return throwVMError(exec, createTypeError(exec, &quot;Receiver should be a typed array view but was not an object&quot;));
+    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-&gt;thisValue();
</span><span class="lines">@@ -261,6 +269,7 @@
</span><span class="cx">     JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(&quot;sort&quot;, typedArrayPrototypeSortCodeGenerator, DontEnum);
</span><span class="cx">     JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames-&gt;builtinNames().entriesPublicName(), typedArrayPrototypeEntriesCodeGenerator, DontEnum);
</span><span class="cx">     JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION(&quot;fill&quot;, typedArrayViewProtoFuncFill, DontEnum, 1);
</span><ins>+    JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION(&quot;includes&quot;, typedArrayViewProtoFuncIncludes, DontEnum, 1);
</ins><span class="cx">     JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(&quot;find&quot;, typedArrayPrototypeFindCodeGenerator, DontEnum);
</span><span class="cx">     JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(&quot;findIndex&quot;, typedArrayPrototypeFindIndexCodeGenerator, DontEnum);
</span><span class="cx">     JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames-&gt;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&lt;typename Adaptor&gt;
+bool toNativeFromValue(ExecState* exec, JSValue value, typename Adaptor::Type&amp; 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&lt;TypeArg&gt;::lowest();
+    constexpr static const TypeArg maxValue = std::numeric_limits&lt;TypeArg&gt;::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&amp; result)
+    {
+        if ((value &gt;= 0 &amp;&amp; static_cast&lt;uint32_t&gt;(value) &gt; static_cast&lt;uint32_t&gt;(maxValue)) || value &lt; static_cast&lt;int32_t&gt;(minValue))
+            return false;
+
+        result = static_cast&lt;Type&gt;(value);
+
+        return true;
+    }
+
+    static bool toNativeFromUint32(uint32_t value, Type&amp; result)
+    {
+        if (value &gt; static_cast&lt;uint32_t&gt;(maxValue))
+            return false;
+
+        result = static_cast&lt;Type&gt;(value);
+
+        return true;
+    }
+
+    static bool toNativeFromDouble(double value, Type&amp; result)
+    {
+        Type integer = static_cast&lt;Type&gt;(value);
+        if (static_cast&lt;double&gt;(integer) != value)
+            return false;
+
+        if (value &lt; 0)
+            return toNativeFromInt32(static_cast&lt;int32_t&gt;(value), result);
+        
+        return toNativeFromUint32(static_cast&lt;uint32_t&gt;(value), result);
+    }
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> template&lt;
</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&lt;TypeArg&gt;::lowest();
+    constexpr static const TypeArg maxValue = std::numeric_limits&lt;TypeArg&gt;::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&lt;double&gt;(value);
</span><span class="lines">@@ -101,22 +137,47 @@
</span><span class="cx">     {
</span><span class="cx">         return static_cast&lt;Type&gt;(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&lt;Type&gt;(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&lt;Type&gt;(value);
</ins><span class="cx">     }
</span><del>-    
</del><ins>+
</ins><span class="cx">     template&lt;typename OtherAdaptor&gt;
</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&amp; result)
+    {
+        result = static_cast&lt;Type&gt;(value);
+        return true;
+    }
+
+    static Type toNativeFromDouble(double value, Type&amp; result)
+    {
+        if (std::isnan(value) || std::isinf(value)) {
+            result = static_cast&lt;Type&gt;(value);
+            return true;
+        }
+
+        Type valueResult = static_cast&lt;Type&gt;(value);
+
+        if (static_cast&lt;double&gt;(valueResult) != value)
+            return false;
+
+        if (value &lt; minValue || value &gt; 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&lt;uint8_t&gt;::lowest();
+    constexpr static const uint8_t maxValue = std::numeric_limits&lt;uint8_t&gt;::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&lt;double&gt;(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&lt;uint32_t&gt;(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 &lt; 0)
</span><span class="lines">@@ -194,7 +257,7 @@
</span><span class="cx">             return 255;
</span><span class="cx">         return static_cast&lt;uint8_t&gt;(lrint(value));
</span><span class="cx">     }
</span><del>-    
</del><ins>+
</ins><span class="cx">     template&lt;typename OtherAdaptor&gt;
</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&amp; result)
+    {
+        if (value &gt; maxValue || value &lt; minValue)
+            return false;
+
+        result = static_cast&lt;Type&gt;(value);
+
+        return true;
+    }
+
+    static bool toNativeFromDouble(double value, uint8_t&amp; result)
+    {
+        uint8_t integer = static_cast&lt;uint8_t&gt;(value);
+        if (static_cast&lt;double&gt;(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>