Skip to content

Instantly share code, notes, and snippets.

@annulen
Created June 14, 2019 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save annulen/6c31880ff564f2788713f8fb56a03a55 to your computer and use it in GitHub Desktop.
Save annulen/6c31880ff564f2788713f8fb56a03a55 to your computer and use it in GitHub Desktop.
commit 7f75ee92f3b59de9f0ba95f6e740dacb2fbcf757
Author: commit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Mon Sep 4 10:50:58 2017 +0000
Source/JavaScriptCore:
[WebIDL] Unify and simplify EnableBySettings with the rest of the runtime settings
https://bugs.webkit.org/show_bug.cgi?id=176312
Patch by Sam Weinig <sam@webkit.org> on 2017-09-04
Reviewed by Darin Adler.
* runtime/CommonIdentifiers.h:
Remove WebCore specific identifiers from CommonIdentifiers. They have been moved
to WebCoreBuiltinNames in WebCore.
Source/WebCore:
[WebIDL] Simplify EnabledBySettings generation
https://bugs.webkit.org/show_bug.cgi?id=176312
Patch by Sam Weinig <sam@webkit.org> on 2017-09-04
Reviewed by Darin Adler.
* bindings/scripts/CodeGeneratorJS.pm:
(NeedsRuntimeCheck):
(OperationShouldBeOnInstance):
(GeneratePropertiesHashTable):
(GenerateRuntimeEnableConditionalString):
(GenerateImplementation):
(GenerateAttributeGetterBodyDefinition):
- Simplify the [EnabledBySetting] code generation by merging it with the other
runtime checks (Exposed, EnabledAtRuntime, EnabledForWorld, and SecureContext).
- Switches to using WebCoreBuiltinNames for identifiers, rather than relying
on the appropriate identifiers being available on JavaScriptCore's CommonIdentifiers
which was an unnecessary layering violation. There are still problems with this
as we continue to be inconsistent about which identifiers deserve to be in
WebCoreBuiltinNames, and which ones can be created each time and there is no
automation of WebCoreBuiltinNames from the IDLs.
- Enforce at code generation time that [EnabledBySetting] can only be used
on interfaces that are uniquely exposed to the window environment. This is a
condition we should find a way to remove (e.g. propagating necessary settings
to an object the ScriptExecutionContext owns), but for now, Settings is a main
thread only object.
* bindings/js/JSDOMWindowCustom.cpp:
(WebCore::jsDOMWindowGetOwnPropertySlotRestrictedAccess):
(WebCore::JSDOMWindow::getOwnPropertySlot):
(WebCore::JSDOMWindow::put):
(WebCore::addCrossOriginWindowPropertyNames):
(WebCore::addCrossOriginWindowOwnPropertyNames):
Switch to using WebCoreBuiltinNames for WebCore specific identifiers.
* bindings/js/WebCoreBuiltinNames.h:
Add WebCore specific identifiers from JavaScriptCore's CommonIdentifiers
as well as some new ones need by the [EnableBySetting] unification.
* bindings/scripts/test/JS/JSTestEnabledBySetting.cpp: Added.
* bindings/scripts/test/JS/JSTestEnabledBySetting.h: Added.
* bindings/scripts/test/TestEnabledBySetting.idl: Added.
Add new test for [EnabledBySetting].
* bindings/scripts/test/JS/JSTestGlobalObject.cpp:
* bindings/scripts/test/JS/JSTestObj.cpp:
* bindings/scripts/test/TestObj.idl:
Remove use of [EnabledBySetting] from TestObj, as it is no longer
valid to use [EnabledBySetting] on interfaces that are no uniquely
exposed to the window environment.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@221585 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm b/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
index 4a073044f5b..bd1bac9c071 100644
--- a/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
+++ b/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
@@ -1695,6 +1695,7 @@ sub NeedsRuntimeCheck
return $context->extendedAttributes->{EnabledAtRuntime}
|| $context->extendedAttributes->{EnabledForWorld}
+ || $context->extendedAttributes->{EnabledBySetting}
|| $context->extendedAttributes->{SecureContext};
}
@@ -1705,11 +1706,11 @@ sub OperationShouldBeOnInstance
return 1 if IsGlobalOrPrimaryGlobalInterface($interface);
- # FIXME: The bindings generator does not support putting runtime-enabled operations on the instance yet (except for global objects).
- return 0 if NeedsRuntimeCheck($interface, $operation);
-
# [Unforgeable] operations should be on the instance. https://heycam.github.io/webidl/#Unforgeable
- return 1 if IsUnforgeable($interface, $operation);
+ if (IsUnforgeable($interface, $operation)) {
+ assert("The bindings generator does not support putting runtime-enabled operations on the instance yet (except for global objects):[" . $interface->type->name . "::" . $operation->name . "]") if NeedsRuntimeCheck($interface, $operation);
+ return 1;
+ }
return 0;
}
@@ -2990,7 +2991,7 @@ sub GenerateHeader
sub GeneratePropertiesHashTable
{
- my ($object, $interface, $isInstance, $hashKeys, $hashSpecials, $hashValue1, $hashValue2, $conditionals, $readWriteConditionals, $runtimeEnabledOperations, $runtimeEnabledAttributes, $settingsEnabledOperations, $settingsEnabledAttributes) = @_;
+ my ($object, $interface, $isInstance, $hashKeys, $hashSpecials, $hashValue1, $hashValue2, $conditionals, $readWriteConditionals, $runtimeEnabledOperations, $runtimeEnabledAttributes) = @_;
# FIXME: These should be functions on $interface.
my $interfaceName = $interface->type->name;
@@ -3053,10 +3054,6 @@ sub GeneratePropertiesHashTable
if (NeedsRuntimeCheck($interface, $attribute)) {
push(@$runtimeEnabledAttributes, $attribute);
}
-
- if ($attribute->extendedAttributes->{EnabledBySetting}) {
- push(@$settingsEnabledAttributes, $attribute);
- }
}
my @operations = @{$interface->operations};
@@ -3098,10 +3095,6 @@ sub GeneratePropertiesHashTable
if (NeedsRuntimeCheck($interface, $operation)) {
push(@$runtimeEnabledOperations, $operation);
}
-
- if ($operation->extendedAttributes->{EnabledBySetting}) {
- push(@$settingsEnabledOperations, $operation);
- }
}
return $propertyCount;
@@ -3660,6 +3653,20 @@ sub GenerateRuntimeEnableConditionalString
push(@conjuncts, "worldForDOMObject(this)." . ToMethodName($context->extendedAttributes->{EnabledForWorld}) . "()");
}
+ if ($context->extendedAttributes->{EnabledBySetting}) {
+ assert("Must specify value for EnabledBySetting.") if $context->extendedAttributes->{EnabledBySetting} eq "VALUE_IS_MISSING";
+
+ AddToImplIncludes("Document.h");
+ AddToImplIncludes("Settings.h");
+
+ assert("EnabledBySetting can only be used by interfaces only exposed to the Window") if $interface->extendedAttributes->{Exposed} && $interface->extendedAttributes->{Exposed} ne "Window";
+
+ my @flags = split(/&/, $context->extendedAttributes->{EnabledBySetting});
+ foreach my $flag (@flags) {
+ push(@conjuncts, "downcast<Document>(jsCast<JSDOMGlobalObject*>(globalObject())->scriptExecutionContext())->settings()." . ToMethodName($flag) . "Enabled()");
+ }
+ }
+
if ($context->extendedAttributes->{EnabledAtRuntime}) {
assert("Must specify value for EnabledAtRuntime.") if $context->extendedAttributes->{EnabledAtRuntime} eq "VALUE_IS_MISSING";
@@ -3950,11 +3957,9 @@ sub GenerateImplementation
my $hashName = $className . "Table";
my @runtimeEnabledOperations = ();
my @runtimeEnabledAttributes = ();
- my @settingsEnabledOperations = ();
- my @settingsEnabledAttributes = ();
# Generate hash table for properties on the instance.
- my $numInstanceProperties = GeneratePropertiesHashTable($object, $interface, 1, \@hashKeys, \@hashSpecials, \@hashValue1, \@hashValue2, \%conditionals, \%readWriteConditionals, \@runtimeEnabledOperations, \@runtimeEnabledAttributes, \@settingsEnabledOperations, \@settingsEnabledAttributes);
+ my $numInstanceProperties = GeneratePropertiesHashTable($object, $interface, 1, \@hashKeys, \@hashSpecials, \@hashValue1, \@hashValue2, \%conditionals, \%readWriteConditionals, \@runtimeEnabledOperations, \@runtimeEnabledAttributes);
$object->GenerateHashTable($className, $hashName, $numInstanceProperties, \@hashKeys, \@hashSpecials, \@hashValue1, \@hashValue2, \%conditionals, \%readWriteConditionals, 0) if $numInstanceProperties > 0;
# - Add all interface object (aka constructor) properties (constants, static attributes, static operations).
@@ -4070,16 +4075,13 @@ sub GenerateImplementation
%readWriteConditionals = ();
@runtimeEnabledOperations = ();
@runtimeEnabledAttributes = ();
- @settingsEnabledOperations = ();
- @settingsEnabledAttributes = ();
# Generate hash table for properties on the prototype.
my $numPrototypeProperties = GeneratePropertiesHashTable($object, $interface, 0,
\@hashKeys, \@hashSpecials,
\@hashValue1, \@hashValue2,
\%conditionals, \%readWriteConditionals,
- \@runtimeEnabledOperations, \@runtimeEnabledAttributes,
- \@settingsEnabledOperations, \@settingsEnabledAttributes);
+ \@runtimeEnabledOperations, \@runtimeEnabledAttributes);
my $hashSize = $numPrototypeProperties;
@@ -4128,31 +4130,6 @@ sub GenerateImplementation
push(@implContent, "#endif\n") if $conditionalString;
}
- my @settingsEnabledProperties = @settingsEnabledOperations;
- push(@settingsEnabledProperties, @settingsEnabledAttributes);
- if (scalar(@settingsEnabledProperties)) {
- AddToImplIncludes("Document.h");
- AddToImplIncludes("Settings.h");
- push(@implContent, " auto* context = jsCast<JSDOMGlobalObject*>(globalObject())->scriptExecutionContext();\n");
- push(@implContent, " ASSERT(!context || context->isDocument());\n");
-
- foreach my $operationOrAttribute (@settingsEnabledProperties) {
- my $conditionalString = $codeGenerator->GenerateConditionalString($operationOrAttribute);
- push(@implContent, "#if ${conditionalString}\n") if $conditionalString;
-
- my $enableFunction = ToMethodName($operationOrAttribute->extendedAttributes->{EnabledBySetting}) . "Enabled";
- my $name = $operationOrAttribute->name;
-
- push(@implContent, " if (!context || !downcast<Document>(*context).settings().${enableFunction}()) {\n");
- push(@implContent, " auto propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>(\"$name\"), strlen(\"$name\"));\n");
- push(@implContent, " VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);\n");
- push(@implContent, " JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName);\n");
- push(@implContent, " }\n");
-
- push(@implContent, "#endif\n") if $conditionalString;
- }
- }
-
foreach my $operation (@{$interface->operations}) {
next unless ($operation->extendedAttributes->{PrivateIdentifier});
AddToImplIncludes("WebCoreJSClientData.h");
@@ -4251,17 +4228,17 @@ sub GenerateImplementation
next unless NeedsRuntimeCheck($interface, $attribute);
next unless AttributeShouldBeOnInstance($interface, $attribute);
- my $conditionalString = $codeGenerator->GenerateConditionalString($attribute);
- push(@implContent, "#if ${conditionalString}\n") if $conditionalString;
+ AddToImplIncludes("WebCoreJSClientData.h");
my $runtimeEnableConditionalString = GenerateRuntimeEnableConditionalString($interface, $attribute);
my $attributeName = $attribute->name;
- push(@implContent, " if (${runtimeEnableConditionalString}) {\n");
my $getter = GetAttributeGetterName($interface, $className, $attribute);
my $setter = IsReadonly($attribute) ? "nullptr" : GetAttributeSetterName($interface, $className, $attribute);
- push(@implContent, " auto* customGetterSetter = CustomGetterSetter::create(vm, $getter, $setter);\n");
my $jscAttributes = GetJSCAttributesForAttribute($interface, $attribute);
- push(@implContent, " putDirectCustomAccessor(vm, vm.propertyNames->$attributeName, customGetterSetter, attributesForStructure($jscAttributes));\n");
- push(@implContent, " }\n");
+
+ my $conditionalString = $codeGenerator->GenerateConditionalString($attribute);
+ push(@implContent, "#if ${conditionalString}\n") if $conditionalString;
+ push(@implContent, " if (${runtimeEnableConditionalString})\n");
+ push(@implContent, " putDirectCustomAccessor(vm, static_cast<JSVMClientData*>(vm.clientData)->builtinNames()." . $attributeName . "PublicName(), CustomGetterSetter::create(vm, $getter, $setter), attributesForStructure($jscAttributes));\n");
push(@implContent, "#endif\n") if $conditionalString;
}
@@ -4286,17 +4263,17 @@ sub GenerateImplementation
next unless OperationShouldBeOnInstance($interface, $operation);
next if $operation->{overloadIndex} && $operation->{overloadIndex} > 1;
- my $conditionalString = $codeGenerator->GenerateConditionalString($operation);
- push(@implContent, "#if ${conditionalString}\n") if $conditionalString;
+ AddToImplIncludes("WebCoreJSClientData.h");
my $runtimeEnableConditionalString = GenerateRuntimeEnableConditionalString($interface, $operation);
my $functionName = $operation->name;
my $implementationFunction = GetFunctionName($interface, $className, $operation);
my $functionLength = GetFunctionLength($operation);
my $jsAttributes = ComputeFunctionSpecial($interface, $operation);
- push(@implContent, " if (${runtimeEnableConditionalString})\n");
- my $propertyName = "vm.propertyNames->$functionName";
- $propertyName = "static_cast<JSVMClientData*>(vm.clientData)->builtinNames()." . $functionName . "PrivateName()" if $operation->extendedAttributes->{PrivateIdentifier};
+ my $conditionalString = $codeGenerator->GenerateConditionalString($operation);
+ push(@implContent, "#if ${conditionalString}\n") if $conditionalString;
+ push(@implContent, " if (${runtimeEnableConditionalString})\n");
+ my $propertyName = "static_cast<JSVMClientData*>(vm.clientData)->builtinNames()." . $functionName . ($operation->extendedAttributes->{PrivateIdentifier} ? "PrivateName()" : "PublicName()");
if (IsJSBuiltin($interface, $operation)) {
push(@implContent, " putDirectBuiltinFunction(vm, this, $propertyName, $implementationFunction(vm), attributesForStructure($jsAttributes));\n");
} else {
@@ -4690,24 +4667,7 @@ sub GenerateAttributeGetterBodyDefinition
push(@$outputArray, "{\n");
push(@$outputArray, " UNUSED_PARAM(throwScope);\n");
push(@$outputArray, " UNUSED_PARAM(state);\n");
-
- # Global constructors can be disabled at runtime.
- # FIXME: Returning undefined is not the same as diasabling. These properties should be removed
- # from the object instead.
- if ($codeGenerator->IsConstructorType($attribute->type)) {
- if ($attribute->extendedAttributes->{EnabledBySetting}) {
- AddToImplIncludes("Frame.h", $conditional);
- AddToImplIncludes("Settings.h", $conditional);
-
- my $enableFunction = ToMethodName($attribute->extendedAttributes->{EnabledBySetting}) . "Enabled";
- push(@$outputArray, " if (UNLIKELY(!thisObject.wrapped().frame()))\n");
- push(@$outputArray, " return jsUndefined();\n");
- push(@$outputArray, " Settings& settings = thisObject.wrapped().frame()->settings();\n");
- push(@$outputArray, " if (!settings.$enableFunction())\n");
- push(@$outputArray, " return jsUndefined();\n");
- }
- }
-
+
if ($interface->extendedAttributes->{CheckSecurity} &&
!$attribute->extendedAttributes->{DoNotCheckSecurity} &&
!$attribute->extendedAttributes->{DoNotCheckSecurityOnGetter}) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment