|
1 /* |
|
2 * Copyright (C) 2009 Google Inc. All rights reserved. |
|
3 * |
|
4 * Redistribution and use in source and binary forms, with or without |
|
5 * modification, are permitted provided that the following conditions are |
|
6 * met: |
|
7 * |
|
8 * * Redistributions of source code must retain the above copyright |
|
9 * notice, this list of conditions and the following disclaimer. |
|
10 * * Redistributions in binary form must reproduce the above |
|
11 * copyright notice, this list of conditions and the following disclaimer |
|
12 * in the documentation and/or other materials provided with the |
|
13 * distribution. |
|
14 * * Neither the name of Google Inc. nor the names of its |
|
15 * contributors may be used to endorse or promote products derived from |
|
16 * this software without specific prior written permission. |
|
17 * |
|
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
29 */ |
|
30 |
|
31 #include "config.h" |
|
32 #include "ScriptArray.h" |
|
33 |
|
34 #include "Document.h" |
|
35 #include "Frame.h" |
|
36 #include "ScriptScope.h" |
|
37 #include "ScriptState.h" |
|
38 #include "SerializedScriptValue.h" |
|
39 #include "V8Binding.h" |
|
40 #include "V8Proxy.h" |
|
41 |
|
42 namespace WebCore { |
|
43 |
|
44 ScriptArray::ScriptArray(ScriptState* scriptState, v8::Handle<v8::Array> v8Array) |
|
45 : ScriptObject(scriptState, v8Array) |
|
46 { |
|
47 } |
|
48 |
|
49 bool ScriptArray::set(unsigned index, const ScriptObject& value) |
|
50 { |
|
51 if (value.scriptState() != m_scriptState) { |
|
52 ASSERT_NOT_REACHED(); |
|
53 return false; |
|
54 } |
|
55 ScriptScope scope(m_scriptState); |
|
56 v8Object()->Set(v8::Integer::New(index), value.v8Value()); |
|
57 return scope.success(); |
|
58 } |
|
59 |
|
60 bool ScriptArray::set(unsigned index, SerializedScriptValue* value) |
|
61 { |
|
62 ScriptValue scriptValue = ScriptValue::deserialize(m_scriptState, value); |
|
63 if (scriptValue.hasNoValue()) { |
|
64 ASSERT_NOT_REACHED(); |
|
65 return false; |
|
66 } |
|
67 |
|
68 ScriptScope scope(m_scriptState); |
|
69 v8Object()->Set(v8::Integer::New(index), scriptValue.v8Value()); |
|
70 return scope.success(); |
|
71 } |
|
72 |
|
73 bool ScriptArray::set(unsigned index, const String& value) |
|
74 { |
|
75 ScriptScope scope(m_scriptState); |
|
76 v8Object()->Set(v8::Integer::New(index), v8String(value)); |
|
77 return scope.success(); |
|
78 } |
|
79 |
|
80 bool ScriptArray::set(unsigned index, double value) |
|
81 { |
|
82 ScriptScope scope(m_scriptState); |
|
83 v8Object()->Set(v8::Integer::New(index), v8::Number::New(value)); |
|
84 return scope.success(); |
|
85 } |
|
86 |
|
87 bool ScriptArray::set(unsigned index, long long value) |
|
88 { |
|
89 ScriptScope scope(m_scriptState); |
|
90 v8Object()->Set(v8::Integer::New(index), v8::Number::New(value)); |
|
91 return scope.success(); |
|
92 } |
|
93 |
|
94 bool ScriptArray::set(unsigned index, int value) |
|
95 { |
|
96 ScriptScope scope(m_scriptState); |
|
97 v8Object()->Set(v8::Integer::New(index), v8::Number::New(value)); |
|
98 return scope.success(); |
|
99 } |
|
100 |
|
101 bool ScriptArray::set(unsigned index, bool value) |
|
102 { |
|
103 ScriptScope scope(m_scriptState); |
|
104 v8Object()->Set(v8::Integer::New(index), v8Boolean(value)); |
|
105 return scope.success(); |
|
106 } |
|
107 |
|
108 unsigned ScriptArray::length() |
|
109 { |
|
110 ScriptScope scope(m_scriptState); |
|
111 return v8::Array::Cast(*v8Value())->Length(); |
|
112 } |
|
113 |
|
114 ScriptArray ScriptArray::createNew(ScriptState* scriptState) |
|
115 { |
|
116 ScriptScope scope(scriptState); |
|
117 return ScriptArray(scriptState, v8::Array::New()); |
|
118 } |
|
119 |
|
120 } // namespace WebCore |