Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/V8Binding.h

Issue 2386173002: reflow comments in Source/bindings/core/v8 (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 v8::Local<v8::String> value) { 388 v8::Local<v8::String> value) {
389 if (value.IsEmpty() || value->IsNull() || value->IsUndefined()) 389 if (value.IsEmpty() || value->IsNull() || value->IsUndefined())
390 return String(); 390 return String();
391 return toCoreString(value); 391 return toCoreString(value);
392 } 392 }
393 393
394 inline AtomicString toCoreAtomicString(v8::Local<v8::String> value) { 394 inline AtomicString toCoreAtomicString(v8::Local<v8::String> value) {
395 return v8StringToWebCoreString<AtomicString>(value, Externalize); 395 return v8StringToWebCoreString<AtomicString>(value, Externalize);
396 } 396 }
397 397
398 // This method will return a null String if the v8::Value does not contain a v8: :String. 398 // This method will return a null String if the v8::Value does not contain a
399 // It will not call ToString() on the v8::Value. If you want ToString() to be ca lled, 399 // v8::String. It will not call ToString() on the v8::Value. If you want
400 // please use the TONATIVE_FOR_V8STRINGRESOURCE_*() macros instead. 400 // ToString() to be called, please use the TONATIVE_FOR_V8STRINGRESOURCE_*()
401 // macros instead.
401 inline String toCoreStringWithUndefinedOrNullCheck(v8::Local<v8::Value> value) { 402 inline String toCoreStringWithUndefinedOrNullCheck(v8::Local<v8::Value> value) {
402 if (value.IsEmpty() || !value->IsString()) 403 if (value.IsEmpty() || !value->IsString())
403 return String(); 404 return String();
404 return toCoreString(value.As<v8::String>()); 405 return toCoreString(value.As<v8::String>());
405 } 406 }
406 407
407 // Convert a string to a V8 string. 408 // Convert a string to a V8 string.
408 409
409 inline v8::Local<v8::String> v8String(v8::Isolate* isolate, 410 inline v8::Local<v8::String> v8String(v8::Isolate* isolate,
410 const StringView& string) { 411 const StringView& string) {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 IntegerConversionConfiguration, 535 IntegerConversionConfiguration,
535 ExceptionState&); 536 ExceptionState&);
536 inline uint32_t toUInt32(v8::Isolate* isolate, 537 inline uint32_t toUInt32(v8::Isolate* isolate,
537 v8::Local<v8::Value> value, 538 v8::Local<v8::Value> value,
538 IntegerConversionConfiguration configuration, 539 IntegerConversionConfiguration configuration,
539 ExceptionState& exceptionState) { 540 ExceptionState& exceptionState) {
540 // Fast case. The value is already a 32-bit unsigned integer. 541 // Fast case. The value is already a 32-bit unsigned integer.
541 if (LIKELY(value->IsUint32())) 542 if (LIKELY(value->IsUint32()))
542 return value.As<v8::Uint32>()->Value(); 543 return value.As<v8::Uint32>()->Value();
543 544
544 // Fast case. The value is a 32-bit signed integer with NormalConversion confi guration. 545 // Fast case. The value is a 32-bit signed integer with NormalConversion
546 // configuration.
545 if (LIKELY(value->IsInt32() && configuration == NormalConversion)) 547 if (LIKELY(value->IsInt32() && configuration == NormalConversion))
546 return value.As<v8::Int32>()->Value(); 548 return value.As<v8::Int32>()->Value();
547 549
548 return toUInt32Slow(isolate, value, configuration, exceptionState); 550 return toUInt32Slow(isolate, value, configuration, exceptionState);
549 } 551 }
550 552
551 // Convert a value to a 64-bit signed integer. The conversion fails if the 553 // Convert a value to a 64-bit signed integer. The conversion fails if the
552 // value cannot be converted to a number or the range violated per WebIDL: 554 // value cannot be converted to a number or the range violated per WebIDL:
553 // http://www.w3.org/TR/WebIDL/#es-long-long 555 // http://www.w3.org/TR/WebIDL/#es-long-long
554 CORE_EXPORT int64_t toInt64Slow(v8::Isolate*, 556 CORE_EXPORT int64_t toInt64Slow(v8::Isolate*,
555 v8::Local<v8::Value>, 557 v8::Local<v8::Value>,
556 IntegerConversionConfiguration, 558 IntegerConversionConfiguration,
557 ExceptionState&); 559 ExceptionState&);
558 inline int64_t toInt64(v8::Isolate* isolate, 560 inline int64_t toInt64(v8::Isolate* isolate,
559 v8::Local<v8::Value> value, 561 v8::Local<v8::Value> value,
560 IntegerConversionConfiguration configuration, 562 IntegerConversionConfiguration configuration,
561 ExceptionState& exceptionState) { 563 ExceptionState& exceptionState) {
562 // Clamping not supported for int64_t/long long int. See Source/wtf/MathExtras .h. 564 // Clamping not supported for int64_t/long long int. See
565 // Source/wtf/MathExtras.h.
563 ASSERT(configuration != Clamp); 566 ASSERT(configuration != Clamp);
564 567
565 // Fast case. The value is a 32-bit integer. 568 // Fast case. The value is a 32-bit integer.
566 if (LIKELY(value->IsInt32())) 569 if (LIKELY(value->IsInt32()))
567 return value.As<v8::Int32>()->Value(); 570 return value.As<v8::Int32>()->Value();
568 571
569 return toInt64Slow(isolate, value, configuration, exceptionState); 572 return toInt64Slow(isolate, value, configuration, exceptionState);
570 } 573 }
571 574
572 // Convert a value to a 64-bit unsigned integer. The conversion fails if the 575 // Convert a value to a 64-bit unsigned integer. The conversion fails if the
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 // Convert a value to a single precision float, throwing on non-finite values. 620 // Convert a value to a single precision float, throwing on non-finite values.
618 CORE_EXPORT float toRestrictedFloat(v8::Isolate*, 621 CORE_EXPORT float toRestrictedFloat(v8::Isolate*,
619 v8::Local<v8::Value>, 622 v8::Local<v8::Value>,
620 ExceptionState&); 623 ExceptionState&);
621 624
622 // Converts a value to a String, throwing if any code unit is outside 0-255. 625 // Converts a value to a String, throwing if any code unit is outside 0-255.
623 CORE_EXPORT String toByteString(v8::Isolate*, 626 CORE_EXPORT String toByteString(v8::Isolate*,
624 v8::Local<v8::Value>, 627 v8::Local<v8::Value>,
625 ExceptionState&); 628 ExceptionState&);
626 629
627 // Converts a value to a String, replacing unmatched UTF-16 surrogates with repl acement characters. 630 // Converts a value to a String, replacing unmatched UTF-16 surrogates with
631 // replacement characters.
628 CORE_EXPORT String toUSVString(v8::Isolate*, 632 CORE_EXPORT String toUSVString(v8::Isolate*,
629 v8::Local<v8::Value>, 633 v8::Local<v8::Value>,
630 ExceptionState&); 634 ExceptionState&);
631 635
632 inline v8::Local<v8::Boolean> v8Boolean(bool value, v8::Isolate* isolate) { 636 inline v8::Local<v8::Boolean> v8Boolean(bool value, v8::Isolate* isolate) {
633 return value ? v8::True(isolate) : v8::False(isolate); 637 return value ? v8::True(isolate) : v8::False(isolate);
634 } 638 }
635 639
636 inline double toCoreDate(v8::Isolate* isolate, 640 inline double toCoreDate(v8::Isolate* isolate,
637 v8::Local<v8::Value> object, 641 v8::Local<v8::Value> object,
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 CORE_EXPORT v8::MaybeLocal<v8::Object> getEsIterator(v8::Isolate*, 828 CORE_EXPORT v8::MaybeLocal<v8::Object> getEsIterator(v8::Isolate*,
825 v8::Local<v8::Object>, 829 v8::Local<v8::Object>,
826 ExceptionState&); 830 ExceptionState&);
827 831
828 // Validates that the passed object is a sequence type per WebIDL spec 832 // Validates that the passed object is a sequence type per WebIDL spec
829 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-sequence 833 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-sequence
830 inline bool toV8Sequence(v8::Local<v8::Value> value, 834 inline bool toV8Sequence(v8::Local<v8::Value> value,
831 uint32_t& length, 835 uint32_t& length,
832 v8::Isolate* isolate, 836 v8::Isolate* isolate,
833 ExceptionState& exceptionState) { 837 ExceptionState& exceptionState) {
834 // Attempt converting to a sequence if the value is not already an array but i s 838 // Attempt converting to a sequence if the value is not already an array but
835 // any kind of object except for a native Date object or a native RegExp objec t. 839 // is any kind of object except for a native Date object or a native RegExp
840 // object.
836 ASSERT(!value->IsArray()); 841 ASSERT(!value->IsArray());
837 // FIXME: Do we really need to special case Date and RegExp object? 842 // FIXME: Do we really need to special case Date and RegExp object?
838 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=22806 843 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=22806
839 if (!value->IsObject() || value->IsDate() || value->IsRegExp()) { 844 if (!value->IsObject() || value->IsDate() || value->IsRegExp()) {
840 // The caller is responsible for reporting a TypeError. 845 // The caller is responsible for reporting a TypeError.
841 return false; 846 return false;
842 } 847 }
843 848
844 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value); 849 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value);
845 v8::Local<v8::String> lengthSymbol = v8AtomicString(isolate, "length"); 850 v8::Local<v8::String> lengthSymbol = v8AtomicString(isolate, "length");
846 851
847 // FIXME: The specification states that the length property should be used as fallback, if value 852 // FIXME: The specification states that the length property should be used as
848 // is not a platform object that supports indexed properties. If it supports i ndexed properties, 853 // fallback, if value is not a platform object that supports indexed
849 // length should actually be one greater than value's maximum indexed property index. 854 // properties. If it supports indexed properties, length should actually be
855 // one greater than value's maximum indexed property index.
850 v8::TryCatch block(isolate); 856 v8::TryCatch block(isolate);
851 v8::Local<v8::Value> lengthValue; 857 v8::Local<v8::Value> lengthValue;
852 if (!v8Call(object->Get(isolate->GetCurrentContext(), lengthSymbol), 858 if (!v8Call(object->Get(isolate->GetCurrentContext(), lengthSymbol),
853 lengthValue, block)) { 859 lengthValue, block)) {
854 exceptionState.rethrowV8Exception(block.Exception()); 860 exceptionState.rethrowV8Exception(block.Exception());
855 return false; 861 return false;
856 } 862 }
857 863
858 if (lengthValue->IsUndefined() || lengthValue->IsNull()) { 864 if (lengthValue->IsUndefined() || lengthValue->IsNull()) {
859 // The caller is responsible for reporting a TypeError. 865 // The caller is responsible for reporting a TypeError.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 DOMWindow* toDOMWindow(v8::Isolate*, v8::Local<v8::Value>); 971 DOMWindow* toDOMWindow(v8::Isolate*, v8::Local<v8::Value>);
966 DOMWindow* toDOMWindow(v8::Local<v8::Context>); 972 DOMWindow* toDOMWindow(v8::Local<v8::Context>);
967 LocalDOMWindow* enteredDOMWindow(v8::Isolate*); 973 LocalDOMWindow* enteredDOMWindow(v8::Isolate*);
968 CORE_EXPORT LocalDOMWindow* currentDOMWindow(v8::Isolate*); 974 CORE_EXPORT LocalDOMWindow* currentDOMWindow(v8::Isolate*);
969 CORE_EXPORT ExecutionContext* toExecutionContext(v8::Local<v8::Context>); 975 CORE_EXPORT ExecutionContext* toExecutionContext(v8::Local<v8::Context>);
970 CORE_EXPORT void registerToExecutionContextForModules( 976 CORE_EXPORT void registerToExecutionContextForModules(
971 ExecutionContext* (*toExecutionContextForModules)(v8::Local<v8::Context>)); 977 ExecutionContext* (*toExecutionContextForModules)(v8::Local<v8::Context>));
972 CORE_EXPORT ExecutionContext* currentExecutionContext(v8::Isolate*); 978 CORE_EXPORT ExecutionContext* currentExecutionContext(v8::Isolate*);
973 CORE_EXPORT ExecutionContext* enteredExecutionContext(v8::Isolate*); 979 CORE_EXPORT ExecutionContext* enteredExecutionContext(v8::Isolate*);
974 980
975 // Returns a V8 context associated with a ExecutionContext and a DOMWrapperWorld . 981 // Returns a V8 context associated with a ExecutionContext and a
976 // This method returns an empty context if there is no frame or the frame is alr eady detached. 982 // DOMWrapperWorld. This method returns an empty context if there is no frame
983 // or the frame is already detached.
977 CORE_EXPORT v8::Local<v8::Context> toV8Context(ExecutionContext*, 984 CORE_EXPORT v8::Local<v8::Context> toV8Context(ExecutionContext*,
978 DOMWrapperWorld&); 985 DOMWrapperWorld&);
979 // Returns a V8 context associated with a Frame and a DOMWrapperWorld. 986 // Returns a V8 context associated with a Frame and a DOMWrapperWorld.
980 // This method returns an empty context if the frame is already detached. 987 // This method returns an empty context if the frame is already detached.
981 CORE_EXPORT v8::Local<v8::Context> toV8Context(Frame*, DOMWrapperWorld&); 988 CORE_EXPORT v8::Local<v8::Context> toV8Context(Frame*, DOMWrapperWorld&);
982 // Like toV8Context but also returns the context if the frame is already detache d. 989 // Like toV8Context but also returns the context if the frame is already
990 // detached.
983 CORE_EXPORT v8::Local<v8::Context> toV8ContextEvenIfDetached(Frame*, 991 CORE_EXPORT v8::Local<v8::Context> toV8ContextEvenIfDetached(Frame*,
984 DOMWrapperWorld&); 992 DOMWrapperWorld&);
985 993
986 // Returns the frame object of the window object associated with 994 // Returns the frame object of the window object associated with
987 // a context, if the window is currently being displayed in a Frame. 995 // a context, if the window is currently being displayed in a Frame.
988 CORE_EXPORT Frame* toFrameIfNotDetached(v8::Local<v8::Context>); 996 CORE_EXPORT Frame* toFrameIfNotDetached(v8::Local<v8::Context>);
989 997
990 CORE_EXPORT EventTarget* toEventTarget(v8::Isolate*, v8::Local<v8::Value>); 998 CORE_EXPORT EventTarget* toEventTarget(v8::Isolate*, v8::Local<v8::Value>);
991 999
992 // If 'storage' is non-null, it must be large enough to copy all bytes in the 1000 // If 'storage' is non-null, it must be large enough to copy all bytes in the
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 const char** validValues, 1097 const char** validValues,
1090 size_t length, 1098 size_t length,
1091 const String& enumName, 1099 const String& enumName,
1092 ExceptionState&); 1100 ExceptionState&);
1093 CORE_EXPORT bool isValidEnum(const Vector<String>& values, 1101 CORE_EXPORT bool isValidEnum(const Vector<String>& values,
1094 const char** validValues, 1102 const char** validValues,
1095 size_t length, 1103 size_t length,
1096 const String& enumName, 1104 const String& enumName,
1097 ExceptionState&); 1105 ExceptionState&);
1098 1106
1099 // These methods store hidden values into an array that is stored in the interna l field of a DOM wrapper. 1107 // These methods store hidden values into an array that is stored in the
1108 // internal field of a DOM wrapper.
1100 bool addHiddenValueToArray(v8::Isolate*, 1109 bool addHiddenValueToArray(v8::Isolate*,
1101 v8::Local<v8::Object>, 1110 v8::Local<v8::Object>,
1102 v8::Local<v8::Value>, 1111 v8::Local<v8::Value>,
1103 int cacheIndex); 1112 int cacheIndex);
1104 void removeHiddenValueFromArray(v8::Isolate*, 1113 void removeHiddenValueFromArray(v8::Isolate*,
1105 v8::Local<v8::Object>, 1114 v8::Local<v8::Object>,
1106 v8::Local<v8::Value>, 1115 v8::Local<v8::Value>,
1107 int cacheIndex); 1116 int cacheIndex);
1108 CORE_EXPORT void moveEventListenerToNewWrapper(v8::Isolate*, 1117 CORE_EXPORT void moveEventListenerToNewWrapper(v8::Isolate*,
1109 v8::Local<v8::Object>, 1118 v8::Local<v8::Object>,
(...skipping 30 matching lines...) Expand all
1140 1149
1141 // Freeze a V8 object. The type of the first parameter and the return value is 1150 // Freeze a V8 object. The type of the first parameter and the return value is
1142 // intentionally v8::Value so that this function can wrap toV8(). 1151 // intentionally v8::Value so that this function can wrap toV8().
1143 // If the argument isn't an object, this will crash. 1152 // If the argument isn't an object, this will crash.
1144 CORE_EXPORT v8::Local<v8::Value> freezeV8Object(v8::Local<v8::Value>, 1153 CORE_EXPORT v8::Local<v8::Value> freezeV8Object(v8::Local<v8::Value>,
1145 v8::Isolate*); 1154 v8::Isolate*);
1146 1155
1147 } // namespace blink 1156 } // namespace blink
1148 1157
1149 #endif // V8Binding_h 1158 #endif // V8Binding_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698