OLD | NEW |
---|---|
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. |
11 # Copyright (C) 2013 Samsung Electronics. All rights reserved. | |
11 # | 12 # |
12 # This library is free software; you can redistribute it and/or | 13 # This library is free software; you can redistribute it and/or |
13 # modify it under the terms of the GNU Library General Public | 14 # modify it under the terms of the GNU Library General Public |
14 # License as published by the Free Software Foundation; either | 15 # License as published by the Free Software Foundation; either |
15 # version 2 of the License, or (at your option) any later version. | 16 # version 2 of the License, or (at your option) any later version. |
16 # | 17 # |
17 # This library is distributed in the hope that it will be useful, | 18 # This library is distributed in the hope that it will be useful, |
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
20 # Library General Public License for more details. | 21 # Library General Public License for more details. |
(...skipping 1628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1649 | 1650 |
1650 # Only DOMString or wrapper types are checked. | 1651 # Only DOMString or wrapper types are checked. |
1651 # For DOMString with StrictTypeChecking only Null, Undefined and Object | 1652 # For DOMString with StrictTypeChecking only Null, Undefined and Object |
1652 # are accepted for compatibility. Otherwise, no restrictions are made to | 1653 # are accepted for compatibility. Otherwise, no restrictions are made to |
1653 # match the non-overloaded behavior. | 1654 # match the non-overloaded behavior. |
1654 # FIXME: Implement WebIDL overload resolution algorithm. | 1655 # FIXME: Implement WebIDL overload resolution algorithm. |
1655 if ($codeGenerator->IsStringType($type)) { | 1656 if ($codeGenerator->IsStringType($type)) { |
1656 if ($parameter->extendedAttributes->{"StrictTypeChecking"}) { | 1657 if ($parameter->extendedAttributes->{"StrictTypeChecking"}) { |
1657 push(@andExpression, "(${value}->IsNull() || ${value}->IsUndefin ed() || ${value}->IsString() || ${value}->IsObject())"); | 1658 push(@andExpression, "(${value}->IsNull() || ${value}->IsUndefin ed() || ${value}->IsString() || ${value}->IsObject())"); |
1658 } | 1659 } |
1659 } elsif ($parameter->extendedAttributes->{"Callback"}) { | 1660 } elsif (IsCallbackInterface($parameter->type)) { |
1660 # For Callbacks only checks if the value is null or object. | 1661 # For Callbacks only checks if the value is null or object. |
1661 push(@andExpression, "(${value}->IsNull() || ${value}->IsFunction()) "); | 1662 push(@andExpression, "(${value}->IsNull() || ${value}->IsFunction()) "); |
1662 } elsif ($codeGenerator->GetArrayType($type) || $codeGenerator->GetSeque nceType($type)) { | 1663 } elsif ($codeGenerator->GetArrayType($type) || $codeGenerator->GetSeque nceType($type)) { |
1663 if ($parameter->isNullable) { | 1664 if ($parameter->isNullable) { |
1664 push(@andExpression, "(${value}->IsNull() || ${value}->IsArray() )"); | 1665 push(@andExpression, "(${value}->IsNull() || ${value}->IsArray() )"); |
1665 } else { | 1666 } else { |
1666 push(@andExpression, "(${value}->IsArray())"); | 1667 push(@andExpression, "(${value}->IsArray())"); |
1667 } | 1668 } |
1668 } elsif (IsWrapperType($type)) { | 1669 } elsif (IsWrapperType($type)) { |
1669 if ($parameter->isNullable) { | 1670 if ($parameter->isNullable) { |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1894 AddToImplIncludes("core/page/Frame.h"); | 1895 AddToImplIncludes("core/page/Frame.h"); |
1895 $code .= <<END; | 1896 $code .= <<END; |
1896 if (!BindingSecurity::shouldAllowAccessToFrame(BindingState::instance(), imp ->frame())) | 1897 if (!BindingSecurity::shouldAllowAccessToFrame(BindingState::instance(), imp ->frame())) |
1897 return v8Undefined(); | 1898 return v8Undefined(); |
1898 END | 1899 END |
1899 } | 1900 } |
1900 | 1901 |
1901 my $raisesExceptions = $function->signature->extendedAttributes->{"RaisesExc eption"}; | 1902 my $raisesExceptions = $function->signature->extendedAttributes->{"RaisesExc eption"}; |
1902 if (!$raisesExceptions) { | 1903 if (!$raisesExceptions) { |
1903 foreach my $parameter (@{$function->parameters}) { | 1904 foreach my $parameter (@{$function->parameters}) { |
1904 if ((!$parameter->extendedAttributes->{"Callback"} and TypeCanFailCo nversion($parameter)) or $parameter->extendedAttributes->{"IsIndex"}) { | 1905 if ((!IsCallbackInterface($parameter->type) and TypeCanFailConversio n($parameter)) or $parameter->extendedAttributes->{"IsIndex"}) { |
1905 $raisesExceptions = 1; | 1906 $raisesExceptions = 1; |
1906 } | 1907 } |
1907 } | 1908 } |
1908 } | 1909 } |
1909 | 1910 |
1910 if ($raisesExceptions) { | 1911 if ($raisesExceptions) { |
1911 AddToImplIncludes("ExceptionCode.h"); | 1912 AddToImplIncludes("ExceptionCode.h"); |
1912 $code .= " ExceptionCode ec = 0;\n"; | 1913 $code .= " ExceptionCode ec = 0;\n"; |
1913 $code .= " {\n"; | 1914 $code .= " {\n"; |
1914 # The brace here is needed to prevent the ensuing 'goto fail's from jump ing past constructors | 1915 # The brace here is needed to prevent the ensuing 'goto fail's from jump ing past constructors |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2017 my $paramIndex = 0; | 2018 my $paramIndex = 0; |
2018 my @paramTransferListNames = (); | 2019 my @paramTransferListNames = (); |
2019 my %replacements = (); | 2020 my %replacements = (); |
2020 | 2021 |
2021 foreach my $parameter (@{$function->parameters}) { | 2022 foreach my $parameter (@{$function->parameters}) { |
2022 my $nativeType = GetNativeTypeFromSignature($parameter, $paramIndex); | 2023 my $nativeType = GetNativeTypeFromSignature($parameter, $paramIndex); |
2023 | 2024 |
2024 # Optional arguments without [Default=...] should generate an early call with fewer arguments. | 2025 # Optional arguments without [Default=...] should generate an early call with fewer arguments. |
2025 # Optional arguments with [Optional=...] should not generate the early c all. | 2026 # Optional arguments with [Optional=...] should not generate the early c all. |
2026 # Optional Dictionary arguments always considered to have default of emp ty dictionary. | 2027 # Optional Dictionary arguments always considered to have default of emp ty dictionary. |
2027 if ($parameter->isOptional && !$parameter->extendedAttributes->{"Default "} && $nativeType ne "Dictionary" && !$parameter->extendedAttributes->{"Callback "}) { | 2028 if ($parameter->isOptional && !$parameter->extendedAttributes->{"Default "} && $nativeType ne "Dictionary" && !IsCallbackInterface($parameter->type)) { |
2028 $parameterCheckString .= " if (args.Length() <= $paramIndex) {\n" ; | 2029 $parameterCheckString .= " if (args.Length() <= $paramIndex) {\n" ; |
2029 my $functionCall = GenerateFunctionCallString($function, $paramIndex , " " x 2, $interfaceName, $forMainWorldSuffix, %replacements); | 2030 my $functionCall = GenerateFunctionCallString($function, $paramIndex , " " x 2, $interfaceName, $forMainWorldSuffix, %replacements); |
2030 $parameterCheckString .= $functionCall; | 2031 $parameterCheckString .= $functionCall; |
2031 $parameterCheckString .= " }\n"; | 2032 $parameterCheckString .= " }\n"; |
2032 } | 2033 } |
2033 | 2034 |
2034 my $parameterDefaultPolicy = "DefaultIsUndefined"; | 2035 my $parameterDefaultPolicy = "DefaultIsUndefined"; |
2035 my $default = defined $parameter->extendedAttributes->{"Default"} ? $par ameter->extendedAttributes->{"Default"} : ""; | 2036 my $default = defined $parameter->extendedAttributes->{"Default"} ? $par ameter->extendedAttributes->{"Default"} : ""; |
2036 if ($parameter->isOptional and $default eq "NullString") { | 2037 if ($parameter->isOptional and $default eq "NullString") { |
2037 $parameterDefaultPolicy = "DefaultIsNullString"; | 2038 $parameterDefaultPolicy = "DefaultIsNullString"; |
2038 } | 2039 } |
2039 | 2040 |
2040 my $parameterName = $parameter->name; | 2041 my $parameterName = $parameter->name; |
2041 if (GetIndexOf($parameterName, @paramTransferListNames) != -1) { | 2042 if (GetIndexOf($parameterName, @paramTransferListNames) != -1) { |
2042 $replacements{$parameterName} = "messagePortArray" . ucfirst($parame terName); | 2043 $replacements{$parameterName} = "messagePortArray" . ucfirst($parame terName); |
2043 $paramIndex++; | 2044 $paramIndex++; |
2044 next; | 2045 next; |
2045 } | 2046 } |
2046 | 2047 |
2047 AddToImplIncludes("ExceptionCode.h"); | 2048 AddToImplIncludes("ExceptionCode.h"); |
2048 if ($parameter->extendedAttributes->{"Callback"}) { | 2049 if (IsCallbackInterface($parameter->type)) { |
2049 my $v8InterfaceName = "V8" . $parameter->type; | 2050 my $v8InterfaceName = "V8" . $parameter->type; |
2050 AddToImplIncludes("$v8InterfaceName.h"); | 2051 AddToImplIncludes("$v8InterfaceName.h"); |
2051 if ($parameter->isOptional) { | 2052 if ($parameter->isOptional) { |
2052 $parameterCheckString .= " RefPtr<" . $parameter->type . "> $ parameterName;\n"; | 2053 $parameterCheckString .= " RefPtr<" . $parameter->type . "> $ parameterName;\n"; |
2053 $parameterCheckString .= " if (args.Length() > $paramIndex && !args[$paramIndex]->IsNull() && !args[$paramIndex]->IsUndefined()) {\n"; | 2054 $parameterCheckString .= " if (args.Length() > $paramIndex && !args[$paramIndex]->IsNull() && !args[$paramIndex]->IsUndefined()) {\n"; |
2054 $parameterCheckString .= " if (!args[$paramIndex]->IsFunc tion())\n"; | 2055 $parameterCheckString .= " if (!args[$paramIndex]->IsFunc tion())\n"; |
2055 $parameterCheckString .= " return throwTypeError(0, a rgs.GetIsolate());\n"; | 2056 $parameterCheckString .= " return throwTypeError(0, a rgs.GetIsolate());\n"; |
2056 $parameterCheckString .= " $parameterName = ${v8Interface Name}::create(args[$paramIndex], getScriptExecutionContext());\n"; | 2057 $parameterCheckString .= " $parameterName = ${v8Interface Name}::create(args[$paramIndex], getScriptExecutionContext());\n"; |
2057 $parameterCheckString .= " }\n"; | 2058 $parameterCheckString .= " }\n"; |
2058 } else { | 2059 } else { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2222 if ($function->{overloadedIndex} > 0) { | 2223 if ($function->{overloadedIndex} > 0) { |
2223 $overloadedIndexString .= $function->{overloadedIndex}; | 2224 $overloadedIndexString .= $function->{overloadedIndex}; |
2224 } | 2225 } |
2225 | 2226 |
2226 my $raisesExceptions = $function->signature->extendedAttributes->{"RaisesExc eption"}; | 2227 my $raisesExceptions = $function->signature->extendedAttributes->{"RaisesExc eption"}; |
2227 if ($interface->extendedAttributes->{"RaisesException"}) { | 2228 if ($interface->extendedAttributes->{"RaisesException"}) { |
2228 $raisesExceptions = 1; | 2229 $raisesExceptions = 1; |
2229 } | 2230 } |
2230 if (!$raisesExceptions) { | 2231 if (!$raisesExceptions) { |
2231 foreach my $parameter (@{$function->parameters}) { | 2232 foreach my $parameter (@{$function->parameters}) { |
2232 if ((!$parameter->extendedAttributes->{"Callback"} and TypeCanFailCo nversion($parameter)) or $parameter->extendedAttributes->{"IsIndex"}) { | 2233 if ((!IsCallbackInterface($parameter->type) and TypeCanFailConversio n($parameter)) or $parameter->extendedAttributes->{"IsIndex"}) { |
2233 $raisesExceptions = 1; | 2234 $raisesExceptions = 1; |
2234 } | 2235 } |
2235 } | 2236 } |
2236 } | 2237 } |
2237 | 2238 |
2238 my @beforeArgumentList; | 2239 my @beforeArgumentList; |
2239 my @afterArgumentList; | 2240 my @afterArgumentList; |
2240 my $code = ""; | 2241 my $code = ""; |
2241 $code .= <<END; | 2242 $code .= <<END; |
2242 static v8::Handle<v8::Value> constructor${overloadedIndexString}(const v8::Argum ents& args) | 2243 static v8::Handle<v8::Value> constructor${overloadedIndexString}(const v8::Argum ents& args) |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2447 my $interface = shift; | 2448 my $interface = shift; |
2448 | 2449 |
2449 my $interfaceName = $interface->name; | 2450 my $interfaceName = $interface->name; |
2450 my $v8InterfaceName = "V8$interfaceName"; | 2451 my $v8InterfaceName = "V8$interfaceName"; |
2451 my $raisesExceptions = $function->signature->extendedAttributes->{"RaisesExc eption"}; | 2452 my $raisesExceptions = $function->signature->extendedAttributes->{"RaisesExc eption"}; |
2452 if ($interface->extendedAttributes->{"RaisesException"}) { | 2453 if ($interface->extendedAttributes->{"RaisesException"}) { |
2453 $raisesExceptions = 1; | 2454 $raisesExceptions = 1; |
2454 } | 2455 } |
2455 if (!$raisesExceptions) { | 2456 if (!$raisesExceptions) { |
2456 foreach my $parameter (@{$function->parameters}) { | 2457 foreach my $parameter (@{$function->parameters}) { |
2457 if ((!$parameter->extendedAttributes->{"Callback"} and TypeCanFailCo nversion($parameter)) or $parameter->extendedAttributes->{"IsIndex"}) { | 2458 if ((!IsCallbackInterface($parameter->type) and TypeCanFailConversio n($parameter)) or $parameter->extendedAttributes->{"IsIndex"}) { |
2458 $raisesExceptions = 1; | 2459 $raisesExceptions = 1; |
2459 } | 2460 } |
2460 } | 2461 } |
2461 } | 2462 } |
2462 | 2463 |
2463 my $maybeObserveFeature = GenerateFeatureObservation($function->signature->e xtendedAttributes->{"MeasureAs"}); | 2464 my $maybeObserveFeature = GenerateFeatureObservation($function->signature->e xtendedAttributes->{"MeasureAs"}); |
2464 my $maybeDeprecateFeature = GenerateDeprecationNotification($function->signa ture->extendedAttributes->{"DeprecateAs"}); | 2465 my $maybeDeprecateFeature = GenerateDeprecationNotification($function->signa ture->extendedAttributes->{"DeprecateAs"}); |
2465 | 2466 |
2466 my @beforeArgumentList; | 2467 my @beforeArgumentList; |
2467 my @afterArgumentList; | 2468 my @afterArgumentList; |
(...skipping 2119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4587 return 0; | 4588 return 0; |
4588 } | 4589 } |
4589 if ($function->isStatic) { | 4590 if ($function->isStatic) { |
4590 return 0; | 4591 return 0; |
4591 } | 4592 } |
4592 # Type checking is performed in the generated code | 4593 # Type checking is performed in the generated code |
4593 if ($function->signature->extendedAttributes->{"StrictTypeChecking"}) { | 4594 if ($function->signature->extendedAttributes->{"StrictTypeChecking"}) { |
4594 return 0; | 4595 return 0; |
4595 } | 4596 } |
4596 foreach my $parameter (@{$function->parameters}) { | 4597 foreach my $parameter (@{$function->parameters}) { |
4597 if (($parameter->isOptional && !$parameter->extendedAttributes->{"Defaul t"}) || $parameter->extendedAttributes->{"Callback"}) { | 4598 if (($parameter->isOptional && !$parameter->extendedAttributes->{"Defaul t"}) || IsCallbackInterface($parameter->type)) { |
4598 return 0; | 4599 return 0; |
4599 } | 4600 } |
4600 } | 4601 } |
4601 | 4602 |
4602 foreach my $parameter (@{$function->parameters}) { | 4603 foreach my $parameter (@{$function->parameters}) { |
4603 if (IsWrapperType($parameter->type)) { | 4604 if (IsWrapperType($parameter->type)) { |
4604 return 1; | 4605 return 1; |
4605 } | 4606 } |
4606 } | 4607 } |
4607 return 0; | 4608 return 0; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4639 | 4640 |
4640 | 4641 |
4641 sub IsWrapperType | 4642 sub IsWrapperType |
4642 { | 4643 { |
4643 my $type = shift; | 4644 my $type = shift; |
4644 # FIXME: Should this return false for Sequence and Array types? | 4645 # FIXME: Should this return false for Sequence and Array types? |
4645 return 0 if $codeGenerator->IsEnumType($type); | 4646 return 0 if $codeGenerator->IsEnumType($type); |
4646 return !($non_wrapper_types{$type}); | 4647 return !($non_wrapper_types{$type}); |
4647 } | 4648 } |
4648 | 4649 |
4650 sub IsCallbackInterface | |
4651 { | |
4652 my $type = shift; | |
4653 return 0 unless IsWrapperType($type); | |
4654 return 0 if $codeGenerator->GetArrayType($type); | |
4655 return 0 if $codeGenerator->GetSequenceType($type); | |
haraken
2013/04/26 18:03:36
I'm OK to land the patch with this, but I think Is
do-not-use
2013/04/26 18:15:57
Yes, I saw but I did not want to be too greedy and
| |
4656 | |
4657 return $codeGenerator->IsCallbackInterfaceFromFile($type); | |
4658 } | |
4659 | |
4649 sub GetTypeNameOfExternalTypedArray | 4660 sub GetTypeNameOfExternalTypedArray |
4650 { | 4661 { |
4651 my $interface = shift; | 4662 my $interface = shift; |
4652 my $interfaceName = $interface->name; | 4663 my $interfaceName = $interface->name; |
4653 my $viewType = $interface->extendedAttributes->{"TypedArray"}; | 4664 my $viewType = $interface->extendedAttributes->{"TypedArray"}; |
4654 return "v8::kExternalByteArray" if $viewType eq "signed char" and $interface Name eq "Int8Array"; | 4665 return "v8::kExternalByteArray" if $viewType eq "signed char" and $interface Name eq "Int8Array"; |
4655 return "v8::kExternalPixelArray" if $viewType eq "unsigned char" and $interf aceName eq "Uint8ClampedArray"; | 4666 return "v8::kExternalPixelArray" if $viewType eq "unsigned char" and $interf aceName eq "Uint8ClampedArray"; |
4656 return "v8::kExternalUnsignedByteArray" if $viewType eq "unsigned char" and $interfaceName eq "Uint8Array"; | 4667 return "v8::kExternalUnsignedByteArray" if $viewType eq "unsigned char" and $interfaceName eq "Uint8Array"; |
4657 return "v8::kExternalShortArray" if $viewType eq "short" and $interfaceName eq "Int16Array"; | 4668 return "v8::kExternalShortArray" if $viewType eq "short" and $interfaceName eq "Int16Array"; |
4658 return "v8::kExternalUnsignedShortArray" if $viewType eq "unsigned short" an d $interfaceName eq "Uint16Array"; | 4669 return "v8::kExternalUnsignedShortArray" if $viewType eq "unsigned short" an d $interfaceName eq "Uint16Array"; |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4897 | 4908 |
4898 sub GetPassRefPtrType | 4909 sub GetPassRefPtrType |
4899 { | 4910 { |
4900 my $v8InterfaceName = shift; | 4911 my $v8InterfaceName = shift; |
4901 | 4912 |
4902 my $angleBracketSpace = $v8InterfaceName =~ />$/ ? " " : ""; | 4913 my $angleBracketSpace = $v8InterfaceName =~ />$/ ? " " : ""; |
4903 return "PassRefPtr<${v8InterfaceName}${angleBracketSpace}>"; | 4914 return "PassRefPtr<${v8InterfaceName}${angleBracketSpace}>"; |
4904 } | 4915 } |
4905 | 4916 |
4906 1; | 4917 1; |
OLD | NEW |