Chromium Code Reviews| 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 if (value.IsEmpty() || value->IsNull() || value->IsUndefined()) | 173 if (value.IsEmpty() || value->IsNull() || value->IsUndefined()) |
| 174 return String(); | 174 return String(); |
| 175 return toCoreString(value); | 175 return toCoreString(value); |
| 176 } | 176 } |
| 177 | 177 |
| 178 inline AtomicString toCoreAtomicString(v8::Handle<v8::String> value) | 178 inline AtomicString toCoreAtomicString(v8::Handle<v8::String> value) |
| 179 { | 179 { |
| 180 return v8StringToWebCoreString<AtomicString>(value, Externalize); | 180 return v8StringToWebCoreString<AtomicString>(value, Externalize); |
| 181 } | 181 } |
| 182 | 182 |
| 183 // Convert v8 types to a WTF::String. If the V8 string is not already | 183 // This method will return a null String if the v8::Value does not contain a v8::String. |
| 184 // an external string then it is transformed into an external string at this | 184 // It will not call ToString() on the v8::Value. If you want ToString() to b e called, |
| 185 // point to avoid repeated conversions. | 185 // please use the V8TRYCATCH_FOR_V8STRINGRESOURCE_*() macros instead. |
| 186 // | |
| 187 // FIXME: Replace all the call sites with V8TRYCATCH_FOR_V8STRINGRESOURCE(). | |
| 188 // Using this method will lead to a wrong behavior, because you cannot stop the | |
| 189 // execution when an exception is thrown inside stringResource.prepare(). | |
| 190 inline String toCoreStringWithUndefinedOrNullCheck(v8::Handle<v8::Value> val ue) | 186 inline String toCoreStringWithUndefinedOrNullCheck(v8::Handle<v8::Value> val ue) |
| 191 { | 187 { |
| 192 V8StringResource<WithUndefinedOrNullCheck> stringResource(value); | 188 if (value.IsEmpty() || value->IsNull() || value->IsUndefined() || !value ->IsString()) |
|
yurys
2013/12/12 20:04:43
Isn't this equal to
if (value.IsEmpty() || !value
Inactive
2013/12/12 22:43:38
Done.
| |
| 193 if (!stringResource.prepare()) | |
| 194 return String(); | 189 return String(); |
| 195 return stringResource; | 190 |
| 191 return toCoreString(value.As<v8::String>()); | |
| 196 } | 192 } |
| 197 | 193 |
| 198 // Convert a string to a V8 string. | 194 // Convert a string to a V8 string. |
| 199 // Return a V8 external string that shares the underlying buffer with the gi ven | 195 // Return a V8 external string that shares the underlying buffer with the gi ven |
| 200 // WebCore string. The reference counting mechanism is used to keep the | 196 // WebCore string. The reference counting mechanism is used to keep the |
| 201 // underlying buffer alive while the string is still live in the V8 engine. | 197 // underlying buffer alive while the string is still live in the V8 engine. |
| 202 inline v8::Handle<v8::String> v8String(v8::Isolate* isolate, const String& s tring) | 198 inline v8::Handle<v8::String> v8String(v8::Isolate* isolate, const String& s tring) |
| 203 { | 199 { |
| 204 if (string.isNull()) | 200 if (string.isNull()) |
| 205 return v8::String::Empty(isolate); | 201 return v8::String::Empty(isolate); |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 696 | 692 |
| 697 // Converts a DOM object to a v8 value. | 693 // Converts a DOM object to a v8 value. |
| 698 // This is a no-inline version of toV8(). If you want to call toV8() | 694 // This is a no-inline version of toV8(). If you want to call toV8() |
| 699 // without creating #include cycles, you can use this function instead. | 695 // without creating #include cycles, you can use this function instead. |
| 700 // Each specialized implementation will be generated. | 696 // Each specialized implementation will be generated. |
| 701 template<typename T> | 697 template<typename T> |
| 702 v8::Handle<v8::Value> toV8NoInline(T* impl, v8::Handle<v8::Object> creationC ontext, v8::Isolate*); | 698 v8::Handle<v8::Value> toV8NoInline(T* impl, v8::Handle<v8::Object> creationC ontext, v8::Isolate*); |
| 703 } // namespace WebCore | 699 } // namespace WebCore |
| 704 | 700 |
| 705 #endif // V8Binding_h | 701 #endif // V8Binding_h |
| OLD | NEW |