| 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 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 *success = true; | 428 *success = true; |
| 429 | 429 |
| 430 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); | 430 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); |
| 431 uint32_t length = 0; | 431 uint32_t length = 0; |
| 432 if (value->IsArray()) | 432 if (value->IsArray()) |
| 433 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | 433 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |
| 434 else if (toV8Sequence(value, length, isolate).IsEmpty()) | 434 else if (toV8Sequence(value, length, isolate).IsEmpty()) |
| 435 return Vector<RefPtr<T> >(); | 435 return Vector<RefPtr<T> >(); |
| 436 | 436 |
| 437 Vector<RefPtr<T> > result; | 437 Vector<RefPtr<T> > result; |
| 438 result.reserveInitialCapacity(length); |
| 438 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | 439 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
| 439 for (uint32_t i = 0; i < length; ++i) { | 440 for (uint32_t i = 0; i < length; ++i) { |
| 440 v8::Handle<v8::Value> element = object->Get(i); | 441 v8::Handle<v8::Value> element = object->Get(i); |
| 441 | 442 |
| 442 if (V8T::HasInstance(element, isolate, worldType(isolate))) { | 443 if (V8T::HasInstance(element, isolate, worldType(isolate))) { |
| 443 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::C
ast(element); | 444 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::C
ast(element); |
| 444 result.append(V8T::toNative(elementObject)); | 445 result.uncheckedAppend(V8T::toNative(elementObject)); |
| 445 } else { | 446 } else { |
| 446 if (success) | 447 if (success) |
| 447 *success = false; | 448 *success = false; |
| 448 throwTypeError("Invalid Array element type", isolate); | 449 throwTypeError("Invalid Array element type", isolate); |
| 449 return Vector<RefPtr<T> >(); | 450 return Vector<RefPtr<T> >(); |
| 450 } | 451 } |
| 451 } | 452 } |
| 452 return result; | 453 return result; |
| 453 } | 454 } |
| 454 | 455 |
| 455 // Converts a JavaScript value to an array as per the Web IDL specification: | 456 // Converts a JavaScript value to an array as per the Web IDL specification: |
| 456 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array | 457 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array |
| 457 template <class T> | 458 template <class T> |
| 458 Vector<T> toNativeArray(v8::Handle<v8::Value> value, v8::Isolate* isolate) | 459 Vector<T> toNativeArray(v8::Handle<v8::Value> value, v8::Isolate* isolate) |
| 459 { | 460 { |
| 460 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); | 461 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); |
| 461 uint32_t length = 0; | 462 uint32_t length = 0; |
| 462 if (value->IsArray()) | 463 if (value->IsArray()) |
| 463 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | 464 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |
| 464 else if (toV8Sequence(value, length, isolate).IsEmpty()) | 465 else if (toV8Sequence(value, length, isolate).IsEmpty()) |
| 465 return Vector<T>(); | 466 return Vector<T>(); |
| 466 | 467 |
| 467 Vector<T> result; | 468 Vector<T> result; |
| 469 result.reserveInitialCapacity(length); |
| 468 typedef NativeValueTraits<T> TraitsType; | 470 typedef NativeValueTraits<T> TraitsType; |
| 469 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | 471 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
| 470 for (uint32_t i = 0; i < length; ++i) | 472 for (uint32_t i = 0; i < length; ++i) |
| 471 result.append(TraitsType::nativeValue(object->Get(i))); | 473 result.uncheckedAppend(TraitsType::nativeValue(object->Get(i))); |
| 472 return result; | 474 return result; |
| 473 } | 475 } |
| 474 | 476 |
| 475 template <class T> | 477 template <class T> |
| 476 Vector<T> toNativeArguments(const v8::FunctionCallbackInfo<v8::Value>& args,
int startIndex) | 478 Vector<T> toNativeArguments(const v8::FunctionCallbackInfo<v8::Value>& args,
int startIndex) |
| 477 { | 479 { |
| 478 ASSERT(startIndex <= args.Length()); | 480 ASSERT(startIndex <= args.Length()); |
| 479 Vector<T> result; | 481 Vector<T> result; |
| 480 typedef NativeValueTraits<T> TraitsType; | 482 typedef NativeValueTraits<T> TraitsType; |
| 481 int length = args.Length(); | 483 int length = args.Length(); |
| 484 result.reserveInitialCapacity(length); |
| 482 for (int i = startIndex; i < length; ++i) | 485 for (int i = startIndex; i < length; ++i) |
| 483 result.append(TraitsType::nativeValue(args[i])); | 486 result.uncheckedAppend(TraitsType::nativeValue(args[i])); |
| 484 return result; | 487 return result; |
| 485 } | 488 } |
| 486 | 489 |
| 487 Vector<v8::Handle<v8::Value> > toVectorOfArguments(const v8::FunctionCallbac
kInfo<v8::Value>& args); | 490 Vector<v8::Handle<v8::Value> > toVectorOfArguments(const v8::FunctionCallbac
kInfo<v8::Value>& args); |
| 488 | 491 |
| 489 // Validates that the passed object is a sequence type per WebIDL spec | 492 // Validates that the passed object is a sequence type per WebIDL spec |
| 490 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-sequence | 493 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-sequence |
| 491 inline v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value> value, uint3
2_t& length, v8::Isolate* isolate) | 494 inline v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value> value, uint3
2_t& length, v8::Isolate* isolate) |
| 492 { | 495 { |
| 493 // Attempt converting to a sequence if the value is not already an array
but is | 496 // Attempt converting to a sequence if the value is not already an array
but is |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 return v8::FunctionTemplate::New(function, environment)->GetFunction(); | 634 return v8::FunctionTemplate::New(function, environment)->GetFunction(); |
| 632 } | 635 } |
| 633 | 636 |
| 634 v8::Local<v8::Value> getHiddenValueFromMainWorldWrapper(v8::Isolate*, Script
Wrappable*, v8::Handle<v8::String> key); | 637 v8::Local<v8::Value> getHiddenValueFromMainWorldWrapper(v8::Isolate*, Script
Wrappable*, v8::Handle<v8::String> key); |
| 635 | 638 |
| 636 v8::Isolate* getIsolateFromScriptExecutionContext(ScriptExecutionContext*); | 639 v8::Isolate* getIsolateFromScriptExecutionContext(ScriptExecutionContext*); |
| 637 | 640 |
| 638 } // namespace WebCore | 641 } // namespace WebCore |
| 639 | 642 |
| 640 #endif // V8Binding_h | 643 #endif // V8Binding_h |
| OLD | NEW |