OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 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 "bindings/core/v8/V8HTMLOptionElement.h" | 36 #include "bindings/core/v8/V8HTMLOptionElement.h" |
37 #include "bindings/core/v8/V8Node.h" | 37 #include "bindings/core/v8/V8Node.h" |
38 #include "bindings/core/v8/V8NodeList.h" | 38 #include "bindings/core/v8/V8NodeList.h" |
39 #include "core/dom/ExceptionCode.h" | 39 #include "core/dom/ExceptionCode.h" |
40 #include "core/html/HTMLOptionElement.h" | 40 #include "core/html/HTMLOptionElement.h" |
41 #include "core/html/HTMLOptionsCollection.h" | 41 #include "core/html/HTMLOptionsCollection.h" |
42 #include "core/html/HTMLSelectElement.h" | 42 #include "core/html/HTMLSelectElement.h" |
43 | 43 |
44 namespace blink { | 44 namespace blink { |
45 | 45 |
46 void V8HTMLOptionsCollection::addMethodCustom(const v8::FunctionCallbackInfo<v8:
:Value>& info) | |
47 { | |
48 ExceptionState exceptionState(ExceptionState::ExecutionContext, "add", "HTML
OptionsCollection", info.Holder(), info.GetIsolate()); | |
49 if (!V8HTMLOptionElement::hasInstance(info[0], info.GetIsolate())) { | |
50 exceptionState.throwTypeError("The element provided was not an HTMLOptio
nElement."); | |
51 } else { | |
52 HTMLOptionsCollection* impl = V8HTMLOptionsCollection::toImpl(info.Holde
r()); | |
53 HTMLOptionElement* option = V8HTMLOptionElement::toImpl(v8::Handle<v8::O
bject>(v8::Handle<v8::Object>::Cast(info[0]))); | |
54 | |
55 if (info.Length() < 2) { | |
56 impl->add(option, exceptionState); | |
57 } else { | |
58 int index = toInt32(info[1], exceptionState); | |
59 if (exceptionState.throwIfNeeded()) | |
60 return; | |
61 | |
62 impl->add(option, index, exceptionState); | |
63 } | |
64 } | |
65 | |
66 exceptionState.throwIfNeeded(); | |
67 } | |
68 | |
69 void V8HTMLOptionsCollection::lengthAttributeSetterCustom(v8::Local<v8::Value> v
alue, const v8::PropertyCallbackInfo<void>& info) | 46 void V8HTMLOptionsCollection::lengthAttributeSetterCustom(v8::Local<v8::Value> v
alue, const v8::PropertyCallbackInfo<void>& info) |
70 { | 47 { |
71 HTMLOptionsCollection* impl = V8HTMLOptionsCollection::toImpl(info.Holder())
; | 48 HTMLOptionsCollection* impl = V8HTMLOptionsCollection::toImpl(info.Holder())
; |
72 double v = value->NumberValue(); | 49 double v = value->NumberValue(); |
73 unsigned newLength = 0; | 50 unsigned newLength = 0; |
74 ExceptionState exceptionState(ExceptionState::SetterContext, "length", "HTML
OptionsCollection", info.Holder(), info.GetIsolate()); | 51 ExceptionState exceptionState(ExceptionState::SetterContext, "length", "HTML
OptionsCollection", info.Holder(), info.GetIsolate()); |
75 if (!std::isnan(v) && !std::isinf(v)) { | 52 if (!std::isnan(v) && !std::isinf(v)) { |
76 if (v < 0.0) | 53 if (v < 0.0) |
77 exceptionState.throwDOMException(IndexSizeError, "The value provided
(" + String::number(v) + ") is negative. Lengths must be greater than or equal
to 0."); | 54 exceptionState.throwDOMException(IndexSizeError, "The value provided
(" + String::number(v) + ") is negative. Lengths must be greater than or equal
to 0."); |
78 else if (v > static_cast<double>(UINT_MAX)) | 55 else if (v > static_cast<double>(UINT_MAX)) |
79 newLength = UINT_MAX; | 56 newLength = UINT_MAX; |
80 else | 57 else |
81 newLength = static_cast<unsigned>(v); | 58 newLength = static_cast<unsigned>(v); |
82 } | 59 } |
83 | 60 |
84 if (exceptionState.throwIfNeeded()) | 61 if (exceptionState.throwIfNeeded()) |
85 return; | 62 return; |
86 | 63 |
87 impl->setLength(newLength, exceptionState); | 64 impl->setLength(newLength, exceptionState); |
88 } | 65 } |
89 | 66 |
90 } // namespace blink | 67 } // namespace blink |
OLD | NEW |