| OLD | NEW |
| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 { | 63 { |
| 64 ASSERT(m_context == v8::Isolate::GetCurrent()->GetCurrentContext()); | 64 ASSERT(m_context == v8::Isolate::GetCurrent()->GetCurrentContext()); |
| 65 } | 65 } |
| 66 | 66 |
| 67 bool CustomElementConstructorBuilder::isFeatureAllowed() const | 67 bool CustomElementConstructorBuilder::isFeatureAllowed() const |
| 68 { | 68 { |
| 69 // Check that we are in the main world | 69 // Check that we are in the main world |
| 70 return !DOMWrapperWorld::isolatedWorld(m_context); | 70 return !DOMWrapperWorld::isolatedWorld(m_context); |
| 71 } | 71 } |
| 72 | 72 |
| 73 bool CustomElementConstructorBuilder::validateOptions(const AtomicString& type,
QualifiedName& tagName, ExceptionState& es) | 73 bool CustomElementConstructorBuilder::validateOptions(const AtomicString& type,
QualifiedName& tagName, ExceptionState& exceptionState) |
| 74 { | 74 { |
| 75 ASSERT(m_prototype.IsEmpty()); | 75 ASSERT(m_prototype.IsEmpty()); |
| 76 | 76 |
| 77 ScriptValue prototypeScriptValue; | 77 ScriptValue prototypeScriptValue; |
| 78 if (m_options->get("prototype", prototypeScriptValue) && !prototypeScriptVal
ue.isNull()) { | 78 if (m_options->get("prototype", prototypeScriptValue) && !prototypeScriptVal
ue.isNull()) { |
| 79 m_prototype = prototypeScriptValue.v8Value().As<v8::Object>(); | 79 m_prototype = prototypeScriptValue.v8Value().As<v8::Object>(); |
| 80 if (m_prototype.IsEmpty()) { | 80 if (m_prototype.IsEmpty()) { |
| 81 CustomElementException::throwException(CustomElementException::Proto
typeNotAnObject, type, es); | 81 CustomElementException::throwException(CustomElementException::Proto
typeNotAnObject, type, exceptionState); |
| 82 return false; | 82 return false; |
| 83 } | 83 } |
| 84 } else { | 84 } else { |
| 85 m_prototype = v8::Object::New(); | 85 m_prototype = v8::Object::New(); |
| 86 v8::Local<v8::Object> basePrototype = V8PerContextData::from(m_context)-
>prototypeForType(&V8HTMLElement::wrapperTypeInfo); | 86 v8::Local<v8::Object> basePrototype = V8PerContextData::from(m_context)-
>prototypeForType(&V8HTMLElement::wrapperTypeInfo); |
| 87 if (!basePrototype.IsEmpty()) | 87 if (!basePrototype.IsEmpty()) |
| 88 m_prototype->SetPrototype(basePrototype); | 88 m_prototype->SetPrototype(basePrototype); |
| 89 } | 89 } |
| 90 | 90 |
| 91 String extends; | 91 String extends; |
| 92 bool extendsProvidedAndNonNull = m_options->get("extends", extends); | 92 bool extendsProvidedAndNonNull = m_options->get("extends", extends); |
| 93 | 93 |
| 94 if (!V8PerContextData::from(m_context)) { | 94 if (!V8PerContextData::from(m_context)) { |
| 95 // FIXME: This should generate an InvalidContext exception at a later po
int. | 95 // FIXME: This should generate an InvalidContext exception at a later po
int. |
| 96 CustomElementException::throwException(CustomElementException::ContextDe
stroyedCheckingPrototype, type, es); | 96 CustomElementException::throwException(CustomElementException::ContextDe
stroyedCheckingPrototype, type, exceptionState); |
| 97 return false; | 97 return false; |
| 98 } | 98 } |
| 99 | 99 |
| 100 AtomicString namespaceURI = HTMLNames::xhtmlNamespaceURI; | 100 AtomicString namespaceURI = HTMLNames::xhtmlNamespaceURI; |
| 101 if (hasValidPrototypeChainFor(&V8SVGElement::wrapperTypeInfo)) | 101 if (hasValidPrototypeChainFor(&V8SVGElement::wrapperTypeInfo)) |
| 102 namespaceURI = SVGNames::svgNamespaceURI; | 102 namespaceURI = SVGNames::svgNamespaceURI; |
| 103 | 103 |
| 104 AtomicString localName; | 104 AtomicString localName; |
| 105 | 105 |
| 106 if (extendsProvidedAndNonNull) { | 106 if (extendsProvidedAndNonNull) { |
| 107 localName = extends.lower(); | 107 localName = extends.lower(); |
| 108 | 108 |
| 109 if (!Document::isValidName(localName)) { | 109 if (!Document::isValidName(localName)) { |
| 110 CustomElementException::throwException(CustomElementException::Exten
dsIsInvalidName, type, es); | 110 CustomElementException::throwException(CustomElementException::Exten
dsIsInvalidName, type, exceptionState); |
| 111 return false; | 111 return false; |
| 112 } | 112 } |
| 113 if (CustomElement::isValidName(localName)) { | 113 if (CustomElement::isValidName(localName)) { |
| 114 CustomElementException::throwException(CustomElementException::Exten
dsIsCustomElementName, type, es); | 114 CustomElementException::throwException(CustomElementException::Exten
dsIsCustomElementName, type, exceptionState); |
| 115 return false; | 115 return false; |
| 116 } | 116 } |
| 117 } else { | 117 } else { |
| 118 localName = type; | 118 localName = type; |
| 119 } | 119 } |
| 120 | 120 |
| 121 if (!extendsProvidedAndNonNull) | 121 if (!extendsProvidedAndNonNull) |
| 122 m_wrapperType = &V8HTMLElement::wrapperTypeInfo; | 122 m_wrapperType = &V8HTMLElement::wrapperTypeInfo; |
| 123 else if (namespaceURI == HTMLNames::xhtmlNamespaceURI) | 123 else if (namespaceURI == HTMLNames::xhtmlNamespaceURI) |
| 124 m_wrapperType = findWrapperTypeForHTMLTagName(localName); | 124 m_wrapperType = findWrapperTypeForHTMLTagName(localName); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 150 } | 150 } |
| 151 | 151 |
| 152 v8::Handle<v8::Function> CustomElementConstructorBuilder::retrieveCallback(v8::I
solate* isolate, const char* name) | 152 v8::Handle<v8::Function> CustomElementConstructorBuilder::retrieveCallback(v8::I
solate* isolate, const char* name) |
| 153 { | 153 { |
| 154 v8::Handle<v8::Value> value = m_prototype->Get(v8String(name, isolate)); | 154 v8::Handle<v8::Value> value = m_prototype->Get(v8String(name, isolate)); |
| 155 if (value.IsEmpty() || !value->IsFunction()) | 155 if (value.IsEmpty() || !value->IsFunction()) |
| 156 return v8::Handle<v8::Function>(); | 156 return v8::Handle<v8::Function>(); |
| 157 return value.As<v8::Function>(); | 157 return value.As<v8::Function>(); |
| 158 } | 158 } |
| 159 | 159 |
| 160 bool CustomElementConstructorBuilder::createConstructor(Document* document, Cust
omElementDefinition* definition, ExceptionState& es) | 160 bool CustomElementConstructorBuilder::createConstructor(Document* document, Cust
omElementDefinition* definition, ExceptionState& exceptionState) |
| 161 { | 161 { |
| 162 ASSERT(!m_prototype.IsEmpty()); | 162 ASSERT(!m_prototype.IsEmpty()); |
| 163 ASSERT(m_constructor.IsEmpty()); | 163 ASSERT(m_constructor.IsEmpty()); |
| 164 ASSERT(document); | 164 ASSERT(document); |
| 165 | 165 |
| 166 v8::Isolate* isolate = m_context->GetIsolate(); | 166 v8::Isolate* isolate = m_context->GetIsolate(); |
| 167 | 167 |
| 168 if (!prototypeIsValid(definition->descriptor().type(), es)) | 168 if (!prototypeIsValid(definition->descriptor().type(), exceptionState)) |
| 169 return false; | 169 return false; |
| 170 | 170 |
| 171 v8::Local<v8::FunctionTemplate> constructorTemplate = v8::FunctionTemplate::
New(); | 171 v8::Local<v8::FunctionTemplate> constructorTemplate = v8::FunctionTemplate::
New(); |
| 172 constructorTemplate->SetCallHandler(constructCustomElement); | 172 constructorTemplate->SetCallHandler(constructCustomElement); |
| 173 m_constructor = constructorTemplate->GetFunction(); | 173 m_constructor = constructorTemplate->GetFunction(); |
| 174 if (m_constructor.IsEmpty()) { | 174 if (m_constructor.IsEmpty()) { |
| 175 CustomElementException::throwException(CustomElementException::ContextDe
stroyedRegisteringDefinition, definition->descriptor().type(), es); | 175 CustomElementException::throwException(CustomElementException::ContextDe
stroyedRegisteringDefinition, definition->descriptor().type(), exceptionState); |
| 176 return false; | 176 return false; |
| 177 } | 177 } |
| 178 | 178 |
| 179 const CustomElementDescriptor& descriptor = definition->descriptor(); | 179 const CustomElementDescriptor& descriptor = definition->descriptor(); |
| 180 | 180 |
| 181 v8::Handle<v8::String> v8TagName = v8String(descriptor.localName(), isolate)
; | 181 v8::Handle<v8::String> v8TagName = v8String(descriptor.localName(), isolate)
; |
| 182 v8::Handle<v8::Value> v8Type; | 182 v8::Handle<v8::Value> v8Type; |
| 183 if (descriptor.isTypeExtension()) | 183 if (descriptor.isTypeExtension()) |
| 184 v8Type = v8String(descriptor.type(), isolate); | 184 v8Type = v8String(descriptor.type(), isolate); |
| 185 else | 185 else |
| (...skipping 16 matching lines...) Expand all Loading... |
| 202 // "prototype" does not affect the value, but can reconfigure the | 202 // "prototype" does not affect the value, but can reconfigure the |
| 203 // property. | 203 // property. |
| 204 m_constructor->ForceSet(prototypeKey, m_prototype, v8::PropertyAttribute(v8:
:ReadOnly | v8::DontEnum | v8::DontDelete)); | 204 m_constructor->ForceSet(prototypeKey, m_prototype, v8::PropertyAttribute(v8:
:ReadOnly | v8::DontEnum | v8::DontDelete)); |
| 205 | 205 |
| 206 V8HiddenPropertyName::setNamedHiddenReference(m_prototype, "customElementIsI
nterfacePrototypeObject", v8::True(isolate)); | 206 V8HiddenPropertyName::setNamedHiddenReference(m_prototype, "customElementIsI
nterfacePrototypeObject", v8::True(isolate)); |
| 207 m_prototype->ForceSet(v8String("constructor", isolate), m_constructor, v8::D
ontEnum); | 207 m_prototype->ForceSet(v8String("constructor", isolate), m_constructor, v8::D
ontEnum); |
| 208 | 208 |
| 209 return true; | 209 return true; |
| 210 } | 210 } |
| 211 | 211 |
| 212 bool CustomElementConstructorBuilder::prototypeIsValid(const AtomicString& type,
ExceptionState& es) const | 212 bool CustomElementConstructorBuilder::prototypeIsValid(const AtomicString& type,
ExceptionState& exceptionState) const |
| 213 { | 213 { |
| 214 if (m_prototype->InternalFieldCount() || !m_prototype->GetHiddenValue(V8Hidd
enPropertyName::customElementIsInterfacePrototypeObject(m_context->GetIsolate())
).IsEmpty()) { | 214 if (m_prototype->InternalFieldCount() || !m_prototype->GetHiddenValue(V8Hidd
enPropertyName::customElementIsInterfacePrototypeObject(m_context->GetIsolate())
).IsEmpty()) { |
| 215 CustomElementException::throwException(CustomElementException::Prototype
InUse, type, es); | 215 CustomElementException::throwException(CustomElementException::Prototype
InUse, type, exceptionState); |
| 216 return false; | 216 return false; |
| 217 } | 217 } |
| 218 | 218 |
| 219 if (m_prototype->GetPropertyAttributes(v8String("constructor", m_context->Ge
tIsolate())) & v8::DontDelete) { | 219 if (m_prototype->GetPropertyAttributes(v8String("constructor", m_context->Ge
tIsolate())) & v8::DontDelete) { |
| 220 CustomElementException::throwException(CustomElementException::Construct
orPropertyNotConfigurable, type, es); | 220 CustomElementException::throwException(CustomElementException::Construct
orPropertyNotConfigurable, type, exceptionState); |
| 221 return false; | 221 return false; |
| 222 } | 222 } |
| 223 | 223 |
| 224 return true; | 224 return true; |
| 225 } | 225 } |
| 226 | 226 |
| 227 bool CustomElementConstructorBuilder::didRegisterDefinition(CustomElementDefinit
ion* definition) const | 227 bool CustomElementConstructorBuilder::didRegisterDefinition(CustomElementDefinit
ion* definition) const |
| 228 { | 228 { |
| 229 ASSERT(!m_constructor.IsEmpty()); | 229 ASSERT(!m_constructor.IsEmpty()); |
| 230 | 230 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 throwUninformativeAndGenericTypeError(isolate); | 265 throwUninformativeAndGenericTypeError(isolate); |
| 266 return; | 266 return; |
| 267 } | 267 } |
| 268 | 268 |
| 269 Document* document = V8Document::toNative(info.Callee()->GetHiddenValue(V8Hi
ddenPropertyName::customElementDocument(isolate)).As<v8::Object>()); | 269 Document* document = V8Document::toNative(info.Callee()->GetHiddenValue(V8Hi
ddenPropertyName::customElementDocument(isolate)).As<v8::Object>()); |
| 270 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, namespaceURI, info.
Callee()->GetHiddenValue(V8HiddenPropertyName::customElementNamespaceURI(isolate
))); | 270 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, namespaceURI, info.
Callee()->GetHiddenValue(V8HiddenPropertyName::customElementNamespaceURI(isolate
))); |
| 271 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, tagName, info.Calle
e()->GetHiddenValue(V8HiddenPropertyName::customElementTagName(isolate))); | 271 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, tagName, info.Calle
e()->GetHiddenValue(V8HiddenPropertyName::customElementTagName(isolate))); |
| 272 v8::Handle<v8::Value> maybeType = info.Callee()->GetHiddenValue(V8HiddenProp
ertyName::customElementType(isolate)); | 272 v8::Handle<v8::Value> maybeType = info.Callee()->GetHiddenValue(V8HiddenProp
ertyName::customElementType(isolate)); |
| 273 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, type, maybeType); | 273 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, type, maybeType); |
| 274 | 274 |
| 275 ExceptionState es(info.GetIsolate()); | 275 ExceptionState exceptionState(info.GetIsolate()); |
| 276 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; | 276 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; |
| 277 RefPtr<Element> element = document->createElementNS(namespaceURI, tagName, m
aybeType->IsNull() ? nullAtom : type, es); | 277 RefPtr<Element> element = document->createElementNS(namespaceURI, tagName, m
aybeType->IsNull() ? nullAtom : type, exceptionState); |
| 278 if (es.throwIfNeeded()) | 278 if (exceptionState.throwIfNeeded()) |
| 279 return; | 279 return; |
| 280 v8SetReturnValueFast(info, element.release(), document); | 280 v8SetReturnValueFast(info, element.release(), document); |
| 281 } | 281 } |
| 282 | 282 |
| 283 } // namespace WebCore | 283 } // namespace WebCore |
| OLD | NEW |