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

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: 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 2705 matching lines...) Expand 10 before | Expand all | Expand 10 after
2716 END 2716 END
2717 $code .= "}\n\n"; 2717 $code .= "}\n\n";
2718 $implementation{nameSpaceInternal}->add($code); 2718 $implementation{nameSpaceInternal}->add($code);
2719 } 2719 }
2720 2720
2721 sub GenerateSingleConstructorCallback 2721 sub GenerateSingleConstructorCallback
2722 { 2722 {
2723 my $interface = shift; 2723 my $interface = shift;
2724 my $function = shift; 2724 my $function = shift;
2725 2725
2726 my $interfaceName = $interface->name;
2726 my $implClassName = GetImplName($interface); 2727 my $implClassName = GetImplName($interface);
2727 my $v8ClassName = GetV8ClassName($interface); 2728 my $v8ClassName = GetV8ClassName($interface);
2728 my $overloadedIndexString = ""; 2729 my $overloadedIndexString = "";
2729 if ($function->overloadedIndex > 0) { 2730 if ($function->overloadedIndex > 0) {
2730 $overloadedIndexString .= $function->overloadedIndex; 2731 $overloadedIndexString .= $function->overloadedIndex;
2731 } 2732 }
2732 2733
2733 my $constructorRaisesException = $interface->extendedAttributes->{"RaisesExc eption"} && $interface->extendedAttributes->{"RaisesException"} eq "Constructor" ; 2734 my $constructorRaisesException = $interface->extendedAttributes->{"RaisesExc eption"} && $interface->extendedAttributes->{"RaisesException"} eq "Constructor" ;
2734 my $raisesExceptions = $function->extendedAttributes->{"RaisesException"} || $constructorRaisesException; 2735 my $raisesExceptions = $function->extendedAttributes->{"RaisesException"} || $constructorRaisesException;
2735 2736
2736 my @beforeArgumentList; 2737 my @beforeArgumentList;
2737 my @afterArgumentList; 2738 my @afterArgumentList;
2738 my $code = ""; 2739 my $code = "";
2739 $code .= <<END; 2740 $code .= <<END;
2740 static void constructor${overloadedIndexString}(const v8::FunctionCallbackInfo<v 8::Value>& info) 2741 static void constructor${overloadedIndexString}(const v8::FunctionCallbackInfo<v 8::Value>& info)
2741 { 2742 {
2742 END 2743 END
2743 2744
2744 if ($function->overloadedIndex == 0) { 2745 if ($function->overloadedIndex == 0) {
2745 $code .= GenerateArgumentsCountCheck($function, $interface); 2746 $code .= GenerateArgumentsCountCheck($function, $interface);
2746 } 2747 }
2747 2748
2748 if ($raisesExceptions) { 2749 if ($raisesExceptions) {
2749 AddToImplIncludes("bindings/v8/ExceptionState.h"); 2750 AddToImplIncludes("bindings/v8/ExceptionState.h");
2750 $code .= " ExceptionState exceptionState(info.Holder(), info.GetIsola te());\n"; 2751 $code .= " ExceptionState exceptionState(ExceptionState::Construction Context, \"${interfaceName}\", info.Holder(), info.GetIsolate());\n";
2751 } 2752 }
2752 2753
2753 # FIXME: Currently [Constructor(...)] does not yet support optional argument s without [Default=...] 2754 # FIXME: Currently [Constructor(...)] does not yet support optional argument s without [Default=...]
2754 my ($parameterCheckString, $paramIndex, %replacements) = GenerateParametersC heck($function, $interface, ""); 2755 my ($parameterCheckString, $paramIndex, %replacements) = GenerateParametersC heck($function, $interface, "");
2755 $code .= $parameterCheckString; 2756 $code .= $parameterCheckString;
2756 2757
2757 if ($interface->extendedAttributes->{"ConstructorCallWith"}) { 2758 if ($interface->extendedAttributes->{"ConstructorCallWith"}) {
2758 if (ExtendedAttributeContains($interface->extendedAttributes->{"Construc torCallWith"}, "ExecutionContext")) { 2759 if (ExtendedAttributeContains($interface->extendedAttributes->{"Construc torCallWith"}, "ExecutionContext")) {
2759 push(@beforeArgumentList, "context"); 2760 push(@beforeArgumentList, "context");
2760 $code .= " ExecutionContext* context = getExecutionContext();\n"; 2761 $code .= " ExecutionContext* context = getExecutionContext();\n";
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
2856 foreach my $constructor (@{$interface->constructors}) { 2857 foreach my $constructor (@{$interface->constructors}) {
2857 GenerateSingleConstructorCallback($interface, $constructor); 2858 GenerateSingleConstructorCallback($interface, $constructor);
2858 } 2859 }
2859 GenerateOverloadedConstructorCallback($interface); 2860 GenerateOverloadedConstructorCallback($interface);
2860 } 2861 }
2861 } 2862 }
2862 2863
2863 sub GenerateEventConstructor 2864 sub GenerateEventConstructor
2864 { 2865 {
2865 my $interface = shift; 2866 my $interface = shift;
2867
jochen (gone - plz use gerrit) 2013/12/10 11:41:19 spurious?
Mike West 2013/12/10 11:51:27 Yes (though I think it's probably good practice to
2866 my $interfaceName = $interface->name; 2868 my $interfaceName = $interface->name;
2867 my $implClassName = GetImplName($interface); 2869 my $implClassName = GetImplName($interface);
2868 my $v8ClassName = GetV8ClassName($interface); 2870 my $v8ClassName = GetV8ClassName($interface);
2869 2871
2870 my $constructorRaisesException = $interface->extendedAttributes->{"RaisesExc eption"} && $interface->extendedAttributes->{"RaisesException"} eq "Constructor" ; 2872 my $constructorRaisesException = $interface->extendedAttributes->{"RaisesExc eption"} && $interface->extendedAttributes->{"RaisesException"} eq "Constructor" ;
2871 2873
2872 my @anyAttributeNames; 2874 my @anyAttributeNames;
2873 my @serializableAnyAttributeNames; 2875 my @serializableAnyAttributeNames;
2874 foreach my $attribute (@{$interface->attributes}) { 2876 foreach my $attribute (@{$interface->attributes}) {
2875 if ($attribute->type eq "any") { 2877 if ($attribute->type eq "any") {
2876 push(@anyAttributeNames, $attribute->name); 2878 push(@anyAttributeNames, $attribute->name);
2877 if (!$attribute->extendedAttributes->{"Unserializable"}) { 2879 if (!$attribute->extendedAttributes->{"Unserializable"}) {
2878 push(@serializableAnyAttributeNames, $attribute->name); 2880 push(@serializableAnyAttributeNames, $attribute->name);
2879 } 2881 }
2880 } 2882 }
2881 } 2883 }
2882 2884
2883 AddToImplIncludes("bindings/v8/Dictionary.h"); 2885 AddToImplIncludes("bindings/v8/Dictionary.h");
2884 $implementation{nameSpaceInternal}->add(<<END); 2886 $implementation{nameSpaceInternal}->add(<<END);
2885 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info) 2887 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
2886 { 2888 {
2889 ExceptionState exceptionState(ExceptionState::ConstructionContext, \"${inter faceName}\", info.Holder(), info.GetIsolate());
2887 if (info.Length() < 1) { 2890 if (info.Length() < 1) {
2888 throwTypeError(ExceptionMessages::failedToConstruct("$interfaceName", "A n event name must be provided."), info.GetIsolate()); 2891 exceptionState.throwTypeError("An event name must be provided.");
2892 exceptionState.throwIfNeeded();
2889 return; 2893 return;
2890 } 2894 }
2891 2895
2892 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, type, info[0]); 2896 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, type, info[0]);
2893 END 2897 END
2894 2898
2895 foreach my $attrName (@anyAttributeNames) { 2899 foreach my $attrName (@anyAttributeNames) {
2896 $implementation{nameSpaceInternal}->add(" v8::Local<v8::Value> ${attr Name};\n"); 2900 $implementation{nameSpaceInternal}->add(" v8::Local<v8::Value> ${attr Name};\n");
2897 } 2901 }
2898 2902
2899 $implementation{nameSpaceInternal}->add(<<END); 2903 $implementation{nameSpaceInternal}->add(<<END);
2900 ${implClassName}Init eventInit; 2904 ${implClassName}Init eventInit;
2901 if (info.Length() >= 2) { 2905 if (info.Length() >= 2) {
2902 V8TRYCATCH_VOID(Dictionary, options, Dictionary(info[1], info.GetIsolate ())); 2906 V8TRYCATCH_VOID(Dictionary, options, Dictionary(info[1], info.GetIsolate ()));
2903 ExceptionState exceptionState(info.Holder(), info.GetIsolate());
2904 if (!initialize${implClassName}(eventInit, options, exceptionState)) { 2907 if (!initialize${implClassName}(eventInit, options, exceptionState)) {
2905 exceptionState.throwIfNeeded(); 2908 exceptionState.throwIfNeeded();
2906 return; 2909 return;
2907 } 2910 }
2908 END 2911 END
2909 2912
2910 # Store 'any'-typed properties on the wrapper to avoid leaking them between isolated worlds. 2913 # Store 'any'-typed properties on the wrapper to avoid leaking them between isolated worlds.
2911 foreach my $attrName (@anyAttributeNames) { 2914 foreach my $attrName (@anyAttributeNames) {
2912 $implementation{nameSpaceInternal}->add(<<END); 2915 $implementation{nameSpaceInternal}->add(<<END);
2913 options.get("${attrName}", ${attrName}); 2916 options.get("${attrName}", ${attrName});
2914 if (!${attrName}.IsEmpty()) 2917 if (!${attrName}.IsEmpty())
2915 info.Holder()->SetHiddenValue(V8HiddenPropertyName::${attrName}(info .GetIsolate()), ${attrName}); 2918 info.Holder()->SetHiddenValue(V8HiddenPropertyName::${attrName}(info .GetIsolate()), ${attrName});
2916 END 2919 END
2917 } 2920 }
2918 2921
2919 $implementation{nameSpaceInternal}->add(<<END); 2922 $implementation{nameSpaceInternal}->add(<<END);
2920 } 2923 }
2921 END 2924 END
2922 2925
2923 my $exceptionStateArgument = ""; 2926 my $exceptionStateArgument = "";
2924 if ($constructorRaisesException) { 2927 if ($constructorRaisesException) {
2925 ${exceptionStateArgument} = ", exceptionState"; 2928 ${exceptionStateArgument} = ", exceptionState";
2926 AddToImplIncludes("bindings/v8/ExceptionState.h");
2927 $implementation{nameSpaceInternal}->add(<<END);
2928 ExceptionState exceptionState(info.Holder(), info.GetIsolate());
2929 END
2930 } 2929 }
2931 2930
2932 $implementation{nameSpaceInternal}->add(<<END); 2931 $implementation{nameSpaceInternal}->add(<<END);
2933 RefPtr<${implClassName}> event = ${implClassName}::create(type, eventInit${e xceptionStateArgument}); 2932 RefPtr<${implClassName}> event = ${implClassName}::create(type, eventInit${e xceptionStateArgument});
2934 END 2933 END
2935 2934
2936 if ($constructorRaisesException) { 2935 if ($constructorRaisesException) {
2937 $implementation{nameSpaceInternal}->add(<<END); 2936 $implementation{nameSpaceInternal}->add(<<END);
2938 if (exceptionState.throwIfNeeded()) 2937 if (exceptionState.throwIfNeeded())
2939 return; 2938 return;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
3031 3030
3032 END 3031 END
3033 $implementation{nameSpaceWebCore}->add($code); 3032 $implementation{nameSpaceWebCore}->add($code);
3034 } 3033 }
3035 3034
3036 sub GenerateNamedConstructor 3035 sub GenerateNamedConstructor
3037 { 3036 {
3038 my $function = shift; 3037 my $function = shift;
3039 my $interface = shift; 3038 my $interface = shift;
3040 3039
3040 my $interfaceName = $interface->name;
3041 my $implClassName = GetImplName($interface); 3041 my $implClassName = GetImplName($interface);
3042 my $v8ClassName = GetV8ClassName($interface); 3042 my $v8ClassName = GetV8ClassName($interface);
3043 my $constructorRaisesException = $interface->extendedAttributes->{"RaisesExc eption"} && $interface->extendedAttributes->{"RaisesException"} eq "Constructor" ; 3043 my $constructorRaisesException = $interface->extendedAttributes->{"RaisesExc eption"} && $interface->extendedAttributes->{"RaisesException"} eq "Constructor" ;
3044 my $raisesExceptions = $function->extendedAttributes->{"RaisesException"} || $constructorRaisesException; 3044 my $raisesExceptions = $function->extendedAttributes->{"RaisesException"} || $constructorRaisesException;
3045 3045
3046 my $maybeObserveFeature = GenerateFeatureObservation($function->extendedAttr ibutes->{"MeasureAs"}); 3046 my $maybeObserveFeature = GenerateFeatureObservation($function->extendedAttr ibutes->{"MeasureAs"});
3047 my $maybeDeprecateFeature = GenerateDeprecationNotification($function->exten dedAttributes->{"DeprecateAs"}); 3047 my $maybeDeprecateFeature = GenerateDeprecationNotification($function->exten dedAttributes->{"DeprecateAs"});
3048 3048
3049 my @beforeArgumentList; 3049 my @beforeArgumentList;
3050 my @afterArgumentList; 3050 my @afterArgumentList;
(...skipping 29 matching lines...) Expand all
3080 // Make sure the document is added to the DOM Node map. Otherwise, the ${imp lClassName} instance 3080 // Make sure the document is added to the DOM Node map. Otherwise, the ${imp lClassName} instance
3081 // may end up being the only node in the map and get garbage-collected prema turely. 3081 // may end up being the only node in the map and get garbage-collected prema turely.
3082 toV8(document, info.Holder(), info.GetIsolate()); 3082 toV8(document, info.Holder(), info.GetIsolate());
3083 3083
3084 END 3084 END
3085 3085
3086 $code .= GenerateArgumentsCountCheck($function, $interface); 3086 $code .= GenerateArgumentsCountCheck($function, $interface);
3087 3087
3088 if ($raisesExceptions) { 3088 if ($raisesExceptions) {
3089 AddToImplIncludes("bindings/v8/ExceptionState.h"); 3089 AddToImplIncludes("bindings/v8/ExceptionState.h");
3090 $code .= " ExceptionState exceptionState(info.Holder(), info.GetIsola te());\n"; 3090 $code .= " ExceptionState exceptionState(ExceptionState::Construction Context, \"${interfaceName}\", info.Holder(), info.GetIsolate());\n";
3091 } 3091 }
3092 3092
3093 my ($parameterCheckString, $paramIndex, %replacements) = GenerateParametersC heck($function, $interface); 3093 my ($parameterCheckString, $paramIndex, %replacements) = GenerateParametersC heck($function, $interface);
3094 $code .= $parameterCheckString; 3094 $code .= $parameterCheckString;
3095 3095
3096 push(@beforeArgumentList, "*document"); 3096 push(@beforeArgumentList, "*document");
3097 3097
3098 if ($constructorRaisesException) { 3098 if ($constructorRaisesException) {
3099 push(@afterArgumentList, "exceptionState"); 3099 push(@afterArgumentList, "exceptionState");
3100 } 3100 }
(...skipping 3234 matching lines...) Expand 10 before | Expand all | Expand 10 after
6335 6335
6336 return 1 if ExtendedAttributeContains($interface->extendedAttributes->{"Cust om"}, "ToV8"); 6336 return 1 if ExtendedAttributeContains($interface->extendedAttributes->{"Cust om"}, "ToV8");
6337 return 1 if ExtendedAttributeContains($interface->extendedAttributes->{"Cust om"}, "Wrap"); 6337 return 1 if ExtendedAttributeContains($interface->extendedAttributes->{"Cust om"}, "Wrap");
6338 return 1 if $interface->extendedAttributes->{"SpecialWrapFor"}; 6338 return 1 if $interface->extendedAttributes->{"SpecialWrapFor"};
6339 return 1 if InheritsInterface($interface, "Document"); 6339 return 1 if InheritsInterface($interface, "Document");
6340 6340
6341 return 0; 6341 return 0;
6342 } 6342 }
6343 6343
6344 1; 6344 1;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698