LCOV - app.info - js/src/vm/MethodGuard-inl.h

LCOV - code coverage report
| Current view: | directory - js/src/vm - MethodGuard-inl.h (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 30 | 29 | 96.7 %
| Date: | 2012-04-07 | Functions: | 16 | 15 | 93.8 %

           1                 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
           2                 :  * vim: set ts=8 sw=4 et tw=99:
           3                 :  *
           4                 :  * ***** BEGIN LICENSE BLOCK *****
           5                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
           6                 :  *
           7                 :  * The contents of this file are subject to the Mozilla Public License Version
           8                 :  * 1.1 (the "License"); you may not use this file except in compliance with
           9                 :  * the License. You may obtain a copy of the License at
          10                 :  * http://www.mozilla.org/MPL/
          11                 :  *
          12                 :  * Software distributed under the License is distributed on an "AS IS" basis,
          13                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
          14                 :  * for the specific language governing rights and limitations under the
          15                 :  * License.
          16                 :  *
          17                 :  * The Original Code is SpiderMonkey method-guard code.
          18                 :  *
          19                 :  * The Initial Developer of the Original Code is
          20                 :  * the Mozilla Foundation.
          21                 :  * Portions created by the Initial Developer are Copyright (C) 2012
          22                 :  * the Initial Developer. All Rights Reserved.
          23                 :  *
          24                 :  * Contributor(s):
          25                 :  *
          26                 :  * Alternatively, the contents of this file may be used under the terms of
          27                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
          28                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
          29                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
          30                 :  * of those above. If you wish to allow use of your version of this file only
          31                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
          32                 :  * use your version of this file under the terms of the MPL, indicate your
          33                 :  * decision by deleting the provisions above and replace them with the notice
          34                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
          35                 :  * the provisions above, a recipient may use your version of this file under
          36                 :  * the terms of any one of the MPL, the GPL or the LGPL.
          37                 :  *
          38                 :  * ***** END LICENSE BLOCK ***** */
          39                 :
          40                 : #ifndef MethodGuard_inl_h___
          41                 : #define MethodGuard_inl_h___
          42                 :
          43                 : #include "jsobj.h"
          44                 :
          45                 : #include "MethodGuard.h"
          46                 :
          47                 : #include "jsobjinlines.h"
          48                 :
          49                 : #include "BooleanObject-inl.h"
          50                 : #include "NumberObject-inl.h"
          51                 : #include "StringObject-inl.h"
          52                 :
          53                 : namespace js {
          54                 :
          55                 : namespace detail {
          56                 :
          57                 : template<typename T> class PrimitiveBehavior { };
          58                 :
          59                 : template<>
          60                 : class PrimitiveBehavior<bool> {
          61                 :   public:
          62             423 :     static inline bool isType(const Value &v) { return v.isBoolean(); }
          63               0 :     static inline bool extract(const Value &v) { return v.toBoolean(); }
          64             225 :     static inline bool extract(JSObject &obj) { return obj.asBoolean().unbox(); }
          65             423 :     static inline Class *getClass() { return &BooleanClass; }
          66                 : };
          67                 :
          68                 : template<>
          69                 : class PrimitiveBehavior<double> {
          70                 :   public:
          71          153549 :     static inline bool isType(const Value &v) { return v.isNumber(); }
          72          152883 :     static inline double extract(const Value &v) { return v.toNumber(); }
          73             279 :     static inline double extract(JSObject &obj) { return obj.asNumber().unbox(); }
          74             666 :     static inline Class *getClass() { return &NumberClass; }
          75                 : };
          76                 :
          77                 : template<>
          78                 : class PrimitiveBehavior<JSString *> {
          79                 :   public:
          80             270 :     static inline bool isType(const Value &v) { return v.isString(); }
          81               9 :     static inline JSString *extract(const Value &v) { return v.toString(); }
          82             135 :     static inline JSString *extract(JSObject &obj) { return obj.asString().unbox(); }
          83             261 :     static inline Class *getClass() { return &StringClass; }
          84                 : };
          85                 :
          86                 : } /* namespace detail */
          87                 :
          88                 : inline JSObject *
          89         1574751 : NonGenericMethodGuard(JSContext *cx, CallArgs args, Native native, Class *clasp, bool *ok)
          90                 : {
          91         1574751 :     const Value &thisv = args.thisv();
          92         1574751 :     if (thisv.isObject()) {
          93         1574733 :         JSObject &obj = thisv.toObject();
          94         1574733 :         if (obj.getClass() == clasp) {
          95         1568937 :             *ok = true;  /* quell gcc overwarning */
          96         1568937 :             return &obj;
          97                 :         }
          98                 :     }
          99                 :
         100            5814 :     *ok = HandleNonGenericMethodClassMismatch(cx, args, native, clasp);
         101            5814 :     return NULL;
         102                 : }
         103                 :
         104                 : template <typename T>
         105                 : inline bool
         106          154242 : BoxedPrimitiveMethodGuard(JSContext *cx, CallArgs args, Native native, T *v, bool *ok)
         107                 : {
         108                 :     typedef detail::PrimitiveBehavior<T> Behavior;
         109                 :
         110          154242 :     const Value &thisv = args.thisv();
         111          154242 :     if (Behavior::isType(thisv)) {
         112          152892 :         *v = Behavior::extract(thisv);
         113          152892 :         return true;
         114                 :     }
         115                 :
         116            1350 :     if (!NonGenericMethodGuard(cx, args, native, Behavior::getClass(), ok))
         117             711 :         return false;
         118                 :
         119             639 :     *v = Behavior::extract(thisv.toObject());
         120             639 :     return true;
         121                 : }
         122                 :
         123                 : } /* namespace js */
         124                 :
         125                 : #endif /* MethodGuard_inl_h___ */

Generated by: LCOV version 1.7