<!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>[188808] trunk/Source/JavaScriptCore</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/188808">188808</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2015-08-21 17:49:20 -0700 (Fri, 21 Aug 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Parse control flow statements in WebAssembly
https://bugs.webkit.org/show_bug.cgi?id=148333

Patch by Sukolsak Sakshuwong &lt;sukolsak@gmail.com&gt; on 2015-08-21
Reviewed by Geoffrey Garen.

Parse control flow statements in WebAssembly files generated by pack-asmjs
&lt;https://github.com/WebAssembly/polyfill-prototype-1&gt;.

* wasm/WASMConstants.h:
* wasm/WASMFunctionParser.cpp:
(JSC::WASMFunctionParser::parseStatement):
(JSC::WASMFunctionParser::parseIfStatement):
(JSC::WASMFunctionParser::parseIfElseStatement):
(JSC::WASMFunctionParser::parseWhileStatement):
(JSC::WASMFunctionParser::parseDoStatement):
(JSC::WASMFunctionParser::parseLabelStatement):
(JSC::WASMFunctionParser::parseBreakStatement):
(JSC::WASMFunctionParser::parseBreakLabelStatement):
(JSC::WASMFunctionParser::parseContinueStatement):
(JSC::WASMFunctionParser::parseContinueLabelStatement):
(JSC::WASMFunctionParser::parseSwitchStatement):
* wasm/WASMFunctionParser.h:
(JSC::WASMFunctionParser::WASMFunctionParser):
* wasm/WASMReader.cpp:
(JSC::WASMReader::readCompactInt32):
(JSC::WASMReader::readSwitchCase):
* wasm/WASMReader.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMConstantsh">trunk/Source/JavaScriptCore/wasm/WASMConstants.h</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMFunctionParsercpp">trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMFunctionParserh">trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.h</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMReadercpp">trunk/Source/JavaScriptCore/wasm/WASMReader.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMReaderh">trunk/Source/JavaScriptCore/wasm/WASMReader.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (188807 => 188808)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-08-22 00:34:31 UTC (rev 188807)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-08-22 00:49:20 UTC (rev 188808)
</span><span class="lines">@@ -1,3 +1,33 @@
</span><ins>+2015-08-21  Sukolsak Sakshuwong  &lt;sukolsak@gmail.com&gt;
+
+        Parse control flow statements in WebAssembly
+        https://bugs.webkit.org/show_bug.cgi?id=148333
+
+        Reviewed by Geoffrey Garen.
+
+        Parse control flow statements in WebAssembly files generated by pack-asmjs
+        &lt;https://github.com/WebAssembly/polyfill-prototype-1&gt;.
+
+        * wasm/WASMConstants.h:
+        * wasm/WASMFunctionParser.cpp:
+        (JSC::WASMFunctionParser::parseStatement):
+        (JSC::WASMFunctionParser::parseIfStatement):
+        (JSC::WASMFunctionParser::parseIfElseStatement):
+        (JSC::WASMFunctionParser::parseWhileStatement):
+        (JSC::WASMFunctionParser::parseDoStatement):
+        (JSC::WASMFunctionParser::parseLabelStatement):
+        (JSC::WASMFunctionParser::parseBreakStatement):
+        (JSC::WASMFunctionParser::parseBreakLabelStatement):
+        (JSC::WASMFunctionParser::parseContinueStatement):
+        (JSC::WASMFunctionParser::parseContinueLabelStatement):
+        (JSC::WASMFunctionParser::parseSwitchStatement):
+        * wasm/WASMFunctionParser.h:
+        (JSC::WASMFunctionParser::WASMFunctionParser):
+        * wasm/WASMReader.cpp:
+        (JSC::WASMReader::readCompactInt32):
+        (JSC::WASMReader::readSwitchCase):
+        * wasm/WASMReader.h:
+
</ins><span class="cx"> 2015-08-21  Geoffrey Garen  &lt;ggaren@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Debugger's VM should never be null
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMConstantsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WASMConstants.h (188807 => 188808)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMConstants.h        2015-08-22 00:34:31 UTC (rev 188807)
+++ trunk/Source/JavaScriptCore/wasm/WASMConstants.h        2015-08-22 00:49:20 UTC (rev 188808)
</span><span class="lines">@@ -182,6 +182,16 @@
</span><span class="cx">     NumberOfVariableTypesWithImmediates
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+enum class WASMSwitchCase : uint8_t {
+    CaseWithNoStatements,
+    CaseWithStatement,
+    CaseWithBlockStatement,
+    DefaultWithNoStatements,
+    DefaultWithStatement,
+    DefaultWithBlockStatement,
+    NumberOfSwitchCases
+};
+
</ins><span class="cx"> enum class WASMExportFormat : uint8_t {
</span><span class="cx">     Default,
</span><span class="cx">     Record,
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMFunctionParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.cpp (188807 => 188808)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.cpp        2015-08-22 00:34:31 UTC (rev 188807)
+++ trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.cpp        2015-08-22 00:49:20 UTC (rev 188808)
</span><span class="lines">@@ -33,10 +33,12 @@
</span><span class="cx"> 
</span><span class="cx"> #define PROPAGATE_ERROR() do { if (!m_errorMessage.isNull()) return 0; } while (0)
</span><span class="cx"> #define FAIL_WITH_MESSAGE(errorMessage) do {  m_errorMessage = errorMessage; return 0; } while (0)
</span><ins>+#define READ_COMPACT_INT32_OR_FAIL(result, errorMessage) do { if (!m_reader.readCompactInt32(result)) FAIL_WITH_MESSAGE(errorMessage); } while (0)
</ins><span class="cx"> #define READ_COMPACT_UINT32_OR_FAIL(result, errorMessage) do { if (!m_reader.readCompactUInt32(result)) FAIL_WITH_MESSAGE(errorMessage); } while (0)
</span><span class="cx"> #define READ_OP_STATEMENT_OR_FAIL(hasImmediate, op, opWithImmediate, immediate, errorMessage) do { if (!m_reader.readOpStatement(hasImmediate, op, opWithImmediate, immediate)) FAIL_WITH_MESSAGE(errorMessage); } while (0)
</span><span class="cx"> #define READ_OP_EXPRESSION_I32_OR_FAIL(hasImmediate, op, opWithImmediate, immediate, errorMessage) do { if (!m_reader.readOpExpressionI32(hasImmediate, op, opWithImmediate, immediate)) FAIL_WITH_MESSAGE(errorMessage); } while (0)
</span><span class="cx"> #define READ_VARIABLE_TYPES_OR_FAIL(hasImmediate, variableTypes, variableTypesWithImmediate, immediate, errorMessage) do { if (!m_reader.readVariableTypes(hasImmediate, variableTypes, variableTypesWithImmediate, immediate)) FAIL_WITH_MESSAGE(errorMessage); } while (0)
</span><ins>+#define READ_SWITCH_CASE_OR_FAIL(result, errorMessage) do { if (!m_reader.readSwitchCase(result)) FAIL_WITH_MESSAGE(errorMessage); } while (0)
</ins><span class="cx"> #define FAIL_IF_FALSE(condition, errorMessage) do { if (!(condition)) FAIL_WITH_MESSAGE(errorMessage); } while (0)
</span><span class="cx"> 
</span><span class="cx"> #define UNUSED 0
</span><span class="lines">@@ -123,17 +125,37 @@
</span><span class="cx">         case WASMOpStatement::Block:
</span><span class="cx">             parseBlockStatement(context);
</span><span class="cx">             break;
</span><del>-        case WASMOpStatement::SetGlobal:
</del><span class="cx">         case WASMOpStatement::If:
</span><ins>+            parseIfStatement(context);
+            break;
</ins><span class="cx">         case WASMOpStatement::IfElse:
</span><ins>+            parseIfElseStatement(context);
+            break;
</ins><span class="cx">         case WASMOpStatement::While:
</span><ins>+            parseWhileStatement(context);
+            break;
</ins><span class="cx">         case WASMOpStatement::Do:
</span><ins>+            parseDoStatement(context);
+            break;
</ins><span class="cx">         case WASMOpStatement::Label:
</span><ins>+            parseLabelStatement(context);
+            break;
</ins><span class="cx">         case WASMOpStatement::Break:
</span><ins>+            parseBreakStatement(context);
+            break;
</ins><span class="cx">         case WASMOpStatement::BreakLabel:
</span><ins>+            parseBreakLabelStatement(context);
+            break;
</ins><span class="cx">         case WASMOpStatement::Continue:
</span><ins>+            parseContinueStatement(context);
+            break;
</ins><span class="cx">         case WASMOpStatement::ContinueLabel:
</span><ins>+            parseContinueLabelStatement(context);
+            break;
</ins><span class="cx">         case WASMOpStatement::Switch:
</span><ins>+            parseSwitchStatement(context);
+            break;
+        case WASMOpStatement::SetGlobal:
</ins><span class="cx">         case WASMOpStatement::I32Store8:
</span><span class="cx">         case WASMOpStatement::I32StoreWithOffset8:
</span><span class="cx">         case WASMOpStatement::I32Store16:
</span><span class="lines">@@ -207,6 +229,155 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> template &lt;class Context&gt;
</span><ins>+ContextStatement WASMFunctionParser::parseIfStatement(Context&amp; context)
+{
+    parseExpressionI32(context);
+    PROPAGATE_ERROR();
+    parseStatement(context);
+    // FIXME: Implement this instruction.
+    return UNUSED;
+}
+
+template &lt;class Context&gt;
+ContextStatement WASMFunctionParser::parseIfElseStatement(Context&amp; context)
+{
+    parseExpressionI32(context);
+    PROPAGATE_ERROR();
+    parseStatement(context);
+    PROPAGATE_ERROR();
+    parseStatement(context);
+    // FIXME: Implement this instruction.
+    return UNUSED;
+}
+
+template &lt;class Context&gt;
+ContextStatement WASMFunctionParser::parseWhileStatement(Context&amp; context)
+{
+    parseExpressionI32(context);
+    PROPAGATE_ERROR();
+
+    m_breakScopeDepth++;
+    m_continueScopeDepth++;
+    parseStatement(context);
+    PROPAGATE_ERROR();
+    m_continueScopeDepth--;
+    m_breakScopeDepth--;
+    // FIXME: Implement this instruction.
+    return UNUSED;
+}
+
+template &lt;class Context&gt;
+ContextStatement WASMFunctionParser::parseDoStatement(Context&amp; context)
+{
+    m_breakScopeDepth++;
+    m_continueScopeDepth++;
+    parseStatement(context);
+    PROPAGATE_ERROR();
+    m_continueScopeDepth--;
+    m_breakScopeDepth--;
+
+    parseExpressionI32(context);
+    // FIXME: Implement this instruction.
+    return UNUSED;
+}
+
+template &lt;class Context&gt;
+ContextStatement WASMFunctionParser::parseLabelStatement(Context&amp; context)
+{
+    m_labelDepth++;
+    parseStatement(context);
+    PROPAGATE_ERROR();
+    m_labelDepth--;
+    // FIXME: Implement this instruction.
+    return UNUSED;
+}
+
+template &lt;class Context&gt;
+ContextStatement WASMFunctionParser::parseBreakStatement(Context&amp;)
+{
+    FAIL_IF_FALSE(m_breakScopeDepth, &quot;'break' is only valid inside a switch or loop statement.&quot;);
+    // FIXME: Implement this instruction.
+    return UNUSED;
+}
+
+template &lt;class Context&gt;
+ContextStatement WASMFunctionParser::parseBreakLabelStatement(Context&amp;)
+{
+    uint32_t labelIndex;
+    READ_COMPACT_UINT32_OR_FAIL(labelIndex, &quot;Cannot read the label index.&quot;);
+    FAIL_IF_FALSE(labelIndex &lt; m_labelDepth, &quot;The label index is incorrect.&quot;);
+    // FIXME: Implement this instruction.
+    return UNUSED;
+}
+
+template &lt;class Context&gt;
+ContextStatement WASMFunctionParser::parseContinueStatement(Context&amp;)
+{
+    FAIL_IF_FALSE(m_continueScopeDepth, &quot;'continue' is only valid inside a loop statement.&quot;);
+    // FIXME: Implement this instruction.
+    return UNUSED;
+}
+
+template &lt;class Context&gt;
+ContextStatement WASMFunctionParser::parseContinueLabelStatement(Context&amp;)
+{
+    uint32_t labelIndex;
+    READ_COMPACT_UINT32_OR_FAIL(labelIndex, &quot;Cannot read the label index.&quot;);
+    FAIL_IF_FALSE(labelIndex &lt; m_labelDepth, &quot;The label index is incorrect.&quot;);
+    // FIXME: Implement this instruction.
+    return UNUSED;
+}
+
+template &lt;class Context&gt;
+ContextStatement WASMFunctionParser::parseSwitchStatement(Context&amp; context)
+{
+    uint32_t numberOfCases;
+    READ_COMPACT_UINT32_OR_FAIL(numberOfCases, &quot;Cannot read the number of cases.&quot;);
+    parseExpressionI32(context);
+    PROPAGATE_ERROR();
+
+    m_breakScopeDepth++;
+    for (uint32_t i = 0; i &lt; numberOfCases; ++i) {
+        WASMSwitchCase switchCase;
+        READ_SWITCH_CASE_OR_FAIL(switchCase, &quot;Cannot read the switch case.&quot;);
+        switch (switchCase) {
+        case WASMSwitchCase::CaseWithNoStatements:
+        case WASMSwitchCase::CaseWithStatement:
+        case WASMSwitchCase::CaseWithBlockStatement: {
+            uint32_t value;
+            READ_COMPACT_INT32_OR_FAIL(value, &quot;Cannot read the value of the switch case.&quot;);
+            if (switchCase == WASMSwitchCase::CaseWithStatement) {
+                parseStatement(context);
+                PROPAGATE_ERROR();
+            } else if (switchCase == WASMSwitchCase::CaseWithBlockStatement) {
+                parseBlockStatement(context);
+                PROPAGATE_ERROR();
+            }
+            break;
+        }
+        case WASMSwitchCase::DefaultWithNoStatements:
+        case WASMSwitchCase::DefaultWithStatement:
+        case WASMSwitchCase::DefaultWithBlockStatement: {
+            FAIL_IF_FALSE(i == numberOfCases - 1, &quot;The default case must be the last case.&quot;);
+            if (switchCase == WASMSwitchCase::DefaultWithStatement) {
+                parseStatement(context);
+                PROPAGATE_ERROR();
+            } else if (switchCase == WASMSwitchCase::DefaultWithBlockStatement) {
+                parseBlockStatement(context);
+                PROPAGATE_ERROR();
+            }
+            break;
+        }
+        default:
+            ASSERT_NOT_REACHED();
+        }
+    }
+    m_breakScopeDepth--;
+    // FIXME: Implement this instruction.
+    return UNUSED;
+}
+
+template &lt;class Context&gt;
</ins><span class="cx"> ContextExpression WASMFunctionParser::parseExpression(Context&amp; context, WASMExpressionType expressionType)
</span><span class="cx"> {
</span><span class="cx">     switch (expressionType) {
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMFunctionParserh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.h (188807 => 188808)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.h        2015-08-22 00:34:31 UTC (rev 188807)
+++ trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.h        2015-08-22 00:49:20 UTC (rev 188808)
</span><span class="lines">@@ -47,6 +47,9 @@
</span><span class="cx">         : m_module(module)
</span><span class="cx">         , m_reader(static_cast&lt;WebAssemblySourceProvider*&gt;(source.provider())-&gt;data())
</span><span class="cx">         , m_functionIndex(functionIndex)
</span><ins>+        , m_breakScopeDepth(0)
+        , m_continueScopeDepth(0)
+        , m_labelDepth(0)
</ins><span class="cx">     {
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -58,6 +61,16 @@
</span><span class="cx">     template &lt;class Context&gt; ContextStatement parseSetLocalStatement(Context&amp;);
</span><span class="cx">     template &lt;class Context&gt; ContextStatement parseReturnStatement(Context&amp;);
</span><span class="cx">     template &lt;class Context&gt; ContextStatement parseBlockStatement(Context&amp;);
</span><ins>+    template &lt;class Context&gt; ContextStatement parseIfStatement(Context&amp;);
+    template &lt;class Context&gt; ContextStatement parseIfElseStatement(Context&amp;);
+    template &lt;class Context&gt; ContextStatement parseWhileStatement(Context&amp;);
+    template &lt;class Context&gt; ContextStatement parseDoStatement(Context&amp;);
+    template &lt;class Context&gt; ContextStatement parseLabelStatement(Context&amp;);
+    template &lt;class Context&gt; ContextStatement parseBreakStatement(Context&amp;);
+    template &lt;class Context&gt; ContextStatement parseBreakLabelStatement(Context&amp;);
+    template &lt;class Context&gt; ContextStatement parseContinueStatement(Context&amp;);
+    template &lt;class Context&gt; ContextStatement parseContinueLabelStatement(Context&amp;);
+    template &lt;class Context&gt; ContextStatement parseSwitchStatement(Context&amp;);
</ins><span class="cx"> 
</span><span class="cx">     template &lt;class Context&gt; ContextExpression parseExpression(Context&amp;, WASMExpressionType);
</span><span class="cx"> 
</span><span class="lines">@@ -75,6 +88,10 @@
</span><span class="cx">     uint32_t m_numberOfI32LocalVariables;
</span><span class="cx">     uint32_t m_numberOfF32LocalVariables;
</span><span class="cx">     uint32_t m_numberOfF64LocalVariables;
</span><ins>+
+    unsigned m_breakScopeDepth;
+    unsigned m_continueScopeDepth;
+    unsigned m_labelDepth;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace JSC
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMReadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WASMReader.cpp (188807 => 188808)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMReader.cpp        2015-08-22 00:34:31 UTC (rev 188807)
+++ trunk/Source/JavaScriptCore/wasm/WASMReader.cpp        2015-08-22 00:49:20 UTC (rev 188808)
</span><span class="lines">@@ -95,6 +95,28 @@
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool WASMReader::readCompactInt32(uint32_t&amp; result)
+{
+    uint32_t sum = 0;
+    unsigned shift = 0;
+    do {
+        CHECK_READ(1);
+        uint8_t byte = *m_cursor++;
+        if (byte &lt; 0x80) {
+            sum |= byte &lt;&lt; shift;
+            int signExtend = (32 - 7) - shift;
+            if (signExtend &gt; 0)
+                result = int32_t(sum) &lt;&lt; signExtend &gt;&gt; signExtend;
+            else
+                result = int32_t(sum);
+            return true;
+        }
+        sum |= (byte &amp; firstSevenBitsMask) &lt;&lt; shift;
+        shift += 7;
+    } while (shift &lt; 35);
+    return false;
+}
+
</ins><span class="cx"> bool WASMReader::readCompactUInt32(uint32_t&amp; result)
</span><span class="cx"> {
</span><span class="cx">     uint32_t sum = 0;
</span><span class="lines">@@ -197,6 +219,11 @@
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool WASMReader::readSwitchCase(WASMSwitchCase&amp; result)
+{
+    return readByte&lt;WASMSwitchCase&gt;(result, static_cast&lt;uint8_t&gt;(WASMSwitchCase::NumberOfSwitchCases));
+}
+
</ins><span class="cx"> } // namespace JSC
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(WEBASSEMBLY)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMReaderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WASMReader.h (188807 => 188808)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMReader.h        2015-08-22 00:34:31 UTC (rev 188807)
+++ trunk/Source/JavaScriptCore/wasm/WASMReader.h        2015-08-22 00:49:20 UTC (rev 188808)
</span><span class="lines">@@ -48,6 +48,7 @@
</span><span class="cx">     bool readUInt32(uint32_t&amp; result);
</span><span class="cx">     bool readFloat(float&amp; result);
</span><span class="cx">     bool readDouble(double&amp; result);
</span><ins>+    bool readCompactInt32(uint32_t&amp; result);
</ins><span class="cx">     bool readCompactUInt32(uint32_t&amp; result);
</span><span class="cx">     bool readString(String&amp; result);
</span><span class="cx">     bool readType(WASMType&amp; result);
</span><span class="lines">@@ -56,6 +57,7 @@
</span><span class="cx">     bool readOpStatement(bool&amp; hasImmediate, WASMOpStatement&amp;, WASMOpStatementWithImmediate&amp;, uint8_t&amp; immediate);
</span><span class="cx">     bool readOpExpressionI32(bool&amp; hasImmediate, WASMOpExpressionI32&amp;, WASMOpExpressionI32WithImmediate&amp;, uint8_t&amp; immediate);
</span><span class="cx">     bool readVariableTypes(bool&amp; hasImmediate, WASMVariableTypes&amp;, WASMVariableTypesWithImmediate&amp;, uint8_t&amp; immediate);
</span><ins>+    bool readSwitchCase(WASMSwitchCase&amp; result);
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     static const uint32_t firstSevenBitsMask = 0x7f;
</span></span></pre>
</div>
</div>

</body>
</html>