| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_BINDING_H__ | 5 #ifndef V8_BINDING_H__ |
| 6 #define V8_BINDING_H__ | 6 #define V8_BINDING_H__ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" |
| 8 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 9 | 10 |
| 10 #include <v8.h> | 11 #include <v8.h> |
| 11 #include "PlatformString.h" | 12 #include "PlatformString.h" |
| 12 #include "MathExtras.h" | 13 #include "MathExtras.h" |
| 13 #include "StringBuffer.h" | 14 #include "StringBuffer.h" |
| 14 | 15 |
| 15 // Suppress warnings in CString of converting size_t to unsigned int. | 16 // Suppress warnings in CString of converting size_t to unsigned int. |
| 16 // TODO(fqian): fix CString.h. | 17 // TODO(fqian): fix CString.h. |
| 17 #pragma warning(push, 0) | 18 MSVC_PUSH_WARNING_LEVEL(0); |
| 18 #include "CString.h" | 19 #include "CString.h" |
| 19 #pragma warning(pop) | 20 MSVC_POP_WARNING(); |
| 20 | 21 |
| 21 #if defined(OS_LINUX) | 22 #if defined(OS_LINUX) |
| 22 // Use the platform.h for linux. | 23 // Use the platform.h for linux. |
| 23 #include "unicode/plinux.h" | 24 #include "unicode/plinux.h" |
| 24 #elif defined(OS_WIN) || defined(OS_MACOSX) | 25 #elif defined(OS_WIN) || defined(OS_MACOSX) |
| 25 // WebKit ships a hacked up version of one of the ICU header files, with all | 26 // WebKit ships a hacked up version of one of the ICU header files, with all |
| 26 // options set for OSX. | 27 // options set for OSX. |
| 27 #include "platform.h" | 28 #include "platform.h" |
| 28 #endif | 29 #endif |
| 29 | 30 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 127 |
| 127 // Convert a value to a 32-bit integer assuming the conversion cannot fail. | 128 // Convert a value to a 32-bit integer assuming the conversion cannot fail. |
| 128 inline int ToInt32(v8::Handle<v8::Value> value) { | 129 inline int ToInt32(v8::Handle<v8::Value> value) { |
| 129 bool ok; | 130 bool ok; |
| 130 return ToInt32(value, ok); | 131 return ToInt32(value, ok); |
| 131 } | 132 } |
| 132 | 133 |
| 133 // If a WebCore string length is greater than the threshold, | 134 // If a WebCore string length is greater than the threshold, |
| 134 // v8String creates an external string to avoid allocating | 135 // v8String creates an external string to avoid allocating |
| 135 // the string in the large object space (which has a high memory overhead). | 136 // the string in the large object space (which has a high memory overhead). |
| 136 static const int kV8ExternalStringThreshold = 2048; | 137 static const unsigned int kV8ExternalStringThreshold = 2048; |
| 137 | 138 |
| 138 // Convert a string to a V8 string. | 139 // Convert a string to a V8 string. |
| 139 inline v8::Handle<v8::String> v8String(const String& str) { | 140 inline v8::Handle<v8::String> v8String(const String& str) { |
| 140 if (str.length() <= kV8ExternalStringThreshold) { | 141 if (str.length() <= kV8ExternalStringThreshold) { |
| 141 return v8::String::New(FromWebCoreString(str), str.length()); | 142 return v8::String::New(FromWebCoreString(str), str.length()); |
| 142 } else { | 143 } else { |
| 143 return v8::String::NewExternal(new WebCoreStringResource(str)); | 144 return v8::String::NewExternal(new WebCoreStringResource(str)); |
| 144 } | 145 } |
| 145 } | 146 } |
| 146 | 147 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 170 inline v8::Handle<v8::Value> v8StringOrFalse(const String& str) { | 171 inline v8::Handle<v8::Value> v8StringOrFalse(const String& str) { |
| 171 return str.isNull() | 172 return str.isNull() |
| 172 ? v8::Handle<v8::Value>(v8::False()) | 173 ? v8::Handle<v8::Value>(v8::False()) |
| 173 : v8::Handle<v8::Value>(v8String(str)); | 174 : v8::Handle<v8::Value>(v8String(str)); |
| 174 } | 175 } |
| 175 | 176 |
| 176 } // namespace WebCore | 177 } // namespace WebCore |
| 177 | 178 |
| 178 #endif // V8_BINDING_H__ | 179 #endif // V8_BINDING_H__ |
| 179 | 180 |
| OLD | NEW |