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 // Save the detail value to a hidden attribute in the V8PCustomEvent, and return it, for convenience. | |
| 49 static v8::Handle<v8::Value> cacheState(v8::Handle<v8::Object> customEvent, v8:: Handle<v8::Value> detail) | |
| 50 { | |
| 51 customEvent->SetHiddenValue(V8HiddenPropertyName::detail(), detail); | |
| 52 return detail; | |
| 53 } | |
| 54 | |
| 55 | |
| 48 void V8CustomEvent::detailAttrGetterCustom(v8::Local<v8::String> name, const v8: :PropertyCallbackInfo<v8::Value>& info) | 56 void V8CustomEvent::detailAttrGetterCustom(v8::Local<v8::String> name, const v8: :PropertyCallbackInfo<v8::Value>& info) |
| 49 { | 57 { |
| 50 CustomEvent* imp = V8CustomEvent::toNative(info.Holder()); | 58 CustomEvent* event = V8CustomEvent::toNative(info.Holder()); |
| 51 RefPtr<SerializedScriptValue> serialized = imp->serializedScriptValue(); | 59 ASSERT(!event->serializedScriptValue().get()); |
| 52 if (serialized) { | 60 |
| 53 v8::Handle<v8::Value> value = info.Holder()->GetHiddenValue(V8HiddenProp ertyName::detail()); | 61 v8::Handle<v8::Value> result = info.Holder()->GetHiddenValue(V8HiddenPropert yName::detail()); |
| 54 if (value.IsEmpty()) { | 62 |
| 55 value = serialized->deserialize(); | 63 if (!result.IsEmpty()) { |
| 56 info.Holder()->SetHiddenValue(V8HiddenPropertyName::detail(), value) ; | 64 v8SetReturnValue(info, result); |
| 57 } | |
| 58 v8SetReturnValue(info, value); | |
| 59 return; | 65 return; |
| 60 } | 66 } |
| 61 v8SetReturnValue(info, imp->detail().v8Value()); | 67 |
| 68 // This is necessary because of the V8 bug 2746. V8 returns an empty | |
| 69 // handler when a hidden value is v8::Undefined. Thus, it is necessary to | |
| 70 // keep extra state around in the event about whether the value was set | |
| 71 // in the first place. That is, if the detail was set, and V8 returns an | |
| 72 // empty handler for the value, we know that the value must actually be a | |
| 73 // v8::Undefined(), so we explicitly set that here. Oy! | |
| 74 // | |
| 75 // Once bug 2746 is addressed, the following 'if' should become dead code | |
| 76 // and should be removable. Please see the related comments in | |
| 77 // V8MessageEventCustom.cpp and V8PopStateEventCustom.cpp as well. | |
|
haraken
2013/06/26 04:40:20
I don't think this is a V8 bug nor you need to han
jww
2013/06/26 17:19:08
If GetHiddenValue returns an empty v8::Handle, the
adamk
2013/06/26 17:43:38
Note that this bug has now been fixed in https://c
| |
| 78 if (event->isDetailSet()) { | |
| 79 v8SetReturnValue(info, v8::Undefined()); | |
| 80 return; | |
| 81 } | |
| 82 | |
| 83 RefPtr<SerializedScriptValue> serialized = event->serializedScriptValue(); | |
| 84 if (serialized) { | |
| 85 result = serialized->deserialize(); | |
| 86 v8SetReturnValue(info, cacheState(info.Holder(), result)); | |
| 87 return; | |
| 88 } | |
| 89 | |
| 90 v8SetReturnValue(info, cacheState(info.Holder(), v8Null(info.GetIsolate()))) ; | |
| 91 } | |
| 92 | |
| 93 void V8CustomEvent::initCustomEventMethodCustom(const v8::FunctionCallbackInfo<v 8::Value>& args) | |
| 94 { | |
| 95 CustomEvent* event = V8CustomEvent::toNative(args.Holder()); | |
| 96 String typeArg = toWebCoreString(args[0]); | |
| 97 bool canBubbleArg = args[1]->BooleanValue(); | |
| 98 bool cancelableArg = args[2]->BooleanValue(); | |
| 99 v8::Handle<v8::Value> detailsArg = args[3]; | |
| 100 | |
| 101 args.Holder()->SetHiddenValue(V8HiddenPropertyName::detail(), detailsArg); | |
| 102 event->initEvent(typeArg, canBubbleArg, cancelableArg); | |
| 62 } | 103 } |
| 63 | 104 |
| 64 } // namespace WebCore | 105 } // namespace WebCore |
| OLD | NEW |