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

Side by Side Diff: sky/engine/bindings/core/v8/CustomElementConstructorBuilder.cpp

Issue 814683002: Custom elements should have class side inheritance. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: better test name. Created 6 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 else 191 else
192 v8Type = v8::Null(isolate); 192 v8Type = v8::Null(isolate);
193 193
194 m_constructor->SetName(v8Type->IsNull() ? v8TagName : v8Type.As<v8::String>( )); 194 m_constructor->SetName(v8Type->IsNull() ? v8TagName : v8Type.As<v8::String>( ));
195 195
196 V8HiddenValue::setHiddenValue(isolate, m_constructor, V8HiddenValue::customE lementDocument(isolate), toV8(document, m_scriptState->context()->Global(), isol ate)); 196 V8HiddenValue::setHiddenValue(isolate, m_constructor, V8HiddenValue::customE lementDocument(isolate), toV8(document, m_scriptState->context()->Global(), isol ate));
197 V8HiddenValue::setHiddenValue(isolate, m_constructor, V8HiddenValue::customE lementTagName(isolate), v8TagName); 197 V8HiddenValue::setHiddenValue(isolate, m_constructor, V8HiddenValue::customE lementTagName(isolate), v8TagName);
198 V8HiddenValue::setHiddenValue(isolate, m_constructor, V8HiddenValue::customE lementType(isolate), v8Type); 198 V8HiddenValue::setHiddenValue(isolate, m_constructor, V8HiddenValue::customE lementType(isolate), v8Type);
199 199
200 v8::Handle<v8::String> prototypeKey = v8String(isolate, "prototype"); 200 v8::Handle<v8::String> prototypeKey = v8String(isolate, "prototype");
201 v8::Handle<v8::String> constructorKey = v8String(isolate, "constructor");
202
201 ASSERT(m_constructor->HasOwnProperty(prototypeKey)); 203 ASSERT(m_constructor->HasOwnProperty(prototypeKey));
202 // This sets the property *value*; calling Set is safe because 204 // This sets the property *value*; calling Set is safe because
203 // "prototype" is a non-configurable data property so there can be 205 // "prototype" is a non-configurable data property so there can be
204 // no side effects. 206 // no side effects.
205 m_constructor->Set(prototypeKey, m_prototype); 207 m_constructor->Set(prototypeKey, m_prototype);
206 // This *configures* the property. ForceSet of a function's 208 // This *configures* the property. ForceSet of a function's
207 // "prototype" does not affect the value, but can reconfigure the 209 // "prototype" does not affect the value, but can reconfigure the
208 // property. 210 // property.
209 m_constructor->ForceSet(prototypeKey, m_prototype, v8::PropertyAttribute(v8: :ReadOnly | v8::DontEnum | v8::DontDelete)); 211 m_constructor->ForceSet(prototypeKey, m_prototype, v8::PropertyAttribute(v8: :ReadOnly | v8::DontEnum | v8::DontDelete));
212 // The generated constructor should inherit from your constructor.
213 m_constructor->SetPrototype(m_prototype->Get(constructorKey));
210 214
211 V8HiddenValue::setHiddenValue(isolate, m_prototype, V8HiddenValue::customEle mentIsInterfacePrototypeObject(isolate), v8::True(isolate)); 215 V8HiddenValue::setHiddenValue(isolate, m_prototype, V8HiddenValue::customEle mentIsInterfacePrototypeObject(isolate), v8::True(isolate));
212 m_prototype->ForceSet(v8String(isolate, "constructor"), m_constructor, v8::D ontEnum); 216 m_prototype->ForceSet(constructorKey, m_constructor, v8::DontEnum);
213 217
214 return true; 218 return true;
215 } 219 }
216 220
217 bool CustomElementConstructorBuilder::prototypeIsValid(const AtomicString& type, ExceptionState& exceptionState) const 221 bool CustomElementConstructorBuilder::prototypeIsValid(const AtomicString& type, ExceptionState& exceptionState) const
218 { 222 {
219 if (m_prototype->InternalFieldCount() || !V8HiddenValue::getHiddenValue(m_sc riptState->isolate(), m_prototype, V8HiddenValue::customElementIsInterfaceProtot ypeObject(m_scriptState->isolate())).IsEmpty()) { 223 if (m_prototype->InternalFieldCount() || !V8HiddenValue::getHiddenValue(m_sc riptState->isolate(), m_prototype, V8HiddenValue::customElementIsInterfaceProtot ypeObject(m_scriptState->isolate())).IsEmpty()) {
220 CustomElementException::throwException(CustomElementException::Prototype InUse, type, exceptionState); 224 CustomElementException::throwException(CustomElementException::Prototype InUse, type, exceptionState);
221 return false; 225 return false;
222 } 226 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 282
279 ExceptionState exceptionState(ExceptionState::ConstructionContext, "CustomEl ement", info.Holder(), info.GetIsolate()); 283 ExceptionState exceptionState(ExceptionState::ConstructionContext, "CustomEl ement", info.Holder(), info.GetIsolate());
280 CustomElementProcessingStack::CallbackDeliveryScope deliveryScope; 284 CustomElementProcessingStack::CallbackDeliveryScope deliveryScope;
281 RefPtr<Element> element = document->createElement(tagName, maybeType->IsNull () ? nullAtom : type, exceptionState); 285 RefPtr<Element> element = document->createElement(tagName, maybeType->IsNull () ? nullAtom : type, exceptionState);
282 if (exceptionState.throwIfNeeded()) 286 if (exceptionState.throwIfNeeded())
283 return; 287 return;
284 v8SetReturnValueFast(info, element.release(), document); 288 v8SetReturnValueFast(info, element.release(), document);
285 } 289 }
286 290
287 } // namespace blink 291 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698