Source/WebCore/Android.jscbindings.mk

@@BINDING_C_INCLUDES := \
5656 $(base_intermediates)/Source/WebCore/xml
5757
5858LOCAL_SRC_FILES += \
 59 bindings/js/CallbackFunction.cpp \
5960 bindings/js/GCController.cpp \
6061 bindings/js/IDBBindingUtilities.cpp \
6162 bindings/js/JSAttrCustom.cpp \

Source/WebCore/CMakeLists.txt

@@SET(WebCore_SOURCES
451451 bindings/generic/ActiveDOMCallback.cpp
452452 bindings/generic/RuntimeEnabledFeatures.cpp
453453
 454 bindings/js/CallbackFunction.cpp
 455
454456 css/CSSBorderImageValue.cpp
455457 css/CSSCanvasValue.cpp
456458 css/CSSCharsetRule.cpp

Source/WebCore/ChangeLog

 12011-04-06 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 * Android.jscbindings.mk:
 15 * CMakeLists.txt:
 16 * GNUmakefile.am:
 17 * WebCore.gypi:
 18 * WebCore.pro:
 19 * WebCore.vcproj/WebCore.vcproj:
 20 * WebCore.xcodeproj/project.pbxproj:
 21 * bindings/js/CallbackFunction.cpp: Added.
 22 (WebCore::checkFunctionOnlyCallback):
 23 * bindings/js/CallbackFunction.h: Added.
 24 (WebCore::createFunctionOnlyCallback):
 25 * bindings/js/JSBindingsAllInOne.cpp:
 26 * bindings/js/JSGeolocationCustom.cpp:
 27 (WebCore::JSGeolocation::getCurrentPosition):
 28 (WebCore::JSGeolocation::watchPosition):
 29
1302011-04-06 Sheriff Bot <webkit.review.bot@gmail.com>
231
332 Unreviewed, rolling out r83045.

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/CallbackFunction.cpp \
 721 Source/WebCore/bindings/js/CallbackFunction.h \
720722 Source/WebCore/bindings/js/DOMObjectHashTableMap.cpp \
721723 Source/WebCore/bindings/js/DOMObjectHashTableMap.h \
722724 Source/WebCore/bindings/js/DOMWrapperWorld.cpp \

Source/WebCore/WebCore.gypi

16711671 'bindings/gobject/WebKitHTMLElementWrapperFactory.cpp',
16721672 'bindings/gobject/WebKitHTMLElementWrapperFactory.h',
16731673 'bindings/js/CachedScriptSourceProvider.h',
 1674 'bindings/js/CallbackFunction.cpp',
 1675 'bindings/js/CallbackFunction.h',
16741676 'bindings/js/DOMObjectHashTableMap.cpp',
16751677 'bindings/js/DOMWrapperWorld.cpp',
16761678 'bindings/js/GCController.cpp',

Source/WebCore/WebCore.pro

@@v8 {
12681268} else {
12691269 HEADERS += \
12701270 bindings/js/CachedScriptSourceProvider.h \
 1271 bindings/js/CallbackFunction.cpp \
 1272 bindings/js/CallbackFunction.h \
12711273 bindings/js/GCController.h \
12721274 bindings/js/DOMObjectHashTableMap.h \
12731275 bindings/js/DOMWrapperWorld.h \

Source/WebCore/WebCore.vcproj/WebCore.vcproj

5648156481 >
5648256482 </File>
5648356483 <File
 56484 RelativePath="..\bindings\js\CallbackFunction.cpp"
 56485 >
 56486 <FileConfiguration
 56487 Name="Debug|Win32"
 56488 ExcludedFromBuild="true"
 56489 >
 56490 <Tool
 56491 Name="VCCLCompilerTool"
 56492 />
 56493 </FileConfiguration>
 56494 <FileConfiguration
 56495 Name="Release|Win32"
 56496 ExcludedFromBuild="true"
 56497 >
 56498 <Tool
 56499 Name="VCCLCompilerTool"
 56500 />
 56501 </FileConfiguration>
 56502 <FileConfiguration
 56503 Name="Debug_Cairo_CFLite|Win32"
 56504 ExcludedFromBuild="true"
 56505 >
 56506 <Tool
 56507 Name="VCCLCompilerTool"
 56508 />
 56509 </FileConfiguration>
 56510 <FileConfiguration
 56511 Name="Release_Cairo_CFLite|Win32"
 56512 ExcludedFromBuild="true"
 56513 >
 56514 <Tool
 56515 Name="VCCLCompilerTool"
 56516 />
 56517 </FileConfiguration>
 56518 <FileConfiguration
 56519 Name="Debug_All|Win32"
 56520 ExcludedFromBuild="true"
 56521 >
 56522 <Tool
 56523 Name="VCCLCompilerTool"
 56524 />
 56525 </FileConfiguration>
 56526 <FileConfiguration
 56527 Name="Production|Win32"
 56528 ExcludedFromBuild="true"
 56529 >
 56530 <Tool
 56531 Name="VCCLCompilerTool"
 56532 />
 56533 </FileConfiguration>
 56534 </File>
 56535 <File
 56536 RelativePath="..\bindings\js\CallbackFunction.h"
 56537 >
 56538 </File>
 56539 <File
5648456540 RelativePath="..\bindings\js\DOMObjectHashTableMap.cpp"
5648556541 >
5648656542 <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 B1827493134CA4C100B98C2D /* CallbackFunction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B1827492134CA4C100B98C2D /* CallbackFunction.cpp */; };
 4099 B1D5ECB5134B58DA0087C78F /* CallbackFunction.h in Headers */ = {isa = PBXBuildFile; fileRef = B1D5ECB4134B58DA0087C78F /* CallbackFunction.h */; };
40984100 B20111070AB7740500DB0E68 /* JSSVGAElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B20111050AB7740500DB0E68 /* JSSVGAElement.cpp */; };
40994101 B20111080AB7740500DB0E68 /* JSSVGAElement.h in Headers */ = {isa = PBXBuildFile; fileRef = B20111060AB7740500DB0E68 /* JSSVGAElement.h */; };
41004102 B22279620D00BF220071B782 /* ColorDistance.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B22277CB0D00BF1F0071B782 /* ColorDistance.cpp */; };

