📄 codegeneratorjs.pm
字号:
push(@implContent, "bool ${className}::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)\n"); push(@implContent, "{\n"); push(@implContent, GenerateGetOwnPropertySlotBody($dataNode, $interfaceName, $className, $implClassName, $numAttributes > 0, 0)); push(@implContent, "}\n\n"); } if (($dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"HasCustomIndexGetter"}) && !$dataNode->extendedAttributes->{"HasOverridingNameGetter"}) { push(@implContent, "bool ${className}::getOwnPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot)\n"); push(@implContent, "{\n"); push(@implContent, " if (propertyName < static_cast<$implClassName*>(impl())->length()) {\n"); if ($dataNode->extendedAttributes->{"HasCustomIndexGetter"}) { push(@implContent, " slot.setValue(getByIndex(exec, propertyName));\n"); } else { push(@implContent, " slot.setCustomIndex(this, propertyName, indexGetter);\n"); } push(@implContent, " return true;\n"); push(@implContent, " }\n"); push(@implContent, " return getOwnPropertySlot(exec, Identifier::from(exec, propertyName), slot);\n"); push(@implContent, "}\n\n"); } if ($numAttributes > 0) { foreach my $attribute (@{$dataNode->attributes}) { my $name = $attribute->signature->name; my $type = $codeGenerator->StripModule($attribute->signature->type); my $getFunctionName = "js" . $interfaceName . $codeGenerator->WK_ucfirst($attribute->signature->name) . ($attribute->signature->type =~ /Constructor$/ ? "Constructor" : ""); my $implGetterFunctionName = $codeGenerator->WK_lcfirst($name); push(@implContent, "JSValuePtr ${getFunctionName}(ExecState* exec, const Identifier&, const PropertySlot& slot)\n"); push(@implContent, "{\n"); my $implClassNameForValueConversion = ""; if (!$podType and ($codeGenerator->IsSVGAnimatedType($implClassName) or $attribute->type !~ /^readonly/)) { $implClassNameForValueConversion = $implClassName; } if ($dataNode->extendedAttributes->{"CheckDomainSecurity"} && !$attribute->signature->extendedAttributes->{"DoNotCheckDomainSecurity"} && !$attribute->signature->extendedAttributes->{"DoNotCheckDomainSecurityOnGet"}) { push(@implContent, " if (!static_cast<$className*>(asObject(slot.slotBase()))->allowsAccessFrom(exec))\n"); push(@implContent, " return jsUndefined();\n"); } if ($attribute->signature->extendedAttributes->{"Custom"} || $attribute->signature->extendedAttributes->{"JSCCustom"} || $attribute->signature->extendedAttributes->{"CustomGetter"}) { push(@implContent, " return static_cast<$className*>(asObject(slot.slotBase()))->$implGetterFunctionName(exec);\n"); } elsif ($attribute->signature->extendedAttributes->{"CheckNodeSecurity"}) { $implIncludes{"JSDOMBinding.h"} = 1; push(@implContent, " $implClassName* imp = static_cast<$implClassName*>(static_cast<$className*>(asObject(slot.slotBase()))->impl());\n"); push(@implContent, " return checkNodeSecurity(exec, imp->$implGetterFunctionName()) ? " . NativeToJSValue($attribute->signature, 0, $implClassName, $implClassNameForValueConversion, "imp->$implGetterFunctionName()", "static_cast<$className*>(asObject(slot.slotBase()))") . " : jsUndefined();\n"); } elsif ($attribute->signature->extendedAttributes->{"CheckFrameSecurity"}) { $implIncludes{"Document.h"} = 1; $implIncludes{"JSDOMBinding.h"} = 1; push(@implContent, " $implClassName* imp = static_cast<$implClassName*>(static_cast<$className*>(asObject(slot.slotBase()))->impl());\n"); push(@implContent, " return checkNodeSecurity(exec, imp->contentDocument()) ? " . NativeToJSValue($attribute->signature, 0, $implClassName, $implClassNameForValueConversion, "imp->$implGetterFunctionName()", "static_cast<$className*>(asObject(slot.slotBase()))") . " : jsUndefined();\n"); } elsif ($type eq "EventListener") { $implIncludes{"JSEventListener.h"} = 1; $implIncludes{"EventListener.h"} = 1; my $listenerType; if ($attribute->signature->extendedAttributes->{"ProtectedListener"}) { $listenerType = "JSEventListener"; } else { $listenerType = "JSUnprotectedEventListener"; } push(@implContent, " UNUSED_PARAM(exec);\n"); push(@implContent, " $implClassName* imp = static_cast<$implClassName*>(static_cast<$className*>(asObject(slot.slotBase()))->impl());\n"); push(@implContent, " if (${listenerType}* listener = static_cast<${listenerType}*>(imp->$implGetterFunctionName())) {\n"); push(@implContent, " if (JSObject* listenerObj = listener->listenerObj())\n"); push(@implContent, " return listenerObj;\n"); push(@implContent, " }\n"); push(@implContent, " return jsNull();\n"); } elsif ($attribute->signature->type =~ /Constructor$/) { my $constructorType = $codeGenerator->StripModule($attribute->signature->type); $constructorType =~ s/Constructor$//; push(@implContent, " UNUSED_PARAM(slot);\n"); push(@implContent, " return JS" . $constructorType . "::getConstructor(exec);\n"); } elsif (!@{$attribute->getterExceptions}) { push(@implContent, " UNUSED_PARAM(exec);\n"); if ($podType) { push(@implContent, " $podType imp(*static_cast<$className*>(asObject(slot.slotBase()))->impl());\n"); if ($podType eq "float") { # Special case for JSSVGNumber push(@implContent, " return " . NativeToJSValue($attribute->signature, 0, $implClassName, "", "imp", "static_cast<$className*>(asObject(slot.slotBase()))") . ";\n"); } else { push(@implContent, " return " . NativeToJSValue($attribute->signature, 0, $implClassName, "", "imp.$implGetterFunctionName()", "static_cast<$className*>(asObject(slot.slotBase()))") . ";\n"); } } else { push(@implContent, " $implClassName* imp = static_cast<$implClassName*>(static_cast<$className*>(asObject(slot.slotBase()))->impl());\n"); my $jsType = NativeToJSValue($attribute->signature, 0, $implClassName, $implClassNameForValueConversion, "imp->$implGetterFunctionName()", "static_cast<$className*>(asObject(slot.slotBase()))"); if ($codeGenerator->IsSVGAnimatedType($type)) { push(@implContent, " RefPtr<$type> obj = $jsType;\n"); push(@implContent, " return toJS(exec, obj.get(), imp);\n"); } else { push(@implContent, " return $jsType;\n"); } } } else { push(@implContent, " ExceptionCode ec = 0;\n"); if ($podType) { push(@implContent, " $podType imp(*static_cast<$className*>(asObject(slot.slotBase()))->impl());\n"); push(@implContent, " JSC::JSValuePtr result = " . NativeToJSValue($attribute->signature, 0, $implClassName, "", "imp.$implGetterFunctionName(ec)", "static_cast<$className*>(asObject(slot.slotBase()))") . ";\n"); } else { push(@implContent, " $implClassName* imp = static_cast<$implClassName*>(static_cast<$className*>(asObject(slot.slotBase()))->impl());\n"); push(@implContent, " JSC::JSValuePtr result = " . NativeToJSValue($attribute->signature, 0, $implClassName, $implClassNameForValueConversion, "imp->$implGetterFunctionName(ec)", "static_cast<$className*>(asObject(slot.slotBase()))") . ";\n"); } push(@implContent, " setDOMException(exec, ec);\n"); push(@implContent, " return result;\n"); } push(@implContent, "}\n\n"); } if ($dataNode->extendedAttributes->{"GenerateConstructor"}) { my $constructorFunctionName = "js" . $interfaceName . "Constructor"; push(@implContent, "JSValuePtr ${constructorFunctionName}(ExecState* exec, const Identifier&, const PropertySlot& slot)\n"); push(@implContent, "{\n"); push(@implContent, " return static_cast<$className*>(asObject(slot.slotBase()))->getConstructor(exec);\n"); push(@implContent, "}\n"); } } # Check if we have any writable attributes my $hasReadWriteProperties = 0; foreach my $attribute (@{$dataNode->attributes}) { $hasReadWriteProperties = 1 if $attribute->type !~ /^readonly/; } my $hasSetter = $hasReadWriteProperties || $dataNode->extendedAttributes->{"CustomPutFunction"} || $dataNode->extendedAttributes->{"HasCustomIndexSetter"}; if ($hasSetter) { push(@implContent, "void ${className}::put(ExecState* exec, const Identifier& propertyName, JSValuePtr value, PutPropertySlot& slot)\n"); push(@implContent, "{\n"); if ($dataNode->extendedAttributes->{"HasCustomIndexSetter"}) { push(@implContent, " bool ok;\n"); push(@implContent, " unsigned index = propertyName.toUInt32(&ok, false);\n"); push(@implContent, " if (ok) {\n"); push(@implContent, " indexSetter(exec, index, value);\n"); push(@implContent, " return;\n"); push(@implContent, " }\n"); } if ($dataNode->extendedAttributes->{"CustomPutFunction"}) { push(@implContent, " if (customPut(exec, propertyName, value, slot))\n"); push(@implContent, " return;\n"); } if ($hasReadWriteProperties) { push(@implContent, " lookupPut<$className, Base>(exec, propertyName, value, " . hashTableAccessor($dataNode->extendedAttributes->{"NoStaticTables"}, $className) . ", this, slot);\n"); } else { push(@implContent, " Base::put(exec, propertyName, value, slot);\n"); } push(@implContent, "}\n\n"); if ($dataNode->extendedAttributes->{"HasCustomIndexSetter"}) { push(@implContent, "void ${className}::put(ExecState* exec, unsigned propertyName, JSValuePtr value)\n"); push(@implContent, "{\n"); push(@implContent, " indexSetter(exec, propertyName, value);\n"); push(@implContent, " return;\n"); push(@implContent, "}\n\n"); } if ($hasReadWriteProperties) { foreach my $attribute (@{$dataNode->attributes}) { if ($attribute->type !~ /^readonly/) { my $name = $attribute->signature->name; my $type = $codeGenerator->StripModule($attribute->signature->type); my $putFunctionName = "setJS" . $interfaceName . $codeGenerator->WK_ucfirst($name) . ($attribute->signature->type =~ /Constructor$/ ? "Constructor" : ""); my $implSetterFunctionName = $codeGenerator->WK_ucfirst($name); push(@implContent, "void ${putFunctionName}(ExecState* exec, JSObject* thisObject, JSValuePtr value)\n"); push(@implContent, "{\n"); if ($dataNode->extendedAttributes->{"CheckDomainSecurity"} && !$attribute->signature->extendedAttributes->{"DoNotCheckDomainSecurity"}) { if ($interfaceName eq "DOMWindow") { push(@implContent, " if (!static_cast<$className*>(thisObject)->allowsAccessFrom(exec))\n"); } else { push(@implContent, " if (!allowsAccessFromFrame(exec, static_cast<$className*>(thisObject)->impl()->frame()))\n"); } push(@implContent, " return;\n"); } if ($attribute->signature->extendedAttributes->{"Custom"} || $attribute->signature->extendedAttributes->{"JSCCustom"} || $attribute->signature->extendedAttributes->{"CustomSetter"}) { push(@implContent, " static_cast<$className*>(thisObject)->set$implSetterFunctionName(exec, value);\n"); } elsif ($type eq "EventListener") { $implIncludes{"JSEventListener.h"} = 1; push(@implContent, " $implClassName* imp = static_cast<$implClassName*>(static_cast<$className*>(thisObject)->impl());\n"); my $listenerType; if ($attribute->signature->extendedAttributes->{"ProtectedListener"}) { $listenerType = "JSEventListener"; } else { $listenerType = "JSUnprotectedEventListener"; } if ($dataNode->extendedAttributes->{"ExtendsDOMGlobalObject"}) { push(@implContent, " JSDOMGlobalObject* globalObject = static_cast<$className*>(thisObject);\n"); } else { $implIncludes{"Frame.h"} = 1; $implIncludes{"JSDOMGlobalObject.h"} = 1; push(@implContent, " JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(imp->scriptExecutionContext());\n"); push(@implContent, " if (!globalObject)\n"); push(@implContent, " return;\n"); } push(@implContent, " imp->set$implSetterFunctionName(globalObject->findOrCreate${listenerType}(exec, value, true));\n"); } elsif ($attribute->signature->type =~ /Constructor$/) { my $constructorType = $attribute->signature->type; $constructorType =~ s/Constructor$//; $implIncludes{"JS" . $constructorType . ".h"} = 1; push(@implContent, " // Shadowing a built-in constructor\n"); push(@implContent, " static_cast<$className*>(thisObject)->putDirect(Identifier(exec, \"$name\"), value);\n"); } elsif ($attribute->signature->extendedAttributes->{"Replaceable"}) { push(@implContent, " // Shadowing a built-in object\n"); push(@implContent, " static_cast<$className*>(thisObject)->putDirect(Identifier(exec, \"$name\"), value);\n"); } else { if ($podType) { push(@implContent, " $podType imp(*static_cast<$className*>(thisObject)->impl());\n"); if ($podType eq "float") { # Special case for JSSVGNumber push(@implContent, " imp = " . JSValueToNative($attribute->signature, "value") . ";\n"); } else { push(@implContent, " imp.set$implSetterFunctionName(" . JSValueToNative($attribute->signature, "value") . ");\n"); } push(@implContent, " static_cast<$className*>(thisObject)->impl()->commitChange(imp, static_cast<$className*>(thisObject)->context());\n"); } else { push(@implContent, " $implClassName* imp = static_cast<$implClassName*>(static_cast<$className*>(thisObject)->impl());\n"); push(@implContent, " ExceptionCode ec = 0;\n") if @{$attribute->setterExceptions}; push(@implContent, " imp->set$implSetterFunctionName(" . JSValueToNative($attribute->signature, "value")); push(@implContent, ", ec") if @{$attribute->setterExceptions}; push(@implContent, ");\n"); push(@implContent, " setDOMException(exec, ec);\n") if @{$attribute->setterExceptions}; if (IsSVGTypeNeedingContextParameter($implClassName)) { push(@implContent, " if (static_cast<$className*>(thisObject)->context())\n"); push(@implContent, " static_cast<$className*>(thisObject)->context()->svgAttributeChanged(static_cast<$className*>(thisObject)->impl()->associatedAttributeName());\n"); } } } push(@implContent, "}\n\n"); } } } } } if ($dataNode->extendedAttributes->{"CustomGetPropertyNames"} || $dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"HasCustomIndexGetter"}) { push(@implContent, "void ${className}::getPropertyNames(ExecState* exec, PropertyNameArray& propertyNames)\n"); push(@implContent, "{\n"); if ($dataNode->extendedAttributes->{"CustomGetPropertyNames"}) { push(@implContent, " if (customGetPropertyNames(exec, propertyNames))\n"); push(@implContent, " return;\n"); } if ($dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"HasCustomIndexGetter"}) { push(@implContent, " for (unsigned i = 0; i < static_cast<${implClassName}*>(impl())->length(); ++i)\n"); push(@implContent, " propertyNames.add(Identifier::from(exec, i));\n"); } push(@implContent, " Ba
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -