Source/WebCore/ChangeLog

 12011-04-05 Leandro Gracia Gil <leandrogracia@chromium.org>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 Factoring the creation of 'FunctionOnly' callbacks in JavaScriptCore.
 6 https://bugs.webkit.org/show_bug.cgi?id=57770
 7
 8 Create a template from an existing functionality in JSGeolocationCustom.cpp
 9 to be used by the custom bindings of both Geolocation and the Media Stream API.
 10 V8 version of this bug: https://bugs.webkit.org/show_bug.cgi?id=57760
 11
 12 No new tests. LayoutTests/fast/dom/Geolocation/argument-types.html
 13
 14 * GNUmakefile.am:
 15 * WebCore.pro:
 16 * WebCore.vcproj/WebCore.vcproj:
 17 * WebCore.xcodeproj/project.pbxproj:
 18 * bindings/js/CallbackUtilities.h: Added.
 19 (WebCore::createFunctionOnlyCallback):
 20 * bindings/js/JSGeolocationCustom.cpp:
 21 (WebCore::JSGeolocation::getCurrentPosition):
 22 (WebCore::JSGeolocation::watchPosition):
 23
1242011-04-05 Pavel Podivilov <podivilov@chromium.org>
225
326 Reviewed by Pavel Feldman.

Source/WebCore/GNUmakefile.am

@@webcore_sources += \
717717 Source/WebCore/bindings/generic/RuntimeEnabledFeatures.cpp \
718718 Source/WebCore/bindings/generic/RuntimeEnabledFeatures.h \
719719 Source/WebCore/bindings/js/CachedScriptSourceProvider.h \
 720 Source/WebCore/bindings/js/CallbackUtilities.h \
720721 Source/WebCore/bindings/js/DOMObjectHashTableMap.cpp \
721722 Source/WebCore/bindings/js/DOMObjectHashTableMap.h \
722723 Source/WebCore/bindings/js/DOMWrapperWorld.cpp \

Source/WebCore/WebCore.pro

@@v8 {
12681268} else {
12691269 HEADERS += \
12701270 bindings/js/CachedScriptSourceProvider.h \
 1271 bindings/js/CallbackUtilities.h \
12711272 bindings/js/GCController.h \
12721273 bindings/js/DOMObjectHashTableMap.h \
12731274 bindings/js/DOMWrapperWorld.h \

Source/WebCore/WebCore.vcproj/WebCore.vcproj

5644556445 >
5644656446 </File>
5644756447 <File
 56448 RelativePath="..\bindings\js\CallbackUtilities.h"
 56449 >
 56450 </File>
 56451 <File
5644856452 RelativePath="..\bindings\js\DOMObjectHashTableMap.cpp"
5644956453 >
5645056454 <FileConfiguration

Source/WebCore/WebCore.xcodeproj/project.pbxproj

40954095 B0149E7E11A4B21500196A7B /* AsyncImageResizer.h in Headers */ = {isa = PBXBuildFile; fileRef = B0149E7A11A4B21500196A7B /* AsyncImageResizer.h */; };
40964096 B0149E7F11A4B21500196A7B /* ImageResizerThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B0149E7B11A4B21500196A7B /* ImageResizerThread.cpp */; };
40974097 B0149E8011A4B21500196A7B /* ImageResizerThread.h in Headers */ = {isa = PBXBuildFile; fileRef = B0149E7C11A4B21500196A7B /* ImageResizerThread.h */; };
 4098 B1D5ECB5134B58DA0087C78F /* CallbackUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = B1D5ECB4134B58DA0087C78F /* CallbackUtilities.h */; };
40984099 B20111070AB7740500DB0E68 /* JSSVGAElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B20111050AB7740500DB0E68 /* JSSVGAElement.cpp */; };
40994100 B20111080AB7740500DB0E68 /* JSSVGAElement.h in Headers */ = {isa = PBXBuildFile; fileRef = B20111060AB7740500DB0E68 /* JSSVGAElement.h */; };
41004101 B22279620D00BF220071B782 /* ColorDistance.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B22277CB0D00BF1F0071B782 /* ColorDistance.cpp */; };

1036010361 B0149E7A11A4B21500196A7B /* AsyncImageResizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AsyncImageResizer.h; sourceTree = "<group>"; };
1036110362 B0149E7B11A4B21500196A7B /* ImageResizerThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ImageResizerThread.cpp; sourceTree = "<group>"; };
1036210363 B0149E7C11A4B21500196A7B /* ImageResizerThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageResizerThread.h; sourceTree = "<group>"; };
 10364 B1D5ECB4134B58DA0087C78F /* CallbackUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CallbackUtilities.h; sourceTree = "<group>"; };
1036310365 B20111050AB7740500DB0E68 /* JSSVGAElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSSVGAElement.cpp; sourceTree = "<group>"; };
1036410366 B20111060AB7740500DB0E68 /* JSSVGAElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSSVGAElement.h; sourceTree = "<group>"; };
1036510367 B22277CB0D00BF1F0071B782 /* ColorDistance.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = ColorDistance.cpp; sourceTree = "<group>"; };

1796517967 BC4EDEF70C08F414007EDD49 /* Custom */,
1796617968 14DFB33F0A7DF7630018F769 /* Derived Sources */,
1796717969 BCD533630ED6848900887468 /* CachedScriptSourceProvider.h */,
 17970 B1D5ECB4134B58DA0087C78F /* CallbackUtilities.h */,
1796817971 93F8B3060A300FEA00F61AB8 /* CodeGeneratorJS.pm */,
1796917972 BC53DA61114314BD000D817E /* DOMObjectHashTableMap.cpp */,
1797017973 BC53DA5F1143141A000D817E /* DOMObjectHashTableMap.h */,

2278822791 93F199ED08245E59001E9ABC /* XSLTProcessor.h in Headers */,
2278922792 E1BE512E0CF6C512002EA959 /* XSLTUnicodeSort.h in Headers */,
2279022793 977E2E0F12F0FC9C00C13379 /* XSSFilter.h in Headers */,
 22794 B1D5ECB5134B58DA0087C78F /* CallbackUtilities.h in Headers */,
2279122795 );
2279222796 runOnlyForDeploymentPostprocessing = 0;
2279322797 };

Source/WebCore/bindings/js/CallbackUtilities.h

 1/*
 2 * Copyright (C) 2011 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 23 */
 24
 25#ifndef CallbackUtilities_h
 26#define CallbackUtilities_h
 27
 28#include "ExceptionCode.h"
 29#include <runtime/JSFunction.h>
 30#include <wtf/Forward.h>
 31
 32namespace WebCore {
 33
 34enum CallbackAllowedValueFlag {
 35 CallbackAllowFunction = 0,
 36 CallbackAllowUndefined = 1,
 37 CallbackAllowNull = 1 << 1
 38};
 39
 40typedef unsigned CallbackAllowedValueFlags;
 41
 42// 'FunctionOnly' is assumed for the created callback. Callable objects created via JSC API are disallowed.
 43template <typename JSCallbackType>
 44PassRefPtr<JSCallbackType> createFunctionOnlyCallback(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, JSC::JSValue value, CallbackAllowedValueFlags acceptedValues)
 45{
 46 if ((value.isUndefined() && (acceptedValues & CallbackAllowUndefined))
 47 || (value.isNull() && (acceptedValues & CallbackAllowNull)))
 48 return 0;
 49
 50 if (!value.inherits(&JSC::JSFunction::s_info)) {
 51 setDOMException(exec, TYPE_MISMATCH_ERR);
 52 return 0;
 53 }
 54
 55 JSC::JSObject* object = asObject(value);
 56 return JSCallbackType::create(object, globalObject);
 57}
 58
 59} // namespace WebCore
 60
 61#endif // CallbackUtilities_h

Source/WebCore/bindings/js/JSGeolocationCustom.cpp

2828
2929#if ENABLE(GEOLOCATION)
3030
 31#include "CallbackUtilities.h"
3132#include "DOMWindow.h"
32 #include "ExceptionCode.h"
3333#include "Geolocation.h"
3434#include "JSCustomPositionCallback.h"
3535#include "JSCustomPositionErrorCallback.h"
3636#include "JSDOMWindow.h"
3737#include "PositionOptions.h"
38 #include <runtime/JSFunction.h>
3938
4039#if !ENABLE(CLIENT_BASED_GEOLOCATION)
4140#include "GeolocationService.h"

@@using namespace std;
4645
4746namespace WebCore {
4847
49 static PassRefPtr<PositionCallback> createPositionCallback(ExecState* exec, JSDOMGlobalObject* globalObject, JSValue value)
50 {
51  // The spec specifies 'FunctionOnly' for this object.
52  // FIXME: This check disallows callable objects created via JSC API. It's not clear what exactly the specification intends to allow.
53  if (!value.inherits(&JSFunction::s_info)) {
54  setDOMException(exec, TYPE_MISMATCH_ERR);
55  return 0;
56  }
57 
58  JSObject* object = asObject(value);
59  return JSCustomPositionCallback::create(object, globalObject);
60 }
61 
62 static PassRefPtr<PositionErrorCallback> createPositionErrorCallback(ExecState* exec, JSDOMGlobalObject* globalObject, JSValue value)
63 {
64  // Argument is optional (hence undefined is allowed), and null is allowed.
65  if (value.isUndefinedOrNull())
66  return 0;
67 
68  // The spec specifies 'FunctionOnly' for this object.
69  // FIXME: This check disallows callable objects created via JSC API. It's not clear what exactly the specification intends to allow.
70  if (!value.inherits(&JSFunction::s_info)) {
71  setDOMException(exec, TYPE_MISMATCH_ERR);
72  return 0;
73  }
74 
75  JSObject* object = asObject(value);
76  return JSCustomPositionErrorCallback::create(object, globalObject);
77 }
78 
7948static PassRefPtr<PositionOptions> createPositionOptions(ExecState* exec, JSValue value)
8049{
8150 // Create default options.

@@JSValue JSGeolocation::getCurrentPosition(ExecState* exec)
144113{
145114 // Arguments: PositionCallback, (optional)PositionErrorCallback, (optional)PositionOptions
146115
147  RefPtr<PositionCallback> positionCallback = createPositionCallback(exec, static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->argument(0));
 116 // FIXME: createFunctionOnlyCallback disallows callable objects created via JSC API. It's not clear what exactly the specification intends to allow.
 117 RefPtr<PositionCallback> positionCallback = createFunctionOnlyCallback<JSCustomPositionCallback>(exec,
 118 static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->argument(0), CallbackAllowFunction);
148119 if (exec->hadException())
149120 return jsUndefined();
150121 ASSERT(positionCallback);
151122
152  RefPtr<PositionErrorCallback> positionErrorCallback = createPositionErrorCallback(exec, static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->argument(1));
 123 // FIXME: createFunctionOnlyCallback disallows callable objects created via JSC API. It's not clear what exactly the specification intends to allow.
 124 RefPtr<PositionErrorCallback> positionErrorCallback = createFunctionOnlyCallback<JSCustomPositionErrorCallback>(exec,
 125 static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->argument(1), CallbackAllowUndefined | CallbackAllowNull);
153126 if (exec->hadException())
154127 return jsUndefined();
155128

@@JSValue JSGeolocation::watchPosition(ExecState* exec)
166139{
167140 // Arguments: PositionCallback, (optional)PositionErrorCallback, (optional)PositionOptions
168141
169  RefPtr<PositionCallback> positionCallback = createPositionCallback(exec, static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->argument(0));
 142 // FIXME: createFunctionOnlyCallback disallows callable objects created via JSC API. It's not clear what exactly the specification intends to allow.
 143 RefPtr<PositionCallback> positionCallback = createFunctionOnlyCallback<JSCustomPositionCallback>(exec,
 144 static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->argument(0), CallbackAllowFunction);
170145 if (exec->hadException())
171146 return jsUndefined();
172147 ASSERT(positionCallback);
173148
174  RefPtr<PositionErrorCallback> positionErrorCallback = createPositionErrorCallback(exec, static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->argument(1));
 149 // FIXME: createFunctionOnlyCallback disallows callable objects created via JSC API. It's not clear what exactly the specification intends to allow.
 150 RefPtr<PositionErrorCallback> positionErrorCallback = createFunctionOnlyCallback<JSCustomPositionErrorCallback>(exec,
 151 static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->argument(1), CallbackAllowUndefined | CallbackAllowNull);
175152 if (exec->hadException())
176153 return jsUndefined();
177154