1037110373 B0149E7A11A4B21500196A7B /* AsyncImageResizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AsyncImageResizer.h; sourceTree = "<group>"; };
1037210374 B0149E7B11A4B21500196A7B /* ImageResizerThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ImageResizerThread.cpp; sourceTree = "<group>"; };
1037310375 B0149E7C11A4B21500196A7B /* ImageResizerThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageResizerThread.h; sourceTree = "<group>"; };
 10376 B1827492134CA4C100B98C2D /* CallbackFunction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CallbackFunction.cpp; sourceTree = "<group>"; };
 10377 B1D5ECB4134B58DA0087C78F /* CallbackFunction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CallbackFunction.h; sourceTree = "<group>"; };
1037410378 B20111050AB7740500DB0E68 /* JSSVGAElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSSVGAElement.cpp; sourceTree = "<group>"; };
1037510379 B20111060AB7740500DB0E68 /* JSSVGAElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSSVGAElement.h; sourceTree = "<group>"; };
1037610380 B22277CB0D00BF1F0071B782 /* ColorDistance.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = ColorDistance.cpp; sourceTree = "<group>"; };

1798917993 BC4EDEF70C08F414007EDD49 /* Custom */,
1799017994 14DFB33F0A7DF7630018F769 /* Derived Sources */,
1799117995 BCD533630ED6848900887468 /* CachedScriptSourceProvider.h */,
 17996 B1827492134CA4C100B98C2D /* CallbackFunction.cpp */,
 17997 B1D5ECB4134B58DA0087C78F /* CallbackFunction.h */,
1799217998 93F8B3060A300FEA00F61AB8 /* CodeGeneratorJS.pm */,
1799317999 BC53DA61114314BD000D817E /* DOMObjectHashTableMap.cpp */,
1799418000 BC53DA5F1143141A000D817E /* DOMObjectHashTableMap.h */,

2282722833 FD06DFA6134A4DEF006F5D7D /* DefaultAudioDestinationNode.h in Headers */,
2282822834 E1A3162D134BC32D007C9A4F /* WebNSAttributedStringExtras.h in Headers */,
2282922835 E1A31663134BCAE8007C9A4F /* HTMLConverter.h in Headers */,
 22836 B1D5ECB5134B58DA0087C78F /* CallbackFunction.h in Headers */,
2283022837 );
2283122838 runOnlyForDeploymentPostprocessing = 0;
2283222839 };

2551425521 FDF6BAF8134A4C9800822920 /* JSOfflineAudioCompletionEvent.cpp in Sources */,
2551525522 FD06DFA5134A4DEF006F5D7D /* DefaultAudioDestinationNode.cpp in Sources */,
2551625523 E1A3162E134BC32D007C9A4F /* WebNSAttributedStringExtras.mm in Sources */,
 25524 B1827493134CA4C100B98C2D /* CallbackFunction.cpp in Sources */,
2551725525 );
2551825526 runOnlyForDeploymentPostprocessing = 0;
2551925527 };

