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

Side by Side Diff: Source/bindings/tests/results/V8TestEventConstructor.cpp

Issue 85263002: Improve handling of dictionary conversions. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Have conversion methods take a context argument; elaborate error msgs further. Created 7 years 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) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 { 104 {
105 if (info.Length() < 1) { 105 if (info.Length() < 1) {
106 throwTypeError(ExceptionMessages::failedToConstruct("TestEventConstructo r", "An event name must be provided."), info.GetIsolate()); 106 throwTypeError(ExceptionMessages::failedToConstruct("TestEventConstructo r", "An event name must be provided."), info.GetIsolate());
107 return; 107 return;
108 } 108 }
109 109
110 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, type, info[0]); 110 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, type, info[0]);
111 TestEventConstructorInit eventInit; 111 TestEventConstructorInit eventInit;
112 if (info.Length() >= 2) { 112 if (info.Length() >= 2) {
113 V8TRYCATCH_VOID(Dictionary, options, Dictionary(info[1], info.GetIsolate ())); 113 V8TRYCATCH_VOID(Dictionary, options, Dictionary(info[1], info.GetIsolate ()));
114 if (!fillTestEventConstructorInit(eventInit, options)) 114 ExceptionState exceptionState(info.Holder(), info.GetIsolate());
115 if (!fillTestEventConstructorInit(eventInit, options, exceptionState)) {
116 exceptionState.throwIfNeeded();
115 return; 117 return;
118 }
116 } 119 }
117
118 RefPtr<TestEventConstructor> event = TestEventConstructor::create(type, even tInit); 120 RefPtr<TestEventConstructor> event = TestEventConstructor::create(type, even tInit);
119 v8::Handle<v8::Object> wrapper = info.Holder(); 121 v8::Handle<v8::Object> wrapper = info.Holder();
120 V8DOMWrapper::associateObjectWithWrapper<V8TestEventConstructor>(event.relea se(), &V8TestEventConstructor::wrapperTypeInfo, wrapper, info.GetIsolate(), Wrap perConfiguration::Dependent); 122 V8DOMWrapper::associateObjectWithWrapper<V8TestEventConstructor>(event.relea se(), &V8TestEventConstructor::wrapperTypeInfo, wrapper, info.GetIsolate(), Wrap perConfiguration::Dependent);
121 v8SetReturnValue(info, wrapper); 123 v8SetReturnValue(info, wrapper);
122 } 124 }
123 } // namespace TestEventConstructorV8Internal 125 } // namespace TestEventConstructorV8Internal
124 126
125 static const V8DOMConfiguration::AttributeConfiguration V8TestEventConstructorAt tributes[] = { 127 static const V8DOMConfiguration::AttributeConfiguration V8TestEventConstructorAt tributes[] = {
126 {"attr1", TestEventConstructorV8Internal::attr1AttributeGetterCallback, 0, 0 , 0, 0, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAtt ribute>(v8::None), 0 /* on instance */}, 128 {"attr1", TestEventConstructorV8Internal::attr1AttributeGetterCallback, 0, 0 , 0, 0, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAtt ribute>(v8::None), 0 /* on instance */},
127 {"attr2", TestEventConstructorV8Internal::attr2AttributeGetterCallback, 0, 0 , 0, 0, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAtt ribute>(v8::None), 0 /* on instance */}, 129 {"attr2", TestEventConstructorV8Internal::attr2AttributeGetterCallback, 0, 0 , 0, 0, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAtt ribute>(v8::None), 0 /* on instance */},
128 }; 130 };
129 131
130 bool fillTestEventConstructorInit(TestEventConstructorInit& eventInit, const Dic tionary& options) 132 bool fillTestEventConstructorInit(TestEventConstructorInit& eventInit, const Dic tionary& options, ExceptionState& exceptionState, const String& forEventName)
131 { 133 {
132 options.get("attr2", eventInit.attr2); 134 Dictionary::ConversionContext conversionContext(forEventName.isEmpty() ? Str ing("TestEventConstructor") : forEventName, "", exceptionState);
135 if (!options.convert(conversionContext, "attr2", eventInit.attr2))
136 return false;
133 return true; 137 return true;
134 } 138 }
135 139
136 void V8TestEventConstructor::constructorCallback(const v8::FunctionCallbackInfo< v8::Value>& info) 140 void V8TestEventConstructor::constructorCallback(const v8::FunctionCallbackInfo< v8::Value>& info)
137 { 141 {
138 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "DOMConstructor"); 142 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "DOMConstructor");
139 if (!info.IsConstructCall()) { 143 if (!info.IsConstructCall()) {
140 throwTypeError(ExceptionMessages::failedToConstruct("TestEventConstructo r", "Please use the 'new' operator, this DOM object constructor cannot be called as a function."), info.GetIsolate()); 144 throwTypeError(ExceptionMessages::failedToConstruct("TestEventConstructo r", "Please use the 'new' operator, this DOM object constructor cannot be called as a function."), info.GetIsolate());
141 return; 145 return;
142 } 146 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 V8DOMWrapper::associateObjectWithWrapper<V8TestEventConstructor>(impl, &wrap perTypeInfo, wrapper, isolate, WrapperConfiguration::Independent); 222 V8DOMWrapper::associateObjectWithWrapper<V8TestEventConstructor>(impl, &wrap perTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
219 return wrapper; 223 return wrapper;
220 } 224 }
221 225
222 void V8TestEventConstructor::derefObject(void* object) 226 void V8TestEventConstructor::derefObject(void* object)
223 { 227 {
224 fromInternalPointer(object)->deref(); 228 fromInternalPointer(object)->deref();
225 } 229 }
226 230
227 } // namespace WebCore 231 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698