| OLD | NEW | 
|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "ppapi/cpp/var.h" | 5 #include "ppapi/cpp/private/var_private.h" | 
| 6 | 6 | 
| 7 #include <stdio.h> |  | 
| 8 #include <string.h> |  | 
| 9 |  | 
| 10 #include <algorithm> |  | 
| 11 |  | 
| 12 #include "ppapi/c/pp_var.h" |  | 
| 13 #include "ppapi/c/dev/ppb_var_deprecated.h" | 7 #include "ppapi/c/dev/ppb_var_deprecated.h" | 
| 14 #include "ppapi/cpp/common.h" |  | 
| 15 #include "ppapi/cpp/instance.h" | 8 #include "ppapi/cpp/instance.h" | 
| 16 #include "ppapi/cpp/logging.h" | 9 #include "ppapi/cpp/logging.h" | 
| 17 #include "ppapi/cpp/module.h" |  | 
| 18 #include "ppapi/cpp/module_impl.h" | 10 #include "ppapi/cpp/module_impl.h" | 
| 19 #include "ppapi/cpp/dev/scriptable_object_deprecated.h" | 11 #include "ppapi/cpp/dev/scriptable_object_deprecated.h" | 
| 20 | 12 | 
| 21 // Define equivalent to snprintf on Windows. |  | 
| 22 #if defined(_MSC_VER) |  | 
| 23 #  define snprintf sprintf_s |  | 
| 24 #endif |  | 
| 25 |  | 
| 26 namespace pp { | 13 namespace pp { | 
| 27 | 14 | 
| 28 namespace { | 15 namespace { | 
| 29 | 16 | 
| 30 template <> const char* interface_name<PPB_Var_Deprecated>() { | 17 template <> const char* interface_name<PPB_Var_Deprecated>() { | 
| 31   return PPB_VAR_DEPRECATED_INTERFACE; | 18   return PPB_VAR_DEPRECATED_INTERFACE; | 
| 32 } | 19 } | 
| 33 | 20 | 
| 34 // Technically you can call AddRef and Release on any Var, but it may involve |  | 
| 35 // cross-process calls depending on the plugin. This is an optimization so we |  | 
| 36 // only do refcounting on the necessary objects. |  | 
| 37 inline bool NeedsRefcounting(const PP_Var& var) { |  | 
| 38   return var.type == PP_VARTYPE_STRING || var.type == PP_VARTYPE_OBJECT; |  | 
| 39 } |  | 
| 40 |  | 
| 41 }  // namespace | 21 }  // namespace | 
| 42 | 22 | 
| 43 using namespace deprecated; | 23 using namespace deprecated; | 
| 44 | 24 | 
| 45 Var::Var() { | 25 VarPrivate::VarPrivate(Instance* instance, ScriptableObject* object) { | 
| 46   var_.type = PP_VARTYPE_UNDEFINED; |  | 
| 47   var_.padding = 0; |  | 
| 48   needs_release_ = false; |  | 
| 49 } |  | 
| 50 |  | 
| 51 Var::Var(Null) { |  | 
| 52   var_.type = PP_VARTYPE_NULL; |  | 
| 53   var_.padding = 0; |  | 
| 54   needs_release_ = false; |  | 
| 55 } |  | 
| 56 |  | 
| 57 Var::Var(bool b) { |  | 
| 58   var_.type = PP_VARTYPE_BOOL; |  | 
| 59   var_.padding = 0; |  | 
| 60   var_.value.as_bool = BoolToPPBool(b); |  | 
| 61   needs_release_ = false; |  | 
| 62 } |  | 
| 63 |  | 
| 64 Var::Var(int32_t i) { |  | 
| 65   var_.type = PP_VARTYPE_INT32; |  | 
| 66   var_.padding = 0; |  | 
| 67   var_.value.as_int = i; |  | 
| 68   needs_release_ = false; |  | 
| 69 } |  | 
| 70 |  | 
| 71 Var::Var(double d) { |  | 
| 72   var_.type = PP_VARTYPE_DOUBLE; |  | 
| 73   var_.padding = 0; |  | 
| 74   var_.value.as_double = d; |  | 
| 75   needs_release_ = false; |  | 
| 76 } |  | 
| 77 |  | 
| 78 Var::Var(const char* utf8_str) { |  | 
| 79   if (has_interface<PPB_Var_Deprecated>()) { |  | 
| 80     uint32_t len = utf8_str ? static_cast<uint32_t>(strlen(utf8_str)) : 0; |  | 
| 81     var_ = get_interface<PPB_Var_Deprecated>()->VarFromUtf8( |  | 
| 82         Module::Get()->pp_module(), utf8_str, len); |  | 
| 83   } else { |  | 
| 84     var_.type = PP_VARTYPE_NULL; |  | 
| 85     var_.padding = 0; |  | 
| 86   } |  | 
| 87   needs_release_ = (var_.type == PP_VARTYPE_STRING); |  | 
| 88 } |  | 
| 89 |  | 
| 90 Var::Var(const std::string& utf8_str) { |  | 
| 91   if (has_interface<PPB_Var_Deprecated>()) { |  | 
| 92     var_ = get_interface<PPB_Var_Deprecated>()->VarFromUtf8( |  | 
| 93         Module::Get()->pp_module(), |  | 
| 94         utf8_str.c_str(), |  | 
| 95         static_cast<uint32_t>(utf8_str.size())); |  | 
| 96   } else { |  | 
| 97     var_.type = PP_VARTYPE_NULL; |  | 
| 98     var_.padding = 0; |  | 
| 99   } |  | 
| 100   needs_release_ = (var_.type == PP_VARTYPE_STRING); |  | 
| 101 } |  | 
| 102 |  | 
| 103 Var::Var(Instance* instance, ScriptableObject* object) { |  | 
| 104   if (has_interface<PPB_Var_Deprecated>()) { | 26   if (has_interface<PPB_Var_Deprecated>()) { | 
| 105     var_ = get_interface<PPB_Var_Deprecated>()->CreateObject( | 27     var_ = get_interface<PPB_Var_Deprecated>()->CreateObject( | 
| 106         instance->pp_instance(), object->GetClass(), object); | 28         instance->pp_instance(), object->GetClass(), object); | 
| 107     needs_release_ = true; | 29     needs_release_ = true; | 
| 108   } else { | 30   } else { | 
| 109     var_.type = PP_VARTYPE_NULL; | 31     var_.type = PP_VARTYPE_NULL; | 
| 110     var_.padding = 0; | 32     var_.padding = 0; | 
| 111     needs_release_ = false; | 33     needs_release_ = false; | 
| 112   } | 34   } | 
| 113 } | 35 } | 
| 114 | 36 | 
| 115 Var::Var(const Var& other) { | 37 ScriptableObject* VarPrivate::AsScriptableObject() const { | 
| 116   var_ = other.var_; |  | 
| 117   if (NeedsRefcounting(var_)) { |  | 
| 118     if (has_interface<PPB_Var_Deprecated>()) { |  | 
| 119       needs_release_ = true; |  | 
| 120       get_interface<PPB_Var_Deprecated>()->AddRef(var_); |  | 
| 121     } else { |  | 
| 122       var_.type = PP_VARTYPE_NULL; |  | 
| 123       needs_release_ = false; |  | 
| 124     } |  | 
| 125   } else { |  | 
| 126     needs_release_ = false; |  | 
| 127   } |  | 
| 128 } |  | 
| 129 |  | 
| 130 Var::~Var() { |  | 
| 131   if (needs_release_ && has_interface<PPB_Var_Deprecated>()) |  | 
| 132     get_interface<PPB_Var_Deprecated>()->Release(var_); |  | 
| 133 } |  | 
| 134 |  | 
| 135 Var& Var::operator=(const Var& other) { |  | 
| 136   if (needs_release_ && has_interface<PPB_Var_Deprecated>()) |  | 
| 137     get_interface<PPB_Var_Deprecated>()->Release(var_); |  | 
| 138   var_ = other.var_; |  | 
| 139   if (NeedsRefcounting(var_)) { |  | 
| 140     if (has_interface<PPB_Var_Deprecated>()) { |  | 
| 141       needs_release_ = true; |  | 
| 142       get_interface<PPB_Var_Deprecated>()->AddRef(var_); |  | 
| 143     } else { |  | 
| 144       var_.type = PP_VARTYPE_NULL; |  | 
| 145       needs_release_ = false; |  | 
| 146     } |  | 
| 147   } else { |  | 
| 148     needs_release_ = false; |  | 
| 149   } |  | 
| 150   return *this; |  | 
| 151 } |  | 
| 152 |  | 
| 153 bool Var::operator==(const Var& other) const { |  | 
| 154   if (var_.type != other.var_.type) |  | 
| 155     return false; |  | 
| 156   switch (var_.type) { |  | 
| 157     case PP_VARTYPE_UNDEFINED: |  | 
| 158     case PP_VARTYPE_NULL: |  | 
| 159       return true; |  | 
| 160     case PP_VARTYPE_BOOL: |  | 
| 161       return AsBool() == other.AsBool(); |  | 
| 162     case PP_VARTYPE_INT32: |  | 
| 163       return AsInt() == other.AsInt(); |  | 
| 164     case PP_VARTYPE_DOUBLE: |  | 
| 165       return AsDouble() == other.AsDouble(); |  | 
| 166     case PP_VARTYPE_STRING: |  | 
| 167       if (var_.value.as_id == other.var_.value.as_id) |  | 
| 168         return true; |  | 
| 169       return AsString() == other.AsString(); |  | 
| 170     // TODO(neb): Document that this is === and not ==, unlike strings. |  | 
| 171     case PP_VARTYPE_OBJECT: |  | 
| 172       return var_.value.as_id == other.var_.value.as_id; |  | 
| 173     default: |  | 
| 174       return false; |  | 
| 175   } |  | 
| 176 } |  | 
| 177 |  | 
| 178 bool Var::AsBool() const { |  | 
| 179   if (!is_bool()) { |  | 
| 180     PP_NOTREACHED(); |  | 
| 181     return false; |  | 
| 182   } |  | 
| 183   return PPBoolToBool(var_.value.as_bool); |  | 
| 184 } |  | 
| 185 |  | 
| 186 int32_t Var::AsInt() const { |  | 
| 187   if (is_int()) |  | 
| 188     return var_.value.as_int; |  | 
| 189   if (is_double()) |  | 
| 190     return static_cast<int>(var_.value.as_double); |  | 
| 191   PP_NOTREACHED(); |  | 
| 192   return 0; |  | 
| 193 } |  | 
| 194 |  | 
| 195 double Var::AsDouble() const { |  | 
| 196   if (is_double()) |  | 
| 197     return var_.value.as_double; |  | 
| 198   if (is_int()) |  | 
| 199     return static_cast<double>(var_.value.as_int); |  | 
| 200   PP_NOTREACHED(); |  | 
| 201   return 0.0; |  | 
| 202 } |  | 
| 203 |  | 
| 204 std::string Var::AsString() const { |  | 
| 205   if (!is_string()) { |  | 
| 206     PP_NOTREACHED(); |  | 
| 207     return std::string(); |  | 
| 208   } |  | 
| 209 |  | 
| 210   if (!has_interface<PPB_Var_Deprecated>()) |  | 
| 211     return std::string(); |  | 
| 212   uint32_t len; |  | 
| 213   const char* str = get_interface<PPB_Var_Deprecated>()->VarToUtf8(var_, &len); |  | 
| 214   return std::string(str, len); |  | 
| 215 } |  | 
| 216 |  | 
| 217 ScriptableObject* Var::AsScriptableObject() const { |  | 
| 218   if (!is_object()) { | 38   if (!is_object()) { | 
| 219     PP_NOTREACHED(); | 39     PP_NOTREACHED(); | 
| 220   } else if (has_interface<PPB_Var_Deprecated>()) { | 40   } else if (has_interface<PPB_Var_Deprecated>()) { | 
| 221     void* object = NULL; | 41     void* object = NULL; | 
| 222     if (get_interface<PPB_Var_Deprecated>()->IsInstanceOf( | 42     if (get_interface<PPB_Var_Deprecated>()->IsInstanceOf( | 
| 223         var_, ScriptableObject::GetClass(), &object)) { | 43         var_, ScriptableObject::GetClass(), &object)) { | 
| 224       return reinterpret_cast<ScriptableObject*>(object); | 44       return reinterpret_cast<ScriptableObject*>(object); | 
| 225     } | 45     } | 
| 226   } | 46   } | 
| 227   return NULL; | 47   return NULL; | 
| 228 } | 48 } | 
| 229 | 49 | 
| 230 bool Var::HasProperty(const Var& name, Var* exception) const { | 50 bool VarPrivate::HasProperty(const Var& name, Var* exception) const { | 
| 231   if (!has_interface<PPB_Var_Deprecated>()) | 51   if (!has_interface<PPB_Var_Deprecated>()) | 
| 232     return false; | 52     return false; | 
| 233   return get_interface<PPB_Var_Deprecated>()->HasProperty( | 53   return get_interface<PPB_Var_Deprecated>()->HasProperty( | 
| 234       var_, name.var_, OutException(exception).get()); | 54       var_, name.pp_var(), OutException(exception).get()); | 
| 235 } | 55 } | 
| 236 | 56 | 
| 237 bool Var::HasMethod(const Var& name, Var* exception) const { | 57 bool VarPrivate::HasMethod(const Var& name, Var* exception) const { | 
| 238   if (!has_interface<PPB_Var_Deprecated>()) | 58   if (!has_interface<PPB_Var_Deprecated>()) | 
| 239     return false; | 59     return false; | 
| 240   return get_interface<PPB_Var_Deprecated>()->HasMethod( | 60   return get_interface<PPB_Var_Deprecated>()->HasMethod( | 
| 241       var_, name.var_, OutException(exception).get()); | 61       var_, name.pp_var(), OutException(exception).get()); | 
| 242 } | 62 } | 
| 243 | 63 | 
| 244 Var Var::GetProperty(const Var& name, Var* exception) const { | 64 VarPrivate VarPrivate::GetProperty(const Var& name, Var* exception) const { | 
| 245   if (!has_interface<PPB_Var_Deprecated>()) | 65   if (!has_interface<PPB_Var_Deprecated>()) | 
| 246     return Var(); | 66     return Var(); | 
| 247   return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->GetProperty( | 67   return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->GetProperty( | 
| 248       var_, name.var_, OutException(exception).get())); | 68       var_, name.pp_var(), OutException(exception).get())); | 
| 249 } | 69 } | 
| 250 | 70 | 
| 251 void Var::GetAllPropertyNames(std::vector<Var>* properties, | 71 void VarPrivate::GetAllPropertyNames(std::vector<Var>* properties, | 
| 252                               Var* exception) const { | 72                                      Var* exception) const { | 
| 253   if (!has_interface<PPB_Var_Deprecated>()) | 73   if (!has_interface<PPB_Var_Deprecated>()) | 
| 254     return; | 74     return; | 
| 255   PP_Var* props = NULL; | 75   PP_Var* props = NULL; | 
| 256   uint32_t prop_count = 0; | 76   uint32_t prop_count = 0; | 
| 257   get_interface<PPB_Var_Deprecated>()->GetAllPropertyNames( | 77   get_interface<PPB_Var_Deprecated>()->GetAllPropertyNames( | 
| 258       var_, &prop_count, &props, OutException(exception).get()); | 78       var_, &prop_count, &props, OutException(exception).get()); | 
| 259   if (!prop_count) | 79   if (!prop_count) | 
| 260     return; | 80     return; | 
| 261   properties->resize(prop_count); | 81   properties->resize(prop_count); | 
| 262   for (uint32_t i = 0; i < prop_count; ++i) { | 82   for (uint32_t i = 0; i < prop_count; ++i) { | 
| 263     Var temp(PassRef(), props[i]); | 83     Var temp(PassRef(), props[i]); | 
| 264     (*properties)[i] = temp; | 84     (*properties)[i] = temp; | 
| 265   } | 85   } | 
| 266   Module::Get()->core()->MemFree(props); | 86   Module::Get()->core()->MemFree(props); | 
| 267 } | 87 } | 
| 268 | 88 | 
| 269 void Var::SetProperty(const Var& name, const Var& value, Var* exception) { | 89 void VarPrivate::SetProperty(const Var& name, const Var& value, | 
|  | 90                              Var* exception) { | 
| 270   if (!has_interface<PPB_Var_Deprecated>()) | 91   if (!has_interface<PPB_Var_Deprecated>()) | 
| 271     return; | 92     return; | 
| 272   get_interface<PPB_Var_Deprecated>()->SetProperty( | 93   get_interface<PPB_Var_Deprecated>()->SetProperty( | 
| 273       var_, name.var_, value.var_, OutException(exception).get()); | 94       var_, name.pp_var(), value.pp_var(), OutException(exception).get()); | 
| 274 } | 95 } | 
| 275 | 96 | 
| 276 void Var::RemoveProperty(const Var& name, Var* exception) { | 97 void VarPrivate::RemoveProperty(const Var& name, Var* exception) { | 
| 277   if (!has_interface<PPB_Var_Deprecated>()) | 98   if (!has_interface<PPB_Var_Deprecated>()) | 
| 278     return; | 99     return; | 
| 279   get_interface<PPB_Var_Deprecated>()->RemoveProperty( | 100   get_interface<PPB_Var_Deprecated>()->RemoveProperty( | 
| 280       var_, name.var_, OutException(exception).get()); | 101       var_, name.pp_var(), OutException(exception).get()); | 
| 281 } | 102 } | 
| 282 | 103 | 
| 283 Var Var::Call(const Var& method_name, uint32_t argc, Var* argv, | 104 VarPrivate VarPrivate::Call(const Var& method_name, uint32_t argc, Var* argv, | 
| 284               Var* exception) { | 105                             Var* exception) { | 
| 285   if (!has_interface<PPB_Var_Deprecated>()) | 106   if (!has_interface<PPB_Var_Deprecated>()) | 
| 286     return Var(); | 107     return Var(); | 
| 287   if (argc > 0) { | 108   if (argc > 0) { | 
| 288     std::vector<PP_Var> args; | 109     std::vector<PP_Var> args; | 
| 289     args.reserve(argc); | 110     args.reserve(argc); | 
| 290     for (size_t i = 0; i < argc; i++) | 111     for (size_t i = 0; i < argc; i++) | 
| 291       args.push_back(argv[i].var_); | 112       args.push_back(argv[i].pp_var()); | 
| 292     return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call( | 113     return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call( | 
| 293         var_, method_name.var_, argc, &args[0], OutException(exception).get())); | 114         var_, method_name.pp_var(), argc, &args[0], | 
|  | 115         OutException(exception).get())); | 
| 294   } else { | 116   } else { | 
| 295     // Don't try to get the address of a vector if it's empty. | 117     // Don't try to get the address of a vector if it's empty. | 
| 296     return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call( | 118     return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call( | 
| 297         var_, method_name.var_, 0, NULL, OutException(exception).get())); | 119         var_, method_name.pp_var(), 0, NULL, | 
|  | 120         OutException(exception).get())); | 
| 298   } | 121   } | 
| 299 } | 122 } | 
| 300 | 123 | 
| 301 Var Var::Construct(uint32_t argc, Var* argv, Var* exception) const { | 124 VarPrivate VarPrivate::Construct(uint32_t argc, Var* argv, | 
|  | 125                                  Var* exception) const { | 
| 302   if (!has_interface<PPB_Var_Deprecated>()) | 126   if (!has_interface<PPB_Var_Deprecated>()) | 
| 303     return Var(); | 127     return Var(); | 
| 304   if (argc > 0) { | 128   if (argc > 0) { | 
| 305     std::vector<PP_Var> args; | 129     std::vector<PP_Var> args; | 
| 306     args.reserve(argc); | 130     args.reserve(argc); | 
| 307     for (size_t i = 0; i < argc; i++) | 131     for (size_t i = 0; i < argc; i++) | 
| 308       args.push_back(argv[i].var_); | 132       args.push_back(argv[i].pp_var()); | 
| 309     return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Construct( | 133     return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Construct( | 
| 310         var_, argc, &args[0], OutException(exception).get())); | 134         var_, argc, &args[0], OutException(exception).get())); | 
| 311   } else { | 135   } else { | 
| 312     // Don't try to get the address of a vector if it's empty. | 136     // Don't try to get the address of a vector if it's empty. | 
| 313     return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Construct( | 137     return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Construct( | 
| 314         var_, 0, NULL, OutException(exception).get())); | 138         var_, 0, NULL, OutException(exception).get())); | 
| 315   } | 139   } | 
| 316 } | 140 } | 
| 317 | 141 | 
| 318 Var Var::Call(const Var& method_name, Var* exception) { | 142 VarPrivate VarPrivate::Call(const Var& method_name, Var* exception) { | 
| 319   if (!has_interface<PPB_Var_Deprecated>()) | 143   if (!has_interface<PPB_Var_Deprecated>()) | 
| 320     return Var(); | 144     return Var(); | 
| 321   return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call( | 145   return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call( | 
| 322       var_, method_name.var_, 0, NULL, OutException(exception).get())); | 146       var_, method_name.pp_var(), 0, NULL, OutException(exception).get())); | 
| 323 } | 147 } | 
| 324 | 148 | 
| 325 Var Var::Call(const Var& method_name, const Var& arg1, Var* exception) { | 149 VarPrivate VarPrivate::Call(const Var& method_name, const Var& arg1, | 
|  | 150                             Var* exception) { | 
| 326   if (!has_interface<PPB_Var_Deprecated>()) | 151   if (!has_interface<PPB_Var_Deprecated>()) | 
| 327     return Var(); | 152     return Var(); | 
| 328   PP_Var args[1] = {arg1.var_}; | 153   PP_Var args[1] = {arg1.pp_var()}; | 
| 329   return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call( | 154   return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call( | 
| 330       var_, method_name.var_, 1, args, OutException(exception).get())); | 155       var_, method_name.pp_var(), 1, args, OutException(exception).get())); | 
| 331 } | 156 } | 
| 332 | 157 | 
| 333 Var Var::Call(const Var& method_name, const Var& arg1, const Var& arg2, | 158 VarPrivate VarPrivate::Call(const Var& method_name, const Var& arg1, | 
| 334               Var* exception) { | 159                             const Var& arg2, Var* exception) { | 
| 335   if (!has_interface<PPB_Var_Deprecated>()) | 160   if (!has_interface<PPB_Var_Deprecated>()) | 
| 336     return Var(); | 161     return Var(); | 
| 337   PP_Var args[2] = {arg1.var_, arg2.var_}; | 162   PP_Var args[2] = {arg1.pp_var(), arg2.pp_var()}; | 
| 338   return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call( | 163   return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call( | 
| 339       var_, method_name.var_, 2, args, OutException(exception).get())); | 164       var_, method_name.pp_var(), 2, args, OutException(exception).get())); | 
| 340 } | 165 } | 
| 341 | 166 | 
| 342 Var Var::Call(const Var& method_name, const Var& arg1, const Var& arg2, | 167 VarPrivate VarPrivate::Call(const Var& method_name, const Var& arg1, | 
| 343               const Var& arg3, Var* exception) { | 168                             const Var& arg2, const Var& arg3, Var* exception) { | 
| 344   if (!has_interface<PPB_Var_Deprecated>()) | 169   if (!has_interface<PPB_Var_Deprecated>()) | 
| 345     return Var(); | 170     return Var(); | 
| 346   PP_Var args[3] = {arg1.var_, arg2.var_, arg3.var_}; | 171   PP_Var args[3] = {arg1.pp_var(), arg2.pp_var(), arg3.pp_var()}; | 
| 347   return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call( | 172   return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call( | 
| 348       var_, method_name.var_, 3, args, OutException(exception).get())); | 173       var_, method_name.pp_var(), 3, args, OutException(exception).get())); | 
| 349 } | 174 } | 
| 350 | 175 | 
| 351 Var Var::Call(const Var& method_name, const Var& arg1, const Var& arg2, | 176 VarPrivate VarPrivate::Call(const Var& method_name, const Var& arg1, | 
| 352               const Var& arg3, const Var& arg4, Var* exception) { | 177                             const Var& arg2, const Var& arg3, const Var& arg4, | 
|  | 178                             Var* exception) { | 
| 353   if (!has_interface<PPB_Var_Deprecated>()) | 179   if (!has_interface<PPB_Var_Deprecated>()) | 
| 354     return Var(); | 180     return Var(); | 
| 355   PP_Var args[4] = {arg1.var_, arg2.var_, arg3.var_, arg4.var_}; | 181   PP_Var args[4] = {arg1.pp_var(), arg2.pp_var(), arg3.pp_var(), arg4.pp_var()}; | 
| 356   return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call( | 182   return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call( | 
| 357       var_, method_name.var_, 4, args, OutException(exception).get())); | 183       var_, method_name.pp_var(), 4, args, OutException(exception).get())); | 
| 358 } |  | 
| 359 |  | 
| 360 std::string Var::DebugString() const { |  | 
| 361   char buf[256]; |  | 
| 362   if (is_undefined()) { |  | 
| 363     snprintf(buf, sizeof(buf), "Var<UNDEFINED>"); |  | 
| 364   } else if (is_null()) { |  | 
| 365     snprintf(buf, sizeof(buf), "Var<NULL>"); |  | 
| 366   } else if (is_bool()) { |  | 
| 367     snprintf(buf, sizeof(buf), AsBool() ? "Var<true>" : "Var<false>"); |  | 
| 368   } else if (is_int()) { |  | 
| 369     // Note that the following static_cast is necessary because |  | 
| 370     // NativeClient's int32_t is actually "long". |  | 
| 371     // TODO(sehr,polina): remove this after newlib is changed. |  | 
| 372     snprintf(buf, sizeof(buf), "Var<%d>", static_cast<int>(AsInt())); |  | 
| 373   } else if (is_double()) { |  | 
| 374     snprintf(buf, sizeof(buf), "Var<%f>", AsDouble()); |  | 
| 375   } else if (is_string()) { |  | 
| 376     char format[] = "Var<'%s'>"; |  | 
| 377     size_t decoration = sizeof(format) - 2;  // The %s is removed. |  | 
| 378     size_t available = sizeof(buf) - decoration; |  | 
| 379     std::string str = AsString(); |  | 
| 380     if (str.length() > available) { |  | 
| 381       str.resize(available - 3);  // Reserve space for ellipsis. |  | 
| 382       str.append("..."); |  | 
| 383     } |  | 
| 384     snprintf(buf, sizeof(buf), format, str.c_str()); |  | 
| 385   } else if (is_object()) { |  | 
| 386     snprintf(buf, sizeof(buf), "Var<OBJECT>"); |  | 
| 387   } |  | 
| 388   return buf; |  | 
| 389 } | 184 } | 
| 390 | 185 | 
| 391 }  // namespace pp | 186 }  // namespace pp | 
| OLD | NEW | 
|---|