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, v8::Isolate*, bool* notASequence = 0); |
Mike West
2013/10/22 06:50:40
I think I'd prefer to keep the Isolate as the last
sof
2013/10/22 16:06:56
Done, and dropped the "nicety" of having the extra
| |
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 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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, v8::Isolate* isolate, bool* notASequence) |
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); | |
Mike West
2013/10/22 06:50:40
I'd be happy to review a subsequent patch that add
sof
2013/10/22 16:06:56
Definitely, I can have a look at improving that.
| |
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 |