Source/WebCore/bindings/js/CallbackFunction.cpp

 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#include "config.h"
 26#include "CallbackFunction.h"
 27
 28#include "ExceptionCode.h"
 29#include "JSDOMBinding.h"
 30#include <runtime/JSFunction.h>
 31
 32namespace WebCore {
 33
 34bool checkFunctionOnlyCallback(JSC::ExecState* exec, JSC::JSValue value, CallbackAllowedValueFlags acceptedValues)
 35{
 36 if (value.isUndefined() && (acceptedValues & CallbackAllowUndefined))
 37 return false;
 38
 39 if (value.isNull() && (acceptedValues & CallbackAllowNull))
 40 return false;
 41
 42 // FIXME: disallows callable objects created via JSC API. It's not clear what exactly the specification intends to allow.
 43 // https://bugs.webkit.org/show_bug.cgi?id=40012
 44 if (!value.inherits(&JSC::JSFunction::s_info)) {
 45 setDOMException(exec, TYPE_MISMATCH_ERR);
 46 return false;
 47 }
 48
 49 return true;
 50}
 51
 52} // namespace WebCore

Source/WebCore/bindings/js/CallbackFunction.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 CallbackFunction_h
 26#define CallbackFunction_h
 27
 28#include <runtime/JSObject.h>
 29
 30namespace JSC {
 31class ExecState;
 32}
 33
 34namespace WebCore {
 35
 36class JSDOMGlobalObject;
 37
 38enum CallbackAllowedValueFlag {
 39 CallbackAllowUndefined = 1,
 40 CallbackAllowNull = 1 << 1
 41};
 42
 43typedef unsigned CallbackAllowedValueFlags;
 44
 45bool checkFunctionOnlyCallback(JSC::ExecState*, JSC::JSValue, CallbackAllowedValueFlags);
 46
 47// Creates callback objects for callbacks marked as FunctionOnly in WebIDL.
 48template <typename JSCallbackType>
 49PassRefPtr<JSCallbackType> createFunctionOnlyCallback(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, JSC::JSValue value, CallbackAllowedValueFlags acceptedValues = 0)
 50{
 51 if (checkFunctionOnlyCallback(exec, value, acceptedValues))
 52 return JSCallbackType::create(asObject(value), globalObject);
 53 return 0;
 54}
 55
 56} // namespace WebCore
 57
 58#endif // CallbackFunction_h

Source/WebCore/bindings/js/JSBindingsAllInOne.cpp

2525
2626// This all-in-one cpp file cuts down on template bloat to allow us to build our Windows release build.
2727
 28#include "CallbackFunction.cpp"
2829#include "DOMObjectHashTableMap.cpp"
2930#include "DOMWrapperWorld.cpp"
3031#include "GCController.cpp"

Source/WebCore/bindings/js/JSGeolocationCustom.cpp

2828
2929#if ENABLE(GEOLOCATION)
3030
 31#include "CallbackFunction.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 RefPtr<PositionCallback> positionCallback = createFunctionOnlyCallback<JSCustomPositionCallback>(exec, static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->argument(0));
148117 if (exec->hadException())
149118 return jsUndefined();
150119 ASSERT(positionCallback);
151120
152  RefPtr<PositionErrorCallback> positionErrorCallback = createPositionErrorCallback(exec, static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->argument(1));
 121 RefPtr<PositionErrorCallback> positionErrorCallback = createFunctionOnlyCallback<JSCustomPositionErrorCallback>(exec, static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->argument(1), CallbackAllowUndefined | CallbackAllowNull);
153122 if (exec->hadException())
154123 return jsUndefined();
155124

@@JSValue JSGeolocation::watchPosition(ExecState* exec)
166135{
167136 // Arguments: PositionCallback, (optional)PositionErrorCallback, (optional)PositionOptions
168137
169  RefPtr<PositionCallback> positionCallback = createPositionCallback(exec, static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->argument(0));
 138 RefPtr<PositionCallback> positionCallback = createFunctionOnlyCallback<JSCustomPositionCallback>(exec, static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->argument(0));
170139 if (exec->hadException())
171140 return jsUndefined();
172141 ASSERT(positionCallback);
173142
174  RefPtr<PositionErrorCallback> positionErrorCallback = createPositionErrorCallback(exec, static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->argument(1));
 143 RefPtr<PositionErrorCallback> positionErrorCallback = createFunctionOnlyCallback<JSCustomPositionErrorCallback>(exec, static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->argument(1), CallbackAllowUndefined | CallbackAllowNull);
175144 if (exec->hadException())
176145 return jsUndefined();
177146