diff options
Diffstat (limited to 'contrib/dom/scripts/CodeGeneratorArabicaV8.pm')
-rw-r--r-- | contrib/dom/scripts/CodeGeneratorArabicaV8.pm | 89 |
1 files changed, 57 insertions, 32 deletions
diff --git a/contrib/dom/scripts/CodeGeneratorArabicaV8.pm b/contrib/dom/scripts/CodeGeneratorArabicaV8.pm index 3382c24..738e981 100644 --- a/contrib/dom/scripts/CodeGeneratorArabicaV8.pm +++ b/contrib/dom/scripts/CodeGeneratorArabicaV8.pm @@ -47,7 +47,7 @@ my %headerIncludes = (); # Default .h template my $headerTemplate = << "EOF"; /* - This file is part of the Arabica open source project. + This file is part of the Wrapper open source project. This file has been generated by generate-bindings.pl. DO NOT MODIFY! This library is free software; you can redistribute it and/or @@ -161,16 +161,20 @@ sub GenerateHeader push(@headerContent, "\nclass V8${interfaceName} {"); push(@headerContent, "\npublic:"); - my $arabicaType = IdlToArabicaType($interfaceName); + my $wrapperType = IdlToWrapperType($interfaceName); push(@headerContent, <<END); struct V8${interfaceName}Private { V8DOM* dom; - ${arabicaType}* arabicaThis; + ${wrapperType}* nativeObj; }; END - push(@headerContent, "\n V8_DESTRUCTOR(V8${interfaceName}Private);"); + if ($extensions->{'DontDestroyWrapped'}) { + push(@headerContent, "\n V8_DESTRUCTOR_KEEP_WRAPPED(V8${interfaceName}Private);"); + } else { + push(@headerContent, "\n V8_DESTRUCTOR(V8${interfaceName}Private);"); + } push(@headerContent, "\n static bool hasInstance(v8::Handle<v8::Value>);"); push(@headerContent, "\n"); @@ -270,8 +274,8 @@ END my $value = $constant->value; my $type = IdlToV8Type($constant->type); push(@headerContent, <<END); - tmpl->Set(v8::String::NewSymbol("${name}"), ${type}::New(${value}), v8::ReadOnly); - prototype->Set(v8::String::NewSymbol("${name}"), ${type}::New(${value}), v8::ReadOnly); + tmpl->Set(v8::String::NewSymbol("${name}"), ${type}::New(${value}), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("${name}"), ${type}::New(${value}), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); END } @@ -294,6 +298,7 @@ sub GenerateImplementationAttributes { my $interface = shift; my $interfaceName = $interface->name; + my $extensions = $interface->extendedAttributes; # Generate property accessors for attributes. for (my $index = 0; $index < @{$interface->attributes}; $index++) { @@ -302,11 +307,16 @@ sub GenerateImplementationAttributes my $attrName = $attribute->signature->name; my $attrExt = $attribute->signature->extendedAttributes; - my $arabicaRetType = IdlToArabicaType($attrType); - my $arabicaType = IdlToArabicaType($interfaceName); - my $arabicaGetter = IdlToArabicaAttrGetter($interface, $attribute); - - next if ($attrExt->{'Custom'}); + my $wrapperRetType = IdlToWrapperType($attrType); + my $wrapperType = IdlToWrapperType($interfaceName); + my $wrapperGetter; + + if ($attrExt->{'AttributeIsPublic'} || $extensions->{'AttributesArePublic'}) { + $wrapperGetter = $attrName; + } else { + $wrapperGetter = IdlToWrapperAttrGetter($interface, $attribute)."()"; + + } # getter if (!$attrExt->{'CustomGetter'}) { @@ -318,15 +328,18 @@ sub GenerateImplementationAttributes END if (IsWrapperType($attrType)) { AddToImplIncludes("V8".$attrType.".h"); + push(@implContent, "\n ".GenerateConditionalUndefReturn($interface, $attribute, "privData->nativeObj->${wrapperGetter}")); + push(@implContent, <<END); - ${arabicaRetType}* arbaicaRet = new ${arabicaRetType}(privData->arabicaThis->${arabicaGetter}()); + + ${wrapperRetType}* arbaicaRet = new ${wrapperRetType}(privData->nativeObj->${wrapperGetter}); v8::Handle<v8::Function> arbaicaRetCtor = V8${attrType}::getTmpl()->GetFunction(); v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::New(arbaicaRetCtor->NewInstance()); struct V8${attrType}::V8${attrType}Private* retPrivData = new V8${attrType}::V8${attrType}Private(); retPrivData->dom = privData->dom; - retPrivData->arabicaThis = arbaicaRet; + retPrivData->nativeObj = arbaicaRet; arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); arbaicaRetObj.MakeWeak(0, V8${attrType}::jsDestructor); @@ -335,9 +348,9 @@ END } else { my $v8Type = IdlToV8Type($attrType); if ($attrType eq "DOMString") { - push(@implContent, "\n return ${v8Type}::New(privData->arabicaThis->${arabicaGetter}().c_str());"); + push(@implContent, "\n return ${v8Type}::New(privData->nativeObj->${wrapperGetter}.c_str());"); } else { - push(@implContent, "\n return ${v8Type}::New(privData->arabicaThis->${arabicaGetter}());"); + push(@implContent, "\n return ${v8Type}::New(privData->nativeObj->${wrapperGetter});"); } } push(@implContent, "\n }\n"); @@ -346,7 +359,7 @@ END if (!$attrExt->{'CustomSetter'}) { # setter if (!IsReadonly($attribute)) { - my $arabicaSetter = IdlToArabicaAttrSetter($attrName); + my $wrapperSetter = IdlToWrapperAttrSetter($attrName); push(@implContent, "\n void V8${interfaceName}::${attrName}AttrSetter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info) {"); push(@implContent, "\n v8::Local<v8::Object> self = info.Holder();"); push(@implContent, "\n struct V8${interfaceName}Private* privData = V8DOM::toClassPtr<V8${interfaceName}Private >(self->GetInternalField(0));"); @@ -354,7 +367,7 @@ END my ($handle, $deref) = IdlToArgHandle($attribute->signature->type, "local".ucfirst($attribute->signature->name), "value"); push(@implContent, "\n $handle"); - push(@implContent, "\n privData->arabicaThis->${arabicaSetter}(${deref});"); + push(@implContent, "\n privData->nativeObj->${wrapperSetter}(${deref});"); push(@implContent, "\n }\n"); } @@ -362,18 +375,29 @@ END } } +sub GenerateConditionalUndefReturn +{ + my $interface = shift; + my $attribute = shift; + my $getterExpression = shift; + + return "" if ($attribute->signature->type eq "NamedNodeMap"); + return "" if ($attribute->signature->type eq "NodeList"); + return "if (!$getterExpression) return v8::Undefined();"; +} + sub GenerateImplementationFunctionCallbacks { my $interface = shift; my $interfaceName = $interface->name; - my $arabicaType = IdlToArabicaType($interfaceName); + my $wrapperType = IdlToWrapperType($interfaceName); # Generate methods for functions. foreach my $function (@{$interface->functions}) { my $name = $function->signature->name; my $attrExt = $function->signature->extendedAttributes; my $retType = $function->signature->type; - my $arabicaRetType = IdlToArabicaType($retType); + my $wrapperRetType = IdlToWrapperType($retType); next if ($attrExt->{'Custom'}); @@ -412,13 +436,13 @@ END # invoke native function with argument handles my $retNativeType = IdlToNativeType($retType); - my $arabicaFunctionName = IdlToArabicaFunction($interface, $function); + my $wrapperFunctionName = IdlToWrapperFunction($interface, $function); if (IsWrapperType($retType)) { - push(@implContent, "\n\n ${retNativeType}* retVal = new $arabicaRetType(privData->arabicaThis->${arabicaFunctionName}(" . join(", ", @argList) . "));\n"); + push(@implContent, "\n\n ${retNativeType}* retVal = new $wrapperRetType(privData->nativeObj->${wrapperFunctionName}(" . join(", ", @argList) . "));\n"); } elsif ($retNativeType eq "void") { - push(@implContent, "\n\n privData->arabicaThis->${arabicaFunctionName}(" . join(", ", @argList) . ");\n"); + push(@implContent, "\n\n privData->nativeObj->${wrapperFunctionName}(" . join(", ", @argList) . ");\n"); } else { - push(@implContent, "\n\n ${retNativeType} retVal = privData->arabicaThis->${arabicaFunctionName}(" . join(", ", @argList) . ");\n"); + push(@implContent, "\n\n ${retNativeType} retVal = privData->nativeObj->${wrapperFunctionName}(" . join(", ", @argList) . ");\n"); } # wrap return type if needed @@ -431,7 +455,7 @@ END struct V8${retType}::V8${retType}Private* retPrivData = new V8${retType}::V8${retType}Private(); retPrivData->dom = privData->dom; - retPrivData->arabicaThis = retVal; + retPrivData->nativeObj = retVal; retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); @@ -455,7 +479,7 @@ sub GenerateImplementation my $interfaceName = $interface->name; my $visibleInterfaceName = $codeGenerator->GetVisibleInterfaceName($interface); my $v8InterfaceName = "V8$interfaceName"; - my $arabicaType = IdlToArabicaType($interfaceName); + my $wrapperType = IdlToWrapperType($interfaceName); AddToImplIncludes("V8${interfaceName}.h"); @@ -572,7 +596,7 @@ sub IdlToNativeType { my $idlType = shift; - return IdlToArabicaType($idlType) if (IsWrapperType($idlType)); + return IdlToWrapperType($idlType) if (IsWrapperType($idlType)); return "std::string" if ($idlType eq "DOMString"); return "bool" if ($idlType eq "boolean"); @@ -594,13 +618,14 @@ sub NativeToHandle die($nativeType); } -sub IdlToArabicaType +sub IdlToWrapperType { my $idlType = shift; return "Arabica::XPath::XPathValue<std::string>" if ($idlType eq "XPathResult"); return "Arabica::XPath::NodeSet<std::string>" if ($idlType eq "NodeSet"); return "Arabica::DOM::Node<std::string>" if ($idlType eq "Node"); return "Arabica::DOM::Element<std::string>" if ($idlType eq "Element"); + return "uscxml::Event" if ($idlType eq "SCXMLEvent"); return "Arabica::DOM::${idlType}<std::string>"; } @@ -616,15 +641,15 @@ sub IdlToArgHandle return ("bool ${localName} = ${paramName}->ToBoolean()->BooleanValue();", ${localName}) if ($type eq "boolean"); if (IsWrapperType($type)) { - my $arabicaType = IdlToArabicaType($type); - return ("${arabicaType}* ${localName} = V8DOM::toClassPtr<V8${type}::V8${type}Private >(${paramName}->ToObject()->GetInternalField(0))->arabicaThis;", "*${localName}"); + my $wrapperType = IdlToWrapperType($type); + return ("${wrapperType}* ${localName} = V8DOM::toClassPtr<V8${type}::V8${type}Private >(${paramName}->ToObject()->GetInternalField(0))->nativeObj;", "*${localName}"); } print $type."\n"; die(); } -sub IdlToArabicaAttrGetter +sub IdlToWrapperAttrGetter { my $interface = shift; my $attribute = shift; @@ -638,7 +663,7 @@ sub IdlToArabicaAttrGetter return "get" . ucfirst($attribute->signature->name); } -sub IdlToArabicaFunction +sub IdlToWrapperFunction { my $interface = shift; my $function = shift; @@ -654,7 +679,7 @@ sub IdlToArabicaFunction } -sub IdlToArabicaAttrSetter +sub IdlToWrapperAttrSetter { my $idlAttr = shift; return "set" . ucfirst($idlAttr); |