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

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

Issue 2455483002: Use v8::TryCatch in toImplSequence (Closed)
Patch Set: Created 4 years, 1 month 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 807 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 result.uncheckedAppend( 818 result.uncheckedAppend(
819 TraitsType::nativeValue(info.GetIsolate(), info[i], exceptionState)); 819 TraitsType::nativeValue(info.GetIsolate(), info[i], exceptionState));
820 if (exceptionState.hadException()) 820 if (exceptionState.hadException())
821 return VectorType(); 821 return VectorType();
822 } 822 }
823 } 823 }
824 return result; 824 return result;
825 } 825 }
826 826
827 // Gets an iterator from an Object. 827 // Gets an iterator from an Object.
828 CORE_EXPORT v8::MaybeLocal<v8::Object> getEsIterator(v8::Isolate*, 828 CORE_EXPORT v8::Local<v8::Object> getEsIterator(v8::Isolate*,
829 v8::Local<v8::Object>, 829 v8::Local<v8::Object>,
830 ExceptionState&); 830 ExceptionState&);
831 831
832 // 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
833 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-sequence 833 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-sequence
834 inline bool toV8Sequence(v8::Local<v8::Value> value, 834 inline bool toV8Sequence(v8::Local<v8::Value> value,
835 uint32_t& length, 835 uint32_t& length,
836 v8::Isolate* isolate, 836 v8::Isolate* isolate,
837 ExceptionState& exceptionState) { 837 ExceptionState& exceptionState) {
838 // Attempt converting to a sequence if the value is not already an array but 838 // Attempt converting to a sequence if the value is not already an array but
839 // is any kind of object except for a native Date object or a native RegExp 839 // is any kind of object except for a native Date object or a native RegExp
840 // object. 840 // object.
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 v8::Local<v8::Value> value, 1012 v8::Local<v8::Value> value,
1013 ExceptionState& exceptionState) { 1013 ExceptionState& exceptionState) {
1014 using ValueType = typename VectorType::ValueType; 1014 using ValueType = typename VectorType::ValueType;
1015 1015
1016 if (!value->IsObject() || value->IsRegExp()) { 1016 if (!value->IsObject() || value->IsRegExp()) {
1017 exceptionState.throwTypeError( 1017 exceptionState.throwTypeError(
1018 "The provided value cannot be converted to a sequence."); 1018 "The provided value cannot be converted to a sequence.");
1019 return VectorType(); 1019 return VectorType();
1020 } 1020 }
1021 1021
1022 v8::Local<v8::Object> iterator; 1022 v8::TryCatch block(isolate);
1023 if (!getEsIterator(isolate, value.As<v8::Object>(), exceptionState) 1023 v8::Local<v8::Object> iterator =
1024 .ToLocal(&iterator)) 1024 getEsIterator(isolate, value.As<v8::Object>(), exceptionState);
1025 if (exceptionState.hadException())
1025 return VectorType(); 1026 return VectorType();
1026 1027
1027 v8::Local<v8::String> nextKey = v8String(isolate, "next"); 1028 v8::Local<v8::String> nextKey = v8String(isolate, "next");
1028 v8::Local<v8::String> valueKey = v8String(isolate, "value"); 1029 v8::Local<v8::String> valueKey = v8String(isolate, "value");
1029 v8::Local<v8::String> doneKey = v8String(isolate, "done"); 1030 v8::Local<v8::String> doneKey = v8String(isolate, "done");
1030 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 1031 v8::Local<v8::Context> context = isolate->GetCurrentContext();
1031 VectorType result; 1032 VectorType result;
1032 while (true) { 1033 while (true) {
1033 v8::Local<v8::Value> next; 1034 v8::Local<v8::Value> next;
1034 if (!iterator->Get(context, nextKey).ToLocal(&next)) 1035 if (!iterator->Get(context, nextKey).ToLocal(&next)) {
1036 exceptionState.rethrowV8Exception(block.Exception());
1035 return VectorType(); 1037 return VectorType();
1038 }
1036 // TODO(bashi): Support callable objects. 1039 // TODO(bashi): Support callable objects.
1037 if (!next->IsObject() || !next.As<v8::Object>()->IsFunction()) { 1040 if (!next->IsObject() || !next.As<v8::Object>()->IsFunction()) {
1038 exceptionState.throwTypeError("Iterator.next should be callable."); 1041 exceptionState.throwTypeError("Iterator.next should be callable.");
1039 return VectorType(); 1042 return VectorType();
1040 } 1043 }
1041 v8::Local<v8::Value> nextResult; 1044 v8::Local<v8::Value> nextResult;
1042 if (!V8ScriptRunner::callFunction(next.As<v8::Function>(), 1045 if (!V8ScriptRunner::callFunction(next.As<v8::Function>(),
1043 toExecutionContext(context), iterator, 0, 1046 toExecutionContext(context), iterator, 0,
1044 nullptr, isolate) 1047 nullptr, isolate)
1045 .ToLocal(&nextResult)) 1048 .ToLocal(&nextResult)) {
1049 exceptionState.rethrowV8Exception(block.Exception());
1046 return VectorType(); 1050 return VectorType();
1051 }
1047 if (!nextResult->IsObject()) { 1052 if (!nextResult->IsObject()) {
1048 exceptionState.throwTypeError( 1053 exceptionState.throwTypeError(
1049 "Iterator.next() did not return an object."); 1054 "Iterator.next() did not return an object.");
1050 return VectorType(); 1055 return VectorType();
1051 } 1056 }
1052 v8::Local<v8::Object> resultObject = nextResult.As<v8::Object>(); 1057 v8::Local<v8::Object> resultObject = nextResult.As<v8::Object>();
1053 v8::Local<v8::Value> element; 1058 v8::Local<v8::Value> element;
1054 v8::Local<v8::Value> done; 1059 v8::Local<v8::Value> done;
1055 if (!resultObject->Get(context, valueKey).ToLocal(&element) || 1060 if (!resultObject->Get(context, valueKey).ToLocal(&element) ||
1056 !resultObject->Get(context, doneKey).ToLocal(&done)) 1061 !resultObject->Get(context, doneKey).ToLocal(&done)) {
1062 exceptionState.rethrowV8Exception(block.Exception());
1057 return VectorType(); 1063 return VectorType();
1064 }
1058 v8::Local<v8::Boolean> doneBoolean; 1065 v8::Local<v8::Boolean> doneBoolean;
1059 if (!done->ToBoolean(context).ToLocal(&doneBoolean)) 1066 if (!done->ToBoolean(context).ToLocal(&doneBoolean)) {
1067 exceptionState.rethrowV8Exception(block.Exception());
1060 return VectorType(); 1068 return VectorType();
1069 }
1061 if (doneBoolean->Value()) 1070 if (doneBoolean->Value())
1062 break; 1071 break;
1063 result.append(NativeValueTraits<ValueType>::nativeValue(isolate, element, 1072 result.append(NativeValueTraits<ValueType>::nativeValue(isolate, element,
1064 exceptionState)); 1073 exceptionState));
1065 } 1074 }
1066 return result; 1075 return result;
1067 } 1076 }
1068 1077
1069 // If the current context causes out of memory, JavaScript setting 1078 // If the current context causes out of memory, JavaScript setting
1070 // is disabled and it returns true. 1079 // is disabled and it returns true.
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 1158
1150 // Freeze a V8 object. The type of the first parameter and the return value is 1159 // Freeze a V8 object. The type of the first parameter and the return value is
1151 // intentionally v8::Value so that this function can wrap toV8(). 1160 // intentionally v8::Value so that this function can wrap toV8().
1152 // If the argument isn't an object, this will crash. 1161 // If the argument isn't an object, this will crash.
1153 CORE_EXPORT v8::Local<v8::Value> freezeV8Object(v8::Local<v8::Value>, 1162 CORE_EXPORT v8::Local<v8::Value> freezeV8Object(v8::Local<v8::Value>,
1154 v8::Isolate*); 1163 v8::Isolate*);
1155 1164
1156 } // namespace blink 1165 } // namespace blink
1157 1166
1158 #endif // V8Binding_h 1167 #endif // V8Binding_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698