diff options
Diffstat (limited to 'WebCore/bindings/scripts')
-rw-r--r-- | WebCore/bindings/scripts/CodeGeneratorJS.pm | 14 | ||||
-rw-r--r-- | WebCore/bindings/scripts/CodeGeneratorV8.pm | 22 |
2 files changed, 35 insertions, 1 deletions
diff --git a/WebCore/bindings/scripts/CodeGeneratorJS.pm b/WebCore/bindings/scripts/CodeGeneratorJS.pm index 0b18d95..84e3919 100644 --- a/WebCore/bindings/scripts/CodeGeneratorJS.pm +++ b/WebCore/bindings/scripts/CodeGeneratorJS.pm @@ -1963,6 +1963,20 @@ sub GenerateImplementation push(@implContent, " RefPtr<" . $parameter->type . "> $name = ${callbackClassName}::create(asObject(exec->argument($argsIndex)), castedThis->globalObject());\n"); } } else { + # For functions with "StrictTypeChecking", if an input parameter's type does not match the signature, + # a TypeError is thrown instead of casting to null. + if ($function->signature->extendedAttributes->{"StrictTypeChecking"}) { + my $argValue = "exec->argument($argsIndex)"; + my $argType = $codeGenerator->StripModule($parameter->type); + if (!IsNativeType($argType)) { + push(@implContent, " if (exec->argumentCount() > $argsIndex && !${argValue}.isUndefinedOrNull() && !${argValue}.inherits(&JS${argType}::s_info))\n"); + push(@implContent, " return throwVMTypeError(exec);\n"); + } elsif ($codeGenerator->IsStringType($argType)) { + push(@implContent, " if (exec->argumentCount() > $argsIndex && !${argValue}.isUndefinedOrNull() && !${argValue}.isString() && !${argValue}.isObject())\n"); + push(@implContent, " return throwVMTypeError(exec);\n"); + } + } + push(@implContent, " " . GetNativeTypeFromSignature($parameter) . " $name = " . JSValueToNative($parameter, "exec->argument($argsIndex)") . ";\n"); # If a parameter is "an index" and it's negative it should throw an INDEX_SIZE_ERR exception. diff --git a/WebCore/bindings/scripts/CodeGeneratorV8.pm b/WebCore/bindings/scripts/CodeGeneratorV8.pm index ebbcf8b..56838ca 100644 --- a/WebCore/bindings/scripts/CodeGeneratorV8.pm +++ b/WebCore/bindings/scripts/CodeGeneratorV8.pm @@ -1245,6 +1245,23 @@ END } } else { $implIncludes{"V8BindingMacros.h"} = 1; + # For functions with "StrictTypeChecking", if an input parameter's type does not match the signature, + # a TypeError is thrown instead of casting to null. + if ($function->signature->extendedAttributes->{"StrictTypeChecking"}) { + my $argValue = "args[$paramIndex]"; + my $argType = GetTypeFromSignature($parameter); + if (IsWrapperType($argType)) { + push(@implContentDecls, " if (args.Length() > $paramIndex && !isUndefinedOrNull($argValue) && !V8${argType}::HasInstance($argValue)) {\n"); + push(@implContentDecls, " V8Proxy::throwTypeError();\n"); + push(@implContentDecls, " return notHandledByInterceptor();\n"); + push(@implContentDecls, " }\n"); + } elsif ($codeGenerator->IsStringType($argType)) { + push(@implContentDecls, " if (args.Length() > $paramIndex && !isUndefinedOrNull($argValue) && !${argValue}->IsString() && !${argValue}->IsObject()) {\n"); + push(@implContentDecls, " V8Proxy::throwTypeError();\n"); + push(@implContentDecls, " return notHandledByInterceptor();\n"); + push(@implContentDecls, " }\n"); + } + } push(@implContentDecls, " EXCEPTION_BLOCK($nativeType, $parameterName, " . JSValueToNative($parameter, "args[$paramIndex]", BasicTypeCanFailConversion($parameter) ? "${parameterName}Ok" : undef) . ");\n"); } @@ -2988,7 +3005,10 @@ sub RequiresCustomSignature if (@{$function->{overloads}} > 1) { return 0; } - + # Type checking is performed in the generated code + if ($function->signature->extendedAttributes->{"StrictTypeChecking"}) { + return 0; + } foreach my $parameter (@{$function->parameters}) { if ($parameter->extendedAttributes->{"Optional"} || $parameter->extendedAttributes->{"Callback"}) { return 0; |