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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 // FIXME: HTML5 specification says this should be a HTMLCollection. | 55 // FIXME: HTML5 specification says this should be a HTMLCollection. |
56 // http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-in terfaces.html#htmlallcollection | 56 // http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-in terfaces.html#htmlallcollection |
57 return toV8(NamedNodesCollection::create(namedItems), callbackInfo.Holder(), callbackInfo.GetIsolate()); | 57 return toV8(NamedNodesCollection::create(namedItems), callbackInfo.Holder(), callbackInfo.GetIsolate()); |
58 } | 58 } |
59 | 59 |
60 template<class CallbackInfo> | 60 template<class CallbackInfo> |
61 static v8::Handle<v8::Value> getItem(HTMLAllCollection* collection, v8::Handle<v 8::Value> argument, const CallbackInfo& callbackInfo) | 61 static v8::Handle<v8::Value> getItem(HTMLAllCollection* collection, v8::Handle<v 8::Value> argument, const CallbackInfo& callbackInfo) |
62 { | 62 { |
63 v8::Local<v8::Uint32> index = argument->ToArrayIndex(); | 63 v8::Local<v8::Uint32> index = argument->ToArrayIndex(); |
64 if (index.IsEmpty()) { | 64 if (index.IsEmpty()) { |
65 v8::Handle<v8::Value> result = getNamedItems(collection, toWebCoreString (argument->ToString()), callbackInfo); | 65 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, name, argumen t, v8::Undefined(callbackInfo.GetIsolate())); |
haraken
2013/09/12 17:33:52
Ditto.
| |
66 v8::Handle<v8::Value> result = getNamedItems(collection, name, callbackI nfo); | |
66 | 67 |
67 if (result.IsEmpty()) | 68 if (result.IsEmpty()) |
68 return v8::Undefined(); | 69 return v8::Undefined(); |
69 | 70 |
70 return result; | 71 return result; |
71 } | 72 } |
72 | 73 |
73 RefPtr<Node> result = collection->item(index->Uint32Value()); | 74 RefPtr<Node> result = collection->item(index->Uint32Value()); |
74 return toV8(result.release(), callbackInfo.Holder(), callbackInfo.GetIsolate ()); | 75 return toV8(result.release(), callbackInfo.Holder(), callbackInfo.GetIsolate ()); |
75 } | 76 } |
76 | 77 |
77 void V8HTMLAllCollection::itemMethodCustom(const v8::FunctionCallbackInfo<v8::Va lue>& args) | 78 void V8HTMLAllCollection::itemMethodCustom(const v8::FunctionCallbackInfo<v8::Va lue>& args) |
78 { | 79 { |
79 HTMLAllCollection* imp = V8HTMLAllCollection::toNative(args.Holder()); | 80 HTMLAllCollection* imp = V8HTMLAllCollection::toNative(args.Holder()); |
80 v8SetReturnValue(args, getItem(imp, args[0], args)); | 81 v8SetReturnValue(args, getItem(imp, args[0], args)); |
81 } | 82 } |
82 | 83 |
83 void V8HTMLAllCollection::namedItemMethodCustom(const v8::FunctionCallbackInfo<v 8::Value>& args) | 84 void V8HTMLAllCollection::namedItemMethodCustom(const v8::FunctionCallbackInfo<v 8::Value>& args) |
84 { | 85 { |
86 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, name, args[0]); | |
87 | |
85 HTMLAllCollection* imp = V8HTMLAllCollection::toNative(args.Holder()); | 88 HTMLAllCollection* imp = V8HTMLAllCollection::toNative(args.Holder()); |
86 v8::Handle<v8::Value> result = getNamedItems(imp, toWebCoreString(args[0]), args); | 89 v8::Handle<v8::Value> result = getNamedItems(imp, name, args); |
87 | 90 |
88 if (result.IsEmpty()) { | 91 if (result.IsEmpty()) { |
89 v8SetReturnValueNull(args); | 92 v8SetReturnValueNull(args); |
90 return; | 93 return; |
91 } | 94 } |
92 | 95 |
93 v8SetReturnValue(args, result); | 96 v8SetReturnValue(args, result); |
94 } | 97 } |
95 | 98 |
96 void V8HTMLAllCollection::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Va lue>& args) | 99 void V8HTMLAllCollection::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Va lue>& args) |
97 { | 100 { |
98 if (args.Length() < 1) | 101 if (args.Length() < 1) |
99 return; | 102 return; |
100 | 103 |
101 HTMLAllCollection* imp = V8HTMLAllCollection::toNative(args.Holder()); | 104 HTMLAllCollection* imp = V8HTMLAllCollection::toNative(args.Holder()); |
102 | 105 |
103 if (args.Length() == 1) { | 106 if (args.Length() == 1) { |
104 v8SetReturnValue(args, getItem(imp, args[0], args)); | 107 v8SetReturnValue(args, getItem(imp, args[0], args)); |
105 return; | 108 return; |
106 } | 109 } |
107 | 110 |
108 // If there is a second argument it is the index of the item we want. | 111 // If there is a second argument it is the index of the item we want. |
109 String name = toWebCoreString(args[0]); | 112 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, name, args[0]); |
110 v8::Local<v8::Uint32> index = args[1]->ToArrayIndex(); | 113 v8::Local<v8::Uint32> index = args[1]->ToArrayIndex(); |
111 if (index.IsEmpty()) | 114 if (index.IsEmpty()) |
112 return; | 115 return; |
113 | 116 |
114 if (Node* node = imp->namedItemWithIndex(name, index->Uint32Value())) { | 117 if (Node* node = imp->namedItemWithIndex(name, index->Uint32Value())) { |
115 v8SetReturnValueFast(args, node, imp); | 118 v8SetReturnValueFast(args, node, imp); |
116 return; | 119 return; |
117 } | 120 } |
118 } | 121 } |
119 | 122 |
120 } // namespace WebCore | 123 } // namespace WebCore |
OLD | NEW |