Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(520)

Side by Side Diff: ppapi/shared_impl/array_var.cc

Issue 12388083: Add PPB_VarArray_Dev support - part 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/shared_impl/array_var.h ('k') | ppapi/shared_impl/dictionary_var.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013 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 #include "ppapi/shared_impl/array_var.h"
6
7 #include <limits>
8
9 #include "base/logging.h"
10 #include "base/memory/ref_counted.h"
11 #include "ppapi/shared_impl/ppapi_globals.h"
12 #include "ppapi/shared_impl/var_tracker.h"
13
14 namespace ppapi {
15
16 ArrayVar::ArrayVar() {
17 }
18
19 ArrayVar::~ArrayVar() {
20 }
21
22 // static
23 ArrayVar* ArrayVar::FromPPVar(const PP_Var& var) {
24 if (var.type != PP_VARTYPE_ARRAY)
25 return NULL;
26
27 scoped_refptr<Var> var_object(
28 PpapiGlobals::Get()->GetVarTracker()->GetVar(var));
29 if (!var_object.get())
30 return NULL;
31 return var_object->AsArrayVar();
32 }
33
34 ArrayVar* ArrayVar::AsArrayVar() {
35 return this;
36 }
37
38 PP_VarType ArrayVar::GetType() const {
39 return PP_VARTYPE_ARRAY;
40 }
41
42 PP_Var ArrayVar::Get(uint32_t index) const {
43 if (index >= elements_.size())
44 return PP_MakeUndefined();
45
46 const PP_Var& element = elements_[index].get();
47 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(element);
48 return element;
49 }
50
51 PP_Bool ArrayVar::Set(uint32_t index, const PP_Var& value) {
52 if (index == std::numeric_limits<uint32_t>::max())
53 return PP_FALSE;
54
55 if (index >= elements_.size()) {
56 // Insert ScopedPPVars of type PP_VARTYPE_UNDEFINED to reach the new size
57 // (index + 1).
58 elements_.resize(index + 1);
59 }
60
61 elements_[index] = value;
62 return PP_TRUE;
63 }
64
65 uint32_t ArrayVar::GetLength() const {
66 if (elements_.size() > std::numeric_limits<uint32_t>::max()) {
67 CHECK(false);
68 return 0;
69 }
70
71 return static_cast<uint32_t>(elements_.size());
72 }
73
74 PP_Bool ArrayVar::SetLength(uint32_t length) {
75 // If |length| is larger than the current size, ScopedPPVars of type
76 // PP_VARTYPE_UNDEFINED will be inserted to reach the new length.
77 elements_.resize(length);
raymes 2013/03/18 20:41:09 Probably need to add the check here too.
yzshen1 2013/03/18 20:50:42 Because the input type is uint32_t already, I thou
78 return PP_TRUE;
79 }
80
81 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/shared_impl/array_var.h ('k') | ppapi/shared_impl/dictionary_var.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698