|
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 "SerializedScriptValue.h" |
|
35 |
|
36 #include <runtime/JSLock.h> |
|
37 |
|
38 using namespace JSC; |
|
39 |
|
40 namespace WebCore { |
|
41 |
|
42 ScriptArray::ScriptArray(ScriptState* scriptState, JSArray* object) |
|
43 : ScriptObject(scriptState, object) |
|
44 { |
|
45 } |
|
46 |
|
47 static bool handleException(ScriptState* scriptState) |
|
48 { |
|
49 if (!scriptState->hadException()) |
|
50 return true; |
|
51 |
|
52 reportException(scriptState, scriptState->exception()); |
|
53 return false; |
|
54 } |
|
55 |
|
56 bool ScriptArray::set(unsigned index, const ScriptObject& value) |
|
57 { |
|
58 if (value.scriptState() != m_scriptState) { |
|
59 ASSERT_NOT_REACHED(); |
|
60 return false; |
|
61 } |
|
62 JSLock lock(SilenceAssertionsOnly); |
|
63 jsArray()->put(m_scriptState, index, value.jsObject()); |
|
64 return handleException(m_scriptState); |
|
65 } |
|
66 |
|
67 bool ScriptArray::set(unsigned index, SerializedScriptValue* value) |
|
68 { |
|
69 ScriptValue scriptValue = ScriptValue::deserialize(m_scriptState, value); |
|
70 if (scriptValue.hasNoValue()) { |
|
71 ASSERT_NOT_REACHED(); |
|
72 return false; |
|
73 } |
|
74 |
|
75 JSLock lock(SilenceAssertionsOnly); |
|
76 jsArray()->put(m_scriptState, index, scriptValue.jsValue()); |
|
77 return handleException(m_scriptState); |
|
78 } |
|
79 |
|
80 bool ScriptArray::set(unsigned index, const String& value) |
|
81 { |
|
82 JSLock lock(SilenceAssertionsOnly); |
|
83 jsArray()->put(m_scriptState, index, jsString(m_scriptState, value)); |
|
84 return handleException(m_scriptState); |
|
85 } |
|
86 |
|
87 bool ScriptArray::set(unsigned index, double value) |
|
88 { |
|
89 JSLock lock(SilenceAssertionsOnly); |
|
90 jsArray()->put(m_scriptState, index, jsNumber(m_scriptState, value)); |
|
91 return handleException(m_scriptState); |
|
92 } |
|
93 |
|
94 bool ScriptArray::set(unsigned index, long long value) |
|
95 { |
|
96 JSLock lock(SilenceAssertionsOnly); |
|
97 jsArray()->put(m_scriptState, index, jsNumber(m_scriptState, value)); |
|
98 return handleException(m_scriptState); |
|
99 } |
|
100 |
|
101 bool ScriptArray::set(unsigned index, int value) |
|
102 { |
|
103 JSLock lock(SilenceAssertionsOnly); |
|
104 jsArray()->put(m_scriptState, index, jsNumber(m_scriptState, value)); |
|
105 return handleException(m_scriptState); |
|
106 } |
|
107 |
|
108 bool ScriptArray::set(unsigned index, bool value) |
|
109 { |
|
110 JSLock lock(SilenceAssertionsOnly); |
|
111 jsArray()->put(m_scriptState, index, jsBoolean(value)); |
|
112 return handleException(m_scriptState); |
|
113 } |
|
114 |
|
115 unsigned ScriptArray::length() |
|
116 { |
|
117 JSLock lock(SilenceAssertionsOnly); |
|
118 return jsArray()->length(); |
|
119 } |
|
120 |
|
121 ScriptArray ScriptArray::createNew(ScriptState* scriptState) |
|
122 { |
|
123 JSLock lock(SilenceAssertionsOnly); |
|
124 return ScriptArray(scriptState, constructEmptyArray(scriptState)); |
|
125 } |
|
126 |
|
127 } // namespace WebCore |