1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2  * vim: set ts=8 sts=2 et sw=2 tw=80:
3  * This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef vm_IsGivenTypeObject_inl_h
8 #define vm_IsGivenTypeObject_inl_h
9 
10 #include "js/Class.h"       // js::ESClass
11 #include "js/Object.h"      // JS::GetBuiltinClass
12 #include "js/RootingAPI.h"  // JS::Handle
13 
14 #include "vm/JSContext-inl.h"  // JSContext::check
15 
16 namespace js {
17 
IsGivenTypeObject(JSContext * cx,JS::Handle<JSObject * > obj,const ESClass & typeClass,bool * isType)18 inline bool IsGivenTypeObject(JSContext* cx, JS::Handle<JSObject*> obj,
19                               const ESClass& typeClass, bool* isType) {
20   cx->check(obj);
21 
22   ESClass cls;
23   if (!JS::GetBuiltinClass(cx, obj, &cls)) {
24     return false;
25   }
26 
27   *isType = cls == typeClass;
28   return true;
29 }
30 
31 }  // namespace js
32 
33 #endif  // vm_IsGivenTypeObject_inl_h
34