Differential D3143 Diff 14286 ps/trunk/libraries/source/spidermonkey/include-win32-debug/js/CallNonGenericMethod.h
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/libraries/source/spidermonkey/include-win32-debug/js/CallNonGenericMethod.h
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- | ||||
* vim: set ts=8 sts=4 et sw=4 tw=99: | * vim: set ts=8 sts=2 et sw=2 tw=80: | ||||
* This Source Code Form is subject to the terms of the Mozilla Public | * This Source Code Form is subject to the terms of the Mozilla Public | ||||
* License, v. 2.0. If a copy of the MPL was not distributed with this | * License, v. 2.0. If a copy of the MPL was not distributed with this | ||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||||
#ifndef js_CallNonGenericMethod_h | #ifndef js_CallNonGenericMethod_h | ||||
#define js_CallNonGenericMethod_h | #define js_CallNonGenericMethod_h | ||||
#include "jstypes.h" | #include "jstypes.h" | ||||
Show All 32 Lines | |||||
// and indicates whether the provided value is an acceptable |this| for the | // and indicates whether the provided value is an acceptable |this| for the | ||||
// method; it must be a pure function only of its argument. | // method; it must be a pure function only of its argument. | ||||
// | // | ||||
// static const JSClass AnswerClass = { ... }; | // static const JSClass AnswerClass = { ... }; | ||||
// | // | ||||
// static bool | // static bool | ||||
// IsAnswerObject(const Value& v) | // IsAnswerObject(const Value& v) | ||||
// { | // { | ||||
// if (!v.isObject()) | // if (!v.isObject()) { | ||||
// return false; | // return false; | ||||
// } | |||||
// return JS_GetClass(&v.toObject()) == &AnswerClass; | // return JS_GetClass(&v.toObject()) == &AnswerClass; | ||||
// } | // } | ||||
// | // | ||||
// The second function implements the NativeImpl signature and defines the | // The second function implements the NativeImpl signature and defines the | ||||
// behavior of the method when it is provided an acceptable |this| value. | // behavior of the method when it is provided an acceptable |this| value. | ||||
// Aside from some typing niceties -- see the CallArgs interface for details -- | // Aside from some typing niceties -- see the CallArgs interface for details -- | ||||
// its interface is the same as that of JSNative. | // its interface is the same as that of JSNative. | ||||
// | // | ||||
Show All 32 Lines | |||||
// | // | ||||
// Note: JS::CallNonGenericMethod will only work correctly if it's called in | // Note: JS::CallNonGenericMethod will only work correctly if it's called in | ||||
// tail position in a JSNative. Do not call it from any other place. | // tail position in a JSNative. Do not call it from any other place. | ||||
// | // | ||||
template <IsAcceptableThis Test, NativeImpl Impl> | template <IsAcceptableThis Test, NativeImpl Impl> | ||||
MOZ_ALWAYS_INLINE bool CallNonGenericMethod(JSContext* cx, | MOZ_ALWAYS_INLINE bool CallNonGenericMethod(JSContext* cx, | ||||
const CallArgs& args) { | const CallArgs& args) { | ||||
HandleValue thisv = args.thisv(); | HandleValue thisv = args.thisv(); | ||||
if (Test(thisv)) return Impl(cx, args); | if (Test(thisv)) { | ||||
return Impl(cx, args); | |||||
} | |||||
return detail::CallMethodIfWrapped(cx, Test, Impl, args); | return detail::CallMethodIfWrapped(cx, Test, Impl, args); | ||||
} | } | ||||
MOZ_ALWAYS_INLINE bool CallNonGenericMethod(JSContext* cx, | MOZ_ALWAYS_INLINE bool CallNonGenericMethod(JSContext* cx, | ||||
IsAcceptableThis Test, | IsAcceptableThis Test, | ||||
NativeImpl Impl, | NativeImpl Impl, | ||||
const CallArgs& args) { | const CallArgs& args) { | ||||
HandleValue thisv = args.thisv(); | HandleValue thisv = args.thisv(); | ||||
if (Test(thisv)) return Impl(cx, args); | if (Test(thisv)) { | ||||
return Impl(cx, args); | |||||
} | |||||
return detail::CallMethodIfWrapped(cx, Test, Impl, args); | return detail::CallMethodIfWrapped(cx, Test, Impl, args); | ||||
} | } | ||||
} // namespace JS | } // namespace JS | ||||
#endif /* js_CallNonGenericMethod_h */ | #endif /* js_CallNonGenericMethod_h */ |
Wildfire Games · Phabricator