org.chromium.sdk/src/org/chromium/sdk/JsValue.java
changeset 2 e4420d2515f1
equal deleted inserted replaced
1:ef76fc2ac88c 2:e4420d2515f1
       
     1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
       
     2 // Use of this source code is governed by a BSD-style license that can be
       
     3 // found in the LICENSE file.
       
     4 
       
     5 package org.chromium.sdk;
       
     6 
       
     7 /**
       
     8  * An object that represents a browser JavaScript VM variable value (compound or
       
     9  * atomic.)
       
    10  */
       
    11 public interface JsValue {
       
    12 
       
    13   /**
       
    14    * Type of a JavaScript value. Two bogus type values (DATE and ARRAY) are
       
    15    * included even though they are not reported by V8. Instead, they are inferred
       
    16    * from the object classname.
       
    17    */
       
    18   public enum Type {
       
    19 
       
    20     /**
       
    21      * Object type.
       
    22      */
       
    23     TYPE_OBJECT,
       
    24 
       
    25     /**
       
    26      * Number type.
       
    27      */
       
    28     TYPE_NUMBER,
       
    29 
       
    30     /**
       
    31      * String type.
       
    32      */
       
    33     TYPE_STRING,
       
    34 
       
    35     /**
       
    36      * Function type.
       
    37      */
       
    38     TYPE_FUNCTION,
       
    39 
       
    40     /**
       
    41      * Boolean type.
       
    42      */
       
    43     TYPE_BOOLEAN,
       
    44 
       
    45     /**
       
    46      * Error type (this one describes a JavaScript exception).
       
    47      */
       
    48     TYPE_ERROR,
       
    49 
       
    50     /**
       
    51      * A regular expression.
       
    52      */
       
    53     TYPE_REGEXP,
       
    54 
       
    55     /**
       
    56      * An object which is actually a Date. This type is not present in the
       
    57      * protocol but is rather induced from the "object" type and "Date" class of
       
    58      * an object.
       
    59      */
       
    60     TYPE_DATE,
       
    61 
       
    62     /**
       
    63      * An object which is actually an array. This type is not present in the
       
    64      * protocol but is rather induced from the "object" type and "Array" class of
       
    65      * an object.
       
    66      */
       
    67     TYPE_ARRAY,
       
    68 
       
    69     /**
       
    70      * undefined type.
       
    71      */
       
    72     TYPE_UNDEFINED,
       
    73 
       
    74     /**
       
    75      * null type.
       
    76      */
       
    77     TYPE_NULL;
       
    78 
       
    79     /**
       
    80      * @param type to check
       
    81      * @return whether {@code type} corresponds to a JsObject
       
    82      */
       
    83     public static boolean isObjectType(Type type) {
       
    84       return type == TYPE_OBJECT || type == TYPE_ARRAY || type == TYPE_ERROR ||
       
    85           type == TYPE_FUNCTION;
       
    86     }
       
    87   }
       
    88 
       
    89   /**
       
    90    * @return this value type
       
    91    */
       
    92   Type getType();
       
    93 
       
    94   /**
       
    95    * @return a string representation of this value
       
    96    */
       
    97   String getValueString();
       
    98 
       
    99   /**
       
   100    * @return this value cast to {@link JsObject} or {@code null} if this value
       
   101    *         is not an object
       
   102    */
       
   103   JsObject asObject();
       
   104 
       
   105 }