| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 // A helper for throwing JavaScript TypeError. | 70 // A helper for throwing JavaScript TypeError. |
| 71 v8::Handle<v8::Value> throwTypeError(const String&, v8::Isolate*); | 71 v8::Handle<v8::Value> throwTypeError(const String&, v8::Isolate*); |
| 72 | 72 |
| 73 // FIXME: Remove this once we kill its callers. | 73 // FIXME: Remove this once we kill its callers. |
| 74 v8::Handle<v8::Value> throwUninformativeAndGenericTypeError(v8::Isolate*); | 74 v8::Handle<v8::Value> throwUninformativeAndGenericTypeError(v8::Isolate*); |
| 75 | 75 |
| 76 v8::ArrayBuffer::Allocator* v8ArrayBufferAllocator(); | 76 v8::ArrayBuffer::Allocator* v8ArrayBufferAllocator(); |
| 77 | 77 |
| 78 v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value>, uint32_t& length,
bool& notASequence, v8::Isolate*); | 78 v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value>, uint32_t& length,
bool& notASequence, v8::Isolate*); |
| 79 | 79 |
| 80 inline v8::Handle<v8::Value> argumentOrNull(const v8::FunctionCallbackInfo<v
8::Value>& args, int index) | 80 inline v8::Handle<v8::Value> argumentOrNull(const v8::FunctionCallbackInfo<v
8::Value>& info, int index) |
| 81 { | 81 { |
| 82 return index >= args.Length() ? v8::Local<v8::Value>() : args[index]; | 82 return index >= info.Length() ? v8::Local<v8::Value>() : info[index]; |
| 83 } | 83 } |
| 84 | 84 |
| 85 // Since v8::Null(isolate) crashes if we pass a null isolate, | 85 // Since v8::Null(isolate) crashes if we pass a null isolate, |
| 86 // we need to use v8NullWithCheck(isolate) if an isolate can be null. | 86 // we need to use v8NullWithCheck(isolate) if an isolate can be null. |
| 87 // | 87 // |
| 88 // FIXME: Remove all null isolates from V8 bindings, and remove v8NullWithCh
eck(isolate). | 88 // FIXME: Remove all null isolates from V8 bindings, and remove v8NullWithCh
eck(isolate). |
| 89 inline v8::Handle<v8::Value> v8NullWithCheck(v8::Isolate* isolate) | 89 inline v8::Handle<v8::Value> v8NullWithCheck(v8::Isolate* isolate) |
| 90 { | 90 { |
| 91 return isolate ? v8::Null(isolate) : v8::Null(); | 91 return isolate ? v8::Null(isolate) : v8::Null(); |
| 92 } | 92 } |
| 93 | 93 |
| 94 template<typename CallbackInfo, typename V> | 94 template<typename CallbackInfo, typename V> |
| 95 inline void v8SetReturnValue(const CallbackInfo& args, V v) | 95 inline void v8SetReturnValue(const CallbackInfo& info, V v) |
| 96 { | 96 { |
| 97 args.GetReturnValue().Set(v); | 97 info.GetReturnValue().Set(v); |
| 98 } | 98 } |
| 99 | 99 |
| 100 template<typename CallbackInfo> | 100 template<typename CallbackInfo> |
| 101 inline void v8SetReturnValueBool(const CallbackInfo& args, bool v) | 101 inline void v8SetReturnValueBool(const CallbackInfo& info, bool v) |
| 102 { | 102 { |
| 103 args.GetReturnValue().Set(v); | 103 info.GetReturnValue().Set(v); |
| 104 } | 104 } |
| 105 | 105 |
| 106 template<typename CallbackInfo> | 106 template<typename CallbackInfo> |
| 107 inline void v8SetReturnValueInt(const CallbackInfo& args, int v) | 107 inline void v8SetReturnValueInt(const CallbackInfo& info, int v) |
| 108 { | 108 { |
| 109 args.GetReturnValue().Set(v); | 109 info.GetReturnValue().Set(v); |
| 110 } | 110 } |
| 111 | 111 |
| 112 template<typename CallbackInfo> | 112 template<typename CallbackInfo> |
| 113 inline void v8SetReturnValueUnsigned(const CallbackInfo& args, unsigned v) | 113 inline void v8SetReturnValueUnsigned(const CallbackInfo& info, unsigned v) |
| 114 { | 114 { |
| 115 args.GetReturnValue().Set(v); | 115 info.GetReturnValue().Set(v); |
| 116 } | 116 } |
| 117 | 117 |
| 118 template<typename CallbackInfo> | 118 template<typename CallbackInfo> |
| 119 inline void v8SetReturnValueNull(const CallbackInfo& args) | 119 inline void v8SetReturnValueNull(const CallbackInfo& info) |
| 120 { | 120 { |
| 121 args.GetReturnValue().SetNull(); | 121 info.GetReturnValue().SetNull(); |
| 122 } | 122 } |
| 123 | 123 |
| 124 template<typename CallbackInfo> | 124 template<typename CallbackInfo> |
| 125 inline void v8SetReturnValueUndefined(const CallbackInfo& args) | 125 inline void v8SetReturnValueUndefined(const CallbackInfo& info) |
| 126 { | 126 { |
| 127 args.GetReturnValue().SetUndefined(); | 127 info.GetReturnValue().SetUndefined(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 template<typename CallbackInfo> | 130 template<typename CallbackInfo> |
| 131 inline void v8SetReturnValueEmptyString(const CallbackInfo& args) | 131 inline void v8SetReturnValueEmptyString(const CallbackInfo& info) |
| 132 { | 132 { |
| 133 args.GetReturnValue().SetEmptyString(); | 133 info.GetReturnValue().SetEmptyString(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 template <class CallbackInfo> | 136 template <class CallbackInfo> |
| 137 inline void v8SetReturnValueString(const CallbackInfo& info, const String& s
tring, v8::Isolate* isolate) | 137 inline void v8SetReturnValueString(const CallbackInfo& info, const String& s
tring, v8::Isolate* isolate) |
| 138 { | 138 { |
| 139 if (string.isNull()) { | 139 if (string.isNull()) { |
| 140 v8SetReturnValueEmptyString(info); | 140 v8SetReturnValueEmptyString(info); |
| 141 return; | 141 return; |
| 142 } | 142 } |
| 143 V8PerIsolateData::from(isolate)->stringCache()->setReturnValueFromString
(info.GetReturnValue(), string.impl()); | 143 V8PerIsolateData::from(isolate)->stringCache()->setReturnValueFromString
(info.GetReturnValue(), string.impl()); |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 Vector<T> result; | 521 Vector<T> result; |
| 522 result.reserveInitialCapacity(length); | 522 result.reserveInitialCapacity(length); |
| 523 typedef NativeValueTraits<T> TraitsType; | 523 typedef NativeValueTraits<T> TraitsType; |
| 524 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | 524 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
| 525 for (uint32_t i = 0; i < length; ++i) | 525 for (uint32_t i = 0; i < length; ++i) |
| 526 result.uncheckedAppend(TraitsType::nativeValue(object->Get(i))); | 526 result.uncheckedAppend(TraitsType::nativeValue(object->Get(i))); |
| 527 return result; | 527 return result; |
| 528 } | 528 } |
| 529 | 529 |
| 530 template <class T> | 530 template <class T> |
| 531 Vector<T> toNativeArguments(const v8::FunctionCallbackInfo<v8::Value>& args,
int startIndex) | 531 Vector<T> toNativeArguments(const v8::FunctionCallbackInfo<v8::Value>& info,
int startIndex) |
| 532 { | 532 { |
| 533 ASSERT(startIndex <= args.Length()); | 533 ASSERT(startIndex <= info.Length()); |
| 534 Vector<T> result; | 534 Vector<T> result; |
| 535 typedef NativeValueTraits<T> TraitsType; | 535 typedef NativeValueTraits<T> TraitsType; |
| 536 int length = args.Length(); | 536 int length = info.Length(); |
| 537 result.reserveInitialCapacity(length); | 537 result.reserveInitialCapacity(length); |
| 538 for (int i = startIndex; i < length; ++i) | 538 for (int i = startIndex; i < length; ++i) |
| 539 result.uncheckedAppend(TraitsType::nativeValue(args[i])); | 539 result.uncheckedAppend(TraitsType::nativeValue(info[i])); |
| 540 return result; | 540 return result; |
| 541 } | 541 } |
| 542 | 542 |
| 543 Vector<v8::Handle<v8::Value> > toVectorOfArguments(const v8::FunctionCallbac
kInfo<v8::Value>& args); | 543 Vector<v8::Handle<v8::Value> > toVectorOfArguments(const v8::FunctionCallbac
kInfo<v8::Value>&); |
| 544 | 544 |
| 545 // Validates that the passed object is a sequence type per WebIDL spec | 545 // Validates that the passed object is a sequence type per WebIDL spec |
| 546 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-sequence | 546 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-sequence |
| 547 inline v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value> value, uint3
2_t& length, bool& notASequence, v8::Isolate* isolate) | 547 inline v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value> value, uint3
2_t& length, bool& notASequence, v8::Isolate* isolate) |
| 548 { | 548 { |
| 549 // Attempt converting to a sequence if the value is not already an array
but is | 549 // Attempt converting to a sequence if the value is not already an array
but is |
| 550 // any kind of object except for a native Date object or a native RegExp
object. | 550 // any kind of object except for a native Date object or a native RegExp
object. |
| 551 ASSERT(!value->IsArray()); | 551 ASSERT(!value->IsArray()); |
| 552 // FIXME: Do we really need to special case Date and RegExp object? | 552 // FIXME: Do we really need to special case Date and RegExp object? |
| 553 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=22806 | 553 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=22806 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 | 691 |
| 692 v8::Isolate* mainThreadIsolate(); | 692 v8::Isolate* mainThreadIsolate(); |
| 693 v8::Isolate* toIsolate(ExecutionContext*); | 693 v8::Isolate* toIsolate(ExecutionContext*); |
| 694 v8::Isolate* toIsolate(Frame*); | 694 v8::Isolate* toIsolate(Frame*); |
| 695 | 695 |
| 696 // Can only be called by WebKit::initialize | 696 // Can only be called by WebKit::initialize |
| 697 void setMainThreadIsolate(v8::Isolate*); | 697 void setMainThreadIsolate(v8::Isolate*); |
| 698 } // namespace WebCore | 698 } // namespace WebCore |
| 699 | 699 |
| 700 #endif // V8Binding_h | 700 #endif // V8Binding_h |
| OLD | NEW |