| 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. |
| (...skipping 1562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1573 $code .= " return toV8Fast$forMainWorldSuffix($wrappedValue, info, im
p);\n"; | 1573 $code .= " return toV8Fast$forMainWorldSuffix($wrappedValue, info, im
p);\n"; |
| 1574 } elsif ($attribute->signature->type eq "SerializedScriptValue" && $attrExt-
>{"CachedAttribute"}) { | 1574 } elsif ($attribute->signature->type eq "SerializedScriptValue" && $attrExt-
>{"CachedAttribute"}) { |
| 1575 my $getterFunc = ToMethodName($attribute->signature->name); | 1575 my $getterFunc = ToMethodName($attribute->signature->name); |
| 1576 $code .= <<END; | 1576 $code .= <<END; |
| 1577 RefPtr<SerializedScriptValue> serialized = imp->${getterFunc}(); | 1577 RefPtr<SerializedScriptValue> serialized = imp->${getterFunc}(); |
| 1578 value = serialized ? serialized->deserialize() : v8::Handle<v8::Value>(v8Nul
l(info.GetIsolate())); | 1578 value = serialized ? serialized->deserialize() : v8::Handle<v8::Value>(v8Nul
l(info.GetIsolate())); |
| 1579 info.Holder()->SetHiddenValue(propertyName, value); | 1579 info.Holder()->SetHiddenValue(propertyName, value); |
| 1580 return value; | 1580 return value; |
| 1581 END | 1581 END |
| 1582 } else { | 1582 } else { |
| 1583 $code .= NativeToJSValue($attribute->signature, $expression, " ", "re
turn", "info.Holder()", "info.GetIsolate()", "info", "imp", "ReturnUnsafeHandle"
, $forMainWorldSuffix) . "\n"; | 1583 $code .= NativeToJSValue($attribute->signature->type, $attribute->signat
ure->extendedAttributes, $expression, " ", "return", "info.Holder()", "info.G
etIsolate()", "info", "imp", "ReturnUnsafeHandle", $forMainWorldSuffix) . "\n"; |
| 1584 } | 1584 } |
| 1585 | 1585 |
| 1586 $code .= "}\n\n"; # end of getter | 1586 $code .= "}\n\n"; # end of getter |
| 1587 $code .= "#endif // ${conditionalString}\n\n" if $conditionalString; | 1587 $code .= "#endif // ${conditionalString}\n\n" if $conditionalString; |
| 1588 $implementation{nameSpaceInternal}->add($code); | 1588 $implementation{nameSpaceInternal}->add($code); |
| 1589 } | 1589 } |
| 1590 | 1590 |
| 1591 sub ShouldKeepAttributeAlive | 1591 sub ShouldKeepAttributeAlive |
| 1592 { | 1592 { |
| 1593 my ($interface, $attribute, $returnType) = @_; | 1593 my ($interface, $attribute, $returnType) = @_; |
| (...skipping 1459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3053 $code .= " } else {\n"; | 3053 $code .= " } else {\n"; |
| 3054 $code .= " ${conditional}$template->Set(v8::String::NewSymbol(\"$
name\"), v8::FunctionTemplate::New(${implClassName}V8Internal::${name}MethodCall
back, v8Undefined(), ${signature}, $functionLength)$property_attributes);\n"; | 3054 $code .= " ${conditional}$template->Set(v8::String::NewSymbol(\"$
name\"), v8::FunctionTemplate::New(${implClassName}V8Internal::${name}MethodCall
back, v8Undefined(), ${signature}, $functionLength)$property_attributes);\n"; |
| 3055 $code .= " }\n"; | 3055 $code .= " }\n"; |
| 3056 } else { | 3056 } else { |
| 3057 $code .= " ${conditional}$template->Set(v8::String::NewSymbol(\"$name
\"), v8::FunctionTemplate::New(${implClassName}V8Internal::${name}MethodCallback
, v8Undefined(), ${signature}, $functionLength)$property_attributes);\n"; | 3057 $code .= " ${conditional}$template->Set(v8::String::NewSymbol(\"$name
\"), v8::FunctionTemplate::New(${implClassName}V8Internal::${name}MethodCallback
, v8Undefined(), ${signature}, $functionLength)$property_attributes);\n"; |
| 3058 } | 3058 } |
| 3059 $code .= "#endif // ${conditionalString}\n" if $conditionalString; | 3059 $code .= "#endif // ${conditionalString}\n" if $conditionalString; |
| 3060 return $code; | 3060 return $code; |
| 3061 } | 3061 } |
| 3062 | 3062 |
| 3063 sub GenerateIsNullExpression |
| 3064 { |
| 3065 my $type = shift; |
| 3066 my $variableName = shift; |
| 3067 if (IsUnionType($type)) { |
| 3068 my $types = $type->unionMemberTypes; |
| 3069 my @expression = (); |
| 3070 for my $i (0 .. scalar(@$types)-1) { |
| 3071 my $unionMemberType = $types->[$i]; |
| 3072 my $unionMemberVariable = $variableName . $i; |
| 3073 my $isNull = GenerateIsNullExpression($unionMemberType, $unionMember
Variable); |
| 3074 push @expression, $isNull; |
| 3075 } |
| 3076 return join " && ", @expression; |
| 3077 } |
| 3078 if (IsRefPtrType($type)) { |
| 3079 return "!${variableName}"; |
| 3080 } else { |
| 3081 return "${variableName}.isNull()"; |
| 3082 } |
| 3083 } |
| 3084 |
| 3063 sub GenerateImplementationIndexedProperty | 3085 sub GenerateImplementationIndexedProperty |
| 3064 { | 3086 { |
| 3065 my $interface = shift; | 3087 my $interface = shift; |
| 3066 my $interfaceName = $interface->name; | 3088 my $interfaceName = $interface->name; |
| 3067 my $implClassName = GetImplName($interface); | 3089 my $implClassName = GetImplName($interface); |
| 3068 my $v8ClassName = GetV8ClassName($interface); | 3090 my $v8ClassName = GetV8ClassName($interface); |
| 3069 | 3091 |
| 3070 my $indexedGetterFunction = GetIndexedGetterFunction($interface); | 3092 my $indexedGetterFunction = GetIndexedGetterFunction($interface); |
| 3071 my $hasCustomIndexedSetter = $interface->extendedAttributes->{"CustomIndexed
Setter"}; | 3093 my $hasCustomIndexedSetter = $interface->extendedAttributes->{"CustomIndexed
Setter"}; |
| 3072 my $hasCustomIndexedGetter = $interface->extendedAttributes->{"CustomIndexed
Getter"}; | 3094 my $hasCustomIndexedGetter = $interface->extendedAttributes->{"CustomIndexed
Getter"}; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 3100 my $code = ""; | 3122 my $code = ""; |
| 3101 $code .= " desc->${setOn}Template()->SetIndexedPropertyHandler(${v8ClassN
ame}::indexedPropertyGetter"; | 3123 $code .= " desc->${setOn}Template()->SetIndexedPropertyHandler(${v8ClassN
ame}::indexedPropertyGetter"; |
| 3102 $code .= $hasCustomIndexedSetter ? ", ${v8ClassName}::indexedPropertySetter"
: ", 0"; | 3124 $code .= $hasCustomIndexedSetter ? ", ${v8ClassName}::indexedPropertySetter"
: ", 0"; |
| 3103 $code .= ", 0"; # IndexedPropertyQuery -- not being used at the moment. | 3125 $code .= ", 0"; # IndexedPropertyQuery -- not being used at the moment. |
| 3104 $code .= $hasDeleter ? ", ${v8ClassName}::indexedPropertyDeleter" : ", 0"; | 3126 $code .= $hasDeleter ? ", ${v8ClassName}::indexedPropertyDeleter" : ", 0"; |
| 3105 $code .= ", nodeCollectionIndexedPropertyEnumerator<${implClassName}>" if $h
asEnumerator; | 3127 $code .= ", nodeCollectionIndexedPropertyEnumerator<${implClassName}>" if $h
asEnumerator; |
| 3106 $code .= ");\n"; | 3128 $code .= ");\n"; |
| 3107 | 3129 |
| 3108 if ($indexedGetterFunction && !$hasCustomIndexedGetter) { | 3130 if ($indexedGetterFunction && !$hasCustomIndexedGetter) { |
| 3109 my $returnType = $indexedGetterFunction->signature->type; | 3131 my $returnType = $indexedGetterFunction->signature->type; |
| 3132 my $nativeType = GetNativeType($returnType); |
| 3110 my $methodName = GetImplName($indexedGetterFunction->signature); | 3133 my $methodName = GetImplName($indexedGetterFunction->signature); |
| 3111 AddToImplIncludes("bindings/v8/V8Collection.h"); | 3134 AddToImplIncludes("bindings/v8/V8Collection.h"); |
| 3112 my $returnJSValueCode = ""; | 3135 my $nativeValue = "element"; |
| 3113 my $nativeType = GetNativeType($returnType); | 3136 $nativeValue .= ".release()" if (IsRefPtrType($returnType)); |
| 3114 my $isNull = ""; | 3137 my $isNull = GenerateIsNullExpression($returnType, "element"); |
| 3115 | 3138 my $returnJSValueCode = NativeToJSValue($indexedGetterFunction->signatur
e->type, $indexedGetterFunction->signature->extendedAttributes, $nativeValue, "
", "return", "info.Holder()", "info.GetIsolate()", "info", "collection"); |
| 3116 if (IsRefPtrType($returnType)) { | 3139 my $methodCallCode = GenerateMethodCall($returnType, "element", "collect
ion->${methodName}", "index"); |
| 3117 AddToImplIncludes("V8$returnType.h"); | 3140 my $getterCode = <<END; |
| 3118 $isNull = "!element"; | |
| 3119 $returnJSValueCode = NativeToJSValue($indexedGetterFunction->signatu
re, "element.release()", " ", "return", "info.Holder()", "info.GetIsolate()",
"info", "collection", "", ""); | |
| 3120 } else { | |
| 3121 $isNull = "element.isNull()"; | |
| 3122 $returnJSValueCode = NativeToJSValue($indexedGetterFunction->signatu
re, "element", " ", "return", "info.Holder()", "info.GetIsolate()"); | |
| 3123 } | |
| 3124 | |
| 3125 $implementation{nameSpaceWebCore}->add(<<END); | |
| 3126 v8::Handle<v8::Value> ${v8ClassName}::indexedPropertyGetter(uint32_t index, cons
t v8::AccessorInfo& info) | 3141 v8::Handle<v8::Value> ${v8ClassName}::indexedPropertyGetter(uint32_t index, cons
t v8::AccessorInfo& info) |
| 3127 { | 3142 { |
| 3128 ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder())); | 3143 ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder())); |
| 3129 ${implClassName}* collection = toNative(info.Holder()); | 3144 ${implClassName}* collection = toNative(info.Holder()); |
| 3130 $nativeType element = collection->$methodName(index); | 3145 ${methodCallCode} |
| 3131 if ($isNull) | |
| 3132 return v8Undefined(); | |
| 3133 ${returnJSValueCode} | |
| 3134 } | |
| 3135 | |
| 3136 END | 3146 END |
| 3147 if (IsUnionType($returnType)) { |
| 3148 $getterCode .= "${returnJSValueCode}\n"; |
| 3149 $getterCode .= " return v8Undefined();\n"; |
| 3150 } else { |
| 3151 $getterCode .= " if (${isNull})\n"; |
| 3152 $getterCode .= " return v8Undefined();\n"; |
| 3153 $getterCode .= $returnJSValueCode . "\n"; |
| 3154 } |
| 3155 $getterCode .= "}\n\n"; |
| 3156 $implementation{nameSpaceWebCore}->add($getterCode); |
| 3137 } | 3157 } |
| 3138 return $code; | 3158 return $code; |
| 3139 } | 3159 } |
| 3140 | 3160 |
| 3141 sub GenerateImplementationNamedPropertyAccessors | 3161 sub GenerateImplementationNamedPropertyAccessors |
| 3142 { | 3162 { |
| 3143 my $interface = shift; | 3163 my $interface = shift; |
| 3144 | 3164 |
| 3145 my $interfaceName = $interface->name; | 3165 my $interfaceName = $interface->name; |
| 3146 my $implClassName = GetImplName($interface); | 3166 my $implClassName = GetImplName($interface); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3190 $subCode .= $hasSetter ? "${v8ClassName}::namedPropertySetter, " : "0, "
; | 3210 $subCode .= $hasSetter ? "${v8ClassName}::namedPropertySetter, " : "0, "
; |
| 3191 $subCode .= $hasQuery ? "${v8ClassName}::namedPropertyQuery, " : "0, "; | 3211 $subCode .= $hasQuery ? "${v8ClassName}::namedPropertyQuery, " : "0, "; |
| 3192 $subCode .= $hasDeleter ? "${v8ClassName}::namedPropertyDeleter, " : "0,
"; | 3212 $subCode .= $hasDeleter ? "${v8ClassName}::namedPropertyDeleter, " : "0,
"; |
| 3193 $subCode .= $hasEnumerator ? "${v8ClassName}::namedPropertyEnumerator" :
"0"; | 3213 $subCode .= $hasEnumerator ? "${v8ClassName}::namedPropertyEnumerator" :
"0"; |
| 3194 $subCode .= ");\n"; | 3214 $subCode .= ");\n"; |
| 3195 } | 3215 } |
| 3196 | 3216 |
| 3197 return $subCode; | 3217 return $subCode; |
| 3198 } | 3218 } |
| 3199 | 3219 |
| 3220 sub GenerateMethodCall |
| 3221 { |
| 3222 my $returnType = shift; # string or UnionType |
| 3223 my $returnName = shift; |
| 3224 my $functionExpression = shift; |
| 3225 my $firstArgument = shift; |
| 3226 if (IsUnionType($returnType)) { |
| 3227 my $code = ""; |
| 3228 my @extraArguments = (); |
| 3229 for my $i (0..scalar(@{$returnType->unionMemberTypes})-1) { |
| 3230 my $unionMemberType = $returnType->unionMemberTypes->[$i]; |
| 3231 my $nativeType = GetNativeType($unionMemberType); |
| 3232 my $unionMemberVariable = $returnName . $i; |
| 3233 $code .= " ${nativeType} ${unionMemberVariable};\n"; |
| 3234 push @extraArguments, $unionMemberVariable; |
| 3235 } |
| 3236 $code .= " ${functionExpression}(${firstArgument}, " . (join ", ", @e
xtraArguments) . ");"; |
| 3237 return $code; |
| 3238 } else { |
| 3239 my $nativeType = GetNativeType($returnType); |
| 3240 return " ${nativeType} element = ${functionExpression}(${firstArgumen
t});" |
| 3241 } |
| 3242 } |
| 3243 |
| 3244 |
| 3200 sub GenerateImplementationNamedPropertyGetter | 3245 sub GenerateImplementationNamedPropertyGetter |
| 3201 { | 3246 { |
| 3202 my $interface = shift; | 3247 my $interface = shift; |
| 3203 my $namedGetterFunction = shift; | 3248 my $namedGetterFunction = shift; |
| 3204 my $implClassName = GetImplName($interface); | 3249 my $implClassName = GetImplName($interface); |
| 3205 my $v8ClassName = GetV8ClassName($interface); | 3250 my $v8ClassName = GetV8ClassName($interface); |
| 3206 my $methodName = GetImplName($namedGetterFunction->signature); | 3251 my $methodName = GetImplName($namedGetterFunction->signature); |
| 3207 | 3252 |
| 3208 AddToImplIncludes("bindings/v8/V8Collection.h"); | 3253 AddToImplIncludes("bindings/v8/V8Collection.h"); |
| 3209 my $returnType = $namedGetterFunction->signature->type; | 3254 my $returnType = $namedGetterFunction->signature->type; |
| 3210 my $nativeType = GetNativeType($returnType); | 3255 my $isNull = GenerateIsNullExpression($returnType, "element"); |
| 3211 my $isNull = ""; | 3256 my $nativeValue = "element"; |
| 3212 my $returnJSValueCode = ""; | 3257 $nativeValue .= ".release()" if (IsRefPtrType($returnType)); |
| 3258 my $returnJSValueCode = NativeToJSValue($namedGetterFunction->signature->typ
e, $namedGetterFunction->signature->extendedAttributes, $nativeValue, " ", "r
eturn", "info.Holder()", "info.GetIsolate()", "info", "collection"); |
| 3259 my $methodCallCode = GenerateMethodCall($returnType, "element", "collection-
>${methodName}", "propertyName"); |
| 3213 | 3260 |
| 3214 if (IsRefPtrType($returnType)) { | 3261 my $code = <<END; |
| 3215 AddToImplIncludes("V8$returnType.h"); | |
| 3216 $isNull = "!element"; | |
| 3217 $returnJSValueCode = NativeToJSValue($namedGetterFunction->signature, "e
lement.release()", " ", "return", "info.Holder()", "info.GetIsolate()", "info
", "collection", "", ""); | |
| 3218 } else { | |
| 3219 $isNull = "element.isNull()"; | |
| 3220 $returnJSValueCode = NativeToJSValue($namedGetterFunction->signature, "e
lement", " ", "return", "info.Holder()", "info.GetIsolate()"); | |
| 3221 } | |
| 3222 | |
| 3223 $implementation{nameSpaceWebCore}->add(<<END); | |
| 3224 v8::Handle<v8::Value> ${v8ClassName}::namedPropertyGetter(v8::Local<v8::String>
name, const v8::AccessorInfo& info) | 3262 v8::Handle<v8::Value> ${v8ClassName}::namedPropertyGetter(v8::Local<v8::String>
name, const v8::AccessorInfo& info) |
| 3225 { | 3263 { |
| 3226 if (!info.Holder()->GetRealNamedPropertyInPrototypeChain(name).IsEmpty()) | 3264 if (!info.Holder()->GetRealNamedPropertyInPrototypeChain(name).IsEmpty()) |
| 3227 return v8Undefined(); | 3265 return v8Undefined(); |
| 3228 if (info.Holder()->HasRealNamedCallbackProperty(name)) | 3266 if (info.Holder()->HasRealNamedCallbackProperty(name)) |
| 3229 return v8Undefined(); | 3267 return v8Undefined(); |
| 3230 | 3268 |
| 3231 ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder())); | 3269 ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder())); |
| 3232 ${implClassName}* collection = toNative(info.Holder()); | 3270 ${implClassName}* collection = toNative(info.Holder()); |
| 3233 AtomicString propertyName = toWebCoreAtomicString(name); | 3271 AtomicString propertyName = toWebCoreAtomicString(name); |
| 3234 ${nativeType} element = collection->${methodName}(propertyName); | 3272 ${methodCallCode} |
| 3235 if (${isNull}) | |
| 3236 return v8Undefined(); | |
| 3237 ${returnJSValueCode} | |
| 3238 } | |
| 3239 | |
| 3240 END | 3273 END |
| 3274 if (IsUnionType($returnType)) { |
| 3275 $code .= "${returnJSValueCode}\n"; |
| 3276 $code .= " return v8Undefined();\n"; |
| 3277 } else { |
| 3278 $code .= " if (${isNull})\n"; |
| 3279 $code .= " return v8Undefined();\n"; |
| 3280 $code .= $returnJSValueCode . "\n"; |
| 3281 } |
| 3282 $code .= "}\n\n"; |
| 3283 $implementation{nameSpaceWebCore}->add($code); |
| 3241 } | 3284 } |
| 3242 | 3285 |
| 3243 sub GenerateImplementationCustomCall | 3286 sub GenerateImplementationCustomCall |
| 3244 { | 3287 { |
| 3245 my $interface = shift; | 3288 my $interface = shift; |
| 3246 my $code = ""; | 3289 my $code = ""; |
| 3247 | 3290 |
| 3248 my $v8ClassName = GetV8ClassName($interface); | 3291 my $v8ClassName = GetV8ClassName($interface); |
| 3249 | 3292 |
| 3250 if ($interface->extendedAttributes->{"CustomCall"}) { | 3293 if ($interface->extendedAttributes->{"CustomCall"}) { |
| (...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4079 $code .= " return true;\n\n"; | 4122 $code .= " return true;\n\n"; |
| 4080 $code .= " v8::HandleScope handleScope;\n\n"; | 4123 $code .= " v8::HandleScope handleScope;\n\n"; |
| 4081 $code .= " v8::Handle<v8::Context> v8Context = toV8Context(script
ExecutionContext(), m_world.get());\n"; | 4124 $code .= " v8::Handle<v8::Context> v8Context = toV8Context(script
ExecutionContext(), m_world.get());\n"; |
| 4082 $code .= " if (v8Context.IsEmpty())\n"; | 4125 $code .= " if (v8Context.IsEmpty())\n"; |
| 4083 $code .= " return true;\n\n"; | 4126 $code .= " return true;\n\n"; |
| 4084 $code .= " v8::Context::Scope scope(v8Context);\n\n"; | 4127 $code .= " v8::Context::Scope scope(v8Context);\n\n"; |
| 4085 | 4128 |
| 4086 @args = (); | 4129 @args = (); |
| 4087 foreach my $param (@params) { | 4130 foreach my $param (@params) { |
| 4088 my $paramName = $param->name; | 4131 my $paramName = $param->name; |
| 4089 $code .= NativeToJSValue($param, $paramName, " ", "v8::Handle
<v8::Value> ${paramName}Handle =", "v8::Handle<v8::Object>()", "v8Context->GetIs
olate()", "") . "\n"; | 4132 $code .= NativeToJSValue($param->type, $param->extendedAttribute
s, $paramName, " ", "v8::Handle<v8::Value> ${paramName}Handle =", "v8::Handle
<v8::Object>()", "v8Context->GetIsolate()", "") . "\n"; |
| 4090 $code .= " if (${paramName}Handle.IsEmpty()) {\n"; | 4133 $code .= " if (${paramName}Handle.IsEmpty()) {\n"; |
| 4091 $code .= " if (!isScriptControllerTerminating())\n"; | 4134 $code .= " if (!isScriptControllerTerminating())\n"; |
| 4092 $code .= " CRASH();\n"; | 4135 $code .= " CRASH();\n"; |
| 4093 $code .= " return true;\n"; | 4136 $code .= " return true;\n"; |
| 4094 $code .= " }\n"; | 4137 $code .= " }\n"; |
| 4095 push(@args, " ${paramName}Handle"); | 4138 push(@args, " ${paramName}Handle"); |
| 4096 } | 4139 } |
| 4097 | 4140 |
| 4098 if (scalar(@args) > 0) { | 4141 if (scalar(@args) > 0) { |
| 4099 $code .= "\n v8::Handle<v8::Value> argv[] = {\n"; | 4142 $code .= "\n v8::Handle<v8::Value> argv[] = {\n"; |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4344 # If the implementing class is a POD type, commit changes | 4387 # If the implementing class is a POD type, commit changes |
| 4345 if (IsSVGTypeNeedingTearOff($interfaceName) and not $interfaceName =~ /List$
/) { | 4388 if (IsSVGTypeNeedingTearOff($interfaceName) and not $interfaceName =~ /List$
/) { |
| 4346 $code .= $indent . "wrapper->commitChange();\n"; | 4389 $code .= $indent . "wrapper->commitChange();\n"; |
| 4347 } | 4390 } |
| 4348 | 4391 |
| 4349 $return .= ".release()" if ($returnIsRef); | 4392 $return .= ".release()" if ($returnIsRef); |
| 4350 | 4393 |
| 4351 my $nativeValue; | 4394 my $nativeValue; |
| 4352 # FIXME: Update for all ScriptWrappables. | 4395 # FIXME: Update for all ScriptWrappables. |
| 4353 if (IsDOMNodeType($interfaceName)) { | 4396 if (IsDOMNodeType($interfaceName)) { |
| 4354 $nativeValue = NativeToJSValue($function->signature, $return, $indent, "
return", "args.Holder()", "args.GetIsolate()", "args", "imp", "ReturnUnsafeHandl
e", $forMainWorldSuffix); | 4397 $nativeValue = NativeToJSValue($function->signature->type, $function->si
gnature->extendedAttributes, $return, $indent, "return", "args.Holder()", "args.
GetIsolate()", "args", "imp", "ReturnUnsafeHandle", $forMainWorldSuffix); |
| 4355 } else { | 4398 } else { |
| 4356 $nativeValue = NativeToJSValue($function->signature, $return, $indent, "
return", "args.Holder()", "args.GetIsolate()", 0, 0, "ReturnUnsafeHandle", $forM
ainWorldSuffix); | 4399 $nativeValue = NativeToJSValue($function->signature->type, $function->si
gnature->extendedAttributes, $return, $indent, "return", "args.Holder()", "args.
GetIsolate()", 0, 0, "ReturnUnsafeHandle", $forMainWorldSuffix); |
| 4357 } | 4400 } |
| 4358 | 4401 |
| 4359 $code .= $nativeValue . "\n"; | 4402 $code .= $nativeValue . "\n"; |
| 4360 | 4403 |
| 4361 return $code; | 4404 return $code; |
| 4362 } | 4405 } |
| 4363 | 4406 |
| 4364 sub GetNativeTypeFromSignature | 4407 sub GetNativeTypeFromSignature |
| 4365 { | 4408 { |
| 4366 my $signature = shift; | 4409 my $signature = shift; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4421 return "double" if $type eq "Date"; | 4464 return "double" if $type eq "Date"; |
| 4422 return "ScriptValue" if $type eq "any"; | 4465 return "ScriptValue" if $type eq "any"; |
| 4423 return "Dictionary" if $type eq "Dictionary"; | 4466 return "Dictionary" if $type eq "Dictionary"; |
| 4424 | 4467 |
| 4425 return "RefPtr<DOMStringList>" if $type eq "DOMStringList"; | 4468 return "RefPtr<DOMStringList>" if $type eq "DOMStringList"; |
| 4426 return "RefPtr<MediaQueryListListener>" if $type eq "MediaQueryListListener"
; | 4469 return "RefPtr<MediaQueryListListener>" if $type eq "MediaQueryListListener"
; |
| 4427 return "RefPtr<NodeFilter>" if $type eq "NodeFilter"; | 4470 return "RefPtr<NodeFilter>" if $type eq "NodeFilter"; |
| 4428 return "RefPtr<SerializedScriptValue>" if $type eq "SerializedScriptValue"; | 4471 return "RefPtr<SerializedScriptValue>" if $type eq "SerializedScriptValue"; |
| 4429 return "RefPtr<XPathNSResolver>" if $type eq "XPathNSResolver"; | 4472 return "RefPtr<XPathNSResolver>" if $type eq "XPathNSResolver"; |
| 4430 | 4473 |
| 4474 die "UnionType is not supported" if IsUnionType($type); |
| 4475 |
| 4431 # We need to check [ImplementedBy] extended attribute for wrapper types. | 4476 # We need to check [ImplementedBy] extended attribute for wrapper types. |
| 4432 if (IsWrapperType($type)) { | 4477 if (IsWrapperType($type)) { |
| 4433 my $interface = ParseInterface($type); | 4478 my $interface = ParseInterface($type); |
| 4434 my $implClassName = GetImplName($interface); | 4479 my $implClassName = GetImplName($interface); |
| 4435 return $isParameter ? "${implClassName}*" : "RefPtr<${implClassName}>"; | 4480 return $isParameter ? "${implClassName}*" : "RefPtr<${implClassName}>"; |
| 4436 } | 4481 } |
| 4437 return "RefPtr<${type}>" if IsRefPtrType($type) and not $isParameter; | 4482 return "RefPtr<${type}>" if IsRefPtrType($type) and not $isParameter; |
| 4438 | 4483 |
| 4439 my $arrayType = GetArrayType($type); | 4484 my $arrayType = GetArrayType($type); |
| 4440 my $sequenceType = GetSequenceType($type); | 4485 my $sequenceType = GetSequenceType($type); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4643 'long long' => 1, | 4688 'long long' => 1, |
| 4644 'long' => 1, | 4689 'long' => 1, |
| 4645 'short' => 1, | 4690 'short' => 1, |
| 4646 'unsigned int' => 1, | 4691 'unsigned int' => 1, |
| 4647 'unsigned long long' => 1, | 4692 'unsigned long long' => 1, |
| 4648 'unsigned long' => 1, | 4693 'unsigned long' => 1, |
| 4649 'unsigned short' => 1, | 4694 'unsigned short' => 1, |
| 4650 'void' => 1 | 4695 'void' => 1 |
| 4651 ); | 4696 ); |
| 4652 | 4697 |
| 4698 sub IsUnionType |
| 4699 { |
| 4700 my $type = shift; # string or UnionType |
| 4701 if(ref($type) eq "UnionType") { |
| 4702 die "Currently only 2 values of non-union type is supported as union typ
e.\n" unless @{$type->unionMemberTypes} == 2; |
| 4703 return 1; |
| 4704 } |
| 4705 return 0; |
| 4706 } |
| 4653 | 4707 |
| 4654 sub IsWrapperType | 4708 sub IsWrapperType |
| 4655 { | 4709 { |
| 4656 my $type = shift; | 4710 my $type = shift; |
| 4657 return 0 if GetArrayType($type); | 4711 return 0 if GetArrayType($type); |
| 4658 return 0 if GetSequenceType($type); | 4712 return 0 if GetSequenceType($type); |
| 4659 return 0 if IsEnumType($type); | 4713 return 0 if IsEnumType($type); |
| 4660 return !($non_wrapper_types{$type}); | 4714 return !($non_wrapper_types{$type}); |
| 4661 } | 4715 } |
| 4662 | 4716 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4719 return 1 if $type =~ /^SVG.*Element$/; | 4773 return 1 if $type =~ /^SVG.*Element$/; |
| 4720 | 4774 |
| 4721 return 1 if $type eq 'TestNode'; | 4775 return 1 if $type eq 'TestNode'; |
| 4722 | 4776 |
| 4723 return 0; | 4777 return 0; |
| 4724 } | 4778 } |
| 4725 | 4779 |
| 4726 | 4780 |
| 4727 sub NativeToJSValue | 4781 sub NativeToJSValue |
| 4728 { | 4782 { |
| 4729 my $signature = shift; | 4783 my $type = shift; |
| 4784 my $extendedAttributes = shift; |
| 4730 my $nativeValue = shift; | 4785 my $nativeValue = shift; |
| 4731 my $indent = shift; # added before every line | 4786 my $indent = shift; # added before every line |
| 4732 my $receiver = shift; # "return" or "<variableName> =" | 4787 my $receiver = shift; # "return" or "<variableName> =" |
| 4733 my $getCreationContext = shift; | 4788 my $getCreationContext = shift; |
| 4734 my $getIsolate = shift; | 4789 my $getIsolate = shift; |
| 4735 die "An Isolate is mandatory for native value => JS value conversion." unles
s $getIsolate; | 4790 die "An Isolate is mandatory for native value => JS value conversion." unles
s $getIsolate; |
| 4736 my $getHolderContainer = shift; | 4791 my $getHolderContainer = shift || ""; |
| 4737 my $getHolderContainerArg = $getHolderContainer ? ", $getHolderContainer" :
""; | 4792 my $getHolderContainerArg = $getHolderContainer ? ", $getHolderContainer" :
""; |
| 4738 my $getScriptWrappable = shift; | 4793 my $getScriptWrappable = shift || ""; |
| 4739 my $getScriptWrappableArg = $getScriptWrappable ? ", $getScriptWrappable" :
""; | 4794 my $getScriptWrappableArg = $getScriptWrappable ? ", $getScriptWrappable" :
""; |
| 4740 my $returnHandleType = shift; | 4795 my $returnHandleType = shift || ""; |
| 4741 my $returnHandleTypeArg = $returnHandleType ? ", $returnHandleType" : ""; | 4796 my $returnHandleTypeArg = $returnHandleType ? ", $returnHandleType" : ""; |
| 4742 my $forMainWorldSuffix = shift; | 4797 my $forMainWorldSuffix = shift || ""; |
| 4743 | 4798 |
| 4744 my $type = $signature->type; | 4799 if (IsUnionType($type)) { |
| 4800 my $types = $type->unionMemberTypes; |
| 4801 my @codes = (); |
| 4802 for my $i (0 .. scalar(@$types)-1) { |
| 4803 my $unionMemberType = $types->[$i]; |
| 4804 my $unionMemberNumber = $i + 1; |
| 4805 my $unionMemberVariable = $nativeValue . $i; |
| 4806 my $unionMemberNativeValue = $unionMemberVariable; |
| 4807 $unionMemberNativeValue .= ".release()" if (IsRefPtrType($unionMembe
rType)); |
| 4808 my $returnJSValueCode = NativeToJSValue($unionMemberType, $extendedA
ttributes, $unionMemberNativeValue, $indent . " ", $receiver, $getCreationCon
text, $getIsolate, $getHolderContainer, $getScriptWrappable, $returnHandleType,
$forMainWorldSuffix); |
| 4809 my $isNotNull = "!" . GenerateIsNullExpression($unionMemberType, $un
ionMemberVariable); |
| 4810 my $code = ""; |
| 4811 $code .= "${indent}if (${isNotNull})\n"; |
| 4812 $code .= "${returnJSValueCode}"; |
| 4813 push @codes, $code; |
| 4814 } |
| 4815 return join "\n", @codes; |
| 4816 } |
| 4745 | 4817 |
| 4746 return "$indent$receiver v8Boolean($nativeValue, $getIsolate);" if $type eq
"boolean"; | 4818 return "$indent$receiver v8Boolean($nativeValue, $getIsolate);" if $type eq
"boolean"; |
| 4747 return "$indent$receiver v8Undefined();" if $type eq "void"; # equivalen
t to v8Undefined() | 4819 return "$indent$receiver v8Undefined();" if $type eq "void"; # equivalen
t to v8Undefined() |
| 4748 | 4820 |
| 4749 # HTML5 says that unsigned reflected attributes should be in the range | 4821 # HTML5 says that unsigned reflected attributes should be in the range |
| 4750 # [0, 2^31). When a value isn't in this range, a default value (or 0) | 4822 # [0, 2^31). When a value isn't in this range, a default value (or 0) |
| 4751 # should be returned instead. | 4823 # should be returned instead. |
| 4752 if ($signature->extendedAttributes->{"Reflect"} and ($type eq "unsigned long
" or $type eq "unsigned short")) { | 4824 if ($extendedAttributes->{"Reflect"} and ($type eq "unsigned long" or $type
eq "unsigned short")) { |
| 4753 $nativeValue =~ s/getUnsignedIntegralAttribute/getIntegralAttribute/g; | 4825 $nativeValue =~ s/getUnsignedIntegralAttribute/getIntegralAttribute/g; |
| 4754 return "$indent$receiver v8UnsignedInteger(std::max(0, " . $nativeValue
. "), $getIsolate);"; | 4826 return "$indent$receiver v8UnsignedInteger(std::max(0, " . $nativeValue
. "), $getIsolate);"; |
| 4755 } | 4827 } |
| 4756 | 4828 |
| 4757 # For all the types where we use 'int' as the representation type, | 4829 # For all the types where we use 'int' as the representation type, |
| 4758 # we use v8Integer() which has a fast small integer conversion check. | 4830 # we use v8Integer() which has a fast small integer conversion check. |
| 4759 my $nativeType = GetNativeType($type); | 4831 my $nativeType = GetNativeType($type); |
| 4760 return "$indent$receiver v8Integer($nativeValue, $getIsolate);" if $nativeTy
pe eq "int"; | 4832 return "$indent$receiver v8Integer($nativeValue, $getIsolate);" if $nativeTy
pe eq "int"; |
| 4761 return "$indent$receiver v8UnsignedInteger($nativeValue, $getIsolate);" if $
nativeType eq "unsigned"; | 4833 return "$indent$receiver v8UnsignedInteger($nativeValue, $getIsolate);" if $
nativeType eq "unsigned"; |
| 4762 | 4834 |
| 4763 return "$indent$receiver v8DateOrNull($nativeValue, $getIsolate);" if $type
eq "Date"; | 4835 return "$indent$receiver v8DateOrNull($nativeValue, $getIsolate);" if $type
eq "Date"; |
| 4764 # long long and unsigned long long are not representable in ECMAScript. | 4836 # long long and unsigned long long are not representable in ECMAScript. |
| 4765 return "$indent$receiver v8::Number::New(static_cast<double>($nativeValue));
" if $type eq "long long" or $type eq "unsigned long long" or $type eq "DOMTimeS
tamp"; | 4837 return "$indent$receiver v8::Number::New(static_cast<double>($nativeValue));
" if $type eq "long long" or $type eq "unsigned long long" or $type eq "DOMTimeS
tamp"; |
| 4766 return "$indent$receiver v8::Number::New($nativeValue);" if IsPrimitiveType(
$type); | 4838 return "$indent$receiver v8::Number::New($nativeValue);" if IsPrimitiveType(
$type); |
| 4767 return "$indent$receiver $nativeValue.v8Value();" if $nativeType eq "ScriptV
alue"; | 4839 return "$indent$receiver $nativeValue.v8Value();" if $nativeType eq "ScriptV
alue"; |
| 4768 | 4840 |
| 4769 if ($type eq "DOMString" or IsEnumType($type)) { | 4841 if ($type eq "DOMString" or IsEnumType($type)) { |
| 4770 my $conv = $signature->extendedAttributes->{"TreatReturnedNullStringAs"}
; | 4842 my $conv = $extendedAttributes->{"TreatReturnedNullStringAs"}; |
| 4771 if (defined $conv) { | 4843 if (defined $conv) { |
| 4772 return "$indent$receiver v8StringOrNull($nativeValue, $getIsolate$re
turnHandleTypeArg);" if $conv eq "Null"; | 4844 return "$indent$receiver v8StringOrNull($nativeValue, $getIsolate$re
turnHandleTypeArg);" if $conv eq "Null"; |
| 4773 return "$indent$receiver v8StringOrUndefined($nativeValue, $getIsola
te$returnHandleTypeArg);" if $conv eq "Undefined"; | 4845 return "$indent$receiver v8StringOrUndefined($nativeValue, $getIsola
te$returnHandleTypeArg);" if $conv eq "Undefined"; |
| 4774 | 4846 |
| 4775 die "Unknown value for TreatReturnedNullStringAs extended attribute"
; | 4847 die "Unknown value for TreatReturnedNullStringAs extended attribute"
; |
| 4776 } | 4848 } |
| 4777 return "$indent$receiver v8String($nativeValue, $getIsolate$returnHandle
TypeArg);"; | 4849 return "$indent$receiver v8String($nativeValue, $getIsolate$returnHandle
TypeArg);"; |
| 4778 } | 4850 } |
| 4779 | 4851 |
| 4780 my $arrayType = GetArrayType($type); | 4852 my $arrayType = GetArrayType($type); |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5060 | 5132 |
| 5061 sub IsRefPtrType | 5133 sub IsRefPtrType |
| 5062 { | 5134 { |
| 5063 my $type = shift; | 5135 my $type = shift; |
| 5064 | 5136 |
| 5065 return 0 if IsPrimitiveType($type); | 5137 return 0 if IsPrimitiveType($type); |
| 5066 return 0 if GetArrayType($type); | 5138 return 0 if GetArrayType($type); |
| 5067 return 0 if GetSequenceType($type); | 5139 return 0 if GetSequenceType($type); |
| 5068 return 0 if $type eq "DOMString"; | 5140 return 0 if $type eq "DOMString"; |
| 5069 return 0 if IsEnumType($type); | 5141 return 0 if IsEnumType($type); |
| 5142 return 0 if IsUnionType($type); |
| 5070 | 5143 |
| 5071 return 1; | 5144 return 1; |
| 5072 } | 5145 } |
| 5073 | 5146 |
| 5074 sub GetSVGTypeNeedingTearOff | 5147 sub GetSVGTypeNeedingTearOff |
| 5075 { | 5148 { |
| 5076 my $type = shift; | 5149 my $type = shift; |
| 5077 | 5150 |
| 5078 return $svgTypeNeedingTearOff{$type} if exists $svgTypeNeedingTearOff{$type}
; | 5151 return $svgTypeNeedingTearOff{$type} if exists $svgTypeNeedingTearOff{$type}
; |
| 5079 return undef; | 5152 return undef; |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5406 if ($currentInterface->extendedAttributes->{$extendedAttribute}) { | 5479 if ($currentInterface->extendedAttributes->{$extendedAttribute}) { |
| 5407 $found = 1; | 5480 $found = 1; |
| 5408 } | 5481 } |
| 5409 return 1 if $found; | 5482 return 1 if $found; |
| 5410 }, 0); | 5483 }, 0); |
| 5411 | 5484 |
| 5412 return $found; | 5485 return $found; |
| 5413 } | 5486 } |
| 5414 | 5487 |
| 5415 1; | 5488 1; |
| OLD | NEW |