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

Side by Side Diff: Source/bindings/v8/custom/V8WebGLRenderingContextCustom.cpp

Issue 22038002: Get rid of the tryFast*alloc API. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Review item. Created 7 years, 4 months 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
« no previous file with comments | « Source/bindings/v8/WrapperTypeInfo.h ('k') | Source/core/loader/NavigationPolicy.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 #include "bindings/v8/V8Binding.h" 73 #include "bindings/v8/V8Binding.h"
74 #include "bindings/v8/V8HiddenPropertyName.h" 74 #include "bindings/v8/V8HiddenPropertyName.h"
75 #include "core/dom/ExceptionCode.h" 75 #include "core/dom/ExceptionCode.h"
76 #include "core/html/canvas/WebGLRenderingContext.h" 76 #include "core/html/canvas/WebGLRenderingContext.h"
77 #include "core/platform/NotImplemented.h" 77 #include "core/platform/NotImplemented.h"
78 #include <limits> 78 #include <limits>
79 #include "wtf/FastMalloc.h" 79 #include "wtf/FastMalloc.h"
80 80
81 namespace WebCore { 81 namespace WebCore {
82 82
83 // Allocates new storage via tryFastMalloc. 83 // Allocates new storage via fastMalloc.
84 // Returns NULL if array failed to convert for any reason. 84 // Returns NULL if array failed to convert for any reason.
85 static float* jsArrayToFloatArray(v8::Handle<v8::Array> array, uint32_t len) 85 static float* jsArrayToFloatArray(v8::Handle<v8::Array> array, uint32_t len)
86 { 86 {
87 // Convert the data element-by-element. 87 // Convert the data element-by-element.
88 float* data = 0; 88 if (len > std::numeric_limits<uint32_t>::max() / sizeof(float))
89 if (len > std::numeric_limits<uint32_t>::max() / sizeof(float)
90 || !tryFastMalloc(len * sizeof(float)).getValue(data))
91 return 0; 89 return 0;
90 float* data = static_cast<float*>(fastMalloc(len * sizeof(float)));
91
92 for (uint32_t i = 0; i < len; i++) { 92 for (uint32_t i = 0; i < len; i++) {
93 v8::Local<v8::Value> val = array->Get(i); 93 v8::Local<v8::Value> val = array->Get(i);
94 if (!val->IsNumber()) { 94 if (!val->IsNumber()) {
95 fastFree(data); 95 fastFree(data);
96 return 0; 96 return 0;
97 } 97 }
98 data[i] = toFloat(val); 98 data[i] = toFloat(val);
99 } 99 }
100 return data; 100 return data;
101 } 101 }
102 102
103 // Allocates new storage via tryFastMalloc. 103 // Allocates new storage via fastMalloc.
104 // Returns NULL if array failed to convert for any reason. 104 // Returns NULL if array failed to convert for any reason.
105 static int* jsArrayToIntArray(v8::Handle<v8::Array> array, uint32_t len) 105 static int* jsArrayToIntArray(v8::Handle<v8::Array> array, uint32_t len)
106 { 106 {
107 // Convert the data element-by-element. 107 // Convert the data element-by-element.
108 int* data = 0; 108 if (len > std::numeric_limits<uint32_t>::max() / sizeof(int))
109 if (len > std::numeric_limits<uint32_t>::max() / sizeof(int)
110 || !tryFastMalloc(len * sizeof(int)).getValue(data))
111 return 0; 109 return 0;
110 int* data = static_cast<int*>(fastMalloc(len * sizeof(int)));
111
112 for (uint32_t i = 0; i < len; i++) { 112 for (uint32_t i = 0; i < len; i++) {
113 v8::Local<v8::Value> val = array->Get(i); 113 v8::Local<v8::Value> val = array->Get(i);
114 bool ok; 114 bool ok;
115 int ival = toInt32(val, ok); 115 int ival = toInt32(val, ok);
116 if (!ok) { 116 if (!ok) {
117 fastFree(data); 117 fastFree(data);
118 return 0; 118 return 0;
119 } 119 }
120 data[i] = ival; 120 data[i] = ival;
121 } 121 }
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 { 798 {
799 vertexAttribAndUniformHelperf(args, kVertexAttrib3v); 799 vertexAttribAndUniformHelperf(args, kVertexAttrib3v);
800 } 800 }
801 801
802 void V8WebGLRenderingContext::vertexAttrib4fvMethodCustom(const v8::FunctionCall backInfo<v8::Value>& args) 802 void V8WebGLRenderingContext::vertexAttrib4fvMethodCustom(const v8::FunctionCall backInfo<v8::Value>& args)
803 { 803 {
804 vertexAttribAndUniformHelperf(args, kVertexAttrib4v); 804 vertexAttribAndUniformHelperf(args, kVertexAttrib4v);
805 } 805 }
806 806
807 } // namespace WebCore 807 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/WrapperTypeInfo.h ('k') | Source/core/loader/NavigationPolicy.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698