<!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>[200121] trunk/Source</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/200121">200121</a></dd>
<dt>Author</dt> <dd>sbarati@apple.com</dd>
<dt>Date</dt> <dd>2016-04-27 00:12:06 -0700 (Wed, 27 Apr 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>JSC should have an option to allow global const redeclarations
https://bugs.webkit.org/show_bug.cgi?id=157006

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

This patch implements an option that dictates whether
const redeclarations at the program level will throw.
This option defaults to true but allows users of JSC
to set it to false. This option is per VM. This is needed
for backwards compatibility with our old const implementation.

* jsc.cpp:
(GlobalObject::finishCreation):
(functionShadowChickenFunctionsOnStack):
(functionSetGlobalConstRedeclarationShouldNotThrow):
(functionReadline):
* runtime/Executable.cpp:
(JSC::ProgramExecutable::initializeGlobalProperties):
* runtime/JSGlobalLexicalEnvironment.cpp:
(JSC::JSGlobalLexicalEnvironment::put):
(JSC::JSGlobalLexicalEnvironment::isConstVariable):
* runtime/JSGlobalLexicalEnvironment.h:
(JSC::JSGlobalLexicalEnvironment::isEmpty):
* runtime/VM.h:
(JSC::VM::setGlobalConstRedeclarationShouldThrow):
(JSC::VM::globalConstRedeclarationShouldThrow):
* tests/stress/global-const-redeclaration-setting: Added.
* tests/stress/global-const-redeclaration-setting-2.js: Added.
(assert):
* tests/stress/global-const-redeclaration-setting-3.js: Added.
(assert):
(catch):
* tests/stress/global-const-redeclaration-setting-4.js: Added.
(assert):
(catch):
* tests/stress/global-const-redeclaration-setting-5.js: Added.
(assert):
(catch):
* tests/stress/global-const-redeclaration-setting.js: Added.
(assert):
* tests/stress/global-const-redeclaration-setting/first.js: Added.
* tests/stress/global-const-redeclaration-setting/let.js: Added.
* tests/stress/global-const-redeclaration-setting/second.js: Added.
* tests/stress/global-const-redeclaration-setting/strict.js: Added.

Source/WebCore:

This patch makes the JS VM not throw global const redeclaration
errors when the application is iBooks.

* bindings/js/JSDOMWindowBase.cpp:
(WebCore::JSDOMWindowBase::commonVM):
* page/Settings.h:
(WebCore::Settings::shouldUseHighResolutionTimers):
(WebCore::Settings::globalConstRedeclarationShouldThrow):
(WebCore::Settings::backgroundShouldExtendBeyondPage):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCorejsccpp">trunk/Source/JavaScriptCore/jsc.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeExecutablecpp">trunk/Source/JavaScriptCore/runtime/Executable.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSGlobalLexicalEnvironmentcpp">trunk/Source/JavaScriptCore/runtime/JSGlobalLexicalEnvironment.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSGlobalLexicalEnvironmenth">trunk/Source/JavaScriptCore/runtime/JSGlobalLexicalEnvironment.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeVMh">trunk/Source/JavaScriptCore/runtime/VM.h</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorebindingsjsJSDOMWindowBasecpp">trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp</a></li>
<li><a href="#trunkSourceWebCorepageSettingsh">trunk/Source/WebCore/page/Settings.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li>trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting/</li>
<li><a href="#trunkSourceJavaScriptCoretestsstressglobalconstredeclarationsettingfirstjs">trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting/first.js</a></li>
<li><a href="#trunkSourceJavaScriptCoretestsstressglobalconstredeclarationsettingletjs">trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting/let.js</a></li>
<li><a href="#trunkSourceJavaScriptCoretestsstressglobalconstredeclarationsettingsecondjs">trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting/second.js</a></li>
<li><a href="#trunkSourceJavaScriptCoretestsstressglobalconstredeclarationsettingstrictjs">trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting/strict.js</a></li>
<li><a href="#trunkSourceJavaScriptCoretestsstressglobalconstredeclarationsetting2js">trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting-2.js</a></li>
<li><a href="#trunkSourceJavaScriptCoretestsstressglobalconstredeclarationsetting3js">trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting-3.js</a></li>
<li><a href="#trunkSourceJavaScriptCoretestsstressglobalconstredeclarationsetting4js">trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting-4.js</a></li>
<li><a href="#trunkSourceJavaScriptCoretestsstressglobalconstredeclarationsetting5js">trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting-5.js</a></li>
<li><a href="#trunkSourceJavaScriptCoretestsstressglobalconstredeclarationsettingjs">trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (200120 => 200121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2016-04-27 03:21:58 UTC (rev 200120)
+++ trunk/Source/JavaScriptCore/ChangeLog        2016-04-27 07:12:06 UTC (rev 200121)
</span><span class="lines">@@ -1,3 +1,50 @@
</span><ins>+2016-04-27  Saam barati  &lt;sbarati@apple.com&gt;
+
+        JSC should have an option to allow global const redeclarations
+        https://bugs.webkit.org/show_bug.cgi?id=157006
+
+        Reviewed by Geoffrey Garen.
+
+        This patch implements an option that dictates whether
+        const redeclarations at the program level will throw.
+        This option defaults to true but allows users of JSC
+        to set it to false. This option is per VM. This is needed
+        for backwards compatibility with our old const implementation.
+
+        * jsc.cpp:
+        (GlobalObject::finishCreation):
+        (functionShadowChickenFunctionsOnStack):
+        (functionSetGlobalConstRedeclarationShouldNotThrow):
+        (functionReadline):
+        * runtime/Executable.cpp:
+        (JSC::ProgramExecutable::initializeGlobalProperties):
+        * runtime/JSGlobalLexicalEnvironment.cpp:
+        (JSC::JSGlobalLexicalEnvironment::put):
+        (JSC::JSGlobalLexicalEnvironment::isConstVariable):
+        * runtime/JSGlobalLexicalEnvironment.h:
+        (JSC::JSGlobalLexicalEnvironment::isEmpty):
+        * runtime/VM.h:
+        (JSC::VM::setGlobalConstRedeclarationShouldThrow):
+        (JSC::VM::globalConstRedeclarationShouldThrow):
+        * tests/stress/global-const-redeclaration-setting: Added.
+        * tests/stress/global-const-redeclaration-setting-2.js: Added.
+        (assert):
+        * tests/stress/global-const-redeclaration-setting-3.js: Added.
+        (assert):
+        (catch):
+        * tests/stress/global-const-redeclaration-setting-4.js: Added.
+        (assert):
+        (catch):
+        * tests/stress/global-const-redeclaration-setting-5.js: Added.
+        (assert):
+        (catch):
+        * tests/stress/global-const-redeclaration-setting.js: Added.
+        (assert):
+        * tests/stress/global-const-redeclaration-setting/first.js: Added.
+        * tests/stress/global-const-redeclaration-setting/let.js: Added.
+        * tests/stress/global-const-redeclaration-setting/second.js: Added.
+        * tests/stress/global-const-redeclaration-setting/strict.js: Added.
+
</ins><span class="cx"> 2016-04-26  Michael Saboff  &lt;msaboff@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [ES] Implement RegExp.prototype.@@replace and use it for String.prototype.replace
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorejsccpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/jsc.cpp (200120 => 200121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/jsc.cpp        2016-04-27 03:21:58 UTC (rev 200120)
+++ trunk/Source/JavaScriptCore/jsc.cpp        2016-04-27 07:12:06 UTC (rev 200121)
</span><span class="lines">@@ -634,6 +634,7 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> static EncodedJSValue JSC_HOST_CALL functionShadowChickenFunctionsOnStack(ExecState*);
</span><ins>+static EncodedJSValue JSC_HOST_CALL functionSetGlobalConstRedeclarationShouldNotThrow(ExecState*);
</ins><span class="cx"> 
</span><span class="cx"> struct Script {
</span><span class="cx">     bool isFile;
</span><span class="lines">@@ -778,6 +779,7 @@
</span><span class="cx">         addFunction(vm, &quot;clearSamplingFlags&quot;, functionClearSamplingFlags, 1);
</span><span class="cx"> #endif
</span><span class="cx">         addFunction(vm, &quot;shadowChickenFunctionsOnStack&quot;, functionShadowChickenFunctionsOnStack, 0);
</span><ins>+        addFunction(vm, &quot;setGlobalConstRedeclarationShouldNotThrow&quot;, functionSetGlobalConstRedeclarationShouldNotThrow, 0);
</ins><span class="cx">         addConstructableFunction(vm, &quot;Root&quot;, functionCreateRoot, 0);
</span><span class="cx">         addConstructableFunction(vm, &quot;Element&quot;, functionCreateElement, 1);
</span><span class="cx">         addFunction(vm, &quot;getElement&quot;, functionGetElement, 1);
</span><span class="lines">@@ -1494,6 +1496,12 @@
</span><span class="cx">     return JSValue::encode(exec-&gt;vm().shadowChicken().functionsOnStack(exec));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+EncodedJSValue JSC_HOST_CALL functionSetGlobalConstRedeclarationShouldNotThrow(ExecState* exec)
+{
+    exec-&gt;vm().setGlobalConstRedeclarationShouldThrow(false);
+    return JSValue::encode(jsUndefined());
+}
+
</ins><span class="cx"> EncodedJSValue JSC_HOST_CALL functionReadline(ExecState* exec)
</span><span class="cx"> {
</span><span class="cx">     Vector&lt;char, 256&gt; line;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeExecutablecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/Executable.cpp (200120 => 200121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/Executable.cpp        2016-04-27 03:21:58 UTC (rev 200120)
+++ trunk/Source/JavaScriptCore/runtime/Executable.cpp        2016-04-27 07:12:06 UTC (rev 200121)
</span><span class="lines">@@ -606,8 +606,15 @@
</span><span class="cx">             if (globalObject-&gt;hasProperty(exec, entry.key.get()))
</span><span class="cx">                 return createSyntaxError(exec, makeString(&quot;Can't create duplicate variable that shadows a global property: '&quot;, String(entry.key.get()), &quot;'&quot;));
</span><span class="cx"> 
</span><del>-            if (globalLexicalEnvironment-&gt;hasProperty(exec, entry.key.get()))
</del><ins>+            if (globalLexicalEnvironment-&gt;hasProperty(exec, entry.key.get())) {
+                if (UNLIKELY(entry.value.isConst() &amp;&amp; !vm.globalConstRedeclarationShouldThrow() &amp;&amp; !isStrictMode())) {
+                    // We only allow &quot;const&quot; duplicate declarations under this setting.
+                    // For example, we don't &quot;let&quot; variables to be overridden by &quot;const&quot; variables.
+                    if (globalLexicalEnvironment-&gt;isConstVariable(entry.key.get()))
+                        continue;
+                }
</ins><span class="cx">                 return createSyntaxError(exec, makeString(&quot;Can't create duplicate variable: '&quot;, String(entry.key.get()), &quot;'&quot;));
</span><ins>+            }
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         // Check if any new &quot;var&quot;s will shadow any previous &quot;let&quot;/&quot;const&quot;/&quot;class&quot; names.
</span><span class="lines">@@ -646,6 +653,10 @@
</span><span class="cx">         SymbolTable* symbolTable = globalLexicalEnvironment-&gt;symbolTable();
</span><span class="cx">         ConcurrentJITLocker locker(symbolTable-&gt;m_lock);
</span><span class="cx">         for (auto&amp; entry : lexicalDeclarations) {
</span><ins>+            if (UNLIKELY(entry.value.isConst() &amp;&amp; !vm.globalConstRedeclarationShouldThrow() &amp;&amp; !isStrictMode())) {
+                if (symbolTable-&gt;contains(locker, entry.key.get()))
+                    continue;
+            }
</ins><span class="cx">             ScopeOffset offset = symbolTable-&gt;takeNextScopeOffset(locker);
</span><span class="cx">             SymbolTableEntry newEntry(VarOffset(offset), entry.value.isConst() ? ReadOnly : 0);
</span><span class="cx">             newEntry.prepareToWatch();
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSGlobalLexicalEnvironmentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSGlobalLexicalEnvironment.cpp (200120 => 200121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSGlobalLexicalEnvironment.cpp        2016-04-27 03:21:58 UTC (rev 200120)
+++ trunk/Source/JavaScriptCore/runtime/JSGlobalLexicalEnvironment.cpp        2016-04-27 07:12:06 UTC (rev 200121)
</span><span class="lines">@@ -49,4 +49,11 @@
</span><span class="cx">     return putResult;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool JSGlobalLexicalEnvironment::isConstVariable(UniquedStringImpl* impl)
+{
+    SymbolTableEntry entry = symbolTable()-&gt;get(impl);
+    ASSERT(!entry.isNull());
+    return entry.isReadOnly();
+}
+
</ins><span class="cx"> } // namespace JSC
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSGlobalLexicalEnvironmenth"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSGlobalLexicalEnvironment.h (200120 => 200121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSGlobalLexicalEnvironment.h        2016-04-27 03:21:58 UTC (rev 200120)
+++ trunk/Source/JavaScriptCore/runtime/JSGlobalLexicalEnvironment.h        2016-04-27 07:12:06 UTC (rev 200121)
</span><span class="lines">@@ -50,6 +50,7 @@
</span><span class="cx">     static bool put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&amp;);
</span><span class="cx"> 
</span><span class="cx">     bool isEmpty() const { return !symbolTable()-&gt;size(); }
</span><ins>+    bool isConstVariable(UniquedStringImpl*);
</ins><span class="cx">     
</span><span class="cx">     DECLARE_INFO;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeVMh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/VM.h (200120 => 200121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/VM.h        2016-04-27 03:21:58 UTC (rev 200120)
+++ trunk/Source/JavaScriptCore/runtime/VM.h        2016-04-27 07:12:06 UTC (rev 200121)
</span><span class="lines">@@ -602,6 +602,8 @@
</span><span class="cx"> 
</span><span class="cx">     JS_EXPORT_PRIVATE void queueMicrotask(JSGlobalObject*, PassRefPtr&lt;Microtask&gt;);
</span><span class="cx">     JS_EXPORT_PRIVATE void drainMicrotasks();
</span><ins>+    JS_EXPORT_PRIVATE void setGlobalConstRedeclarationShouldThrow(bool globalConstRedeclarationThrow) { m_globalConstRedeclarationShouldThrow = globalConstRedeclarationThrow; }
+    ALWAYS_INLINE bool globalConstRedeclarationShouldThrow() const { return m_globalConstRedeclarationShouldThrow; }
</ins><span class="cx"> 
</span><span class="cx">     inline bool shouldTriggerTermination(ExecState*);
</span><span class="cx"> 
</span><span class="lines">@@ -662,6 +664,7 @@
</span><span class="cx">     Exception* m_lastException { nullptr };
</span><span class="cx">     bool m_failNextNewCodeBlock { false };
</span><span class="cx">     bool m_inDefineOwnProperty;
</span><ins>+    bool m_globalConstRedeclarationShouldThrow { true };
</ins><span class="cx">     bool m_shouldBuildPCToCodeOriginMapping { false };
</span><span class="cx">     std::unique_ptr&lt;CodeCache&gt; m_codeCache;
</span><span class="cx">     LegacyProfiler* m_enabledProfiler;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstressglobalconstredeclarationsettingfirstjs"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting/first.js (0 => 200121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting/first.js                                (rev 0)
+++ trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting/first.js        2016-04-27 07:12:06 UTC (rev 200121)
</span><span class="lines">@@ -0,0 +1 @@
</span><ins>+const foo = 20;
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstressglobalconstredeclarationsettingletjs"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting/let.js (0 => 200121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting/let.js                                (rev 0)
+++ trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting/let.js        2016-04-27 07:12:06 UTC (rev 200121)
</span><span class="lines">@@ -0,0 +1 @@
</span><ins>+let foo = 50;
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstressglobalconstredeclarationsettingsecondjs"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting/second.js (0 => 200121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting/second.js                                (rev 0)
+++ trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting/second.js        2016-04-27 07:12:06 UTC (rev 200121)
</span><span class="lines">@@ -0,0 +1 @@
</span><ins>+const foo = 40;
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstressglobalconstredeclarationsettingstrictjs"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting/strict.js (0 => 200121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting/strict.js                                (rev 0)
+++ trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting/strict.js        2016-04-27 07:12:06 UTC (rev 200121)
</span><span class="lines">@@ -0,0 +1,2 @@
</span><ins>+&quot;use strict&quot;;
+const foo = 45;
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstressglobalconstredeclarationsetting2js"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting-2.js (0 => 200121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting-2.js                                (rev 0)
+++ trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting-2.js        2016-04-27 07:12:06 UTC (rev 200121)
</span><span class="lines">@@ -0,0 +1,13 @@
</span><ins>+function assert(b) {
+    if (!b)
+        throw new Error(&quot;Bad assertion.&quot;);
+}
+
+setGlobalConstRedeclarationShouldNotThrow(); // Allow duplicate const declarations at the global level.
+
+for (let i = 0; i &lt; 100; i++) {
+    load(&quot;./global-const-redeclaration-setting/first.js&quot;);
+    assert(foo === 20);
+    load(&quot;./global-const-redeclaration-setting/second.js&quot;);
+    assert(foo === 40);
+}
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstressglobalconstredeclarationsetting3js"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting-3.js (0 => 200121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting-3.js                                (rev 0)
+++ trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting-3.js        2016-04-27 07:12:06 UTC (rev 200121)
</span><span class="lines">@@ -0,0 +1,18 @@
</span><ins>+function assert(b) {
+    if (!b)
+        throw new Error(&quot;Bad assertion.&quot;);
+}
+
+setGlobalConstRedeclarationShouldNotThrow(); // Allow duplicate const declarations at the global level.
+
+load(&quot;./global-const-redeclaration-setting/first.js&quot;);
+assert(foo === 20);
+let threw = false;
+try {
+    load(&quot;./global-const-redeclaration-setting/strict.js&quot;); // We ignore the setting and always throw an error when in strict mode!
+} catch(e) {
+    threw = true;
+}
+
+assert(threw);
+assert(foo === 20);
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstressglobalconstredeclarationsetting4js"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting-4.js (0 => 200121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting-4.js                                (rev 0)
+++ trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting-4.js        2016-04-27 07:12:06 UTC (rev 200121)
</span><span class="lines">@@ -0,0 +1,18 @@
</span><ins>+function assert(b) {
+    if (!b)
+        throw new Error(&quot;Bad assertion.&quot;);
+}
+
+setGlobalConstRedeclarationShouldNotThrow(); // Allow duplicate const declarations at the global level.
+
+load(&quot;./global-const-redeclaration-setting/first.js&quot;);
+assert(foo === 20);
+let threw = false;
+try {
+    load(&quot;./global-const-redeclaration-setting/let.js&quot;); // Redeclaration a 'let' variable should throw because this doesn't break backwards compat.
+} catch(e) {
+    threw = true;
+}
+
+assert(threw);
+assert(foo === 20);
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstressglobalconstredeclarationsetting5js"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting-5.js (0 => 200121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting-5.js                                (rev 0)
+++ trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting-5.js        2016-04-27 07:12:06 UTC (rev 200121)
</span><span class="lines">@@ -0,0 +1,18 @@
</span><ins>+function assert(b) {
+    if (!b)
+        throw new Error(&quot;Bad assertion.&quot;);
+}
+
+setGlobalConstRedeclarationShouldNotThrow(); // Allow duplicate const declarations at the global level.
+
+load(&quot;./global-const-redeclaration-setting/let.js&quot;);
+assert(foo === 50);
+let threw = false;
+try {
+    load(&quot;./global-const-redeclaration-setting/first.js&quot;); // Redeclaration of a 'let' to 'const' should always throw because it isn't breaking backwards compat.
+} catch(e) {
+    threw = true;
+}
+
+assert(threw);
+assert(foo === 50);
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstressglobalconstredeclarationsettingjs"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting.js (0 => 200121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting.js                                (rev 0)
+++ trunk/Source/JavaScriptCore/tests/stress/global-const-redeclaration-setting.js        2016-04-27 07:12:06 UTC (rev 200121)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+function assert(b) {
+    if (!b)
+        throw new Error(&quot;Bad assertion.&quot;);
+}
+
+setGlobalConstRedeclarationShouldNotThrow(); // Allow duplicate const declarations at the global level.
+
+load(&quot;./global-const-redeclaration-setting/first.js&quot;);
+assert(foo === 20);
+load(&quot;./global-const-redeclaration-setting/second.js&quot;);
+assert(foo === 40);
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (200120 => 200121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-04-27 03:21:58 UTC (rev 200120)
+++ trunk/Source/WebCore/ChangeLog        2016-04-27 07:12:06 UTC (rev 200121)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2016-04-27  Saam barati  &lt;sbarati@apple.com&gt;
+
+        JSC should have an option to allow global const redeclarations
+        https://bugs.webkit.org/show_bug.cgi?id=157006
+
+        Reviewed by Geoffrey Garen.
+
+        This patch makes the JS VM not throw global const redeclaration
+        errors when the application is iBooks.
+
+        * bindings/js/JSDOMWindowBase.cpp:
+        (WebCore::JSDOMWindowBase::commonVM):
+        * page/Settings.h:
+        (WebCore::Settings::shouldUseHighResolutionTimers):
+        (WebCore::Settings::globalConstRedeclarationShouldThrow):
+        (WebCore::Settings::backgroundShouldExtendBeyondPage):
+
</ins><span class="cx"> 2016-04-26  John Wilander  &lt;wilander@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Support legacy HTTP headers in WebSockets
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsJSDOMWindowBasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp (200120 => 200121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp        2016-04-27 03:21:58 UTC (rev 200120)
+++ trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp        2016-04-27 07:12:06 UTC (rev 200121)
</span><span class="lines">@@ -269,6 +269,8 @@
</span><span class="cx">         vm-&gt;heap.machineThreads().addCurrentThread();
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+        vm-&gt;setGlobalConstRedeclarationShouldThrow(Settings::globalConstRedeclarationShouldThrow());
+
</ins><span class="cx">         initNormalWorldClientData(vm);
</span><span class="cx">     }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorepageSettingsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Settings.h (200120 => 200121)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Settings.h        2016-04-27 03:21:58 UTC (rev 200120)
+++ trunk/Source/WebCore/page/Settings.h        2016-04-27 07:12:06 UTC (rev 200121)
</span><span class="lines">@@ -30,6 +30,7 @@
</span><span class="cx"> #include &quot;ClipboardAccessPolicy.h&quot;
</span><span class="cx"> #include &quot;EditingBehaviorTypes.h&quot;
</span><span class="cx"> #include &quot;IntSize.h&quot;
</span><ins>+#include &quot;RuntimeApplicationChecks.h&quot;
</ins><span class="cx"> #include &quot;SecurityOrigin.h&quot;
</span><span class="cx"> #include &quot;SettingsMacros.h&quot;
</span><span class="cx"> #include &quot;TextFlags.h&quot;
</span><span class="lines">@@ -189,6 +190,17 @@
</span><span class="cx">     static bool shouldUseHighResolutionTimers() { return gShouldUseHighResolutionTimers; }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+    static bool globalConstRedeclarationShouldThrow()
+    { 
+#if PLATFORM(MAC)
+        return !MacApplication::isIBooks();
+#elif PLATFORM(IOS)
+        return !IOSApplication::isIBooks();
+#else
+        return true;
+#endif
+    }
+
</ins><span class="cx">     WEBCORE_EXPORT void setBackgroundShouldExtendBeyondPage(bool);
</span><span class="cx">     bool backgroundShouldExtendBeyondPage() const { return m_backgroundShouldExtendBeyondPage; }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>