Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: Source/bindings/scripts/code_generator_v8.pm

Issue 111373003: Migrate bindings constructors to the new ExceptionState model. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Ugh. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 2746 matching lines...) Expand 10 before | Expand all | Expand 10 after
2757 } 2757 }
2758 $code .= "}\n\n"; 2758 $code .= "}\n\n";
2759 $implementation{nameSpaceInternal}->add($header . $code); 2759 $implementation{nameSpaceInternal}->add($header . $code);
2760 } 2760 }
2761 2761
2762 sub GenerateSingleConstructorCallback 2762 sub GenerateSingleConstructorCallback
2763 { 2763 {
2764 my $interface = shift; 2764 my $interface = shift;
2765 my $function = shift; 2765 my $function = shift;
2766 2766
2767 my $interfaceName = $interface->name;
2767 my $implClassName = GetImplName($interface); 2768 my $implClassName = GetImplName($interface);
2768 my $v8ClassName = GetV8ClassName($interface); 2769 my $v8ClassName = GetV8ClassName($interface);
2769 my $overloadedIndexString = ""; 2770 my $overloadedIndexString = "";
2770 if ($function->overloadedIndex > 0) { 2771 if ($function->overloadedIndex > 0) {
2771 $overloadedIndexString .= $function->overloadedIndex; 2772 $overloadedIndexString .= $function->overloadedIndex;
2772 } 2773 }
2773 2774
2774 my $constructorRaisesException = $interface->extendedAttributes->{"RaisesExc eption"} && $interface->extendedAttributes->{"RaisesException"} eq "Constructor" ; 2775 my $constructorRaisesException = $interface->extendedAttributes->{"RaisesExc eption"} && $interface->extendedAttributes->{"RaisesException"} eq "Constructor" ;
2775 my $raisesExceptions = $function->extendedAttributes->{"RaisesException"} || $constructorRaisesException; 2776 my $raisesExceptions = $function->extendedAttributes->{"RaisesException"} || $constructorRaisesException;
2776 2777
2777 my @beforeArgumentList; 2778 my @beforeArgumentList;
2778 my @afterArgumentList; 2779 my @afterArgumentList;
2779 my $code = ""; 2780 my $code = "";
2780 $code .= <<END; 2781 $code .= <<END;
2781 static void constructor${overloadedIndexString}(const v8::FunctionCallbackInfo<v 8::Value>& info) 2782 static void constructor${overloadedIndexString}(const v8::FunctionCallbackInfo<v 8::Value>& info)
2782 { 2783 {
2783 END 2784 END
2784 2785
2785 if ($function->overloadedIndex == 0) { 2786 if ($function->overloadedIndex == 0) {
2786 my $hasExceptionState = 0; 2787 my $hasExceptionState = 0;
2787 $code .= GenerateArgumentsCountCheck($function, $interface, $hasExceptio nState); 2788 $code .= GenerateArgumentsCountCheck($function, $interface, $hasExceptio nState);
2788 } 2789 }
2789 2790
2790 if ($raisesExceptions) { 2791 if ($raisesExceptions) {
2791 AddToImplIncludes("bindings/v8/ExceptionState.h"); 2792 AddToImplIncludes("bindings/v8/ExceptionState.h");
2792 $code .= " ExceptionState exceptionState(info.Holder(), info.GetIsola te());\n"; 2793 $code .= " ExceptionState exceptionState(ExceptionState::Construction Context, \"${interfaceName}\", info.Holder(), info.GetIsolate());\n";
2793 } 2794 }
2794 2795
2795 # FIXME: Currently [Constructor(...)] does not yet support optional argument s without [Default=...] 2796 # FIXME: Currently [Constructor(...)] does not yet support optional argument s without [Default=...]
2796 my ($parameterCheckString, $paramIndex, %replacements) = GenerateParametersC heck($function, $interface, ""); 2797 my ($parameterCheckString, $paramIndex, %replacements) = GenerateParametersC heck($function, $interface, "");
2797 $code .= $parameterCheckString; 2798 $code .= $parameterCheckString;
2798 2799
2799 if ($interface->extendedAttributes->{"ConstructorCallWith"}) { 2800 if ($interface->extendedAttributes->{"ConstructorCallWith"}) {
2800 if (ExtendedAttributeContains($interface->extendedAttributes->{"Construc torCallWith"}, "ExecutionContext")) { 2801 if (ExtendedAttributeContains($interface->extendedAttributes->{"Construc torCallWith"}, "ExecutionContext")) {
2801 push(@beforeArgumentList, "context"); 2802 push(@beforeArgumentList, "context");
2802 $code .= " ExecutionContext* context = getExecutionContext();\n"; 2803 $code .= " ExecutionContext* context = getExecutionContext();\n";
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
2898 foreach my $constructor (@{$interface->constructors}) { 2899 foreach my $constructor (@{$interface->constructors}) {
2899 GenerateSingleConstructorCallback($interface, $constructor); 2900 GenerateSingleConstructorCallback($interface, $constructor);
2900 } 2901 }
2901 GenerateOverloadedConstructorCallback($interface); 2902 GenerateOverloadedConstructorCallback($interface);
2902 } 2903 }
2903 } 2904 }
2904 2905
2905 sub GenerateEventConstructor 2906 sub GenerateEventConstructor
2906 { 2907 {
2907 my $interface = shift; 2908 my $interface = shift;
2909
2908 my $interfaceName = $interface->name; 2910 my $interfaceName = $interface->name;
2909 my $implClassName = GetImplName($interface); 2911 my $implClassName = GetImplName($interface);
2910 my $v8ClassName = GetV8ClassName($interface); 2912 my $v8ClassName = GetV8ClassName($interface);
2911 2913
2912 my $constructorRaisesException = $interface->extendedAttributes->{"RaisesExc eption"} && $interface->extendedAttributes->{"RaisesException"} eq "Constructor" ; 2914 my $constructorRaisesException = $interface->extendedAttributes->{"RaisesExc eption"} && $interface->extendedAttributes->{"RaisesException"} eq "Constructor" ;
2913 2915
2914 my @anyAttributeNames; 2916 my @anyAttributeNames;
2915 my @serializableAnyAttributeNames; 2917 my @serializableAnyAttributeNames;
2916 foreach my $attribute (@{$interface->attributes}) { 2918 foreach my $attribute (@{$interface->attributes}) {
2917 if ($attribute->type eq "any") { 2919 if ($attribute->type eq "any") {
2918 push(@anyAttributeNames, $attribute->name); 2920 push(@anyAttributeNames, $attribute->name);
2919 if (!$attribute->extendedAttributes->{"Unserializable"}) { 2921 if (!$attribute->extendedAttributes->{"Unserializable"}) {
2920 push(@serializableAnyAttributeNames, $attribute->name); 2922 push(@serializableAnyAttributeNames, $attribute->name);
2921 } 2923 }
2922 } 2924 }
2923 } 2925 }
2924 2926
2925 AddToImplIncludes("bindings/v8/Dictionary.h"); 2927 AddToImplIncludes("bindings/v8/Dictionary.h");
2926 $implementation{nameSpaceInternal}->add(<<END); 2928 $implementation{nameSpaceInternal}->add(<<END);
2927 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info) 2929 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
2928 { 2930 {
2931 ExceptionState exceptionState(ExceptionState::ConstructionContext, \"${inter faceName}\", info.Holder(), info.GetIsolate());
2929 if (info.Length() < 1) { 2932 if (info.Length() < 1) {
2930 throwTypeError(ExceptionMessages::failedToConstruct("$interfaceName", "A n event name must be provided."), info.GetIsolate()); 2933 exceptionState.throwTypeError("An event name must be provided.");
2934 exceptionState.throwIfNeeded();
2931 return; 2935 return;
2932 } 2936 }
2933 2937
2934 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, type, info[0]); 2938 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, type, info[0]);
2935 END 2939 END
2936 2940
2937 foreach my $attrName (@anyAttributeNames) { 2941 foreach my $attrName (@anyAttributeNames) {
2938 $implementation{nameSpaceInternal}->add(" v8::Local<v8::Value> ${attr Name};\n"); 2942 $implementation{nameSpaceInternal}->add(" v8::Local<v8::Value> ${attr Name};\n");
2939 } 2943 }
2940 2944
2941 $implementation{nameSpaceInternal}->add(<<END); 2945 $implementation{nameSpaceInternal}->add(<<END);
2942 ${implClassName}Init eventInit; 2946 ${implClassName}Init eventInit;
2943 if (info.Length() >= 2) { 2947 if (info.Length() >= 2) {
2944 V8TRYCATCH_VOID(Dictionary, options, Dictionary(info[1], info.GetIsolate ())); 2948 V8TRYCATCH_VOID(Dictionary, options, Dictionary(info[1], info.GetIsolate ()));
2945 ExceptionState exceptionState(info.Holder(), info.GetIsolate());
2946 if (!initialize${implClassName}(eventInit, options, exceptionState)) { 2949 if (!initialize${implClassName}(eventInit, options, exceptionState)) {
2947 exceptionState.throwIfNeeded(); 2950 exceptionState.throwIfNeeded();
2948 return; 2951 return;
2949 } 2952 }
2950 END 2953 END
2951 2954
2952 # Store 'any'-typed properties on the wrapper to avoid leaking them between isolated worlds. 2955 # Store 'any'-typed properties on the wrapper to avoid leaking them between isolated worlds.
2953 foreach my $attrName (@anyAttributeNames) { 2956 foreach my $attrName (@anyAttributeNames) {
2954 $implementation{nameSpaceInternal}->add(<<END); 2957 $implementation{nameSpaceInternal}->add(<<END);
2955 options.get("${attrName}", ${attrName}); 2958 options.get("${attrName}", ${attrName});
2956 if (!${attrName}.IsEmpty()) 2959 if (!${attrName}.IsEmpty())
2957 info.Holder()->SetHiddenValue(V8HiddenPropertyName::${attrName}(info .GetIsolate()), ${attrName}); 2960 info.Holder()->SetHiddenValue(V8HiddenPropertyName::${attrName}(info .GetIsolate()), ${attrName});
2958 END 2961 END
2959 } 2962 }
2960 2963
2961 $implementation{nameSpaceInternal}->add(<<END); 2964 $implementation{nameSpaceInternal}->add(<<END);
2962 } 2965 }
2963 END 2966 END
2964 2967
2965 my $exceptionStateArgument = ""; 2968 my $exceptionStateArgument = "";
2966 if ($constructorRaisesException) { 2969 if ($constructorRaisesException) {
2967 ${exceptionStateArgument} = ", exceptionState"; 2970 ${exceptionStateArgument} = ", exceptionState";
2968 AddToImplIncludes("bindings/v8/ExceptionState.h");
2969 $implementation{nameSpaceInternal}->add(<<END);
2970 ExceptionState exceptionState(info.Holder(), info.GetIsolate());
2971 END
2972 } 2971 }
2973 2972
2974 $implementation{nameSpaceInternal}->add(<<END); 2973 $implementation{nameSpaceInternal}->add(<<END);
2975 RefPtr<${implClassName}> event = ${implClassName}::create(type, eventInit${e xceptionStateArgument}); 2974 RefPtr<${implClassName}> event = ${implClassName}::create(type, eventInit${e xceptionStateArgument});
2976 END 2975 END
2977 2976
2978 if ($constructorRaisesException) { 2977 if ($constructorRaisesException) {
2979 $implementation{nameSpaceInternal}->add(<<END); 2978 $implementation{nameSpaceInternal}->add(<<END);
2980 if (exceptionState.throwIfNeeded()) 2979 if (exceptionState.throwIfNeeded())
2981 return; 2980 return;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
3073 3072
3074 END 3073 END
3075 $implementation{nameSpaceWebCore}->add($code); 3074 $implementation{nameSpaceWebCore}->add($code);
3076 } 3075 }
3077 3076
3078 sub GenerateNamedConstructor 3077 sub GenerateNamedConstructor
3079 { 3078 {
3080 my $function = shift; 3079 my $function = shift;
3081 my $interface = shift; 3080 my $interface = shift;
3082 3081
3082 my $interfaceName = $interface->name;
3083 my $implClassName = GetImplName($interface); 3083 my $implClassName = GetImplName($interface);
3084 my $v8ClassName = GetV8ClassName($interface); 3084 my $v8ClassName = GetV8ClassName($interface);
3085 my $constructorRaisesException = $interface->extendedAttributes->{"RaisesExc eption"} && $interface->extendedAttributes->{"RaisesException"} eq "Constructor" ; 3085 my $constructorRaisesException = $interface->extendedAttributes->{"RaisesExc eption"} && $interface->extendedAttributes->{"RaisesException"} eq "Constructor" ;
3086 my $raisesExceptions = $function->extendedAttributes->{"RaisesException"} || $constructorRaisesException; 3086 my $raisesExceptions = $function->extendedAttributes->{"RaisesException"} || $constructorRaisesException;
3087 3087
3088 my $maybeObserveFeature = GenerateFeatureObservation($function->extendedAttr ibutes->{"MeasureAs"}); 3088 my $maybeObserveFeature = GenerateFeatureObservation($function->extendedAttr ibutes->{"MeasureAs"});
3089 my $maybeDeprecateFeature = GenerateDeprecationNotification($function->exten dedAttributes->{"DeprecateAs"}); 3089 my $maybeDeprecateFeature = GenerateDeprecationNotification($function->exten dedAttributes->{"DeprecateAs"});
3090 3090
3091 my @beforeArgumentList; 3091 my @beforeArgumentList;
3092 my @afterArgumentList; 3092 my @afterArgumentList;
(...skipping 27 matching lines...) Expand all
3120 ASSERT(document); 3120 ASSERT(document);
3121 3121
3122 // Make sure the document is added to the DOM Node map. Otherwise, the ${imp lClassName} instance 3122 // Make sure the document is added to the DOM Node map. Otherwise, the ${imp lClassName} instance
3123 // may end up being the only node in the map and get garbage-collected prema turely. 3123 // may end up being the only node in the map and get garbage-collected prema turely.
3124 toV8(document, info.Holder(), info.GetIsolate()); 3124 toV8(document, info.Holder(), info.GetIsolate());
3125 3125
3126 END 3126 END
3127 3127
3128 if ($raisesExceptions) { 3128 if ($raisesExceptions) {
3129 AddToImplIncludes("bindings/v8/ExceptionState.h"); 3129 AddToImplIncludes("bindings/v8/ExceptionState.h");
3130 my $interfaceName = $interface->name;
3131 $code .= " ExceptionState exceptionState(ExceptionState::Construction Context, \"${interfaceName}\", info.Holder(), info.GetIsolate());\n"; 3130 $code .= " ExceptionState exceptionState(ExceptionState::Construction Context, \"${interfaceName}\", info.Holder(), info.GetIsolate());\n";
3132 } 3131 }
3133 3132
3134 my $hasExceptionState = $raisesExceptions; 3133 my $hasExceptionState = $raisesExceptions;
3135 $code .= GenerateArgumentsCountCheck($function, $interface, $hasExceptionSta te); 3134 $code .= GenerateArgumentsCountCheck($function, $interface, $hasExceptionSta te);
3136 3135
3137 my ($parameterCheckString, $paramIndex, %replacements) = GenerateParametersC heck($function, $interface); 3136 my ($parameterCheckString, $paramIndex, %replacements) = GenerateParametersC heck($function, $interface);
3138 $code .= $parameterCheckString; 3137 $code .= $parameterCheckString;
3139 3138
3140 push(@beforeArgumentList, "*document"); 3139 push(@beforeArgumentList, "*document");
(...skipping 3238 matching lines...) Expand 10 before | Expand all | Expand 10 after
6379 6378
6380 return 1 if ExtendedAttributeContains($interface->extendedAttributes->{"Cust om"}, "ToV8"); 6379 return 1 if ExtendedAttributeContains($interface->extendedAttributes->{"Cust om"}, "ToV8");
6381 return 1 if ExtendedAttributeContains($interface->extendedAttributes->{"Cust om"}, "Wrap"); 6380 return 1 if ExtendedAttributeContains($interface->extendedAttributes->{"Cust om"}, "Wrap");
6382 return 1 if $interface->extendedAttributes->{"SpecialWrapFor"}; 6381 return 1 if $interface->extendedAttributes->{"SpecialWrapFor"};
6383 return 1 if InheritsInterface($interface, "Document"); 6382 return 1 if InheritsInterface($interface, "Document");
6384 6383
6385 return 0; 6384 return 0;
6386 } 6385 }
6387 6386
6388 1; 6387 1;
OLDNEW
« no previous file with comments | « LayoutTests/webaudio/dom-exceptions-expected.txt ('k') | Source/bindings/tests/results/V8TestExtendedEvent.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698