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

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

Issue 171533006: V8 Binding: Introduce toNativeWithTypeCheck (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl.re lease(), &V8TestInterfaceConstructor::wrapperTypeInfo, wrapper, info.GetIsolate( ), WrapperConfiguration::Dependent); 87 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl.re lease(), &V8TestInterfaceConstructor::wrapperTypeInfo, wrapper, info.GetIsolate( ), WrapperConfiguration::Dependent);
88 v8SetReturnValue(info, wrapper); 88 v8SetReturnValue(info, wrapper);
89 } 89 }
90 90
91 static void constructor2(const v8::FunctionCallbackInfo<v8::Value>& info) 91 static void constructor2(const v8::FunctionCallbackInfo<v8::Value>& info)
92 { 92 {
93 ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInte rfaceConstructor", info.Holder(), info.GetIsolate()); 93 ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInte rfaceConstructor", info.Holder(), info.GetIsolate());
94 V8TRYCATCH_VOID(double, doubleArg, static_cast<double>(info[0]->NumberValue( ))); 94 V8TRYCATCH_VOID(double, doubleArg, static_cast<double>(info[0]->NumberValue( )));
95 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, stringArg, info[1]) ; 95 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, stringArg, info[1]) ;
96 V8TRYCATCH_VOID(TestInterfaceEmpty*, testInterfaceEmptyArg, V8TestInterfaceE mpty::hasInstance(info[2], info.GetIsolate()) ? V8TestInterfaceEmpty::toNative(v 8::Handle<v8::Object>::Cast(info[2])) : 0); 96 V8TRYCATCH_VOID(TestInterfaceEmpty*, testInterfaceEmptyArg, V8TestInterfaceE mpty::toNativeWithTypeCheck(info.GetIsolate(), info[2]));
97 V8TRYCATCH_VOID(Dictionary, dictionaryArg, Dictionary(info[3], info.GetIsola te())); 97 V8TRYCATCH_VOID(Dictionary, dictionaryArg, Dictionary(info[3], info.GetIsola te()));
98 if (!dictionaryArg.isUndefinedOrNull() && !dictionaryArg.isObject()) { 98 if (!dictionaryArg.isUndefinedOrNull() && !dictionaryArg.isObject()) {
99 exceptionState.throwTypeError("parameter 4 ('dictionaryArg') is not an o bject."); 99 exceptionState.throwTypeError("parameter 4 ('dictionaryArg') is not an o bject.");
100 exceptionState.throwIfNeeded(); 100 exceptionState.throwIfNeeded();
101 return; 101 return;
102 } 102 }
103 V8TRYCATCH_VOID(Vector<String>, sequenceStringArg, toNativeArray<String>(inf o[4], 5, info.GetIsolate())); 103 V8TRYCATCH_VOID(Vector<String>, sequenceStringArg, toNativeArray<String>(inf o[4], 5, info.GetIsolate()));
104 V8TRYCATCH_VOID(Dictionary, optionalDictionaryArg, Dictionary(info[5], info. GetIsolate())); 104 V8TRYCATCH_VOID(Dictionary, optionalDictionaryArg, Dictionary(info[5], info. GetIsolate()));
105 if (!optionalDictionaryArg.isUndefinedOrNull() && !optionalDictionaryArg.isO bject()) { 105 if (!optionalDictionaryArg.isUndefinedOrNull() && !optionalDictionaryArg.isO bject()) {
106 exceptionState.throwTypeError("parameter 6 ('optionalDictionaryArg') is not an object."); 106 exceptionState.throwTypeError("parameter 6 ('optionalDictionaryArg') is not an object.");
107 exceptionState.throwIfNeeded(); 107 exceptionState.throwIfNeeded();
108 return; 108 return;
109 } 109 }
110 V8TRYCATCH_VOID(TestInterfaceEmpty*, optionalTestInterfaceEmptyArg, V8TestIn terfaceEmpty::hasInstance(info[6], info.GetIsolate()) ? V8TestInterfaceEmpty::to Native(v8::Handle<v8::Object>::Cast(info[6])) : 0); 110 V8TRYCATCH_VOID(TestInterfaceEmpty*, optionalTestInterfaceEmptyArg, V8TestIn terfaceEmpty::toNativeWithTypeCheck(info.GetIsolate(), info[6]));
111 ExecutionContext* context = currentExecutionContext(info.GetIsolate()); 111 ExecutionContext* context = currentExecutionContext(info.GetIsolate());
112 Document& document = *toDocument(currentExecutionContext(info.GetIsolate())) ; 112 Document& document = *toDocument(currentExecutionContext(info.GetIsolate())) ;
113 RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::create(con text, document, doubleArg, stringArg, testInterfaceEmptyArg, dictionaryArg, sequ enceStringArg, optionalDictionaryArg, optionalTestInterfaceEmptyArg, exceptionSt ate); 113 RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::create(con text, document, doubleArg, stringArg, testInterfaceEmptyArg, dictionaryArg, sequ enceStringArg, optionalDictionaryArg, optionalTestInterfaceEmptyArg, exceptionSt ate);
114 v8::Handle<v8::Object> wrapper = info.Holder(); 114 v8::Handle<v8::Object> wrapper = info.Holder();
115 if (exceptionState.throwIfNeeded()) 115 if (exceptionState.throwIfNeeded())
116 return; 116 return;
117 117
118 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl.re lease(), &V8TestInterfaceConstructor::wrapperTypeInfo, wrapper, info.GetIsolate( ), WrapperConfiguration::Dependent); 118 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl.re lease(), &V8TestInterfaceConstructor::wrapperTypeInfo, wrapper, info.GetIsolate( ), WrapperConfiguration::Dependent);
119 v8SetReturnValue(info, wrapper); 119 v8SetReturnValue(info, wrapper);
120 } 120 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 data->templateMap(currentWorldType).add(&wrapperTypeInfo, UnsafePersistent<v 8::FunctionTemplate>(isolate, templ)); 184 data->templateMap(currentWorldType).add(&wrapperTypeInfo, UnsafePersistent<v 8::FunctionTemplate>(isolate, templ));
185 return handleScope.Escape(templ); 185 return handleScope.Escape(templ);
186 } 186 }
187 187
188 bool V8TestInterfaceConstructor::hasInstance(v8::Handle<v8::Value> jsValue, v8:: Isolate* isolate) 188 bool V8TestInterfaceConstructor::hasInstance(v8::Handle<v8::Value> jsValue, v8:: Isolate* isolate)
189 { 189 {
190 return V8PerIsolateData::from(isolate)->hasInstanceInMainWorld(&wrapperTypeI nfo, jsValue) 190 return V8PerIsolateData::from(isolate)->hasInstanceInMainWorld(&wrapperTypeI nfo, jsValue)
191 || V8PerIsolateData::from(isolate)->hasInstanceInNonMainWorld(&wrapperTy peInfo, jsValue); 191 || V8PerIsolateData::from(isolate)->hasInstanceInNonMainWorld(&wrapperTy peInfo, jsValue);
192 } 192 }
193 193
194 TestInterfaceConstructor* V8TestInterfaceConstructor::toNativeWithTypeCheck(v8:: Isolate* isolate, v8::Handle<v8::Value> value)
195 {
196 return hasInstance(value, isolate) ? fromInternalPointer(v8::Handle<v8::Obje ct>::Cast(value)->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex)) : 0;
197 }
198
194 v8::Handle<v8::Object> V8TestInterfaceConstructor::createWrapper(PassRefPtr<Test InterfaceConstructor> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 199 v8::Handle<v8::Object> V8TestInterfaceConstructor::createWrapper(PassRefPtr<Test InterfaceConstructor> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
195 { 200 {
196 ASSERT(impl); 201 ASSERT(impl);
197 ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceConstructor>(impl.get() , isolate)); 202 ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceConstructor>(impl.get() , isolate));
198 if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) { 203 if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
199 const WrapperTypeInfo* actualInfo = ScriptWrappable::getTypeInfoFromObje ct(impl.get()); 204 const WrapperTypeInfo* actualInfo = ScriptWrappable::getTypeInfoFromObje ct(impl.get());
200 // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapper TypeInfo. These will both have 205 // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapper TypeInfo. These will both have
201 // the same object de-ref functions, though, so use that as the basis of the check. 206 // the same object de-ref functions, though, so use that as the basis of the check.
202 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction); 207 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
203 } 208 }
(...skipping 12 matching lines...) Expand all
216 fromInternalPointer(object)->deref(); 221 fromInternalPointer(object)->deref();
217 } 222 }
218 223
219 template<> 224 template<>
220 v8::Handle<v8::Value> toV8NoInline(TestInterfaceConstructor* impl, v8::Handle<v8 ::Object> creationContext, v8::Isolate* isolate) 225 v8::Handle<v8::Value> toV8NoInline(TestInterfaceConstructor* impl, v8::Handle<v8 ::Object> creationContext, v8::Isolate* isolate)
221 { 226 {
222 return toV8(impl, creationContext, isolate); 227 return toV8(impl, creationContext, isolate);
223 } 228 }
224 229
225 } // namespace WebCore 230 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698