| 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 25 matching lines...) Expand all Loading... |
| 36 #include "V8Document.h" | 36 #include "V8Document.h" |
| 37 #include "V8HTMLElementWrapperFactory.h" | 37 #include "V8HTMLElementWrapperFactory.h" |
| 38 #include "V8SVGElementWrapperFactory.h" | 38 #include "V8SVGElementWrapperFactory.h" |
| 39 #include "bindings/v8/CustomElementBinding.h" | 39 #include "bindings/v8/CustomElementBinding.h" |
| 40 #include "bindings/v8/DOMWrapperWorld.h" | 40 #include "bindings/v8/DOMWrapperWorld.h" |
| 41 #include "bindings/v8/Dictionary.h" | 41 #include "bindings/v8/Dictionary.h" |
| 42 #include "bindings/v8/ExceptionState.h" | 42 #include "bindings/v8/ExceptionState.h" |
| 43 #include "bindings/v8/ScriptState.h" | 43 #include "bindings/v8/ScriptState.h" |
| 44 #include "bindings/v8/UnsafePersistent.h" | 44 #include "bindings/v8/UnsafePersistent.h" |
| 45 #include "bindings/v8/V8Binding.h" | 45 #include "bindings/v8/V8Binding.h" |
| 46 #include "bindings/v8/V8HiddenPropertyName.h" | |
| 47 #include "bindings/v8/V8PerContextData.h" | 46 #include "bindings/v8/V8PerContextData.h" |
| 48 #include "core/dom/Document.h" | 47 #include "core/dom/Document.h" |
| 49 #include "core/dom/custom/CustomElementCallbackDispatcher.h" | 48 #include "core/dom/custom/CustomElementCallbackDispatcher.h" |
| 50 #include "core/dom/custom/CustomElementDefinition.h" | 49 #include "core/dom/custom/CustomElementDefinition.h" |
| 51 #include "core/dom/custom/CustomElementDescriptor.h" | 50 #include "core/dom/custom/CustomElementDescriptor.h" |
| 52 #include "core/dom/custom/CustomElementException.h" | 51 #include "core/dom/custom/CustomElementException.h" |
| 53 #include "wtf/Assertions.h" | 52 #include "wtf/Assertions.h" |
| 54 | 53 |
| 55 namespace WebCore { | 54 namespace WebCore { |
| 56 | 55 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 183 |
| 185 v8::Handle<v8::String> v8TagName = v8String(isolate, descriptor.localName())
; | 184 v8::Handle<v8::String> v8TagName = v8String(isolate, descriptor.localName())
; |
| 186 v8::Handle<v8::Value> v8Type; | 185 v8::Handle<v8::Value> v8Type; |
| 187 if (descriptor.isTypeExtension()) | 186 if (descriptor.isTypeExtension()) |
| 188 v8Type = v8String(isolate, descriptor.type()); | 187 v8Type = v8String(isolate, descriptor.type()); |
| 189 else | 188 else |
| 190 v8Type = v8::Null(isolate); | 189 v8Type = v8::Null(isolate); |
| 191 | 190 |
| 192 m_constructor->SetName(v8Type->IsNull() ? v8TagName : v8Type.As<v8::String>(
)); | 191 m_constructor->SetName(v8Type->IsNull() ? v8TagName : v8Type.As<v8::String>(
)); |
| 193 | 192 |
| 194 V8HiddenPropertyName::setNamedHiddenReference(m_constructor, "customElementD
ocument", toV8(document, m_context->Global(), isolate)); | 193 setHiddenValue(m_constructor, v8AtomicString(isolate, "customElementDocument
"), toV8(document, m_context->Global(), isolate)); |
| 195 V8HiddenPropertyName::setNamedHiddenReference(m_constructor, "customElementN
amespaceURI", v8String(isolate, descriptor.namespaceURI())); | 194 setHiddenValue(m_constructor, v8AtomicString(isolate, "customElementNamespac
eURI"), v8String(isolate, descriptor.namespaceURI())); |
| 196 V8HiddenPropertyName::setNamedHiddenReference(m_constructor, "customElementT
agName", v8TagName); | 195 setHiddenValue(m_constructor, v8AtomicString(isolate, "customElementTagName"
), v8TagName); |
| 197 V8HiddenPropertyName::setNamedHiddenReference(m_constructor, "customElementT
ype", v8Type); | 196 setHiddenValue(m_constructor, v8AtomicString(isolate, "customElementType"),
v8Type); |
| 198 | 197 |
| 199 v8::Handle<v8::String> prototypeKey = v8String(isolate, "prototype"); | 198 v8::Handle<v8::String> prototypeKey = v8String(isolate, "prototype"); |
| 200 ASSERT(m_constructor->HasOwnProperty(prototypeKey)); | 199 ASSERT(m_constructor->HasOwnProperty(prototypeKey)); |
| 201 // This sets the property *value*; calling Set is safe because | 200 // This sets the property *value*; calling Set is safe because |
| 202 // "prototype" is a non-configurable data property so there can be | 201 // "prototype" is a non-configurable data property so there can be |
| 203 // no side effects. | 202 // no side effects. |
| 204 m_constructor->Set(prototypeKey, m_prototype); | 203 m_constructor->Set(prototypeKey, m_prototype); |
| 205 // This *configures* the property. ForceSet of a function's | 204 // This *configures* the property. ForceSet of a function's |
| 206 // "prototype" does not affect the value, but can reconfigure the | 205 // "prototype" does not affect the value, but can reconfigure the |
| 207 // property. | 206 // property. |
| 208 m_constructor->ForceSet(prototypeKey, m_prototype, v8::PropertyAttribute(v8:
:ReadOnly | v8::DontEnum | v8::DontDelete)); | 207 m_constructor->ForceSet(prototypeKey, m_prototype, v8::PropertyAttribute(v8:
:ReadOnly | v8::DontEnum | v8::DontDelete)); |
| 209 | 208 |
| 210 V8HiddenPropertyName::setNamedHiddenReference(m_prototype, "customElementIsI
nterfacePrototypeObject", v8::True(isolate)); | 209 setHiddenValue(m_prototype, v8AtomicString(isolate, "customElementIsInterfac
ePrototypeObject"), v8::True(isolate)); |
| 211 m_prototype->ForceSet(v8String(isolate, "constructor"), m_constructor, v8::D
ontEnum); | 210 m_prototype->ForceSet(v8String(isolate, "constructor"), m_constructor, v8::D
ontEnum); |
| 212 | 211 |
| 213 return true; | 212 return true; |
| 214 } | 213 } |
| 215 | 214 |
| 216 bool CustomElementConstructorBuilder::prototypeIsValid(const AtomicString& type,
ExceptionState& exceptionState) const | 215 bool CustomElementConstructorBuilder::prototypeIsValid(const AtomicString& type,
ExceptionState& exceptionState) const |
| 217 { | 216 { |
| 218 if (m_prototype->InternalFieldCount() || !m_prototype->GetHiddenValue(V8Hidd
enPropertyName::customElementIsInterfacePrototypeObject(m_context->GetIsolate())
).IsEmpty()) { | 217 if (m_prototype->InternalFieldCount() || !getHiddenValue(m_prototype, v8Atom
icString(m_context->GetIsolate(), "customElementIsInterfacePrototypeObject")).Is
Empty()) { |
| 219 CustomElementException::throwException(CustomElementException::Prototype
InUse, type, exceptionState); | 218 CustomElementException::throwException(CustomElementException::Prototype
InUse, type, exceptionState); |
| 220 return false; | 219 return false; |
| 221 } | 220 } |
| 222 | 221 |
| 223 if (m_prototype->GetPropertyAttributes(v8String(m_context->GetIsolate(), "co
nstructor")) & v8::DontDelete) { | 222 if (m_prototype->GetPropertyAttributes(v8String(m_context->GetIsolate(), "co
nstructor")) & v8::DontDelete) { |
| 224 CustomElementException::throwException(CustomElementException::Construct
orPropertyNotConfigurable, type, exceptionState); | 223 CustomElementException::throwException(CustomElementException::Construct
orPropertyNotConfigurable, type, exceptionState); |
| 225 return false; | 224 return false; |
| 226 } | 225 } |
| 227 | 226 |
| 228 return true; | 227 return true; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 if (!info.IsConstructCall()) { | 262 if (!info.IsConstructCall()) { |
| 264 throwTypeError("DOM object constructor cannot be called as a function.",
isolate); | 263 throwTypeError("DOM object constructor cannot be called as a function.",
isolate); |
| 265 return; | 264 return; |
| 266 } | 265 } |
| 267 | 266 |
| 268 if (info.Length() > 0) { | 267 if (info.Length() > 0) { |
| 269 throwTypeError("This constructor should be called without arguments.", i
solate); | 268 throwTypeError("This constructor should be called without arguments.", i
solate); |
| 270 return; | 269 return; |
| 271 } | 270 } |
| 272 | 271 |
| 273 Document* document = V8Document::toNative(info.Callee()->GetHiddenValue(V8Hi
ddenPropertyName::customElementDocument(isolate)).As<v8::Object>()); | 272 Document* document = V8Document::toNative(getHiddenValue(info.Callee(), v8At
omicString(isolate, "customElementDocument")).As<v8::Object>()); |
| 274 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, namespaceURI, info.
Callee()->GetHiddenValue(V8HiddenPropertyName::customElementNamespaceURI(isolate
))); | 273 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, namespaceURI, getHi
ddenValue(info.Callee(), v8AtomicString(isolate, "customElementNamespaceURI"))); |
| 275 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, tagName, info.Calle
e()->GetHiddenValue(V8HiddenPropertyName::customElementTagName(isolate))); | 274 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, tagName, getHiddenV
alue(info.Callee(), v8AtomicString(isolate, "customElementTagName"))); |
| 276 v8::Handle<v8::Value> maybeType = info.Callee()->GetHiddenValue(V8HiddenProp
ertyName::customElementType(isolate)); | 275 v8::Handle<v8::Value> maybeType = getHiddenValue(info.Callee(), v8AtomicStri
ng(isolate, "customElementType")); |
| 277 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, type, maybeType); | 276 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, type, maybeType); |
| 278 | 277 |
| 279 ExceptionState exceptionState(ExceptionState::ConstructionContext, "CustomEl
ement", info.Holder(), info.GetIsolate()); | 278 ExceptionState exceptionState(ExceptionState::ConstructionContext, "CustomEl
ement", info.Holder(), info.GetIsolate()); |
| 280 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; | 279 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; |
| 281 RefPtr<Element> element = document->createElementNS(namespaceURI, tagName, m
aybeType->IsNull() ? nullAtom : type, exceptionState); | 280 RefPtr<Element> element = document->createElementNS(namespaceURI, tagName, m
aybeType->IsNull() ? nullAtom : type, exceptionState); |
| 282 if (exceptionState.throwIfNeeded()) | 281 if (exceptionState.throwIfNeeded()) |
| 283 return; | 282 return; |
| 284 v8SetReturnValueFast(info, element.release(), document); | 283 v8SetReturnValueFast(info, element.release(), document); |
| 285 } | 284 } |
| 286 | 285 |
| 287 } // namespace WebCore | 286 } // namespace WebCore |
| OLD | NEW |