Changeset 181064 in webkit


Ignore:
Timestamp:
Mar 4, 2015 8:25:49 PM (9 years ago)
Author:
Yusuke Suzuki
Message:

Hide Promise with runtime flags under Cocoa JSContext API
https://bugs.webkit.org/show_bug.cgi?id=141965

Reviewed by Filip Pizlo.

Source/JavaScriptCore:

Since there's no run loop in JavaScriptCore APIs, Promises don't work currently.
So until they work, we hide Promise from a global object.
Introduce new JSC runtime flag, PromiseDisabled. When isPromiseDisabled is true,
Promise constructor is not attached to JSGlobalObject.

To make 0 as default runtime flags, we choose PromiseDisabled flag
instead of PromiseEnabled flag. So by default, Promise is enabled.

  • API/JSCallbackObjectFunctions.h:

(JSC::JSCallbackObject<Parent>::JSCallbackObject):

  • API/JSContextRef.cpp:

(javaScriptRuntimeFlags):
(JSGlobalContextCreateInGroup):

  • API/tests/testapi.c:

(main):

  • API/tests/testapi.mm:

(testObjectiveCAPI):

  • runtime/JSGlobalObject.cpp:

(JSC::JSGlobalObject::init):

  • runtime/JSGlobalObject.h:

(JSC::JSGlobalObject::create):

  • runtime/RuntimeFlags.h:

(JSC::RuntimeFlags::createAllEnabled):

Source/WebKit/mac:

Add new JSC runtime flag, PromiseDisabled.

  • WebView/WebPreferencesPrivate.h:

Source/WebKit/win:

Add new JSC runtime flag, PromiseDisabled.

  • Interfaces/IWebPreferences.idl:
  • Interfaces/IWebPreferencesPrivate.idl:

Source/WebKit2:

Add new JSC runtime flag, PromiseDisabled.

  • UIProcess/API/C/WKPreferencesRefPrivate.h:
  • UIProcess/API/Cocoa/WKPreferencesPrivate.h:
