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 14 matching lines...) Expand all Loading... |
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 */ | 30 */ |
31 | 31 |
32 #ifndef V8Binding_h | 32 #ifndef V8Binding_h |
33 #define V8Binding_h | 33 #define V8Binding_h |
34 | 34 |
35 #include "bindings/core/v8/DOMDataStore.h" | 35 #include "platform/PlatformExport.h" |
36 #include "bindings/core/v8/DOMWrapperWorld.h" | 36 #include "platform/bindings/DOMDataStore.h" |
37 #include "bindings/core/v8/ScriptWrappable.h" | 37 #include "platform/bindings/DOMWrapperWorld.h" |
38 #include "bindings/core/v8/StringResource.h" | 38 #include "platform/bindings/ScriptWrappable.h" |
39 #include "bindings/core/v8/V8BindingMacros.h" | 39 #include "platform/bindings/StringResource.h" |
40 #include "bindings/core/v8/V8PerIsolateData.h" | 40 #include "platform/bindings/V8BindingMacros.h" |
41 #include "bindings/core/v8/V8ScriptRunner.h" | 41 #include "platform/bindings/V8PerIsolateData.h" |
42 #include "bindings/core/v8/V8ValueCache.h" | 42 #include "platform/bindings/V8ValueCache.h" |
43 #include "core/CoreExport.h" | |
44 #include "platform/heap/Handle.h" | 43 #include "platform/heap/Handle.h" |
45 #include "platform/wtf/text/AtomicString.h" | 44 #include "platform/wtf/text/AtomicString.h" |
46 #include "platform/wtf/text/StringView.h" | 45 #include "platform/wtf/text/StringView.h" |
47 #include "v8/include/v8.h" | 46 #include "v8/include/v8.h" |
48 | 47 |
49 namespace blink { | 48 namespace blink { |
50 | 49 |
51 // This file contains bindings helper functions that do not have dependencies | 50 // This file contains bindings helper functions that do not have dependencies |
52 // to core/ or bindings/core. For core-specific helper functions, see | 51 // to core/ or bindings/core. For core-specific helper functions, see |
53 // bindings/core/v8/V8BindingForCore.h. | 52 // bindings/core/v8/V8BindingForCore.h. |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 return ToCoreString(value.As<v8::String>()); | 247 return ToCoreString(value.As<v8::String>()); |
249 } | 248 } |
250 | 249 |
251 // Convert a string to a V8 string. | 250 // Convert a string to a V8 string. |
252 | 251 |
253 inline v8::Local<v8::String> V8String(v8::Isolate* isolate, | 252 inline v8::Local<v8::String> V8String(v8::Isolate* isolate, |
254 const StringView& string) { | 253 const StringView& string) { |
255 DCHECK(isolate); | 254 DCHECK(isolate); |
256 if (string.IsNull()) | 255 if (string.IsNull()) |
257 return v8::String::Empty(isolate); | 256 return v8::String::Empty(isolate); |
258 if (StringImpl* impl = string.SharedImpl()) | 257 if (StringImpl* impl = string.SharedImpl()) { |
259 return V8PerIsolateData::From(isolate)->GetStringCache()->V8ExternalString( | 258 return V8PerIsolateData::From(isolate)->GetStringCache()->V8ExternalString( |
260 isolate, impl); | 259 isolate, impl); |
261 if (string.Is8Bit()) | 260 } |
| 261 if (string.Is8Bit()) { |
262 return v8::String::NewFromOneByte( | 262 return v8::String::NewFromOneByte( |
263 isolate, reinterpret_cast<const uint8_t*>(string.Characters8()), | 263 isolate, reinterpret_cast<const uint8_t*>(string.Characters8()), |
264 v8::NewStringType::kNormal, static_cast<int>(string.length())) | 264 v8::NewStringType::kNormal, static_cast<int>(string.length())) |
265 .ToLocalChecked(); | 265 .ToLocalChecked(); |
| 266 } |
266 return v8::String::NewFromTwoByte( | 267 return v8::String::NewFromTwoByte( |
267 isolate, reinterpret_cast<const uint16_t*>(string.Characters16()), | 268 isolate, reinterpret_cast<const uint16_t*>(string.Characters16()), |
268 v8::NewStringType::kNormal, static_cast<int>(string.length())) | 269 v8::NewStringType::kNormal, static_cast<int>(string.length())) |
269 .ToLocalChecked(); | 270 .ToLocalChecked(); |
270 } | 271 } |
271 | 272 |
272 // As above, for string literals. The compiler doesn't optimize away the is8Bit | 273 // As above, for string literals. The compiler doesn't optimize away the is8Bit |
273 // and sharedImpl checks for string literals in the StringView version. | 274 // and sharedImpl checks for string literals in the StringView version. |
274 inline v8::Local<v8::String> V8String(v8::Isolate* isolate, | 275 inline v8::Local<v8::String> V8String(v8::Isolate* isolate, |
275 const char* string) { | 276 const char* string) { |
(...skipping 10 matching lines...) Expand all Loading... |
286 const AtomicString& string) { | 287 const AtomicString& string) { |
287 if (string.IsNull()) | 288 if (string.IsNull()) |
288 return v8::Null(isolate); | 289 return v8::Null(isolate); |
289 return V8PerIsolateData::From(isolate)->GetStringCache()->V8ExternalString( | 290 return V8PerIsolateData::From(isolate)->GetStringCache()->V8ExternalString( |
290 isolate, string.Impl()); | 291 isolate, string.Impl()); |
291 } | 292 } |
292 | 293 |
293 inline v8::Local<v8::String> V8AtomicString(v8::Isolate* isolate, | 294 inline v8::Local<v8::String> V8AtomicString(v8::Isolate* isolate, |
294 const StringView& string) { | 295 const StringView& string) { |
295 DCHECK(isolate); | 296 DCHECK(isolate); |
296 if (string.Is8Bit()) | 297 if (string.Is8Bit()) { |
297 return v8::String::NewFromOneByte( | 298 return v8::String::NewFromOneByte( |
298 isolate, reinterpret_cast<const uint8_t*>(string.Characters8()), | 299 isolate, reinterpret_cast<const uint8_t*>(string.Characters8()), |
299 v8::NewStringType::kInternalized, | 300 v8::NewStringType::kInternalized, |
300 static_cast<int>(string.length())) | 301 static_cast<int>(string.length())) |
301 .ToLocalChecked(); | 302 .ToLocalChecked(); |
| 303 } |
302 return v8::String::NewFromTwoByte( | 304 return v8::String::NewFromTwoByte( |
303 isolate, reinterpret_cast<const uint16_t*>(string.Characters16()), | 305 isolate, reinterpret_cast<const uint16_t*>(string.Characters16()), |
304 v8::NewStringType::kInternalized, | 306 v8::NewStringType::kInternalized, |
305 static_cast<int>(string.length())) | 307 static_cast<int>(string.length())) |
306 .ToLocalChecked(); | 308 .ToLocalChecked(); |
307 } | 309 } |
308 | 310 |
309 // As above, for string literals. The compiler doesn't optimize away the is8Bit | 311 // As above, for string literals. The compiler doesn't optimize away the is8Bit |
310 // check for string literals in the StringView version. | 312 // check for string literals in the StringView version. |
311 inline v8::Local<v8::String> V8AtomicString(v8::Isolate* isolate, | 313 inline v8::Local<v8::String> V8AtomicString(v8::Isolate* isolate, |
(...skipping 22 matching lines...) Expand all Loading... |
334 | 336 |
335 inline v8::MaybeLocal<v8::Value> V8DateOrNaN(v8::Isolate* isolate, | 337 inline v8::MaybeLocal<v8::Value> V8DateOrNaN(v8::Isolate* isolate, |
336 double value) { | 338 double value) { |
337 DCHECK(isolate); | 339 DCHECK(isolate); |
338 return v8::Date::New(isolate->GetCurrentContext(), value); | 340 return v8::Date::New(isolate->GetCurrentContext(), value); |
339 } | 341 } |
340 | 342 |
341 inline bool IsUndefinedOrNull(v8::Local<v8::Value> value) { | 343 inline bool IsUndefinedOrNull(v8::Local<v8::Value> value) { |
342 return value.IsEmpty() || value->IsNullOrUndefined(); | 344 return value.IsEmpty() || value->IsNullOrUndefined(); |
343 } | 345 } |
344 v8::Local<v8::Function> GetBoundFunction(v8::Local<v8::Function>); | 346 PLATFORM_EXPORT v8::Local<v8::Function> GetBoundFunction( |
| 347 v8::Local<v8::Function>); |
345 | 348 |
346 // FIXME: This will be soon embedded in the generated code. | 349 // FIXME: This will be soon embedded in the generated code. |
347 template <typename Collection> | 350 template <typename Collection> |
348 static void IndexedPropertyEnumerator( | 351 static void IndexedPropertyEnumerator( |
349 const v8::PropertyCallbackInfo<v8::Array>& info) { | 352 const v8::PropertyCallbackInfo<v8::Array>& info) { |
350 Collection* collection = | 353 Collection* collection = |
351 ToScriptWrappable(info.Holder())->ToImpl<Collection>(); | 354 ToScriptWrappable(info.Holder())->ToImpl<Collection>(); |
352 int length = collection->length(); | 355 int length = collection->length(); |
353 v8::Local<v8::Array> properties = v8::Array::New(info.GetIsolate(), length); | 356 v8::Local<v8::Array> properties = v8::Array::New(info.GetIsolate(), length); |
354 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext(); | 357 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext(); |
355 for (int i = 0; i < length; ++i) { | 358 for (int i = 0; i < length; ++i) { |
356 v8::Local<v8::Integer> integer = v8::Integer::New(info.GetIsolate(), i); | 359 v8::Local<v8::Integer> integer = v8::Integer::New(info.GetIsolate(), i); |
357 if (!V8CallBoolean(properties->CreateDataProperty(context, i, integer))) | 360 if (!V8CallBoolean(properties->CreateDataProperty(context, i, integer))) |
358 return; | 361 return; |
359 } | 362 } |
360 V8SetReturnValue(info, properties); | 363 V8SetReturnValue(info, properties); |
361 } | 364 } |
362 | 365 |
363 // These methods store hidden values into an array that is stored in the | 366 // These methods store hidden values into an array that is stored in the |
364 // internal field of a DOM wrapper. | 367 // internal field of a DOM wrapper. |
365 bool AddHiddenValueToArray(v8::Isolate*, | 368 PLATFORM_EXPORT bool AddHiddenValueToArray(v8::Isolate*, |
366 v8::Local<v8::Object>, | 369 v8::Local<v8::Object>, |
367 v8::Local<v8::Value>, | 370 v8::Local<v8::Value>, |
368 int cache_index); | 371 int cache_index); |
369 void RemoveHiddenValueFromArray(v8::Isolate*, | 372 PLATFORM_EXPORT void RemoveHiddenValueFromArray(v8::Isolate*, |
370 v8::Local<v8::Object>, | 373 v8::Local<v8::Object>, |
371 v8::Local<v8::Value>, | 374 v8::Local<v8::Value>, |
372 int cache_index); | 375 int cache_index); |
373 | 376 |
374 // Freeze a V8 object. The type of the first parameter and the return value is | 377 // Freeze a V8 object. The type of the first parameter and the return value is |
375 // intentionally v8::Value so that this function can wrap ToV8(). | 378 // intentionally v8::Value so that this function can wrap ToV8(). |
376 // If the argument isn't an object, this will crash. | 379 // If the argument isn't an object, this will crash. |
377 CORE_EXPORT v8::Local<v8::Value> FreezeV8Object(v8::Local<v8::Value>, | 380 PLATFORM_EXPORT v8::Local<v8::Value> FreezeV8Object(v8::Local<v8::Value>, |
378 v8::Isolate*); | 381 v8::Isolate*); |
379 | 382 |
380 } // namespace blink | 383 } // namespace blink |
381 | 384 |
382 #endif // V8Binding_h | 385 #endif // V8Binding_h |
OLD | NEW |