Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(537)

Side by Side Diff: Source/bindings/scripts/code_generator_v8.pm

Issue 114363002: Structured cloning: improve DataCloneError reporting. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased + reset V8TestInterfaceConstructor.cpp result Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright (C) 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> 1 # Copyright (C) 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org>
2 # Copyright (C) 2006 Anders Carlsson <andersca@mac.com> 2 # Copyright (C) 2006 Anders Carlsson <andersca@mac.com>
3 # Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> 3 # Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
4 # Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org> 4 # Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org>
5 # Copyright (C) 2006 Apple Computer, Inc. 5 # Copyright (C) 2006 Apple Computer, Inc.
6 # Copyright (C) 2007, 2008, 2009, 2012 Google Inc. 6 # Copyright (C) 2007, 2008, 2009, 2012 Google Inc.
7 # Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au> 7 # Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au>
8 # Copyright (C) Research In Motion Limited 2010. All rights reserved. 8 # Copyright (C) Research In Motion Limited 2010. All rights reserved.
9 # Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 # Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 # Copyright (C) 2012 Ericsson AB. All rights reserved. 10 # Copyright (C) 2012 Ericsson AB. All rights reserved.
(...skipping 2148 matching lines...) Expand 10 before | Expand all | Expand 10 after
2159 my $value = "info[$parameterIndex]"; 2159 my $value = "info[$parameterIndex]";
2160 my $type = $parameter->type; 2160 my $type = $parameter->type;
2161 2161
2162 # Only DOMString or wrapper types are checked. 2162 # Only DOMString or wrapper types are checked.
2163 # For DOMString with StrictTypeChecking only Null, Undefined and Object 2163 # For DOMString with StrictTypeChecking only Null, Undefined and Object
2164 # are accepted for compatibility. Otherwise, no restrictions are made to 2164 # are accepted for compatibility. Otherwise, no restrictions are made to
2165 # match the non-overloaded behavior. 2165 # match the non-overloaded behavior.
2166 # FIXME: Implement WebIDL overload resolution algorithm. 2166 # FIXME: Implement WebIDL overload resolution algorithm.
2167 if ($type eq "DOMString") { 2167 if ($type eq "DOMString") {
2168 if ($parameter->extendedAttributes->{"StrictTypeChecking"}) { 2168 if ($parameter->extendedAttributes->{"StrictTypeChecking"}) {
2169 push(@andExpression, "${value}->IsNull() || ${value}->IsUndefine d() || ${value}->IsString() || ${value}->IsObject()"); 2169 push(@andExpression, "isUndefinedOrNull(${value}) || ${value}->I sString() || ${value}->IsObject()");
2170 } 2170 }
2171 } elsif (IsCallbackInterface($parameter->type)) { 2171 } elsif (IsCallbackInterface($parameter->type)) {
2172 # For Callbacks only checks if the value is null or object. 2172 # For Callbacks only checks if the value is null or object.
2173 push(@andExpression, "${value}->IsNull() || ${value}->IsFunction()") ; 2173 push(@andExpression, "${value}->IsNull() || ${value}->IsFunction()") ;
2174 } elsif (GetArrayOrSequenceType($type)) { 2174 } elsif (GetArrayOrSequenceType($type)) {
2175 if ($parameter->isNullable) { 2175 if ($parameter->isNullable) {
2176 push(@andExpression, "${value}->IsNull() || ${value}->IsArray()" ); 2176 push(@andExpression, "${value}->IsNull() || ${value}->IsArray()" );
2177 } else { 2177 } else {
2178 push(@andExpression, "${value}->IsArray()"); 2178 push(@andExpression, "${value}->IsArray()");
2179 } 2179 }
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
2361 2361
2362 # We throw exceptions using 'ExceptionState' if the function explicitly clai ms that exceptions 2362 # We throw exceptions using 'ExceptionState' if the function explicitly clai ms that exceptions
2363 # may be raised, or for event listeners, or for security-checking, and for w eird SVG stuff. 2363 # may be raised, or for event listeners, or for security-checking, and for w eird SVG stuff.
2364 my $isEventListener = $name eq "addEventListener" || $name eq "removeEventLi stener"; 2364 my $isEventListener = $name eq "addEventListener" || $name eq "removeEventLi stener";
2365 my $isSecurityCheckNecessary = $interface->extendedAttributes->{"CheckSecuri ty"} && !$function->extendedAttributes->{"DoNotCheckSecurity"}; 2365 my $isSecurityCheckNecessary = $interface->extendedAttributes->{"CheckSecuri ty"} && !$function->extendedAttributes->{"DoNotCheckSecurity"};
2366 my $raisesExceptions = $function->extendedAttributes->{"RaisesException"}; 2366 my $raisesExceptions = $function->extendedAttributes->{"RaisesException"};
2367 my ($svgPropertyType, $svgListPropertyType, $svgNativeType) = GetSVGProperty Types($interfaceName); 2367 my ($svgPropertyType, $svgListPropertyType, $svgNativeType) = GetSVGProperty Types($interfaceName);
2368 my $isNonListSVGType = $svgNativeType && !($interfaceName =~ /List$/); 2368 my $isNonListSVGType = $svgNativeType && !($interfaceName =~ /List$/);
2369 2369
2370 my $hasExceptionState = 0; 2370 my $hasExceptionState = 0;
2371 if ($raisesExceptions || $isEventListener || $isSecurityCheckNecessary || $i sNonListSVGType) { 2371 if ($raisesExceptions || $isEventListener || $isSecurityCheckNecessary || $i sNonListSVGType || HasSerializedScriptValueParameter($function)) {
2372 $code .= " ExceptionState exceptionState(ExceptionState::ExecutionCon text, \"${unoverloadedName}\", \"${interfaceName}\", info.Holder(), info.GetIsol ate());\n"; 2372 $code .= " ExceptionState exceptionState(ExceptionState::ExecutionCon text, \"${unoverloadedName}\", \"${interfaceName}\", info.Holder(), info.GetIsol ate());\n";
2373 $hasExceptionState = 1; 2373 $hasExceptionState = 1;
2374 } 2374 }
2375 2375
2376 if ($isEventListener) { 2376 if ($isEventListener) {
2377 my $lookupType = ($name eq "addEventListener") ? "OrCreate" : "Only"; 2377 my $lookupType = ($name eq "addEventListener") ? "OrCreate" : "Only";
2378 my $passRefPtrHandling = ($name eq "addEventListener") ? "" : ".get()"; 2378 my $passRefPtrHandling = ($name eq "addEventListener") ? "" : ".get()";
2379 my $hiddenDependencyAction = ($name eq "addEventListener") ? "create" : "remove"; 2379 my $hiddenDependencyAction = ($name eq "addEventListener") ? "create" : "remove";
2380 2380
2381 AddToImplIncludes("bindings/v8/BindingSecurity.h"); 2381 AddToImplIncludes("bindings/v8/BindingSecurity.h");
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
2447 if ($function->extendedAttributes->{"CheckSecurity"}) { 2447 if ($function->extendedAttributes->{"CheckSecurity"}) {
2448 AddToImplIncludes("bindings/v8/BindingSecurity.h"); 2448 AddToImplIncludes("bindings/v8/BindingSecurity.h");
2449 $code .= " if (!BindingSecurity::shouldAllowAccessToNode(imp->" . Get ImplName($function) . "(exceptionState), exceptionState)) {\n"; 2449 $code .= " if (!BindingSecurity::shouldAllowAccessToNode(imp->" . Get ImplName($function) . "(exceptionState), exceptionState)) {\n";
2450 $code .= " v8SetReturnValueNull(info);\n"; 2450 $code .= " v8SetReturnValueNull(info);\n";
2451 $code .= " exceptionState.throwIfNeeded();\n"; 2451 $code .= " exceptionState.throwIfNeeded();\n";
2452 $code .= " return;\n"; 2452 $code .= " return;\n";
2453 $code .= " }\n"; 2453 $code .= " }\n";
2454 END 2454 END
2455 } 2455 }
2456 2456
2457 my ($parameterCheckString, $paramIndex, %replacements) = GenerateParametersC heck($function, $interface, $forMainWorldSuffix); 2457 my ($parameterCheckString, $paramIndex, %replacements) = GenerateParametersC heck($function, $interface, $forMainWorldSuffix, $hasExceptionState);
2458 $code .= $parameterCheckString; 2458 $code .= $parameterCheckString;
2459 2459
2460 # Build the function call string. 2460 # Build the function call string.
2461 $code .= GenerateFunctionCallString($function, $paramIndex, " ", $interfa ce, $forMainWorldSuffix, %replacements); 2461 $code .= GenerateFunctionCallString($function, $paramIndex, " ", $interfa ce, $forMainWorldSuffix, %replacements);
2462 $code .= "}\n"; 2462 $code .= "}\n";
2463 $code .= "#endif // ${conditionalString}\n" if $conditionalString; 2463 $code .= "#endif // ${conditionalString}\n" if $conditionalString;
2464 $code .= "\n"; 2464 $code .= "\n";
2465 $implementation{nameSpaceInternal}->add($code); 2465 $implementation{nameSpaceInternal}->add($code);
2466 } 2466 }
2467 2467
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
2536 $argumentsCountCheckString .= " }\n"; 2536 $argumentsCountCheckString .= " }\n";
2537 } 2537 }
2538 return $argumentsCountCheckString; 2538 return $argumentsCountCheckString;
2539 } 2539 }
2540 2540
2541 sub GenerateParametersCheck 2541 sub GenerateParametersCheck
2542 { 2542 {
2543 my $function = shift; 2543 my $function = shift;
2544 my $interface = shift; 2544 my $interface = shift;
2545 my $forMainWorldSuffix = shift; 2545 my $forMainWorldSuffix = shift;
2546 my $hasExceptionState = shift;
2546 my $style = shift || "new"; 2547 my $style = shift || "new";
2547 2548
2548 my $functionName = $function->name; 2549 my $functionName = $function->name;
2549 my $interfaceName = $interface->name; 2550 my $interfaceName = $interface->name;
2550 my $implClassName = GetImplName($interface); 2551 my $implClassName = GetImplName($interface);
2551 2552
2552 my $parameterCheckString = ""; 2553 my $parameterCheckString = "";
2553 my $paramIndex = 0; 2554 my $paramIndex = 0;
2554 my %replacements = (); 2555 my %replacements = ();
2555 2556
(...skipping 13 matching lines...) Expand all
2569 } 2570 }
2570 END 2571 END
2571 } 2572 }
2572 2573
2573 my $parameterName = $parameter->name; 2574 my $parameterName = $parameter->name;
2574 if (IsCallbackInterface($parameter->type)) { 2575 if (IsCallbackInterface($parameter->type)) {
2575 my $v8ClassName = "V8" . $parameter->type; 2576 my $v8ClassName = "V8" . $parameter->type;
2576 AddToImplIncludes("$v8ClassName.h"); 2577 AddToImplIncludes("$v8ClassName.h");
2577 if ($parameter->isOptional) { 2578 if ($parameter->isOptional) {
2578 $parameterCheckString .= " OwnPtr<" . $parameter->type . "> $ parameterName;\n"; 2579 $parameterCheckString .= " OwnPtr<" . $parameter->type . "> $ parameterName;\n";
2579 $parameterCheckString .= " if (info.Length() > $paramIndex && !info[$paramIndex]->IsNull() && !info[$paramIndex]->IsUndefined()) {\n"; 2580 $parameterCheckString .= " if (info.Length() > $paramIndex && !isUndefinedOrNull(info[$paramIndex])) {\n";
2580 $parameterCheckString .= " if (!info[$paramIndex]->IsFunc tion()) {\n"; 2581 $parameterCheckString .= " if (!info[$paramIndex]->IsFunc tion()) {\n";
2581 $parameterCheckString .= " throwTypeError(ExceptionMe ssages::failedToExecute(\"$functionName\", \"$interfaceName\", \"The callback pr ovided as parameter $humanFriendlyIndex is not a function.\"), info.GetIsolate() );\n"; 2582 if ($hasExceptionState) {
2583 $parameterCheckString .= " exceptionState.throwTy peError(\"The callback provided as parameter $humanFriendlyIndex is not a functi on.\");\n";
2584 $parameterCheckString .= " exceptionState.throwIf Needed();\n";
2585 } else {
2586 $parameterCheckString .= " throwTypeError(Excepti onMessages::failedToExecute(\"$functionName\", \"$interfaceName\", \"The callbac k provided as parameter $humanFriendlyIndex is not a function.\"), info.GetIsola te());\n";
2587 }
2582 $parameterCheckString .= " return;\n"; 2588 $parameterCheckString .= " return;\n";
2583 $parameterCheckString .= " }\n"; 2589 $parameterCheckString .= " }\n";
2584 $parameterCheckString .= " $parameterName = ${v8ClassName }::create(v8::Handle<v8::Function>::Cast(info[$paramIndex]), getExecutionContext ());\n"; 2590 $parameterCheckString .= " $parameterName = ${v8ClassName }::create(v8::Handle<v8::Function>::Cast(info[$paramIndex]), getExecutionContext ());\n";
2585 $parameterCheckString .= " }\n"; 2591 $parameterCheckString .= " }\n";
2586 } else { 2592 } else {
2587 $parameterCheckString .= " if (info.Length() <= $paramIndex | | "; 2593 $parameterCheckString .= " if (info.Length() <= $paramIndex | | ";
2588 if ($parameter->isNullable) { 2594 if ($parameter->isNullable) {
2589 $parameterCheckString .= "!(info[$paramIndex]->IsFunction() || info[$paramIndex]->IsNull())"; 2595 $parameterCheckString .= "!(info[$paramIndex]->IsFunction() || info[$paramIndex]->IsNull())";
2590 } else { 2596 } else {
2591 $parameterCheckString .= "!info[$paramIndex]->IsFunction()"; 2597 $parameterCheckString .= "!info[$paramIndex]->IsFunction()";
2592 } 2598 }
2593 $parameterCheckString .= ") {\n"; 2599 $parameterCheckString .= ") {\n";
2594 $parameterCheckString .= " throwTypeError(ExceptionMessag es::failedToExecute(\"$functionName\", \"$interfaceName\", \"The callback provid ed as parameter $humanFriendlyIndex is not a function.\"), info.GetIsolate());\n "; 2600 if ($hasExceptionState) {
2601 $parameterCheckString .= " exceptionState.throwTypeEr ror(\"The callback provided as parameter $humanFriendlyIndex is not a function.\ ");\n";
2602 $parameterCheckString .= " exceptionState.throwIfNeed ed();\n";
2603 } else {
2604 $parameterCheckString .= " throwTypeError(ExceptionMe ssages::failedToExecute(\"$functionName\", \"$interfaceName\", \"The callback pr ovided as parameter $humanFriendlyIndex is not a function.\"), info.GetIsolate() );\n";
2605 }
2595 $parameterCheckString .= " return;\n"; 2606 $parameterCheckString .= " return;\n";
2596 $parameterCheckString .= " }\n"; 2607 $parameterCheckString .= " }\n";
2597 $parameterCheckString .= " OwnPtr<" . $parameter->type . "> $ parameterName = "; 2608 $parameterCheckString .= " OwnPtr<" . $parameter->type . "> $ parameterName = ";
2598 $parameterCheckString .= "info[$paramIndex]->IsNull() ? nullptr : " if $parameter->isNullable; 2609 $parameterCheckString .= "info[$paramIndex]->IsNull() ? nullptr : " if $parameter->isNullable;
2599 $parameterCheckString .= "${v8ClassName}::create(v8::Handle<v8:: Function>::Cast(info[$paramIndex]), getExecutionContext());\n"; 2610 $parameterCheckString .= "${v8ClassName}::create(v8::Handle<v8:: Function>::Cast(info[$paramIndex]), getExecutionContext());\n";
2600 } 2611 }
2601 } elsif ($parameter->extendedAttributes->{"Clamp"}) { 2612 } elsif ($parameter->extendedAttributes->{"Clamp"}) {
2602 my $nativeValue = "${parameterName}NativeValue"; 2613 my $nativeValue = "${parameterName}NativeValue";
2603 my $idlType = $parameter->type; 2614 my $idlType = $parameter->type;
2604 $parameterCheckString .= " $nativeType $parameterName = 0;\n" ; 2615 $parameterCheckString .= " $nativeType $parameterName = 0;\n" ;
2605 $parameterCheckString .= " V8TRYCATCH_VOID(double, $nativeVal ue, info[$paramIndex]->NumberValue());\n"; 2616 $parameterCheckString .= " V8TRYCATCH_VOID(double, $nativeVal ue, info[$paramIndex]->NumberValue());\n";
2606 $parameterCheckString .= " if (!std::isnan($nativeValue))\n"; 2617 $parameterCheckString .= " if (!std::isnan($nativeValue))\n";
2607 $parameterCheckString .= " $parameterName = clampTo<$idlT ype>($nativeValue);\n"; 2618 $parameterCheckString .= " $parameterName = clampTo<$idlT ype>($nativeValue);\n";
2608 } elsif ($parameter->type eq "SerializedScriptValue") { 2619 } elsif ($parameter->type eq "SerializedScriptValue") {
2609 AddToImplIncludes("bindings/v8/SerializedScriptValue.h"); 2620 AddToImplIncludes("bindings/v8/SerializedScriptValue.h");
2610 $parameterCheckString .= " bool ${parameterName}DidThrow = false; \n"; 2621 $parameterCheckString .= " $nativeType $parameterName = Serialize dScriptValue::create(info[$paramIndex], 0, 0, exceptionState, info.GetIsolate()) ;\n";
2611 $parameterCheckString .= " $nativeType $parameterName = Serialize dScriptValue::create(info[$paramIndex], 0, 0, ${parameterName}DidThrow, info.Get Isolate());\n"; 2622 $parameterCheckString .= " if (exceptionState.throwIfNeeded())\n" ;
2612 $parameterCheckString .= " if (${parameterName}DidThrow)\n";
2613 $parameterCheckString .= " return;\n"; 2623 $parameterCheckString .= " return;\n";
2614 } elsif ($parameter->isVariadic) { 2624 } elsif ($parameter->isVariadic) {
2615 my $nativeElementType = GetNativeType($parameter->type); 2625 my $nativeElementType = GetNativeType($parameter->type);
2616 if ($nativeElementType =~ />$/) { 2626 if ($nativeElementType =~ />$/) {
2617 $nativeElementType .= " "; 2627 $nativeElementType .= " ";
2618 } 2628 }
2619 2629
2620 my $argType = $parameter->type; 2630 my $argType = $parameter->type;
2621 if (IsWrapperType($argType)) { 2631 if (IsWrapperType($argType)) {
2622 $parameterCheckString .= " Vector<$nativeElementType> $parame terName;\n"; 2632 $parameterCheckString .= " Vector<$nativeElementType> $parame terName;\n";
2623 $parameterCheckString .= " for (int i = $paramIndex; i < info .Length(); ++i) {\n"; 2633 $parameterCheckString .= " for (int i = $paramIndex; i < info .Length(); ++i) {\n";
2624 $parameterCheckString .= " if (!V8${argType}::hasInstance (info[i], info.GetIsolate(), worldType(info.GetIsolate()))) {\n"; 2634 $parameterCheckString .= " if (!V8${argType}::hasInstance (info[i], info.GetIsolate(), worldType(info.GetIsolate()))) {\n";
2625 $parameterCheckString .= " throwTypeError(ExceptionMe ssages::failedToExecute(\"$functionName\", \"$interfaceName\", \"parameter $huma nFriendlyIndex is not of type \'$argType\'.\"), info.GetIsolate());\n"; 2635 if ($hasExceptionState) {
2636 $parameterCheckString .= " exceptionState.throwTy peError(\"parameter $humanFriendlyIndex is not of type \'$argType\'.\");\n";
2637 $parameterCheckString .= " exceptionState.throwIf Needed();\n";
2638 } else {
2639 $parameterCheckString .= " throwTypeError(Excepti onMessages::failedToExecute(\"$functionName\", \"$interfaceName\", \"parameter $ humanFriendlyIndex is not of type \'$argType\'.\"), info.GetIsolate());\n";
2640 }
2626 $parameterCheckString .= " return;\n"; 2641 $parameterCheckString .= " return;\n";
2627 $parameterCheckString .= " }\n"; 2642 $parameterCheckString .= " }\n";
2628 $parameterCheckString .= " $parameterName.append(V8${argT ype}::toNative(v8::Handle<v8::Object>::Cast(info[i])));\n"; 2643 $parameterCheckString .= " $parameterName.append(V8${argT ype}::toNative(v8::Handle<v8::Object>::Cast(info[i])));\n";
2629 $parameterCheckString .= " }\n"; 2644 $parameterCheckString .= " }\n";
2630 } else { 2645 } else {
2631 $parameterCheckString .= " V8TRYCATCH_VOID(Vector<$nativeElem entType>, $parameterName, toNativeArguments<$nativeElementType>(info, $paramInde x));\n"; 2646 $parameterCheckString .= " V8TRYCATCH_VOID(Vector<$nativeElem entType>, $parameterName, toNativeArguments<$nativeElementType>(info, $paramInde x));\n";
2632 } 2647 }
2633 } elsif ($nativeType =~ /^V8StringResource/) { 2648 } elsif ($nativeType =~ /^V8StringResource/) {
2634 my $default = defined $parameter->extendedAttributes->{"Default"} ? $parameter->extendedAttributes->{"Default"} : ""; 2649 my $default = defined $parameter->extendedAttributes->{"Default"} ? $parameter->extendedAttributes->{"Default"} : "";
2635 my $jsValue = $parameter->isOptional && $default eq "NullString" ? " argumentOrNull(info, $paramIndex)" : "info[$paramIndex]"; 2650 my $jsValue = $parameter->isOptional && $default eq "NullString" ? " argumentOrNull(info, $paramIndex)" : "info[$paramIndex]";
2636 my $stringResourceParameterName = $parameterName; 2651 my $stringResourceParameterName = $parameterName;
2637 my $isNullable = IsNullableParameter($parameter); 2652 my $isNullable = IsNullableParameter($parameter);
2638 if ($isNullable) { 2653 if ($isNullable) {
2639 $parameterCheckString .= " bool ${parameterName}IsNull = $jsV alue->IsNull();\n"; 2654 $parameterCheckString .= " bool ${parameterName}IsNull = $jsV alue->IsNull();\n";
2640 $stringResourceParameterName .= "StringResource"; 2655 $stringResourceParameterName .= "StringResource";
2641 } 2656 }
2642 $parameterCheckString .= JSValueToNativeStatement($parameter->type, $parameter->extendedAttributes, $humanFriendlyIndex, $jsValue, $stringResourcePa rameterName, " ", "info.GetIsolate()"); 2657 $parameterCheckString .= JSValueToNativeStatement($parameter->type, $parameter->extendedAttributes, $humanFriendlyIndex, $jsValue, $stringResourcePa rameterName, " ", "info.GetIsolate()");
2643 $parameterCheckString .= " String $parameterName = $stringResourc eParameterName;\n" if $isNullable; 2658 $parameterCheckString .= " String $parameterName = $stringResourc eParameterName;\n" if $isNullable;
2644 if (IsEnumType($parameter->type)) { 2659 if (IsEnumType($parameter->type)) {
2645 my @enumValues = ValidEnumValues($parameter->type); 2660 my @enumValues = ValidEnumValues($parameter->type);
2646 my @validEqualities = (); 2661 my @validEqualities = ();
2647 foreach my $enumValue (@enumValues) { 2662 foreach my $enumValue (@enumValues) {
2648 push(@validEqualities, "string == \"$enumValue\""); 2663 push(@validEqualities, "string == \"$enumValue\"");
2649 } 2664 }
2650 my $enumValidationExpression = join(" || ", @validEqualities); 2665 my $enumValidationExpression = join(" || ", @validEqualities);
2651 $parameterCheckString .= " String string = $parameterName;\n "; 2666 $parameterCheckString .= " String string = $parameterName;\n ";
2652 $parameterCheckString .= " if (!($enumValidationExpression)) {\n"; 2667 $parameterCheckString .= " if (!($enumValidationExpression)) {\n";
2653 $parameterCheckString .= " throwTypeError(ExceptionMessag es::failedToExecute(\"$functionName\", \"$interfaceName\", \"parameter $humanFri endlyIndex (\'\" + string + \"\') is not a valid enum value.\"), info.GetIsolate ());\n"; 2668 if ($hasExceptionState) {
2669 $parameterCheckString .= " exceptionState.throwTypeEr ror(\"parameter $humanFriendlyIndex (\'\" + string + \"\') is not a valid enum v alue.\");\n";
2670 $parameterCheckString .= " exceptionState.throwIfNeed ed();\n";
2671 } else {
2672 $parameterCheckString .= " throwTypeError(ExceptionMe ssages::failedToExecute(\"$functionName\", \"$interfaceName\", \"parameter $huma nFriendlyIndex (\'\" + string + \"\') is not a valid enum value.\"), info.GetIso late());\n";
2673 }
2654 $parameterCheckString .= " return;\n"; 2674 $parameterCheckString .= " return;\n";
2655 $parameterCheckString .= " }\n"; 2675 $parameterCheckString .= " }\n";
2656 } 2676 }
2657 } else { 2677 } else {
2658 # If the "StrictTypeChecking" extended attribute is present, and the argument's type is an 2678 # If the "StrictTypeChecking" extended attribute is present, and the argument's type is an
2659 # interface type, then if the incoming value does not implement that interface, a TypeError 2679 # interface type, then if the incoming value does not implement that interface, a TypeError
2660 # is thrown rather than silently passing NULL to the C++ code. 2680 # is thrown rather than silently passing NULL to the C++ code.
2661 # Per the Web IDL and ECMAScript specifications, incoming values can always be converted 2681 # Per the Web IDL and ECMAScript specifications, incoming values can always be converted
2662 # to both strings and numbers, so do not throw TypeError if the argu ment is of these 2682 # to both strings and numbers, so do not throw TypeError if the argu ment is of these
2663 # types. 2683 # types.
2664 if ($function->extendedAttributes->{"StrictTypeChecking"}) { 2684 if ($function->extendedAttributes->{"StrictTypeChecking"}) {
2665 my $argValue = "info[$paramIndex]"; 2685 my $argValue = "info[$paramIndex]";
2666 my $argType = $parameter->type; 2686 my $argType = $parameter->type;
2667 if (IsWrapperType($argType)) { 2687 if (IsWrapperType($argType)) {
2668 $parameterCheckString .= " if (info.Length() > $paramInde x && !isUndefinedOrNull($argValue) && !V8${argType}::hasInstance($argValue, info .GetIsolate(), worldType(info.GetIsolate()))) {\n"; 2688 $parameterCheckString .= " if (info.Length() > $paramInde x && !isUndefinedOrNull($argValue) && !V8${argType}::hasInstance($argValue, info .GetIsolate(), worldType(info.GetIsolate()))) {\n";
2669 $parameterCheckString .= " throwTypeError(ExceptionMe ssages::failedToExecute(\"$functionName\", \"$interfaceName\", \"parameter $huma nFriendlyIndex is not of type \'$argType\'.\"), info.GetIsolate());\n"; 2689 if ($hasExceptionState) {
2690 $parameterCheckString .= " exceptionState.throwTy peError(\"parameter $humanFriendlyIndex is not of type \'$argType\'.\");\n";
2691 $parameterCheckString .= " exceptionState.throwIf Needed();\n";
2692 }else {
2693 $parameterCheckString .= " throwTypeError(Excepti onMessages::failedToExecute(\"$functionName\", \"$interfaceName\", \"parameter $ humanFriendlyIndex is not of type \'$argType\'.\"), info.GetIsolate());\n";
2694 }
2670 $parameterCheckString .= " return;\n"; 2695 $parameterCheckString .= " return;\n";
2671 $parameterCheckString .= " }\n"; 2696 $parameterCheckString .= " }\n";
2672 } 2697 }
2673 } 2698 }
2674 my $default = defined $parameter->extendedAttributes->{"Default"} ? $parameter->extendedAttributes->{"Default"} : ""; 2699 my $default = defined $parameter->extendedAttributes->{"Default"} ? $parameter->extendedAttributes->{"Default"} : "";
2675 my $jsValue = $parameter->isOptional && $default eq "NullString" ? " argumentOrNull(info, $paramIndex)" : "info[$paramIndex]"; 2700 my $jsValue = $parameter->isOptional && $default eq "NullString" ? " argumentOrNull(info, $paramIndex)" : "info[$paramIndex]";
2676 my $isNullable = IsNullableParameter($parameter); 2701 my $isNullable = IsNullableParameter($parameter);
2677 $parameterCheckString .= " bool ${parameterName}IsNull = $jsValue ->IsNull();\n" if $isNullable; 2702 $parameterCheckString .= " bool ${parameterName}IsNull = $jsValue ->IsNull();\n" if $isNullable;
2678 $parameterCheckString .= JSValueToNativeStatement($parameter->type, $parameter->extendedAttributes, $humanFriendlyIndex, $jsValue, $parameterName, " ", "info.GetIsolate()"); 2703 $parameterCheckString .= JSValueToNativeStatement($parameter->type, $parameter->extendedAttributes, $humanFriendlyIndex, $jsValue, $parameterName, " ", "info.GetIsolate()");
2679 if ($nativeType eq 'Dictionary' or $nativeType eq 'ScriptPromise') { 2704 if ($nativeType eq 'Dictionary' or $nativeType eq 'ScriptPromise') {
2680 $parameterCheckString .= " if (!$parameterName.isUndefinedOrN ull() && !$parameterName.isObject()) {\n"; 2705 $parameterCheckString .= " if (!$parameterName.isUndefinedOrN ull() && !$parameterName.isObject()) {\n";
2681 if ($functionName eq "Constructor") { 2706 if ($hasExceptionState) {
2707 $parameterCheckString .= " exceptionState.throwTypeEr ror(\"parameter ${humanFriendlyIndex} ('${parameterName}') is not an object.\"); \n";
2708 $parameterCheckString .= " exceptionState.throwIfNeed ed();\n";
2709 } elsif ($functionName eq "Constructor") {
2682 $parameterCheckString .= " throwTypeError(ExceptionMe ssages::failedToConstruct(\"$interfaceName\", \"parameter ${humanFriendlyIndex} ('${parameterName}') is not an object.\"), info.GetIsolate());\n"; 2710 $parameterCheckString .= " throwTypeError(ExceptionMe ssages::failedToConstruct(\"$interfaceName\", \"parameter ${humanFriendlyIndex} ('${parameterName}') is not an object.\"), info.GetIsolate());\n";
2683 } else { 2711 } else {
2684 $parameterCheckString .= " throwTypeError(ExceptionMe ssages::failedToExecute(\"$functionName\", \"$interfaceName\", \"parameter ${hum anFriendlyIndex} ('${parameterName}') is not an object.\"), info.GetIsolate());\ n"; 2712 $parameterCheckString .= " throwTypeError(ExceptionMe ssages::failedToExecute(\"$functionName\", \"$interfaceName\", \"parameter ${hum anFriendlyIndex} ('${parameterName}') is not an object.\"), info.GetIsolate());\ n";
2685 } 2713 }
2686 $parameterCheckString .= " return;\n"; 2714 $parameterCheckString .= " return;\n";
2687 $parameterCheckString .= " }\n"; 2715 $parameterCheckString .= " }\n";
2688 } 2716 }
2689 } 2717 }
2690 2718
2691 $paramIndex++; 2719 $paramIndex++;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2740 2768
2741 my $interfaceName = $interface->name; 2769 my $interfaceName = $interface->name;
2742 my $implClassName = GetImplName($interface); 2770 my $implClassName = GetImplName($interface);
2743 my $v8ClassName = GetV8ClassName($interface); 2771 my $v8ClassName = GetV8ClassName($interface);
2744 my $overloadedIndexString = ""; 2772 my $overloadedIndexString = "";
2745 if ($function->overloadedIndex > 0) { 2773 if ($function->overloadedIndex > 0) {
2746 $overloadedIndexString .= $function->overloadedIndex; 2774 $overloadedIndexString .= $function->overloadedIndex;
2747 } 2775 }
2748 2776
2749 my $constructorRaisesException = $interface->extendedAttributes->{"RaisesExc eption"} && $interface->extendedAttributes->{"RaisesException"} eq "Constructor" ; 2777 my $constructorRaisesException = $interface->extendedAttributes->{"RaisesExc eption"} && $interface->extendedAttributes->{"RaisesException"} eq "Constructor" ;
2750 my $raisesExceptions = $function->extendedAttributes->{"RaisesException"} || $constructorRaisesException; 2778 my $raisesExceptions = $function->extendedAttributes->{"RaisesException"} || $constructorRaisesException || HasSerializedScriptValueParameter($function);
2751 2779
2752 my @beforeArgumentList; 2780 my @beforeArgumentList;
2753 my @afterArgumentList; 2781 my @afterArgumentList;
2754 my $code = ""; 2782 my $code = "";
2755 $code .= <<END; 2783 $code .= <<END;
2756 static void constructor${overloadedIndexString}(const v8::FunctionCallbackInfo<v 8::Value>& info) 2784 static void constructor${overloadedIndexString}(const v8::FunctionCallbackInfo<v 8::Value>& info)
2757 { 2785 {
2758 END 2786 END
2759 2787
2760 if ($function->overloadedIndex == 0) { 2788 if ($function->overloadedIndex == 0) {
2761 my $hasExceptionState = 0; 2789 my $hasExceptionState = 0;
2762 $code .= GenerateArgumentsCountCheck($function, $interface, $hasExceptio nState); 2790 $code .= GenerateArgumentsCountCheck($function, $interface, $hasExceptio nState);
2763 } 2791 }
2764 2792
2765 if ($raisesExceptions) { 2793 if ($raisesExceptions) {
2766 $code .= " ExceptionState exceptionState(ExceptionState::Construction Context, \"${interfaceName}\", info.Holder(), info.GetIsolate());\n"; 2794 $code .= " ExceptionState exceptionState(ExceptionState::Construction Context, \"${interfaceName}\", info.Holder(), info.GetIsolate());\n";
2767 } 2795 }
2768 2796
2769 # FIXME: Currently [Constructor(...)] does not yet support optional argument s without [Default=...] 2797 # FIXME: Currently [Constructor(...)] does not yet support optional argument s without [Default=...]
2770 my ($parameterCheckString, $paramIndex, %replacements) = GenerateParametersC heck($function, $interface, ""); 2798 my ($parameterCheckString, $paramIndex, %replacements) = GenerateParametersC heck($function, $interface, "", $raisesExceptions);
2771 $code .= $parameterCheckString; 2799 $code .= $parameterCheckString;
2772 2800
2773 if ($interface->extendedAttributes->{"ConstructorCallWith"}) { 2801 if ($interface->extendedAttributes->{"ConstructorCallWith"}) {
2774 if (ExtendedAttributeContains($interface->extendedAttributes->{"Construc torCallWith"}, "ExecutionContext")) { 2802 if (ExtendedAttributeContains($interface->extendedAttributes->{"Construc torCallWith"}, "ExecutionContext")) {
2775 push(@beforeArgumentList, "context"); 2803 push(@beforeArgumentList, "context");
2776 $code .= " ExecutionContext* context = getExecutionContext();\n"; 2804 $code .= " ExecutionContext* context = getExecutionContext();\n";
2777 } 2805 }
2778 if (ExtendedAttributeContains($interface->extendedAttributes->{"Construc torCallWith"}, "Document")) { 2806 if (ExtendedAttributeContains($interface->extendedAttributes->{"Construc torCallWith"}, "Document")) {
2779 push(@beforeArgumentList, "document"); 2807 push(@beforeArgumentList, "document");
2780 $code .= " Document& document = *toDocument(getExecutionContext() );\n"; 2808 $code .= " Document& document = *toDocument(getExecutionContext() );\n";
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
2948 if (exceptionState.throwIfNeeded()) 2976 if (exceptionState.throwIfNeeded())
2949 return; 2977 return;
2950 END 2978 END
2951 } 2979 }
2952 2980
2953 if (@anyAttributeNames) { 2981 if (@anyAttributeNames) {
2954 # Separate check to simplify Python code 2982 # Separate check to simplify Python code
2955 AddToImplIncludes("bindings/v8/SerializedScriptValue.h"); 2983 AddToImplIncludes("bindings/v8/SerializedScriptValue.h");
2956 } 2984 }
2957 if (@anyAttributeNames && $interface->name ne 'ErrorEvent') { 2985 if (@anyAttributeNames && $interface->name ne 'ErrorEvent') {
2958 # If we're in an isolated world, create a SerializedScriptValue andi 2986 # If we're in an isolated world, create a SerializedScriptValue and
2959 # store it in the event for later cloning if the property is accessed 2987 # store it in the event for later cloning if the property is accessed
2960 # from another world. 2988 # from another world.
2961 # The main world case is handled lazily (in Custom code). 2989 # The main world case is handled lazily (in Custom code).
2962 # 2990 #
2963 # We do not clone Error objects (exceptions), for 2 reasons: 2991 # We do not clone Error objects (exceptions), for 2 reasons:
2964 # 1) Errors carry a reference to the isolated world's global object, 2992 # 1) Errors carry a reference to the isolated world's global object,
2965 # and thus passing it around would cause leakage. 2993 # and thus passing it around would cause leakage.
2966 # 2) Errors cannot be cloned (or serialized): 2994 # 2) Errors cannot be cloned (or serialized):
2967 # http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom -interfaces.html#safe-passing-of-structured-data 2995 # http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom -interfaces.html#safe-passing-of-structured-data
2968 $implementation{nameSpaceInternal}->add(" if (isolatedWorldForIsolate (info.GetIsolate())) {\n"); 2996 $implementation{nameSpaceInternal}->add(" if (isolatedWorldForIsolate (info.GetIsolate())) {\n");
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
3034 3062
3035 sub GenerateNamedConstructor 3063 sub GenerateNamedConstructor
3036 { 3064 {
3037 my $function = shift; 3065 my $function = shift;
3038 my $interface = shift; 3066 my $interface = shift;
3039 3067
3040 my $interfaceName = $interface->name; 3068 my $interfaceName = $interface->name;
3041 my $implClassName = GetImplName($interface); 3069 my $implClassName = GetImplName($interface);
3042 my $v8ClassName = GetV8ClassName($interface); 3070 my $v8ClassName = GetV8ClassName($interface);
3043 my $constructorRaisesException = $interface->extendedAttributes->{"RaisesExc eption"} && $interface->extendedAttributes->{"RaisesException"} eq "Constructor" ; 3071 my $constructorRaisesException = $interface->extendedAttributes->{"RaisesExc eption"} && $interface->extendedAttributes->{"RaisesException"} eq "Constructor" ;
3044 my $raisesExceptions = $function->extendedAttributes->{"RaisesException"} || $constructorRaisesException; 3072 my $raisesExceptions = $function->extendedAttributes->{"RaisesException"} || $constructorRaisesException || HasSerializedScriptValueParameter($function);
3045 3073
3046 my $maybeObserveFeature = GenerateFeatureObservation($function->extendedAttr ibutes->{"MeasureAs"}); 3074 my $maybeObserveFeature = GenerateFeatureObservation($function->extendedAttr ibutes->{"MeasureAs"});
3047 my $maybeDeprecateFeature = GenerateDeprecationNotification($function->exten dedAttributes->{"DeprecateAs"}); 3075 my $maybeDeprecateFeature = GenerateDeprecationNotification($function->exten dedAttributes->{"DeprecateAs"});
3048 3076
3049 my @beforeArgumentList; 3077 my @beforeArgumentList;
3050 my @afterArgumentList; 3078 my @afterArgumentList;
3051 3079
3052 my $toActiveDOMObject = "0"; 3080 my $toActiveDOMObject = "0";
3053 if (InheritsExtendedAttribute($interface, "ActiveDOMObject")) { 3081 if (InheritsExtendedAttribute($interface, "ActiveDOMObject")) {
3054 $toActiveDOMObject = "${v8ClassName}::toActiveDOMObject"; 3082 $toActiveDOMObject = "${v8ClassName}::toActiveDOMObject";
(...skipping 27 matching lines...) Expand all
3082 3110
3083 END 3111 END
3084 3112
3085 if ($raisesExceptions) { 3113 if ($raisesExceptions) {
3086 $code .= " ExceptionState exceptionState(ExceptionState::Construction Context, \"${interfaceName}\", info.Holder(), info.GetIsolate());\n"; 3114 $code .= " ExceptionState exceptionState(ExceptionState::Construction Context, \"${interfaceName}\", info.Holder(), info.GetIsolate());\n";
3087 } 3115 }
3088 3116
3089 my $hasExceptionState = $raisesExceptions; 3117 my $hasExceptionState = $raisesExceptions;
3090 $code .= GenerateArgumentsCountCheck($function, $interface, $hasExceptionSta te); 3118 $code .= GenerateArgumentsCountCheck($function, $interface, $hasExceptionSta te);
3091 3119
3092 my ($parameterCheckString, $paramIndex, %replacements) = GenerateParametersC heck($function, $interface); 3120 my ($parameterCheckString, $paramIndex, %replacements) = GenerateParametersC heck($function, $interface, "", $raisesExceptions);
3093 $code .= $parameterCheckString; 3121 $code .= $parameterCheckString;
3094 3122
3095 push(@beforeArgumentList, "*document"); 3123 push(@beforeArgumentList, "*document");
3096 3124
3097 if ($constructorRaisesException) { 3125 if ($constructorRaisesException) {
3098 push(@afterArgumentList, "exceptionState"); 3126 push(@afterArgumentList, "exceptionState");
3099 } 3127 }
3100 3128
3101 my @argumentList; 3129 my @argumentList;
3102 my $index = 0; 3130 my $index = 0;
(...skipping 3233 matching lines...) Expand 10 before | Expand all | Expand 10 after
6336 my $interface = shift; 6364 my $interface = shift;
6337 6365
6338 return 1 if ExtendedAttributeContains($interface->extendedAttributes->{"Cust om"}, "ToV8"); 6366 return 1 if ExtendedAttributeContains($interface->extendedAttributes->{"Cust om"}, "ToV8");
6339 return 1 if ExtendedAttributeContains($interface->extendedAttributes->{"Cust om"}, "Wrap"); 6367 return 1 if ExtendedAttributeContains($interface->extendedAttributes->{"Cust om"}, "Wrap");
6340 return 1 if $interface->extendedAttributes->{"SpecialWrapFor"}; 6368 return 1 if $interface->extendedAttributes->{"SpecialWrapFor"};
6341 return 1 if InheritsInterface($interface, "Document"); 6369 return 1 if InheritsInterface($interface, "Document");
6342 6370
6343 return 0; 6371 return 0;
6344 } 6372 }
6345 6373
6374 sub HasSerializedScriptValueParameter
6375 {
6376 my $function = shift;
6377
6378 foreach my $parameter (@{$function->parameters}) {
6379 if ($parameter->type eq "SerializedScriptValue") {
6380 return 1;
6381 }
6382 }
6383 return 0;
6384 }
6385
6346 1; 6386 1;
OLDNEW
« no previous file with comments | « LayoutTests/storage/indexeddb/structured-clone-expected.txt ('k') | Source/bindings/tests/results/V8SupportTestInterface.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698