Chromium Code Reviews| 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 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 721 result.reserveInitialCapacity(length - startIndex); | 721 result.reserveInitialCapacity(length - startIndex); |
| 722 for (int i = startIndex; i < length; ++i) { | 722 for (int i = startIndex; i < length; ++i) { |
| 723 result.uncheckedAppend(TraitsType::nativeValue(info.GetIsolate(), in fo[i], exceptionState)); | 723 result.uncheckedAppend(TraitsType::nativeValue(info.GetIsolate(), in fo[i], exceptionState)); |
| 724 if (exceptionState.hadException()) | 724 if (exceptionState.hadException()) |
| 725 return VectorType(); | 725 return VectorType(); |
| 726 } | 726 } |
| 727 } | 727 } |
| 728 return result; | 728 return result; |
| 729 } | 729 } |
| 730 | 730 |
| 731 // Gets an iterator from an Object. | |
| 732 CORE_EXPORT v8::MaybeLocal<v8::Object> getEsIterator(v8::Isolate*, v8::Local<v8: :Object>, ExceptionState&); | |
| 733 | |
| 731 // Validates that the passed object is a sequence type per WebIDL spec | 734 // Validates that the passed object is a sequence type per WebIDL spec |
| 732 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-sequence | 735 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-sequence |
| 733 inline bool toV8Sequence(v8::Local<v8::Value> value, uint32_t& length, v8::Isola te* isolate, ExceptionState& exceptionState) | 736 inline bool toV8Sequence(v8::Local<v8::Value> value, uint32_t& length, v8::Isola te* isolate, ExceptionState& exceptionState) |
| 734 { | 737 { |
| 735 // Attempt converting to a sequence if the value is not already an array but is | 738 // Attempt converting to a sequence if the value is not already an array but is |
| 736 // any kind of object except for a native Date object or a native RegExp obj ect. | 739 // any kind of object except for a native Date object or a native RegExp obj ect. |
| 737 ASSERT(!value->IsArray()); | 740 ASSERT(!value->IsArray()); |
| 738 // FIXME: Do we really need to special case Date and RegExp object? | 741 // FIXME: Do we really need to special case Date and RegExp object? |
| 739 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=22806 | 742 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=22806 |
| 740 if (!value->IsObject() || value->IsDate() || value->IsRegExp()) { | 743 if (!value->IsObject() || value->IsDate() || value->IsRegExp()) { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 873 // a context, if the window is currently being displayed in a Frame. | 876 // a context, if the window is currently being displayed in a Frame. |
| 874 CORE_EXPORT Frame* toFrameIfNotDetached(v8::Local<v8::Context>); | 877 CORE_EXPORT Frame* toFrameIfNotDetached(v8::Local<v8::Context>); |
| 875 | 878 |
| 876 CORE_EXPORT EventTarget* toEventTarget(v8::Isolate*, v8::Local<v8::Value>); | 879 CORE_EXPORT EventTarget* toEventTarget(v8::Isolate*, v8::Local<v8::Value>); |
| 877 | 880 |
| 878 // If 'storage' is non-null, it must be large enough to copy all bytes in the | 881 // If 'storage' is non-null, it must be large enough to copy all bytes in the |
| 879 // array buffer view into it. Use allocateFlexibleArrayBufferStorage(v8Value) | 882 // array buffer view into it. Use allocateFlexibleArrayBufferStorage(v8Value) |
| 880 // to allocate it using alloca() in the callers stack frame. | 883 // to allocate it using alloca() in the callers stack frame. |
| 881 CORE_EXPORT void toFlexibleArrayBufferView(v8::Isolate*, v8::Local<v8::Value>, F lexibleArrayBufferView&, void* storage = nullptr); | 884 CORE_EXPORT void toFlexibleArrayBufferView(v8::Isolate*, v8::Local<v8::Value>, F lexibleArrayBufferView&, void* storage = nullptr); |
| 882 | 885 |
| 886 // Converts a V8 value to an array (an IDL sequence) as per the WebIDL | |
| 887 // specification: http://heycam.github.io/webidl/#es-sequence | |
| 888 template <typename VectorType> | |
| 889 VectorType toImplSequence(v8::Isolate* isolate, v8::Local<v8::Value> value, Exce ptionState& exceptionState) | |
|
bashi
2016/09/09 00:54:23
Moved below toExecutionContext(). We can't call ca
| |
| 890 { | |
| 891 using ValueType = typename VectorType::ValueType; | |
| 892 | |
| 893 if (!value->IsObject() || value->IsRegExp()) { | |
| 894 exceptionState.throwTypeError("The provided value cannot be converted to a sequence."); | |
| 895 return VectorType(); | |
| 896 } | |
| 897 | |
| 898 v8::Local<v8::Object> iterator; | |
| 899 if (!getEsIterator(isolate, value.As<v8::Object>(), exceptionState).ToLocal( &iterator)) | |
| 900 return VectorType(); | |
| 901 | |
| 902 v8::Local<v8::String> nextKey = v8String(isolate, "next"); | |
| 903 v8::Local<v8::String> valueKey = v8String(isolate, "value"); | |
| 904 v8::Local<v8::String> doneKey = v8String(isolate, "done"); | |
| 905 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | |
| 906 VectorType result; | |
| 907 while (true) { | |
|
haraken
2016/09/09 01:38:42
Maybe we want to share this code with DictionaryIt
| |
| 908 v8::Local<v8::Value> next; | |
| 909 if (!iterator->Get(context, nextKey).ToLocal(&next)) | |
| 910 return VectorType(); | |
| 911 // TODO(bashi): Support callable objects. | |
| 912 if (!next->IsObject() || !next.As<v8::Object>()->IsFunction()) { | |
| 913 exceptionState.throwTypeError("Iterator.next should be callable."); | |
| 914 return VectorType(); | |
| 915 } | |
| 916 v8::Local<v8::Value> nextResult; | |
| 917 if (!V8ScriptRunner::callFunction(next.As<v8::Function>(), toExecutionCo ntext(context), iterator, 0, nullptr, isolate).ToLocal(&nextResult)) | |
| 918 return VectorType(); | |
| 919 if (!nextResult->IsObject()) { | |
| 920 exceptionState.throwTypeError("Iterator.next() did not return an obj ect."); | |
| 921 return VectorType(); | |
| 922 } | |
| 923 v8::Local<v8::Object> resultObject = nextResult.As<v8::Object>(); | |
| 924 v8::Local<v8::Value> element; | |
| 925 v8::Local<v8::Value> done; | |
| 926 if (!resultObject->Get(context, valueKey).ToLocal(&element) | |
| 927 || !resultObject->Get(context, doneKey).ToLocal(&done)) | |
| 928 return VectorType(); | |
| 929 v8::Local<v8::Boolean> doneBoolean; | |
| 930 if (!done->ToBoolean(context).ToLocal(&doneBoolean)) | |
| 931 return VectorType(); | |
| 932 if (doneBoolean->Value()) | |
|
bashi
2016/09/09 00:54:23
Don't append when |done| is true, as |value| is `u
| |
| 933 break; | |
| 934 result.append(NativeValueTraits<ValueType>::nativeValue(isolate, element , exceptionState)); | |
| 935 } | |
| 936 return result; | |
| 937 } | |
| 938 | |
| 883 // Installs all of the origin-trial-enabled V8 bindings for the given context | 939 // Installs all of the origin-trial-enabled V8 bindings for the given context |
| 884 // and world, based on the trial tokens which have been added to the | 940 // and world, based on the trial tokens which have been added to the |
| 885 // ExecutionContext. This should be called after the V8 context has been | 941 // ExecutionContext. This should be called after the V8 context has been |
| 886 // installed, but may be called multiple times, as trial tokens are | 942 // installed, but may be called multiple times, as trial tokens are |
| 887 // encountered. It indirectly calls the function set by | 943 // encountered. It indirectly calls the function set by |
| 888 // |setInstallOriginTrialsFunction|. | 944 // |setInstallOriginTrialsFunction|. |
| 889 CORE_EXPORT void installOriginTrials(ScriptState*); | 945 CORE_EXPORT void installOriginTrials(ScriptState*); |
| 890 | 946 |
| 891 // Sets the function to be called by |installOriginTrials|. The function is | 947 // Sets the function to be called by |installOriginTrials|. The function is |
| 892 // initially set to the private |installOriginTrialsForCore| function, but | 948 // initially set to the private |installOriginTrialsForCore| function, but |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 962 typedef void (*InstallTemplateFunction)(v8::Isolate*, const DOMWrapperWorld&, v8 ::Local<v8::FunctionTemplate> interfaceTemplate); | 1018 typedef void (*InstallTemplateFunction)(v8::Isolate*, const DOMWrapperWorld&, v8 ::Local<v8::FunctionTemplate> interfaceTemplate); |
| 963 | 1019 |
| 964 // Freeze a V8 object. The type of the first parameter and the return value is | 1020 // Freeze a V8 object. The type of the first parameter and the return value is |
| 965 // intentionally v8::Value so that this function can wrap toV8(). | 1021 // intentionally v8::Value so that this function can wrap toV8(). |
| 966 // If the argument isn't an object, this will crash. | 1022 // If the argument isn't an object, this will crash. |
| 967 CORE_EXPORT v8::Local<v8::Value> freezeV8Object(v8::Local<v8::Value>, v8::Isolat e*); | 1023 CORE_EXPORT v8::Local<v8::Value> freezeV8Object(v8::Local<v8::Value>, v8::Isolat e*); |
| 968 | 1024 |
| 969 } // namespace blink | 1025 } // namespace blink |
| 970 | 1026 |
| 971 #endif // V8Binding_h | 1027 #endif // V8Binding_h |
| OLD | NEW |