| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 // A helper for throwing JavaScript TypeError. | 69 // A helper for throwing JavaScript TypeError. |
| 70 v8::Handle<v8::Value> throwTypeError(v8::Isolate*); | 70 v8::Handle<v8::Value> throwTypeError(v8::Isolate*); |
| 71 v8::Handle<v8::Value> throwTypeError(const String&, v8::Isolate*); | 71 v8::Handle<v8::Value> throwTypeError(const String&, v8::Isolate*); |
| 72 | 72 |
| 73 // A helper for throwing JavaScript TypeError for not enough arguments. | 73 // A helper for throwing JavaScript TypeError for not enough arguments. |
| 74 v8::Handle<v8::Value> throwNotEnoughArgumentsError(v8::Isolate*); | 74 v8::Handle<v8::Value> throwNotEnoughArgumentsError(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,
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>& args, int index) |
| 81 { | 81 { |
| 82 return index >= args.Length() ? v8::Local<v8::Value>() : args[index]; | 82 return index >= args.Length() ? v8::Local<v8::Value>() : args[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). |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 template <class T, class V8T> | 443 template <class T, class V8T> |
| 444 Vector<RefPtr<T> > toRefPtrNativeArray(v8::Handle<v8::Value> value, v8::Isol
ate* isolate, bool* success = 0) | 444 Vector<RefPtr<T> > toRefPtrNativeArray(v8::Handle<v8::Value> value, v8::Isol
ate* isolate, bool* success = 0) |
| 445 { | 445 { |
| 446 if (success) | 446 if (success) |
| 447 *success = true; | 447 *success = true; |
| 448 | 448 |
| 449 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); | 449 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); |
| 450 uint32_t length = 0; | 450 uint32_t length = 0; |
| 451 if (value->IsArray()) | 451 if (value->IsArray()) |
| 452 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | 452 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |
| 453 else if (toV8Sequence(value, length, isolate).IsEmpty()) | 453 else if (toV8Sequence(value, length, 0, isolate).IsEmpty()) |
| 454 return Vector<RefPtr<T> >(); | 454 return Vector<RefPtr<T> >(); |
| 455 | 455 |
| 456 Vector<RefPtr<T> > result; | 456 Vector<RefPtr<T> > result; |
| 457 result.reserveInitialCapacity(length); | 457 result.reserveInitialCapacity(length); |
| 458 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | 458 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
| 459 for (uint32_t i = 0; i < length; ++i) { | 459 for (uint32_t i = 0; i < length; ++i) { |
| 460 v8::Handle<v8::Value> element = object->Get(i); | 460 v8::Handle<v8::Value> element = object->Get(i); |
| 461 | 461 |
| 462 if (V8T::HasInstance(element, isolate, worldType(isolate))) { | 462 if (V8T::HasInstance(element, isolate, worldType(isolate))) { |
| 463 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::C
ast(element); | 463 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::C
ast(element); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 474 | 474 |
| 475 // Converts a JavaScript value to an array as per the Web IDL specification: | 475 // Converts a JavaScript value to an array as per the Web IDL specification: |
| 476 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array | 476 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array |
| 477 template <class T> | 477 template <class T> |
| 478 Vector<T> toNativeArray(v8::Handle<v8::Value> value, v8::Isolate* isolate) | 478 Vector<T> toNativeArray(v8::Handle<v8::Value> value, v8::Isolate* isolate) |
| 479 { | 479 { |
| 480 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); | 480 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); |
| 481 uint32_t length = 0; | 481 uint32_t length = 0; |
| 482 if (value->IsArray()) | 482 if (value->IsArray()) |
| 483 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | 483 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |
| 484 else if (toV8Sequence(value, length, isolate).IsEmpty()) | 484 else if (toV8Sequence(value, length, 0, isolate).IsEmpty()) |
| 485 return Vector<T>(); | 485 return Vector<T>(); |
| 486 | 486 |
| 487 Vector<T> result; | 487 Vector<T> result; |
| 488 result.reserveInitialCapacity(length); | 488 result.reserveInitialCapacity(length); |
| 489 typedef NativeValueTraits<T> TraitsType; | 489 typedef NativeValueTraits<T> TraitsType; |
| 490 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | 490 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
| 491 for (uint32_t i = 0; i < length; ++i) | 491 for (uint32_t i = 0; i < length; ++i) |
| 492 result.uncheckedAppend(TraitsType::nativeValue(object->Get(i))); | 492 result.uncheckedAppend(TraitsType::nativeValue(object->Get(i))); |
| 493 return result; | 493 return result; |
| 494 } | 494 } |
| 495 | 495 |
| 496 template <class T> | 496 template <class T> |
| 497 Vector<T> toNativeArguments(const v8::FunctionCallbackInfo<v8::Value>& args,
int startIndex) | 497 Vector<T> toNativeArguments(const v8::FunctionCallbackInfo<v8::Value>& args,
int startIndex) |
| 498 { | 498 { |
| 499 ASSERT(startIndex <= args.Length()); | 499 ASSERT(startIndex <= args.Length()); |
| 500 Vector<T> result; | 500 Vector<T> result; |
| 501 typedef NativeValueTraits<T> TraitsType; | 501 typedef NativeValueTraits<T> TraitsType; |
| 502 int length = args.Length(); | 502 int length = args.Length(); |
| 503 result.reserveInitialCapacity(length); | 503 result.reserveInitialCapacity(length); |
| 504 for (int i = startIndex; i < length; ++i) | 504 for (int i = startIndex; i < length; ++i) |
| 505 result.uncheckedAppend(TraitsType::nativeValue(args[i])); | 505 result.uncheckedAppend(TraitsType::nativeValue(args[i])); |
| 506 return result; | 506 return result; |
| 507 } | 507 } |
| 508 | 508 |
| 509 Vector<v8::Handle<v8::Value> > toVectorOfArguments(const v8::FunctionCallbac
kInfo<v8::Value>& args); | 509 Vector<v8::Handle<v8::Value> > toVectorOfArguments(const v8::FunctionCallbac
kInfo<v8::Value>& args); |
| 510 | 510 |
| 511 // Validates that the passed object is a sequence type per WebIDL spec | 511 // Validates that the passed object is a sequence type per WebIDL spec |
| 512 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-sequence | 512 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-sequence |
| 513 inline v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value> value, uint3
2_t& length, v8::Isolate* isolate) | 513 inline v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value> value, uint3
2_t& length, bool* notASequence, v8::Isolate* isolate) |
| 514 { | 514 { |
| 515 // Attempt converting to a sequence if the value is not already an array
but is | 515 // Attempt converting to a sequence if the value is not already an array
but is |
| 516 // any kind of object except for a native Date object or a native RegExp
object. | 516 // any kind of object except for a native Date object or a native RegExp
object. |
| 517 ASSERT(!value->IsArray()); | 517 ASSERT(!value->IsArray()); |
| 518 // FIXME: Do we really need to special case Date and RegExp object? | 518 // FIXME: Do we really need to special case Date and RegExp object? |
| 519 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=22806 | 519 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=22806 |
| 520 if (!value->IsObject() || value->IsDate() || value->IsRegExp()) { | 520 if (!value->IsObject() || value->IsDate() || value->IsRegExp()) { |
| 521 throwTypeError(isolate); | 521 // Signal that the caller must handle the type error. |
| 522 if (notASequence) |
| 523 *notASequence = true; |
| 524 else |
| 525 throwTypeError(isolate); |
| 522 return v8Undefined(); | 526 return v8Undefined(); |
| 523 } | 527 } |
| 524 | 528 |
| 525 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); | 529 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); |
| 526 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | 530 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
| 527 | 531 |
| 528 // FIXME: The specification states that the length property should be us
ed as fallback, if value | 532 // FIXME: The specification states that the length property should be us
ed as fallback, if value |
| 529 // is not a platform object that supports indexed properties. If it supp
orts indexed properties, | 533 // is not a platform object that supports indexed properties. If it supp
orts indexed properties, |
| 530 // length should actually be one greater than value’s maximum indexed pr
operty index. | 534 // length should actually be one greater than value’s maximum indexed pr
operty index. |
| 531 V8TRYCATCH(v8::Local<v8::Value>, lengthValue, object->Get(v8::String::Ne
wSymbol("length"))); | 535 V8TRYCATCH(v8::Local<v8::Value>, lengthValue, object->Get(v8::String::Ne
wSymbol("length"))); |
| 532 | 536 |
| 533 if (lengthValue->IsUndefined() || lengthValue->IsNull()) { | 537 if (lengthValue->IsUndefined() || lengthValue->IsNull()) { |
| 534 throwTypeError(isolate); | 538 // Signal that the caller must handle the type error. |
| 539 if (notASequence) |
| 540 *notASequence = true; |
| 541 else |
| 542 throwTypeError(isolate); |
| 535 return v8Undefined(); | 543 return v8Undefined(); |
| 536 } | 544 } |
| 537 | 545 |
| 538 V8TRYCATCH(uint32_t, sequenceLength, lengthValue->Int32Value()); | 546 V8TRYCATCH(uint32_t, sequenceLength, lengthValue->Int32Value()); |
| 539 length = sequenceLength; | 547 length = sequenceLength; |
| 540 | 548 |
| 541 return v8Value; | 549 return v8Value; |
| 542 } | 550 } |
| 543 | 551 |
| 544 PassRefPtr<NodeFilter> toNodeFilter(v8::Handle<v8::Value>, v8::Isolate*); | 552 PassRefPtr<NodeFilter> toNodeFilter(v8::Handle<v8::Value>, v8::Isolate*); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 | 664 |
| 657 v8::Isolate* mainThreadIsolate(); | 665 v8::Isolate* mainThreadIsolate(); |
| 658 v8::Isolate* toIsolate(ExecutionContext*); | 666 v8::Isolate* toIsolate(ExecutionContext*); |
| 659 v8::Isolate* toIsolate(Frame*); | 667 v8::Isolate* toIsolate(Frame*); |
| 660 | 668 |
| 661 // Can only be called by WebKit::initialize | 669 // Can only be called by WebKit::initialize |
| 662 void setMainThreadIsolate(v8::Isolate*); | 670 void setMainThreadIsolate(v8::Isolate*); |
| 663 } // namespace WebCore | 671 } // namespace WebCore |
| 664 | 672 |
| 665 #endif // V8Binding_h | 673 #endif // V8Binding_h |
| OLD | NEW |