Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 "bindings/v8/V8Binding.h" | 38 #include "bindings/v8/V8Binding.h" |
| 39 #include "bindings/v8/V8DOMWrapper.h" | 39 #include "bindings/v8/V8DOMWrapper.h" |
| 40 #include "bindings/v8/V8HiddenPropertyName.h" | 40 #include "bindings/v8/V8HiddenPropertyName.h" |
| 41 #include "core/dom/ContextFeatures.h" | 41 #include "core/dom/ContextFeatures.h" |
| 42 #include "core/dom/ExceptionCode.h" | 42 #include "core/dom/ExceptionCode.h" |
| 43 #include "core/page/Frame.h" | 43 #include "core/page/Frame.h" |
| 44 #include "RuntimeEnabledFeatures.h" | 44 #include "RuntimeEnabledFeatures.h" |
| 45 | 45 |
| 46 namespace WebCore { | 46 namespace WebCore { |
| 47 | 47 |
| 48 void V8CustomEvent::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& args) | |
|
haraken
2013/06/22 13:16:46
We don't want to increase custom bindings, which a
jww
2013/06/25 01:50:29
Good idea. I'v generalized the constructor to take
| |
| 49 { | |
| 50 if (args.Length() < 1) { | |
| 51 throwNotEnoughArgumentsError(args.GetIsolate()); | |
| 52 return; | |
| 53 } | |
| 54 | |
| 55 String type = toWebCoreString(args[0]); | |
| 56 CustomEventInit eventInit; | |
| 57 | |
| 58 if (args.Length() >= 2) { | |
| 59 Dictionary options = Dictionary(args[1], args.GetIsolate()); | |
|
adamk
2013/06/22 01:00:04
This syntax looks odd to me, can you get rid of th
jww
2013/06/25 01:50:29
Done.
| |
| 60 if (!fillEventInit(eventInit, options)) | |
| 61 return; | |
| 62 v8::Local<v8::Value> detail; | |
| 63 options.getKey("detail", detail); | |
| 64 args.Holder()->SetHiddenValue(V8HiddenPropertyName::detail(), detail); | |
|
adamk
2013/06/22 01:00:04
Guard this with an if() check on the above? Or at
jww
2013/06/25 01:50:29
I wrapped the "SetHiddenValue" with an "if" check
| |
| 65 } | |
| 66 | |
| 67 RefPtr<CustomEvent> event = CustomEvent::create(type, eventInit); | |
| 68 | |
| 69 v8::Handle<v8::Object> wrapper = args.Holder(); | |
| 70 V8DOMWrapper::associateObjectWithWrapper(event.release(), &V8CustomEvent::in fo, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent); | |
| 71 args.GetReturnValue().Set(wrapper); | |
|
haraken
2013/06/22 13:16:46
Nit: You can use v8SetRuturnValue().
jww
2013/06/25 01:50:29
Done.
| |
| 72 } | |
| 73 | |
| 48 void V8CustomEvent::detailAttrGetterCustom(v8::Local<v8::String> name, const v8: :PropertyCallbackInfo<v8::Value>& info) | 74 void V8CustomEvent::detailAttrGetterCustom(v8::Local<v8::String> name, const v8: :PropertyCallbackInfo<v8::Value>& info) |
| 49 { | 75 { |
| 50 CustomEvent* imp = V8CustomEvent::toNative(info.Holder()); | 76 CustomEvent* imp = V8CustomEvent::toNative(info.Holder()); |
| 51 RefPtr<SerializedScriptValue> serialized = imp->serializedScriptValue(); | 77 RefPtr<SerializedScriptValue> serialized = imp->serializedScriptValue(); |
| 52 if (serialized) { | 78 if (serialized) { |
| 53 v8::Handle<v8::Value> value = info.Holder()->GetHiddenValue(V8HiddenProp ertyName::detail()); | 79 v8::Handle<v8::Value> value = info.Holder()->GetHiddenValue(V8HiddenProp ertyName::detail()); |
| 54 if (value.IsEmpty()) { | 80 if (value.IsEmpty()) { |
| 55 value = serialized->deserialize(); | 81 value = serialized->deserialize(); |
| 56 info.Holder()->SetHiddenValue(V8HiddenPropertyName::detail(), value) ; | 82 info.Holder()->SetHiddenValue(V8HiddenPropertyName::detail(), value) ; |
| 57 } | 83 } |
| 58 v8SetReturnValue(info, value); | 84 v8SetReturnValue(info, value); |
| 59 return; | 85 return; |
| 60 } | 86 } |
| 61 v8SetReturnValue(info, imp->detail().v8Value()); | 87 v8SetReturnValue(info, info.Holder()->GetHiddenValue(V8HiddenPropertyName::d etail())); |
| 88 } | |
| 89 | |
| 90 void V8CustomEvent::initCustomEventMethodCustom(const v8::FunctionCallbackInfo<v 8::Value>& args) | |
|
haraken
2013/06/22 13:16:46
Ditto. I hope you can improve the code generator a
jww
2013/06/25 01:50:29
adamk@ and I discussed this, and while we agree th
haraken
2013/06/25 02:06:58
Hmm, I'm neutral about this. I agree that the gene
adamk
2013/06/25 19:10:04
My argument is that we'd have to special case even
haraken
2013/06/25 23:55:30
Good point. It makes sense to keep the code in cus
| |
| 91 { | |
| 92 CustomEvent* event = V8CustomEvent::toNative(args.Holder()); | |
|
adamk
2013/06/22 01:00:04
Can you add an ASSERT() that this event doesn't ha
jww
2013/06/25 01:50:29
Done.
| |
| 93 String typeArg = toWebCoreString(args[0]); | |
| 94 bool canBubbleArg = args[1]->BooleanValue(); | |
| 95 bool cancelableArg = args[2]->BooleanValue(); | |
| 96 v8::Handle<v8::Value> detailsArg = args[3]; | |
| 97 | |
| 98 args.Holder()->SetHiddenValue(V8HiddenPropertyName::detail(), detailsArg); | |
|
haraken
2013/06/22 13:16:46
SetHiddenValue affects the lifetime of 'detail'. I
jww
2013/06/25 01:50:29
I think the answer is 'no,' but honestly, I'm not
haraken
2013/06/25 02:06:58
I expect a test that fails if we miss SetHiddenVal
adamk
2013/06/25 19:10:04
The trouble with the old code was that it was leak
haraken
2013/06/25 23:55:30
Regarding GC issues, ideally we should have the fo
| |
| 99 event->initCustomEvent(typeArg, canBubbleArg, cancelableArg); | |
|
adamk
2013/06/22 01:00:04
Can you just call initEvent() here and get rid of
jww
2013/06/25 01:50:29
Done.
| |
| 62 } | 100 } |
| 63 | 101 |
| 64 } // namespace WebCore | 102 } // namespace WebCore |
| OLD | NEW |