Changeset 207328 in webkit
- Timestamp:
- Oct 13, 2016 11:58:28 PM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r207325 r207328 1 2016-10-13 Youenn Fablet <youenn@apple.com> 2 3 Binding generated code for private operations should assert for casted-this checks 4 https://bugs.webkit.org/show_bug.cgi?id=163326 5 6 Reviewed by Darin Adler. 7 8 Covered by existing tests. 9 10 Private operations are not exposed to user scripts and are only called by built-in scripts or other WebKit-controlled code. 11 The call sites already ensure that the caller is of the right type so there is no need to do that work twice. 12 13 Introducing a casted-this-error Assert mode for casted-this checks, which may be reused for other binding generated code. 14 Updated binding generator to use that mode for private operations. 15 16 * bindings/js/JSDOMBinding.h: 17 (WebCore::BindingCaller::callPromiseOperation): 18 (WebCore::BindingCaller::callOperation): 19 * bindings/scripts/CodeGeneratorJS.pm: 20 (GenerateImplementation): 21 * bindings/scripts/test/JS/JSTestGlobalObject.cpp: 22 (WebCore::jsTestGlobalObjectInstanceFunctionTestPrivateFunction): 23 * bindings/scripts/test/JS/JSTestObj.cpp: 24 (WebCore::jsTestObjPrototypeFunctionPrivateMethod): 25 1 26 2016-10-13 Carlos Garcia Campos <cgarcia@igalia.com> 2 27 -
trunk/Source/WebCore/bindings/js/JSDOMBinding.h
r207193 r207328 332 332 333 333 334 enum class CastedThisErrorBehavior { Throw, ReturnEarly, RejectPromise };334 enum class CastedThisErrorBehavior { Throw, ReturnEarly, RejectPromise, Assert }; 335 335 336 336 template<typename JSClass> … … 344 344 static JSClass* castForOperation(JSC::ExecState&); 345 345 346 template<PromiseOperationCallerFunction operationCaller >346 template<PromiseOperationCallerFunction operationCaller, CastedThisErrorBehavior shouldThrow = CastedThisErrorBehavior::RejectPromise> 347 347 static JSC::EncodedJSValue callPromiseOperation(JSC::ExecState* state, Ref<DeferredPromise>&& promise, const char* operationName) 348 348 { … … 350 350 auto throwScope = DECLARE_THROW_SCOPE(state->vm()); 351 351 auto* thisObject = castForOperation(*state); 352 if ( UNLIKELY(!thisObject)) {352 if (shouldThrow != CastedThisErrorBehavior::Assert && UNLIKELY(!thisObject)) { 353 353 ASSERT(JSClass::info()); 354 354 return rejectPromiseWithThisTypeError(promise.get(), JSClass::info()->className, operationName); 355 355 } 356 ASSERT(thisObject); 356 357 ASSERT_GC_OBJECT_INHERITS(thisObject, JSClass::info()); 357 358 // FIXME: We should refactor the binding generated code to use references for state and thisObject. … … 365 366 auto throwScope = DECLARE_THROW_SCOPE(state->vm()); 366 367 auto* thisObject = castForOperation(*state); 367 if ( UNLIKELY(!thisObject)) {368 if (shouldThrow != CastedThisErrorBehavior::Assert && UNLIKELY(!thisObject)) { 368 369 ASSERT(JSClass::info()); 369 370 if (shouldThrow == CastedThisErrorBehavior::Throw) … … 372 373 return rejectPromiseWithThisTypeError(*state, JSClass::info()->className, operationName); 373 374 } 375 ASSERT(thisObject); 374 376 ASSERT_GC_OBJECT_INHERITS(thisObject, JSClass::info()); 375 377 // FIXME: We should refactor the binding generated code to use references for state and thisObject. -
trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
r207324 r207328 3678 3678 my $methodName = $function->signature->name; 3679 3679 if (IsReturningPromise($function) && !$isCustom) { 3680 push(@implContent, " return BindingCaller<$className>::callPromiseOperation<${functionName}Caller>(state, WTFMove(promise), \"${methodName}\");\n"); 3680 my $templateParameters = "${functionName}Caller"; 3681 $templateParameters .= ", CastedThisErrorBehavior::Assert" if ($function->signature->extendedAttributes->{PrivateIdentifier} and not $function->signature->extendedAttributes->{PublicIdentifier}); 3682 push(@implContent, " return BindingCaller<$className>::callPromiseOperation<${templateParameters}>(state, WTFMove(promise), \"${methodName}\");\n"); 3681 3683 push(@implContent, "}\n"); 3682 3684 push(@implContent, "\n"); … … 3685 3687 my $classParameterType = $className eq "JSEventTarget" ? "JSEventTargetWrapper*" : "${className}*"; 3686 3688 my $templateParameters = "${functionName}Caller"; 3687 # FIXME: We need this specific handling for custom promise-returning functions. 3688 # It would be better to have the casted-this code calling the promise-specific code. 3689 $templateParameters .= ", CastedThisErrorBehavior::RejectPromise" if IsReturningPromise($function); 3689 if ($function->signature->extendedAttributes->{PrivateIdentifier} and not $function->signature->extendedAttributes->{PublicIdentifier}) { 3690 $templateParameters .= ", CastedThisErrorBehavior::Assert"; 3691 } elsif (IsReturningPromise($function)) { 3692 # FIXME: We need this specific handling for custom promise-returning functions. 3693 # It would be better to have the casted-this code calling the promise-specific code. 3694 $templateParameters .= ", CastedThisErrorBehavior::RejectPromise" if IsReturningPromise($function); 3695 } 3690 3696 3691 3697 push(@implContent, " return BindingCaller<$className>::callOperation<${templateParameters}>(state, \"${methodName}\");\n"); -
trunk/Source/WebCore/bindings/scripts/test/JS/JSTestGlobalObject.cpp
r207193 r207328 459 459 EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionTestPrivateFunction(ExecState* state) 460 460 { 461 return BindingCaller<JSTestGlobalObject>::callOperation<jsTestGlobalObjectInstanceFunctionTestPrivateFunctionCaller >(state, "testPrivateFunction");461 return BindingCaller<JSTestGlobalObject>::callOperation<jsTestGlobalObjectInstanceFunctionTestPrivateFunctionCaller, CastedThisErrorBehavior::Assert>(state, "testPrivateFunction"); 462 462 } 463 463 -
trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp
r207324 r207328 5353 5353 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionPrivateMethod(ExecState* state) 5354 5354 { 5355 return BindingCaller<JSTestObj>::callOperation<jsTestObjPrototypeFunctionPrivateMethodCaller >(state, "privateMethod");5355 return BindingCaller<JSTestObj>::callOperation<jsTestObjPrototypeFunctionPrivateMethodCaller, CastedThisErrorBehavior::Assert>(state, "privateMethod"); 5356 5356 } 5357 5357
Note: See TracChangeset
for help on using the changeset viewer.