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 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 | 392 |
393 template<> | 393 template<> |
394 struct NativeValueTraits<double> { | 394 struct NativeValueTraits<double> { |
395 static inline double nativeValue(const v8::Handle<v8::Value>& value) | 395 static inline double nativeValue(const v8::Handle<v8::Value>& value) |
396 { | 396 { |
397 return static_cast<double>(value->NumberValue()); | 397 return static_cast<double>(value->NumberValue()); |
398 } | 398 } |
399 }; | 399 }; |
400 | 400 |
401 template <class T, class V8T> | 401 template <class T, class V8T> |
402 Vector<RefPtr<T> > toRefPtrNativeArray(v8::Handle<v8::Value> value, v8::Isol
ate* isolate) | 402 Vector<RefPtr<T> > toRefPtrNativeArray(v8::Handle<v8::Value> value, v8::Isol
ate* isolate, bool* success = 0) |
403 { | 403 { |
| 404 if (success) |
| 405 *success = true; |
| 406 |
404 if (!value->IsArray()) | 407 if (!value->IsArray()) |
405 return Vector<RefPtr<T> >(); | 408 return Vector<RefPtr<T> >(); |
406 | 409 |
407 Vector<RefPtr<T> > result; | 410 Vector<RefPtr<T> > result; |
408 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(value)); | 411 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(value)); |
409 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(v8Value); | 412 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(v8Value); |
410 size_t length = array->Length(); | 413 size_t length = array->Length(); |
411 for (size_t i = 0; i < length; ++i) { | 414 for (size_t i = 0; i < length; ++i) { |
412 v8::Handle<v8::Value> element = array->Get(i); | 415 v8::Handle<v8::Value> element = array->Get(i); |
413 | 416 |
414 if (V8T::HasInstance(element, isolate, worldType(isolate))) { | 417 if (V8T::HasInstance(element, isolate, worldType(isolate))) { |
415 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(ele
ment); | 418 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(ele
ment); |
416 result.append(V8T::toNative(object)); | 419 result.append(V8T::toNative(object)); |
417 } else { | 420 } else { |
| 421 if (success) |
| 422 *success = false; |
418 throwTypeError("Invalid Array element type", isolate); | 423 throwTypeError("Invalid Array element type", isolate); |
419 return Vector<RefPtr<T> >(); | 424 return Vector<RefPtr<T> >(); |
420 } | 425 } |
421 } | 426 } |
422 return result; | 427 return result; |
423 } | 428 } |
424 | 429 |
425 template <class T> | 430 template <class T> |
426 Vector<T> toNativeArray(v8::Handle<v8::Value> value) | 431 Vector<T> toNativeArray(v8::Handle<v8::Value> value) |
427 { | 432 { |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 inline v8::Local<v8::Function> createClosure(v8::FunctionCallback function,
v8::Handle<v8::Value> environment) | 591 inline v8::Local<v8::Function> createClosure(v8::FunctionCallback function,
v8::Handle<v8::Value> environment) |
587 { | 592 { |
588 return v8::FunctionTemplate::New(function, environment)->GetFunction(); | 593 return v8::FunctionTemplate::New(function, environment)->GetFunction(); |
589 } | 594 } |
590 | 595 |
591 v8::Local<v8::Value> getHiddenValueFromMainWorldWrapper(v8::Isolate*, Script
Wrappable*, v8::Handle<v8::String> key); | 596 v8::Local<v8::Value> getHiddenValueFromMainWorldWrapper(v8::Isolate*, Script
Wrappable*, v8::Handle<v8::String> key); |
592 | 597 |
593 } // namespace WebCore | 598 } // namespace WebCore |
594 | 599 |
595 #endif // V8Binding_h | 600 #endif // V8Binding_h |
OLD | NEW |