diff --git a/js/src/jsdate.cpp b/js/src/jsdate.cpp index 7b7cc83bbdb..18ad814fec9 100644 --- a/js/src/jsdate.cpp +++ b/js/src/jsdate.cpp @@ -3241,3 +3241,50 @@ js_DateGetMsecSinceEpoch(RawObject obj) return obj->isDate() ? obj->getDateUTCTime().toNumber() : 0; } + +static const NativeImpl sReadOnlyDateMethods[] = { + date_getTime_impl, + date_getYear_impl, + date_getFullYear_impl, + date_getUTCFullYear_impl, + date_getMonth_impl, + date_getUTCMonth_impl, + date_getDate_impl, + date_getUTCDate_impl, + date_getDay_impl, + date_getUTCDay_impl, + date_getHours_impl, + date_getUTCHours_impl, + date_getMinutes_impl, + date_getUTCMinutes_impl, + date_getUTCSeconds_impl, + date_getUTCMilliseconds_impl, + date_getTimezoneOffset_impl, + date_toGMTString_impl, + date_toISOString_impl, + date_toLocaleString_impl, + date_toLocaleDateString_impl, + date_toLocaleTimeString_impl, + date_toLocaleFormat_impl, + date_toTimeString_impl, + date_toDateString_impl, + date_toSource_impl, + date_toString_impl, + date_valueOf_impl +}; + +JS_FRIEND_API(bool) +js::IsReadOnlyDateMethod(IsAcceptableThis test, NativeImpl method) +{ + /* Avoid a linear search in the common case by checking the |this| test. */ + if (test != IsDate) + return false; + + /* Linear search, comparing function pointers. */ + unsigned max = sizeof(sReadOnlyDateMethods) / sizeof(sReadOnlyDateMethods[0]); + for (unsigned i = 0; i < max; ++i) { + if (method == sReadOnlyDateMethods[i]) + return true; + } + return false; +} diff --git a/js/src/jsfriendapi.h b/js/src/jsfriendapi.h index 675ef2412d0..172b2e98869 100644 --- a/js/src/jsfriendapi.h +++ b/js/src/jsfriendapi.h @@ -1549,6 +1549,12 @@ IdToJsval(jsid id) return IdToValue(id); } +extern JS_FRIEND_API(bool) +IsReadOnlyDateMethod(JS::IsAcceptableThis test, JS::NativeImpl method); + +extern JS_FRIEND_API(bool) +IsTypedArrayThisCheck(JS::IsAcceptableThis test); + } /* namespace js */ #endif /* jsfriendapi_h___ */ diff --git a/js/src/jstypedarray.cpp b/js/src/jstypedarray.cpp index 392fbb7b5ea..9c77e937c4a 100644 --- a/js/src/jstypedarray.cpp +++ b/js/src/jstypedarray.cpp @@ -3424,6 +3424,23 @@ Class TypedArray::protoClasses[TYPE_MAX] = { IMPL_TYPED_ARRAY_PROTO_CLASS(Uint8ClampedArray) }; +#define CHECK(t, a) { if (t == a::IsThisClass) return true; } +JS_FRIEND_API(bool) +js::IsTypedArrayThisCheck(JS::IsAcceptableThis test) +{ + CHECK(test, Int8Array); + CHECK(test, Uint8Array); + CHECK(test, Int16Array); + CHECK(test, Uint16Array); + CHECK(test, Int32Array); + CHECK(test, Uint32Array); + CHECK(test, Float32Array); + CHECK(test, Float64Array); + CHECK(test, Uint8ClampedArray); + return false; +} +#undef CHECK + static JSObject * InitArrayBufferClass(JSContext *cx) {