| Index: Source/bindings/scripts/CodeGeneratorV8.pm
|
| diff --git a/Source/bindings/scripts/CodeGeneratorV8.pm b/Source/bindings/scripts/CodeGeneratorV8.pm
|
| index 862fd09ec4cb00c52f24c4e13a9852272d01f8c4..4f3bd4a5a007428c86b2a9046e0b8769f9e43c43 100644
|
| --- a/Source/bindings/scripts/CodeGeneratorV8.pm
|
| +++ b/Source/bindings/scripts/CodeGeneratorV8.pm
|
| @@ -1642,7 +1642,7 @@ END
|
| return value;
|
| END
|
| } else {
|
| - $code .= " return " . NativeToJSValue($attribute->signature, $expression, "info.Holder()", "info.GetIsolate()", "info", "imp", "ReturnUnsafeHandle", $forMainWorldSuffix).";\n";
|
| + $code .= " return " . NativeToJSValue($attribute->signature->type, $attribute->signature->extendedAttributes, $expression, "info.Holder()", "info.GetIsolate()", "info", "imp", "ReturnUnsafeHandle", $forMainWorldSuffix).";\n";
|
| }
|
|
|
| $code .= "}\n\n"; # end of getter
|
| @@ -3153,6 +3153,53 @@ END
|
| return $code;
|
| }
|
|
|
| +sub GetIsNullExpression
|
| +{
|
| + my $type = shift;
|
| + my $variableName = shift;
|
| + if (IsRefPtrType($type)) {
|
| + return "!${variableName}";
|
| + } else {
|
| + return "${variableName}.isNull()";
|
| + }
|
| +}
|
| +
|
| +sub GetCreateJSValueStatements
|
| +{
|
| + my $variableName = shift;
|
| + my $type = shift;
|
| + my $extendedAttributes = shift;
|
| + my $value = shift; # expression of native value
|
| + my $getCreationContext = shift;
|
| + my $getIsolate = shift;
|
| + my $getHolderContainer = shift;
|
| + my $getHolderContainerArg = $getHolderContainer ? ", $getHolderContainer" : "";
|
| + my $getScriptWrappable = shift;
|
| + my $getScriptWrappableArg = $getScriptWrappable ? ", $getScriptWrappable" : "";
|
| + my $returnHandleType = shift;
|
| + my $returnHandleTypeArg = $returnHandleType ? ", $returnHandleType" : "";
|
| + my $forMainWorldSuffix = shift;
|
| +
|
| + # Union type
|
| + if (ref $type) {
|
| + my $types = $type->unionType->unionMemberTypes;
|
| + die "Currently only 2 values of non-union type is supported as union type.\n" unless scalar(@$types)==2 && scalar(grep {ref $_} @$types)==0;
|
| + my $code = "";
|
| + for my $i (0 .. scalar(@$types)-1) {
|
| + my $unionMemberType = $types->[$i];
|
| + my $jsValue = NativeToJSValue($unionMemberType, $extendedAttributes, "$value.getValue${i}()", $getCreationContext, $getIsolate, $getHolderContainer, $getScriptWrappable, $returnHandleType, $forMainWorldSuffix);
|
| + $code .= <<END
|
| + if (${value}.isValue${i}Enabled())
|
| + ${variableName} = ${jsValue};
|
| +END
|
| + }
|
| + return $code;
|
| + } else {
|
| + my $jsValue = NativeToJSValue($type, $extendedAttributes, $value, $getCreationContext, $getIsolate, $getHolderContainer, $getScriptWrappable, $returnHandleType, $forMainWorldSuffix);
|
| + return " ${variableName} = ${jsValue};";
|
| + }
|
| +}
|
| +
|
| sub GenerateImplementationIndexedProperty
|
| {
|
| my $interface = shift;
|
| @@ -3200,21 +3247,14 @@ sub GenerateImplementationIndexedProperty
|
|
|
| if ($indexedGetterfunction && !$hasCustomIndexedGetter) {
|
| my $returnType = $indexedGetterfunction->signature->type;
|
| + my $nativeType = GetNativeType($returnType);
|
| my $methodName = $indexedGetterfunction->signature->name;
|
| $methodName ||= $indexedGetterfunction->signature->extendedAttributes->{"ImplementedAs"};
|
| AddToImplIncludes("bindings/v8/V8Collection.h");
|
| - my $jsValue = "";
|
| - my $nativeType = GetNativeType($returnType);
|
| - my $isNull = "";
|
| -
|
| - if (IsRefPtrType($returnType)) {
|
| - AddToImplIncludes("V8$returnType.h");
|
| - $isNull = "!element";
|
| - $jsValue = NativeToJSValue($indexedGetterfunction->signature, "element.release()", "info.Holder()", "info.GetIsolate()", "info", "collection", "", "");
|
| - } else {
|
| - $isNull = "element.isNull()";
|
| - $jsValue = NativeToJSValue($indexedGetterfunction->signature, "element", "info.Holder()", "info.GetIsolate()");
|
| - }
|
| + my $nativeExpression = "element";
|
| + $nativeExpression .= ".release()" if (IsRefPtrType($returnType));
|
| + my $isNull = GetIsNullExpression($returnType, "element");
|
| + my $genJSValueStatements = GetCreateJSValueStatements("jsValue", $returnType, $indexedGetterfunction->signature->extendedAttributes, $nativeExpression, "info.Holder()", "info.GetIsolate()", "info", "collection", "", "");
|
|
|
| $implementation{nameSpaceWebCore}->add(<<END);
|
| v8::Handle<v8::Value> ${v8ClassName}::indexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info)
|
| @@ -3222,9 +3262,12 @@ v8::Handle<v8::Value> ${v8ClassName}::indexedPropertyGetter(uint32_t index, cons
|
| ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder()));
|
| ${implClassName}* collection = toNative(info.Holder());
|
| $nativeType element = collection->$methodName(index);
|
| - if ($isNull)
|
| + if (${isNull})
|
| return v8Undefined();
|
| - return $jsValue;
|
| +
|
| + v8::Handle<v8::Value> jsValue;
|
| +$genJSValueStatements
|
| + return jsValue;
|
| }
|
|
|
| END
|
| @@ -3245,25 +3288,18 @@ sub GenerateImplementationNamedPropertyGetter
|
| my $hasCustomNamedGetter = $interface->extendedAttributes->{"CustomNamedGetter"};
|
|
|
| if ($namedGetterFunction && !$hasCustomNamedGetter) {
|
| + $subCode .= <<END;
|
| + desc->InstanceTemplate()->SetNamedPropertyHandler(${v8ClassName}::namedPropertyGetter, 0, 0, 0, 0);
|
| +END
|
| my $returnType = $namedGetterFunction->signature->type;
|
| + my $nativeType = GetNativeType($namedGetterFunction->signature->type);
|
| my $methodName = $namedGetterFunction->signature->name;
|
| $methodName ||= $namedGetterFunction->signature->extendedAttributes->{"ImplementedAs"};
|
| AddToImplIncludes("bindings/v8/V8Collection.h");
|
| - $subCode .= <<END;
|
| - desc->InstanceTemplate()->SetNamedPropertyHandler(${v8ClassName}::namedPropertyGetter, 0, 0, 0, 0);
|
| -END
|
| - my $jsValue = "";
|
| - my $nativeType = GetNativeType($returnType);
|
| - my $isNull = "";
|
| -
|
| - if (IsRefPtrType($returnType)) {
|
| - AddToImplIncludes("V8$returnType.h");
|
| - $isNull = "!element";
|
| - $jsValue = NativeToJSValue($namedGetterFunction->signature, "element.release()", "info.Holder()", "info.GetIsolate()", "info", "collection", "", "");
|
| - } else {
|
| - $isNull = "element.isNull()";
|
| - $jsValue = NativeToJSValue($namedGetterFunction->signature, "element", "info.Holder()", "info.GetIsolate()");
|
| - }
|
| + my $nativeExpression = "element";
|
| + $nativeExpression .= ".release()" if (IsRefPtrType($returnType));
|
| + my $isNull = GetIsNullExpression($returnType, "element");
|
| + my $genJSValueStatements = GetCreateJSValueStatements("jsValue", $returnType, $namedGetterFunction->signature->extendedAttributes, $nativeExpression, "info.Holder()", "info.GetIsolate()", "info", "collection", "", "");
|
|
|
| $implementation{nameSpaceWebCore}->add(<<END);
|
| v8::Handle<v8::Value> ${v8ClassName}::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
|
| @@ -3279,7 +3315,10 @@ v8::Handle<v8::Value> ${v8ClassName}::namedPropertyGetter(v8::Local<v8::String>
|
| ${nativeType} element = collection->${methodName}(propertyName);
|
| if (${isNull})
|
| return v8Undefined();
|
| - return ${jsValue};
|
| +
|
| + v8::Handle<v8::Value> jsValue;
|
| +$genJSValueStatements
|
| + return jsValue;
|
| }
|
|
|
| END
|
| @@ -4199,7 +4238,7 @@ END
|
| @args = ();
|
| foreach my $param (@params) {
|
| my $paramName = $param->name;
|
| - $code .= " v8::Handle<v8::Value> ${paramName}Handle = " . NativeToJSValue($param, $paramName, "v8::Handle<v8::Object>()", "v8Context->GetIsolate()", "") . ";\n";
|
| + $code .= " v8::Handle<v8::Value> ${paramName}Handle = " . NativeToJSValue($param->type, $param->extendedAttributes, $paramName, "v8::Handle<v8::Object>()", "v8Context->GetIsolate()", "") . ";\n";
|
| $code .= " if (${paramName}Handle.IsEmpty()) {\n";
|
| $code .= " if (!isScriptControllerTerminating())\n";
|
| $code .= " CRASH();\n";
|
| @@ -4572,9 +4611,9 @@ sub GenerateFunctionCallString
|
| my $nativeValue;
|
| # FIXME: Update for all ScriptWrappables.
|
| if (IsDOMNodeType($interfaceName)) {
|
| - $nativeValue = NativeToJSValue($function->signature, $return, "args.Holder()", "args.GetIsolate()", "args", "imp", "ReturnUnsafeHandle", $forMainWorldSuffix);
|
| + $nativeValue = NativeToJSValue($function->signature->type, $function->signature->extendedAttributes, $return, "args.Holder()", "args.GetIsolate()", "args", "imp", "ReturnUnsafeHandle", $forMainWorldSuffix);
|
| } else {
|
| - $nativeValue = NativeToJSValue($function->signature, $return, "args.Holder()", "args.GetIsolate()", 0, 0, "ReturnUnsafeHandle", $forMainWorldSuffix);
|
| + $nativeValue = NativeToJSValue($function->signature->type, $function->signature->extendedAttributes, $return, "args.Holder()", "args.GetIsolate()", 0, 0, "ReturnUnsafeHandle", $forMainWorldSuffix);
|
| }
|
|
|
| $code .= $indent . "return " . $nativeValue . ";\n";
|
| @@ -4649,6 +4688,13 @@ sub GetNativeType
|
| return "RefPtr<SerializedScriptValue>" if $type eq "SerializedScriptValue";
|
| return "RefPtr<XPathNSResolver>" if $type eq "XPathNSResolver";
|
|
|
| + # Union type
|
| + if (ref $type) {
|
| + my $types = $type->unionType->unionMemberTypes;
|
| + die "Currently only 2 values of non-union type is supported as union type.\n" unless scalar(@$types)==2 && scalar(grep {ref $_} @$types)==0;
|
| + return "WTF::UnionType2<" . (join ", ", @$types) . ">";
|
| + }
|
| +
|
| # We need to check [ImplementedBy] extended attribute for wrapper types.
|
| if (IsWrapperType($type)) {
|
| my $interface = ParseInterface($type);
|
| @@ -4977,8 +5023,9 @@ sub IsDOMNodeType
|
|
|
| sub NativeToJSValue
|
| {
|
| - my $signature = shift;
|
| - my $value = shift;
|
| + my $type = shift;
|
| + my $extendedAttributes = shift;
|
| + my $value = shift; # expression of native value
|
| my $getCreationContext = shift;
|
| my $getIsolate = shift;
|
| die "An Isolate is mandatory for native value => JS value conversion." unless $getIsolate;
|
| @@ -4990,7 +5037,11 @@ sub NativeToJSValue
|
| my $returnHandleTypeArg = $returnHandleType ? ", $returnHandleType" : "";
|
| my $forMainWorldSuffix = shift;
|
|
|
| - my $type = $signature->type;
|
| + # Union type
|
| + if (ref $type) {
|
| + my $types = $type->unionType->unionMemberTypes;
|
| + die "JSValue of UnionType can not be obtained as expression. use GetCreateJSValueStatements() instead.\n";
|
| + }
|
|
|
| return "v8Boolean($value, $getIsolate)" if $type eq "boolean";
|
| return "v8Undefined()" if $type eq "void"; # equivalent to v8Undefined()
|
| @@ -4998,7 +5049,7 @@ sub NativeToJSValue
|
| # HTML5 says that unsigned reflected attributes should be in the range
|
| # [0, 2^31). When a value isn't in this range, a default value (or 0)
|
| # should be returned instead.
|
| - if ($signature->extendedAttributes->{"Reflect"} and ($type eq "unsigned long" or $type eq "unsigned short")) {
|
| + if ($extendedAttributes->{"Reflect"} and ($type eq "unsigned long" or $type eq "unsigned short")) {
|
| $value =~ s/getUnsignedIntegralAttribute/getIntegralAttribute/g;
|
| return "v8UnsignedInteger(std::max(0, " . $value . "), $getIsolate)";
|
| }
|
| @@ -5016,7 +5067,7 @@ sub NativeToJSValue
|
| return "$value.v8Value()" if $nativeType eq "ScriptValue";
|
|
|
| if ($type eq "DOMString" or IsEnumType($type)) {
|
| - my $conv = $signature->extendedAttributes->{"TreatReturnedNullStringAs"};
|
| + my $conv = $extendedAttributes->{"TreatReturnedNullStringAs"};
|
| if (defined $conv) {
|
| return "v8StringOrNull($value, $getIsolate$returnHandleTypeArg)" if $conv eq "Null";
|
| return "v8StringOrUndefined($value, $getIsolate$returnHandleTypeArg)" if $conv eq "Undefined";
|
| @@ -5345,6 +5396,7 @@ sub IsRefPtrType
|
| return 0 if GetSequenceType($type);
|
| return 0 if $type eq "DOMString";
|
| return 0 if IsEnumType($type);
|
| + return 0 if ref $type; # Union
|
|
|
| return 1;
|
| }
|
|
|