| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/var.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "ppapi/c/pp_var.h" | 11 #include "ppapi/c/pp_var.h" |
| 12 #include "ppapi/c/dev/ppb_var_deprecated.h" | 12 #include "ppapi/c/dev/ppb_var_deprecated.h" |
| 13 #include "ppapi/cpp/common.h" |
| 13 #include "ppapi/cpp/logging.h" | 14 #include "ppapi/cpp/logging.h" |
| 14 #include "ppapi/cpp/module.h" | 15 #include "ppapi/cpp/module.h" |
| 15 #include "ppapi/cpp/module_impl.h" | 16 #include "ppapi/cpp/module_impl.h" |
| 16 #include "ppapi/cpp/dev/scriptable_object_deprecated.h" | 17 #include "ppapi/cpp/dev/scriptable_object_deprecated.h" |
| 17 | 18 |
| 18 // Defining snprintf | 19 // Defining snprintf |
| 19 #include <stdio.h> | 20 #include <stdio.h> |
| 20 #if defined(_MSC_VER) | 21 #if defined(_MSC_VER) |
| 21 # define snprintf _snprintf_s | 22 # define snprintf _snprintf_s |
| 22 #endif | 23 #endif |
| (...skipping 20 matching lines...) Expand all Loading... |
| 43 needs_release_ = false; | 44 needs_release_ = false; |
| 44 } | 45 } |
| 45 | 46 |
| 46 Var::Var(Null) { | 47 Var::Var(Null) { |
| 47 var_.type = PP_VARTYPE_NULL; | 48 var_.type = PP_VARTYPE_NULL; |
| 48 needs_release_ = false; | 49 needs_release_ = false; |
| 49 } | 50 } |
| 50 | 51 |
| 51 Var::Var(bool b) { | 52 Var::Var(bool b) { |
| 52 var_.type = PP_VARTYPE_BOOL; | 53 var_.type = PP_VARTYPE_BOOL; |
| 53 var_.value.as_bool = b; | 54 var_.value.as_bool = BoolToPPBool(b); |
| 54 needs_release_ = false; | 55 needs_release_ = false; |
| 55 } | 56 } |
| 56 | 57 |
| 57 Var::Var(int32_t i) { | 58 Var::Var(int32_t i) { |
| 58 var_.type = PP_VARTYPE_INT32; | 59 var_.type = PP_VARTYPE_INT32; |
| 59 var_.value.as_int = i; | 60 var_.value.as_int = i; |
| 60 needs_release_ = false; | 61 needs_release_ = false; |
| 61 } | 62 } |
| 62 | 63 |
| 63 Var::Var(double d) { | 64 Var::Var(double d) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 default: | 160 default: |
| 160 return false; | 161 return false; |
| 161 } | 162 } |
| 162 } | 163 } |
| 163 | 164 |
| 164 bool Var::AsBool() const { | 165 bool Var::AsBool() const { |
| 165 if (!is_bool()) { | 166 if (!is_bool()) { |
| 166 PP_NOTREACHED(); | 167 PP_NOTREACHED(); |
| 167 return false; | 168 return false; |
| 168 } | 169 } |
| 169 return var_.value.as_bool; | 170 return PPBoolToBool(var_.value.as_bool); |
| 170 } | 171 } |
| 171 | 172 |
| 172 int32_t Var::AsInt() const { | 173 int32_t Var::AsInt() const { |
| 173 if (is_int()) | 174 if (is_int()) |
| 174 return var_.value.as_int; | 175 return var_.value.as_int; |
| 175 if (is_double()) | 176 if (is_double()) |
| 176 return static_cast<int>(var_.value.as_double); | 177 return static_cast<int>(var_.value.as_double); |
| 177 PP_NOTREACHED(); | 178 PP_NOTREACHED(); |
| 178 return 0; | 179 return 0; |
| 179 } | 180 } |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 else if (is_double()) | 357 else if (is_double()) |
| 357 snprintf(buf, sizeof(buf), "Var<%f>", AsDouble()); | 358 snprintf(buf, sizeof(buf), "Var<%f>", AsDouble()); |
| 358 else if (is_string()) | 359 else if (is_string()) |
| 359 snprintf(buf, sizeof(buf), "Var<'%s'>", AsString().c_str()); | 360 snprintf(buf, sizeof(buf), "Var<'%s'>", AsString().c_str()); |
| 360 else if (is_object()) | 361 else if (is_object()) |
| 361 snprintf(buf, sizeof(buf), "Var<OBJECT>"); | 362 snprintf(buf, sizeof(buf), "Var<OBJECT>"); |
| 362 return buf; | 363 return buf; |
| 363 } | 364 } |
| 364 | 365 |
| 365 } // namespace pp | 366 } // namespace pp |
| OLD | NEW |