OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * Copyright (C) 2012 Ericsson AB. All rights reserved. | 3 * Copyright (C) 2012 Ericsson AB. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 template <class CallbackInfo> | 156 template <class CallbackInfo> |
157 inline void v8SetReturnValueStringOrUndefined(const CallbackInfo& info, cons
t String& string, v8::Isolate* isolate) | 157 inline void v8SetReturnValueStringOrUndefined(const CallbackInfo& info, cons
t String& string, v8::Isolate* isolate) |
158 { | 158 { |
159 if (string.isNull()) { | 159 if (string.isNull()) { |
160 v8SetReturnValueUndefined(info); | 160 v8SetReturnValueUndefined(info); |
161 return; | 161 return; |
162 } | 162 } |
163 V8PerIsolateData::from(isolate)->stringCache()->setReturnValueFromString
(info.GetReturnValue(), string.impl()); | 163 V8PerIsolateData::from(isolate)->stringCache()->setReturnValueFromString
(info.GetReturnValue(), string.impl()); |
164 } | 164 } |
165 | 165 |
| 166 // Convert v8::String to a WTF::String. If the V8 string is not already |
| 167 // an external string then it is transformed into an external string at this |
| 168 // point to avoid repeated conversions. |
| 169 inline String toWebCoreString(v8::Handle<v8::String> value) |
| 170 { |
| 171 return v8StringToWebCoreString<String>(value, Externalize); |
| 172 } |
| 173 |
| 174 inline String toWebCoreStringWithNullCheck(v8::Handle<v8::String> value) |
| 175 { |
| 176 if (value.IsEmpty() || value->IsNull()) |
| 177 return String(); |
| 178 return toWebCoreString(value); |
| 179 } |
| 180 |
| 181 inline String toWebCoreStringWithUndefinedOrNullCheck(v8::Handle<v8::String>
value) |
| 182 { |
| 183 if (value.IsEmpty() || value->IsNull() || value->IsUndefined()) |
| 184 return String(); |
| 185 return toWebCoreString(value); |
| 186 } |
| 187 |
| 188 inline AtomicString toWebCoreAtomicString(v8::Handle<v8::String> value) |
| 189 { |
| 190 return v8StringToWebCoreString<AtomicString>(value, Externalize); |
| 191 } |
| 192 |
166 // Convert v8 types to a WTF::String. If the V8 string is not already | 193 // Convert v8 types to a WTF::String. If the V8 string is not already |
167 // an external string then it is transformed into an external string at this | 194 // an external string then it is transformed into an external string at this |
168 // point to avoid repeated conversions. | 195 // point to avoid repeated conversions. |
169 // | 196 // |
170 // FIXME: Replace all the call sites with V8TRYCATCH_FOR_V8STRINGRESOURCE(). | 197 // FIXME: Replace all the call sites with V8TRYCATCH_FOR_V8STRINGRESOURCE(). |
171 // Using this method will lead to a wrong behavior, because you cannot stop
the | 198 // Using this method will lead to a wrong behavior, because you cannot stop
the |
172 // execution when an exception is thrown inside stringResource.prepare(). | 199 // execution when an exception is thrown inside stringResource.prepare(). |
173 inline String toWebCoreString(v8::Handle<v8::Value> value) | 200 inline String toWebCoreString(v8::Handle<v8::Value> value) |
174 { | 201 { |
175 V8StringResource<> stringResource(value); | 202 V8StringResource<> stringResource(value); |
(...skipping 22 matching lines...) Expand all Loading... |
198 | 225 |
199 // FIXME: See the above comment. | 226 // FIXME: See the above comment. |
200 inline AtomicString toWebCoreAtomicString(v8::Handle<v8::Value> value) | 227 inline AtomicString toWebCoreAtomicString(v8::Handle<v8::Value> value) |
201 { | 228 { |
202 V8StringResource<> stringResource(value); | 229 V8StringResource<> stringResource(value); |
203 if (!stringResource.prepare()) | 230 if (!stringResource.prepare()) |
204 return AtomicString(); | 231 return AtomicString(); |
205 return stringResource; | 232 return stringResource; |
206 } | 233 } |
207 | 234 |
208 // FIXME: See the above comment. | |
209 inline AtomicString toWebCoreAtomicStringWithNullCheck(v8::Handle<v8::Value>
value) | |
210 { | |
211 V8StringResource<WithNullCheck> stringResource(value); | |
212 if (!stringResource.prepare()) | |
213 return AtomicString(); | |
214 return stringResource; | |
215 } | |
216 | |
217 // Convert a string to a V8 string. | 235 // Convert a string to a V8 string. |
218 // Return a V8 external string that shares the underlying buffer with the gi
ven | 236 // Return a V8 external string that shares the underlying buffer with the gi
ven |
219 // WebCore string. The reference counting mechanism is used to keep the | 237 // WebCore string. The reference counting mechanism is used to keep the |
220 // underlying buffer alive while the string is still live in the V8 engine. | 238 // underlying buffer alive while the string is still live in the V8 engine. |
221 inline v8::Handle<v8::String> v8String(const String& string, v8::Isolate* is
olate) | 239 inline v8::Handle<v8::String> v8String(const String& string, v8::Isolate* is
olate) |
222 { | 240 { |
223 if (string.isNull()) | 241 if (string.isNull()) |
224 return v8::String::Empty(isolate); | 242 return v8::String::Empty(isolate); |
225 return V8PerIsolateData::from(isolate)->stringCache()->v8ExternalString(
string.impl(), isolate); | 243 return V8PerIsolateData::from(isolate)->stringCache()->v8ExternalString(
string.impl(), isolate); |
226 } | 244 } |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 } | 653 } |
636 | 654 |
637 v8::Local<v8::Value> getHiddenValueFromMainWorldWrapper(v8::Isolate*, Script
Wrappable*, v8::Handle<v8::String> key); | 655 v8::Local<v8::Value> getHiddenValueFromMainWorldWrapper(v8::Isolate*, Script
Wrappable*, v8::Handle<v8::String> key); |
638 | 656 |
639 v8::Isolate* isolateForScriptExecutionContext(ScriptExecutionContext*); | 657 v8::Isolate* isolateForScriptExecutionContext(ScriptExecutionContext*); |
640 v8::Isolate* isolateForFrame(Frame*); | 658 v8::Isolate* isolateForFrame(Frame*); |
641 | 659 |
642 } // namespace WebCore | 660 } // namespace WebCore |
643 | 661 |
644 #endif // V8Binding_h | 662 #endif // V8Binding_h |
OLD | NEW |