Ignore:
Timestamp:
Apr 2, 2015, 5:09:42 PM (10 years ago)
Author:
[email protected]
Message:

JavaScriptCore API should support type checking for Array and Date
https://bugs.webkit.org/show_bug.cgi?id=143324

Reviewed by Darin Adler, Sam Weinig, Dan Bernstein.

  • API/JSValue.h:
  • API/JSValue.mm:

(-[JSValue isArray]):
(-[JSValue isDate]): Added an ObjC API.

  • API/JSValueRef.cpp:

(JSValueIsArray):
(JSValueIsDate):

  • API/JSValueRef.h: Added a C API.
  • API/WebKitAvailability.h: Brought our availability macros up to date

and fixed a harmless bug where "10_10" translated to "10.0".

  • API/tests/testapi.c:

(main): Added a test and corrected a pre-existing leak.

  • API/tests/testapi.mm:

(testObjectiveCAPI): Added a test.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/JSValueRef.cpp

    r173326 r182297  
    2828
    2929#include "APICast.h"
     30#include "DateInstance.h"
    3031#include "JSAPIWrapperObject.h"
     32#include "JSCInlines.h"
    3133#include "JSCJSValue.h"
    3234#include "JSCallbackObject.h"
     
    3537#include "JSString.h"
    3638#include "LiteralParser.h"
    37 #include "JSCInlines.h"
    3839#include "Protect.h"
    39 
     40#include <algorithm>
    4041#include <wtf/Assertions.h>
    4142#include <wtf/text/StringHash.h>
    4243#include <wtf/text/WTFString.h>
    43 
    44 #include <algorithm> // for std::min
    4544
    4645#if PLATFORM(MAC)
     
    9998    JSLockHolder locker(exec);
    10099
    101     JSValue jsValue = toJS(exec, value);
    102     return jsValue.isUndefined();
     100    return toJS(exec, value).isUndefined();
    103101}
    104102
     
    112110    JSLockHolder locker(exec);
    113111
    114     JSValue jsValue = toJS(exec, value);
    115     return jsValue.isNull();
     112    return toJS(exec, value).isNull();
    116113}
    117114
     
    125122    JSLockHolder locker(exec);
    126123
    127     JSValue jsValue = toJS(exec, value);
    128     return jsValue.isBoolean();
     124    return toJS(exec, value).isBoolean();
    129125}
    130126
     
    138134    JSLockHolder locker(exec);
    139135
    140     JSValue jsValue = toJS(exec, value);
    141     return jsValue.isNumber();
     136    return toJS(exec, value).isNumber();
    142137}
    143138
     
    151146    JSLockHolder locker(exec);
    152147
    153     JSValue jsValue = toJS(exec, value);
    154     return jsValue.isString();
     148    return toJS(exec, value).isString();
    155149}
    156150
     
    164158    JSLockHolder locker(exec);
    165159
    166     JSValue jsValue = toJS(exec, value);
    167     return jsValue.isObject();
     160    return toJS(exec, value).isObject();
     161}
     162
     163bool JSValueIsArray(JSContextRef ctx, JSValueRef value)
     164{
     165    if (!ctx) {
     166        ASSERT_NOT_REACHED();
     167        return false;
     168    }
     169    ExecState* exec = toJS(ctx);
     170    JSLockHolder locker(exec);
     171
     172    return toJS(exec, value).inherits(JSArray::info());
     173}
     174
     175bool JSValueIsDate(JSContextRef ctx, JSValueRef value)
     176{
     177    if (!ctx) {
     178        ASSERT_NOT_REACHED();
     179        return false;
     180    }
     181    ExecState* exec = toJS(ctx);
     182    JSLockHolder locker(exec);
     183
     184    return toJS(exec, value).inherits(DateInstance::info());
    168185}
    169186
Note: See TracChangeset for help on using the changeset viewer.