| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2009, 2010 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 27 matching lines...) Expand all Loading... |
| 38 #include "HTMLNames.h" | 38 #include "HTMLNames.h" |
| 39 #include "V8Binding.h" | 39 #include "V8Binding.h" |
| 40 #include "V8Document.h" | 40 #include "V8Document.h" |
| 41 #include "V8HTMLImageElement.h" | 41 #include "V8HTMLImageElement.h" |
| 42 #include <wtf/RefPtr.h> | 42 #include <wtf/RefPtr.h> |
| 43 | 43 |
| 44 namespace WebCore { | 44 namespace WebCore { |
| 45 | 45 |
| 46 WrapperTypeInfo V8HTMLImageElementConstructor::info = { V8HTMLImageElementConstr
uctor::GetTemplate, V8HTMLImageElement::derefObject, 0, V8HTMLImageElement::toEv
entTarget, 0, V8HTMLImageElement::installPerContextPrototypeProperties, 0, Wrapp
erTypeObjectPrototype }; | 46 WrapperTypeInfo V8HTMLImageElementConstructor::info = { V8HTMLImageElementConstr
uctor::GetTemplate, V8HTMLImageElement::derefObject, 0, V8HTMLImageElement::toEv
entTarget, 0, V8HTMLImageElement::installPerContextPrototypeProperties, 0, Wrapp
erTypeObjectPrototype }; |
| 47 | 47 |
| 48 static v8::Handle<v8::Value> namedConstructor(const v8::Arguments& args) | 48 static v8::Handle<v8::Value> v8HTMLImageElementConstructorMethodCustom(const v8:
:Arguments& args) |
| 49 { | 49 { |
| 50 if (!args.IsConstructCall()) | 50 if (!args.IsConstructCall()) |
| 51 return throwTypeError("DOM object constructor cannot be called as a func
tion.", args.GetIsolate()); | 51 return throwTypeError("DOM object constructor cannot be called as a func
tion.", args.GetIsolate()); |
| 52 | 52 |
| 53 if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) | 53 if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) |
| 54 return args.Holder(); | 54 return args.Holder(); |
| 55 | 55 |
| 56 Document* document = currentDocument(BindingState::instance()); | 56 Document* document = currentDocument(BindingState::instance()); |
| 57 | 57 |
| 58 // Make sure the document is added to the DOM Node map. Otherwise, the HTMLI
mageElement instance | 58 // Make sure the document is added to the DOM Node map. Otherwise, the HTMLI
mageElement instance |
| (...skipping 15 matching lines...) Expand all Loading... |
| 74 height = toInt32(args[1]); | 74 height = toInt32(args[1]); |
| 75 optionalHeight = &height; | 75 optionalHeight = &height; |
| 76 } | 76 } |
| 77 | 77 |
| 78 RefPtr<HTMLImageElement> image = HTMLImageElement::createForJSConstructor(do
cument, optionalWidth, optionalHeight); | 78 RefPtr<HTMLImageElement> image = HTMLImageElement::createForJSConstructor(do
cument, optionalWidth, optionalHeight); |
| 79 v8::Handle<v8::Object> wrapper = args.Holder(); | 79 v8::Handle<v8::Object> wrapper = args.Holder(); |
| 80 V8DOMWrapper::associateObjectWithWrapper(image.release(), &V8HTMLImageElemen
tConstructor::info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent)
; | 80 V8DOMWrapper::associateObjectWithWrapper(image.release(), &V8HTMLImageElemen
tConstructor::info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent)
; |
| 81 return wrapper; | 81 return wrapper; |
| 82 } | 82 } |
| 83 | 83 |
| 84 static v8::Handle<v8::Value> namedConstructorCallback(const v8::Arguments& args) | |
| 85 { | |
| 86 return namedConstructor(args); | |
| 87 } | |
| 88 | |
| 89 v8::Persistent<v8::FunctionTemplate> V8HTMLImageElementConstructor::GetTemplate(
v8::Isolate* isolate) | 84 v8::Persistent<v8::FunctionTemplate> V8HTMLImageElementConstructor::GetTemplate(
v8::Isolate* isolate) |
| 90 { | 85 { |
| 91 static v8::Persistent<v8::FunctionTemplate> cachedTemplate; | 86 static v8::Persistent<v8::FunctionTemplate> cachedTemplate; |
| 92 if (!cachedTemplate.IsEmpty()) | 87 if (!cachedTemplate.IsEmpty()) |
| 93 return cachedTemplate; | 88 return cachedTemplate; |
| 94 | 89 |
| 95 v8::HandleScope scope; | 90 v8::HandleScope scope; |
| 96 v8::Local<v8::FunctionTemplate> result = v8::FunctionTemplate::New(namedCons
tructorCallback); | 91 v8::Local<v8::FunctionTemplate> result = v8::FunctionTemplate::New(v8HTMLIma
geElementConstructorMethodCustom); |
| 97 | 92 |
| 98 v8::Local<v8::ObjectTemplate> instance = result->InstanceTemplate(); | 93 v8::Local<v8::ObjectTemplate> instance = result->InstanceTemplate(); |
| 99 instance->SetInternalFieldCount(V8HTMLImageElement::internalFieldCount); | 94 instance->SetInternalFieldCount(V8HTMLImageElement::internalFieldCount); |
| 100 result->SetClassName(v8::String::NewSymbol("HTMLImageElement")); | 95 result->SetClassName(v8::String::NewSymbol("HTMLImageElement")); |
| 101 result->Inherit(V8HTMLImageElement::GetTemplate(isolate)); | 96 result->Inherit(V8HTMLImageElement::GetTemplate(isolate)); |
| 102 | 97 |
| 103 cachedTemplate = v8::Persistent<v8::FunctionTemplate>::New(isolate, result); | 98 cachedTemplate = v8::Persistent<v8::FunctionTemplate>::New(isolate, result); |
| 104 return cachedTemplate; | 99 return cachedTemplate; |
| 105 } | 100 } |
| 106 | 101 |
| 107 } // namespace WebCore | 102 } // namespace WebCore |
| OLD | NEW |