Location:
trunk/Source
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/JSCallbackObjectFunctions.h

    r172176 r181064  
    6363}
    6464
     65extern const GlobalObjectMethodTable javaScriptCoreAPIGlobalObjectMethodTable;
     66
    6567// Global object constructor.
    6668// FIXME: Move this into a separate JSGlobalCallbackObject class derived from this one.
    6769template <class Parent>
    6870JSCallbackObject<Parent>::JSCallbackObject(VM& vm, JSClassRef jsClass, Structure* structure)
    69     : Parent(vm, structure)
     71    : Parent(vm, structure, &javaScriptCoreAPIGlobalObjectMethodTable)
    7072    , m_callbackObjectData(adoptPtr(new JSCallbackObjectData(0, jsClass)))
    7173{
  • trunk/Source/JavaScriptCore/API/JSContextRef.cpp

    r179609 r181064  
    3636#include "JSObject.h"
    3737#include "JSCInlines.h"
     38#include "RuntimeFlags.h"
    3839#include "SourceProvider.h"
    3940#include "StackVisitor.h"
     
    5758
    5859using namespace JSC;
     60
     61static RuntimeFlags javaScriptRuntimeFlags(const JSGlobalObject* globalObject)
     62{
     63    RuntimeFlags runtimeFlags = JSGlobalObject::javaScriptRuntimeFlags(globalObject);
     64    runtimeFlags.setPromiseDisabled(true);
     65    return runtimeFlags;
     66}
     67
     68const GlobalObjectMethodTable JSC::javaScriptCoreAPIGlobalObjectMethodTable = { &JSGlobalObject::allowsAccessFrom, &JSGlobalObject::supportsProfiling, &JSGlobalObject::supportsRichSourceInfo, &JSGlobalObject::shouldInterruptScript, &javaScriptRuntimeFlags, nullptr, &JSGlobalObject::shouldInterruptScriptBeforeTimeout };
    5969
    6070// From the API's perspective, a context group remains alive iff
     
    141151
    142152    if (!globalObjectClass) {
    143         JSGlobalObject* globalObject = JSGlobalObject::create(*vm, JSGlobalObject::createStructure(*vm, jsNull()));
     153        JSGlobalObject* globalObject = JSGlobalObject::create(*vm, JSGlobalObject::createStructure(*vm, jsNull()), &javaScriptCoreAPIGlobalObjectMethodTable);
    144154#if ENABLE(REMOTE_INSPECTOR)
    145155        globalObject->setRemoteDebuggingEnabled(true);
  • trunk/Source/JavaScriptCore/API/tests/testapi.c

    r179993 r181064  
    18921892    }
    18931893
     1894    // Check Promise is not exposed.
     1895    {
     1896        JSObjectRef globalObject = JSContextGetGlobalObject(context);
     1897        {
     1898            JSStringRef promiseProperty = JSStringCreateWithUTF8CString("Promise");
     1899            ASSERT(!JSObjectHasProperty(context, globalObject, promiseProperty));
     1900            JSStringRelease(promiseProperty);
     1901        }
     1902        {
     1903            JSStringRef script = JSStringCreateWithUTF8CString("typeof Promise");
     1904            JSStringRef undefined = JSStringCreateWithUTF8CString("undefined");
     1905            JSValueRef value = JSEvaluateScript(context, script, NULL, NULL, 1, NULL);
     1906            ASSERT(JSValueIsString(context, value));
     1907            JSStringRef valueAsString = JSValueToStringCopy(context, value, NULL);
     1908            ASSERT(JSStringIsEqual(valueAsString, undefined));
     1909            JSStringRelease(valueAsString);
     1910            JSStringRelease(undefined);
     1911            JSStringRelease(script);
     1912        }
     1913        printf("PASS: Promise is not exposed under JSContext API.\n");
     1914    }
     1915
    18941916#if OS(DARWIN)
    18951917    JSStringRef currentCPUTimeStr = JSStringCreateWithUTF8CString("currentCPUTime");
  • trunk/Source/JavaScriptCore/API/tests/testapi.mm

    r180992 r181064  
    515515    @autoreleasepool {
    516516        JSContext *context = [[JSContext alloc] init];
     517        checkResult(@"Promise is not exposed", [context[@"Promise"] isUndefined]);
     518        JSValue *result = [context evaluateScript:@"typeof Promise"];
     519        checkResult(@"typeof Promise is 'undefined'", [result isString] && [result isEqualToObject:@"undefined"]);
     520    }
     521
     522    @autoreleasepool {
     523        JSContext *context = [[JSContext alloc] init];
    517524        JSValue *result = [context evaluateScript:@"({ x:42 })"];
    518525        checkResult(@"({ x:42 })", [result isObject] && [result[@"x"] isEqualToObject:@42]);
  • trunk/Source/JavaScriptCore/ChangeLog

    r181061 r181064  
     12015-03-04  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        Hide Promise with runtime flags under Cocoa JSContext API
     4        https://bugs.webkit.org/show_bug.cgi?id=141965
     5
     6        Reviewed by Filip Pizlo.
     7
     8        Since there's no run loop in JavaScriptCore APIs, Promises don't work currently.
     9        So until they work, we hide Promise from a global object.
     10        Introduce new JSC runtime flag, PromiseDisabled. When `isPromiseDisabled` is true,
     11        Promise constructor is not attached to JSGlobalObject.
     12
     13        To make 0 as default runtime flags, we choose PromiseDisabled flag
     14        instead of PromiseEnabled flag. So by default, Promise is enabled.
     15
     16        * API/JSCallbackObjectFunctions.h:
     17        (JSC::JSCallbackObject<Parent>::JSCallbackObject):
     18        * API/JSContextRef.cpp:
     19        (javaScriptRuntimeFlags):
     20        (JSGlobalContextCreateInGroup):
     21        * API/tests/testapi.c:
     22        (main):
     23        * API/tests/testapi.mm:
     24        (testObjectiveCAPI):
     25        * runtime/JSGlobalObject.cpp:
     26        (JSC::JSGlobalObject::init):
     27        * runtime/JSGlobalObject.h:
     28        (JSC::JSGlobalObject::create):
     29        * runtime/RuntimeFlags.h:
     30        (JSC::RuntimeFlags::createAllEnabled):
     31
    1322015-03-04  Joseph Pecoraro  <pecoraro@apple.com>
    233
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp

    r181010 r181064  
    367367    putDirectWithoutTransition(vm, vm.propertyNames->URIError, m_URIErrorConstructor.get(), DontEnum);
    368368#if ENABLE(PROMISES)
    369     putDirectWithoutTransition(vm, vm.propertyNames->Promise, m_promiseConstructor.get(), DontEnum);
     369    if (!m_runtimeFlags.isPromiseDisabled())
     370        putDirectWithoutTransition(vm, vm.propertyNames->Promise, m_promiseConstructor.get(), DontEnum);
    370371#endif
    371372   
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h

    r180570 r181064  
    294294    typedef JSSegmentedVariableObject Base;
    295295
    296     static JSGlobalObject* create(VM& vm, Structure* structure)
    297     {
    298         JSGlobalObject* globalObject = new (NotNull, allocateCell<JSGlobalObject>(vm.heap)) JSGlobalObject(vm, structure);
     296    static JSGlobalObject* create(VM& vm, Structure* structure, const GlobalObjectMethodTable* globalObjectMethodTable = nullptr)
     297    {
     298        JSGlobalObject* globalObject = new (NotNull, allocateCell<JSGlobalObject>(vm.heap)) JSGlobalObject(vm, structure, globalObjectMethodTable);
    299299        globalObject->finishCreation(vm);
    300300        vm.heap.addFinalizer(globalObject, destroy);
  • trunk/Source/JavaScriptCore/runtime/RuntimeFlags.h

    r180570 r181064  
    3131namespace JSC {
    3232
     33// macro(name, isEnabledFlag)
    3334#define JSC_RUNTIME_FLAG(macro) \
    34     macro(SymbolEnabled)
     35    macro(SymbolEnabled, true)\
     36    macro(PromiseDisabled, false)
    3537
    3638
     
    3840private:
    3941    enum RuntimeFlagShiftValue : unsigned {
    40 #define JSC_DECLARE_RUNTIME_FLAG_SHIFT_VALUE(name) shiftValueFor##name,
     42#define JSC_DECLARE_RUNTIME_FLAG_SHIFT_VALUE(name, isEnabledFlag) shiftValueFor##name,
    4143        JSC_RUNTIME_FLAG(JSC_DECLARE_RUNTIME_FLAG_SHIFT_VALUE)
    4244#undef JSC_DECLARE_RUNTIME_FLAG_SHIFT_VALUE
     
    4547public:
    4648    enum RuntimeFlag : unsigned {
    47 #define JSC_DECLARE_RUNTIME_FLAG(name) name = 1u << (shiftValueFor##name),
     49#define JSC_DECLARE_RUNTIME_FLAG(name, isEnabledFlag) name = 1u << (shiftValueFor##name),
    4850        JSC_RUNTIME_FLAG(JSC_DECLARE_RUNTIME_FLAG)
    4951#undef JSC_DECLARE_RUNTIME_FLAG
    5052    };
    5153
    52 #define JSC_DECLARE_RUNTIME_FLAG_ACCESSOR(name) \
     54#define JSC_DECLARE_RUNTIME_FLAG_ACCESSOR(name, isEnabledFlag) \
    5355    void set##name(bool value)\
    5456    {\
     
    8486    static RuntimeFlags createAllEnabled()
    8587    {
    86         return {
    87 #define JSC_USE_RUNTIME_FLAG(name) name,
     88        return RuntimeFlags(
     89#define JSC_USE_RUNTIME_FLAG(name, isEnabledFlag) ((isEnabledFlag) ? name : 0u) |
    8890            JSC_RUNTIME_FLAG(JSC_USE_RUNTIME_FLAG)
    8991#undef JSC_USE_RUNTIME_FLAG
    90         };
     92            0u
     93        );
    9194    }
    9295
  • trunk/Source/WebKit/mac/ChangeLog

    r180985 r181064  
     12015-03-04  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        Hide Promise with runtime flags under Cocoa JSContext API
     4        https://bugs.webkit.org/show_bug.cgi?id=141965
     5
     6        Reviewed by Filip Pizlo.
     7
     8        Add new JSC runtime flag, PromiseDisabled.
     9
     10        * WebView/WebPreferencesPrivate.h:
     11
    1122015-03-03  Andy Estes  <aestes@apple.com>
    213
  • trunk/Source/WebKit/mac/WebView/WebPreferencesPrivate.h

    r180570 r181064  
    5555typedef enum {
    5656    WebKitJavaScriptRuntimeFlagsSymbolEnabled = 1u << 0,
     57    WebKitJavaScriptRuntimeFlagsPromiseDisabled = 1u << 1,
    5758    WebKitJavaScriptRuntimeFlagsAllEnabled = WebKitJavaScriptRuntimeFlagsSymbolEnabled
    5859} WebKitJavaScriptRuntimeFlags;
  • trunk/Source/WebKit/win/ChangeLog

    r180963 r181064  
     12015-03-04  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        Hide Promise with runtime flags under Cocoa JSContext API
     4        https://bugs.webkit.org/show_bug.cgi?id=141965
     5
     6        Reviewed by Filip Pizlo.
     7
     8        Add new JSC runtime flag, PromiseDisabled.
     9
     10        * Interfaces/IWebPreferences.idl:
     11        * Interfaces/IWebPreferencesPrivate.idl:
     12
    1132015-03-03  Chris Dumez  <cdumez@apple.com>
    214
  • trunk/Source/WebKit/win/Interfaces/IWebPreferences.idl

    r180570 r181064  
    6060} WebCacheModel;
    6161
    62 typedef enum WebKitJavaScriptRuntimeFlags {
    63     WebKitJavaScriptRuntimeFlagsSymbolEnabled = 1,  // 1u << 0
    64     WebKitJavaScriptRuntimeFlagsAllEnabled = WebKitJavaScriptRuntimeFlagsSymbolEnabled
    65 } WebKitJavaScriptRuntimeFlags;
    66 
    6762[
    6863    object,
  • trunk/Source/WebKit/win/Interfaces/IWebPreferencesPrivate.idl

    r180765 r181064  
    3131import "ocidl.idl";
    3232#endif
     33
     34typedef enum WebKitJavaScriptRuntimeFlags {
     35    WebKitJavaScriptRuntimeFlagsSymbolEnabled = 1,  // 1u << 0
     36    WebKitJavaScriptRuntimeFlagsPromiseDisabled = 2,  // 1u << 1
     37    WebKitJavaScriptRuntimeFlagsAllEnabled = WebKitJavaScriptRuntimeFlagsSymbolEnabled
     38} WebKitJavaScriptRuntimeFlags;
    3339
    3440[
  • trunk/Source/WebKit2/ChangeLog

    r181039 r181064  
     12015-03-04  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        Hide Promise with runtime flags under Cocoa JSContext API
     4        https://bugs.webkit.org/show_bug.cgi?id=141965
     5
     6        Reviewed by Filip Pizlo.
     7
     8        Add new JSC runtime flag, PromiseDisabled.
     9
     10        * UIProcess/API/C/WKPreferencesRefPrivate.h:
     11        * UIProcess/API/Cocoa/WKPreferencesPrivate.h:
     12
    1132015-03-04  Beth Dakin  <bdakin@apple.com>
    214
  • trunk/Source/WebKit2/UIProcess/API/C/WKPreferencesRefPrivate.h

    r180570 r181064  
    5252enum WKJavaScriptRuntimeFlags {
    5353    kWKJavaScriptRuntimeFlagsSymbolEnabled = 1 << 0,
     54    kWKJavaScriptRuntimeFlagsPromiseDisabled = 1 << 1,
    5455    kWKJavaScriptRuntimeFlagsAllEnabled = kWKJavaScriptRuntimeFlagsSymbolEnabled
    5556};
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKPreferencesPrivate.h

    r180570 r181064  
    4545typedef NS_OPTIONS(NSUInteger, _WKJavaScriptRuntimeFlags) {
    4646    _WKJavaScriptRuntimeFlagsSymbolEnabled = 1 << 0,
     47    _WKJavaScriptRuntimeFlagsPromiseDisabled = 1 << 1,
    4748    _WKJavaScriptRuntimeFlagsAllEnabled = _WKJavaScriptRuntimeFlagsSymbolEnabled
    4849} WK_ENUM_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
Note: See TracChangeset for help on using the changeset viewer.