Rewrite "const" as "var" for iTunes/iBooks on the Mac
authorsbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Nov 2015 23:23:23 +0000 (23:23 +0000)
committersbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Nov 2015 23:23:23 +0000 (23:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150852

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

VM now has a setting indicating if we should treat
"const" variables as "var" to more closely match
JSC's previous implementation of "const" before ES6.

* parser/Parser.h:
(JSC::Parser::next):
(JSC::Parser::nextExpectIdentifier):
* runtime/VM.h:
(JSC::VM::setShouldRewriteConstAsVar):
(JSC::VM::shouldRewriteConstAsVar):

Source/WebCore:

* bindings/js/JSDOMWindowBase.cpp:
(WebCore::JSDOMWindowBase::commonVM):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@191982 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/parser/Parser.h
Source/JavaScriptCore/runtime/VM.h
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSDOMWindowBase.cpp

index 1b2a662de146eac306fba28478542233ce7a7960..d8317fa15bcc2d8a9c732577f2d2402bb5dc6988 100644 (file)
@@ -1,3 +1,21 @@
+2015-11-03  Saam barati  <sbarati@apple.com>
+
+        Rewrite "const" as "var" for iTunes/iBooks on the Mac
+        https://bugs.webkit.org/show_bug.cgi?id=150852
+
+        Reviewed by Geoffrey Garen.
+
+        VM now has a setting indicating if we should treat
+        "const" variables as "var" to more closely match
+        JSC's previous implementation of "const" before ES6.
+
+        * parser/Parser.h:
+        (JSC::Parser::next):
+        (JSC::Parser::nextExpectIdentifier):
+        * runtime/VM.h:
+        (JSC::VM::setShouldRewriteConstAsVar):
+        (JSC::VM::shouldRewriteConstAsVar):
+
 2015-11-03  Mark Lam  <mark.lam@apple.com>
 
         Fix some inefficiencies in the baseline usage of JITAddGenerator.
index d4e6e9918bb55da29d1bbf946adfd92b353eca99..aba35a211f909f73d6d12fc61d3e1c2f29764511 100644 (file)
@@ -908,6 +908,8 @@ private:
         m_lastTokenEndPosition = JSTextPosition(lastLine, lastTokenEnd, lastTokenLineStart);
         m_lexer->setLastLineNumber(lastLine);
         m_token.m_type = m_lexer->lex(&m_token, lexerFlags, strictMode());
+        if (UNLIKELY(m_token.m_type == CONSTTOKEN && m_vm->shouldRewriteConstAsVar()))
+            m_token.m_type = VAR;
     }
 
     ALWAYS_INLINE void nextExpectIdentifier(unsigned lexerFlags = 0)
index ef31b752e20d511442c3cca5ad41412b29e3eaaa..ced3194089006bf3e178193ca629e8e68d2b81e6 100644 (file)
@@ -581,6 +581,8 @@ public:
 
     JS_EXPORT_PRIVATE void queueMicrotask(JSGlobalObject*, PassRefPtr<Microtask>);
     JS_EXPORT_PRIVATE void drainMicrotasks();
+    JS_EXPORT_PRIVATE void setShouldRewriteConstAsVar(bool shouldRewrite) { m_shouldRewriteConstAsVar = shouldRewrite; }
+    ALWAYS_INLINE bool shouldRewriteConstAsVar() { return m_shouldRewriteConstAsVar; }
 
     inline bool shouldTriggerTermination(ExecState*);
 
@@ -634,6 +636,7 @@ private:
     Exception* m_lastException { nullptr };
     bool m_failNextNewCodeBlock { false };
     bool m_inDefineOwnProperty;
+    bool m_shouldRewriteConstAsVar { false };
     std::unique_ptr<CodeCache> m_codeCache;
     LegacyProfiler* m_enabledProfiler;
     std::unique_ptr<BuiltinExecutables> m_builtinExecutables;
index 8ed98d12d89eae2325ee3c22f658bdde74ad167a..7b6d6f83cc5482a9ac0bbd853f4f81f3ce27e2c0 100644 (file)
@@ -1,3 +1,13 @@
+2015-11-03  Saam barati  <sbarati@apple.com>
+
+        Rewrite "const" as "var" for iTunes/iBooks on the Mac
+        https://bugs.webkit.org/show_bug.cgi?id=150852
+
+        Reviewed by Geoffrey Garen.
+
+        * bindings/js/JSDOMWindowBase.cpp:
+        (WebCore::JSDOMWindowBase::commonVM):
+
 2015-10-30  Jon Honeycutt  <jhoneycutt@apple.com>
 
         Implement support for the autocomplete attribute
index db076358419e76f2e9980c7164ab09b5678275db..ea1bed574ca0ece0838d65ba2b4deab67e07faba 100644 (file)
@@ -34,6 +34,7 @@
 #include "JSNode.h"
 #include "Logging.h"
 #include "Page.h"
+#include "RuntimeApplicationChecks.h"
 #include "ScriptController.h"
 #include "SecurityOrigin.h"
 #include "Settings.h"
@@ -261,6 +262,12 @@ VM& JSDOMWindowBase::commonVM()
         vm->heap.setIncrementalSweeper(std::make_unique<WebSafeIncrementalSweeper>(&vm->heap));
         vm->heap.machineThreads().addCurrentThread();
 #endif
+
+#if PLATFORM(MAC)
+        if (applicationIsITunes() || applicationIsIBooks())
+            vm->setShouldRewriteConstAsVar(true);
+#endif
+
         initNormalWorldClientData(vm);
     }