| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 throwTypeError("DOM object constructor cannot be called as a function.",
args.GetIsolate()); | 52 throwTypeError("DOM object constructor cannot be called as a function.",
args.GetIsolate()); |
| 53 return; | 53 return; |
| 54 } | 54 } |
| 55 | 55 |
| 56 if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) { | 56 if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) { |
| 57 v8SetReturnValue(args, args.Holder()); | 57 v8SetReturnValue(args, args.Holder()); |
| 58 return; | 58 return; |
| 59 } | 59 } |
| 60 | 60 |
| 61 Document* document = currentDocument(); | 61 Document* document = currentDocument(); |
| 62 ASSERT(document); |
| 62 | 63 |
| 63 // Make sure the document is added to the DOM Node map. Otherwise, the HTMLI
mageElement instance | 64 // Make sure the document is added to the DOM Node map. Otherwise, the HTMLI
mageElement instance |
| 64 // may end up being the only node in the map and get garbage-collected prema
turely. | 65 // may end up being the only node in the map and get garbage-collected prema
turely. |
| 65 // FIXME: The correct way to do this would be to make HTMLImageElement deriv
e from | 66 // FIXME: The correct way to do this would be to make HTMLImageElement deriv
e from |
| 66 // ActiveDOMObject and use its interface to keep its wrapper alive. Then we
would | 67 // ActiveDOMObject and use its interface to keep its wrapper alive. Then we
would |
| 67 // remove this code and the special case in isObservableThroughDOM. | 68 // remove this code and the special case in isObservableThroughDOM. |
| 68 toV8(document, args.Holder(), args.GetIsolate()); | 69 toV8(document, args.Holder(), args.GetIsolate()); |
| 69 | 70 |
| 70 int width; | 71 int width; |
| 71 int height; | 72 int height; |
| 72 int* optionalWidth = 0; | 73 int* optionalWidth = 0; |
| 73 int* optionalHeight = 0; | 74 int* optionalHeight = 0; |
| 74 if (args.Length() > 0) { | 75 if (args.Length() > 0) { |
| 75 width = toInt32(args[0]); | 76 width = toInt32(args[0]); |
| 76 optionalWidth = &width; | 77 optionalWidth = &width; |
| 77 } | 78 } |
| 78 if (args.Length() > 1) { | 79 if (args.Length() > 1) { |
| 79 height = toInt32(args[1]); | 80 height = toInt32(args[1]); |
| 80 optionalHeight = &height; | 81 optionalHeight = &height; |
| 81 } | 82 } |
| 82 | 83 |
| 83 RefPtr<HTMLImageElement> image = HTMLImageElement::createForJSConstructor(do
cument, optionalWidth, optionalHeight); | 84 RefPtr<HTMLImageElement> image = HTMLImageElement::createForJSConstructor(*d
ocument, optionalWidth, optionalHeight); |
| 84 v8::Handle<v8::Object> wrapper = args.Holder(); | 85 v8::Handle<v8::Object> wrapper = args.Holder(); |
| 85 V8DOMWrapper::associateObjectWithWrapper<V8HTMLImageElement>(image.release()
, &V8HTMLImageElementConstructor::info, wrapper, args.GetIsolate(), WrapperConfi
guration::Dependent); | 86 V8DOMWrapper::associateObjectWithWrapper<V8HTMLImageElement>(image.release()
, &V8HTMLImageElementConstructor::info, wrapper, args.GetIsolate(), WrapperConfi
guration::Dependent); |
| 86 v8SetReturnValue(args, wrapper); | 87 v8SetReturnValue(args, wrapper); |
| 87 } | 88 } |
| 88 | 89 |
| 89 v8::Handle<v8::FunctionTemplate> V8HTMLImageElementConstructor::GetTemplate(v8::
Isolate* isolate, WrapperWorldType currentWorldType) | 90 v8::Handle<v8::FunctionTemplate> V8HTMLImageElementConstructor::GetTemplate(v8::
Isolate* isolate, WrapperWorldType currentWorldType) |
| 90 { | 91 { |
| 91 // This is only for getting a unique pointer which we can pass to privateTem
plate. | 92 // This is only for getting a unique pointer which we can pass to privateTem
plate. |
| 92 static const char* privateTemplateUniqueKey = "V8HTMLImageElementConstructor
::GetTemplatePrivateTemplate"; | 93 static const char* privateTemplateUniqueKey = "V8HTMLImageElementConstructor
::GetTemplatePrivateTemplate"; |
| 93 V8PerIsolateData* data = V8PerIsolateData::from(isolate); | 94 V8PerIsolateData* data = V8PerIsolateData::from(isolate); |
| 94 v8::Handle<v8::FunctionTemplate> result = data->privateTemplateIfExists(curr
entWorldType, &privateTemplateUniqueKey); | 95 v8::Handle<v8::FunctionTemplate> result = data->privateTemplateIfExists(curr
entWorldType, &privateTemplateUniqueKey); |
| 95 if (!result.IsEmpty()) | 96 if (!result.IsEmpty()) |
| 96 return result; | 97 return result; |
| 97 | 98 |
| 98 v8::HandleScope scope(isolate); | 99 v8::HandleScope scope(isolate); |
| 99 result = v8::FunctionTemplate::New(v8HTMLImageElementConstructorMethodCustom
); | 100 result = v8::FunctionTemplate::New(v8HTMLImageElementConstructorMethodCustom
); |
| 100 | 101 |
| 101 v8::Local<v8::ObjectTemplate> instance = result->InstanceTemplate(); | 102 v8::Local<v8::ObjectTemplate> instance = result->InstanceTemplate(); |
| 102 instance->SetInternalFieldCount(V8HTMLImageElement::internalFieldCount); | 103 instance->SetInternalFieldCount(V8HTMLImageElement::internalFieldCount); |
| 103 result->SetClassName(v8::String::NewSymbol("HTMLImageElement")); | 104 result->SetClassName(v8::String::NewSymbol("HTMLImageElement")); |
| 104 result->Inherit(V8HTMLImageElement::GetTemplate(isolate, currentWorldType)); | 105 result->Inherit(V8HTMLImageElement::GetTemplate(isolate, currentWorldType)); |
| 105 | 106 |
| 106 data->setPrivateTemplate(currentWorldType, &privateTemplateUniqueKey, result
); | 107 data->setPrivateTemplate(currentWorldType, &privateTemplateUniqueKey, result
); |
| 107 return scope.Close(result); | 108 return scope.Close(result); |
| 108 } | 109 } |
| 109 | 110 |
| 110 } // namespace WebCore | 111 } // namespace WebCore |
| OLD | NEW |