Index: third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp |
diff --git a/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp b/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp |
index 1c7cf0f6b1bd990e571bc530520c1ecd66fd4eb4..6a620f40354c4829551292713317e3ca9ea52c3d 100644 |
--- a/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp |
+++ b/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp |
@@ -448,6 +448,14 @@ void StripComments::process(UChar c) |
break; |
case InSingleLineComment: |
+ // Line-continuation characters are processed before comment processing. |
+ // Advance string if a new line character is immediately behind |
+ // line-continuation character. |
+ if (c == '\\') { |
+ if (peek(temp) && isNewline(temp)) |
Zhenyao Mo
2016/06/30 16:10:39
What if it's "\r\n"? Two characters but still one
Zhenyao Mo
2016/06/30 16:40:55
Never mind. It doesn't matter.
|
+ advance(); |
+ } |
+ |
// The newline code at the top of this function takes care |
// of resetting our state when we get out of the |
// single-line comment. Swallow all other characters. |
@@ -3856,9 +3864,9 @@ void WebGLRenderingContextBase::shaderSource(WebGLShader* shader, const String& |
if (isContextLost() || !validateWebGLObject("shaderSource", shader)) |
return; |
String stringWithoutComments = StripComments(string).result(); |
- // TODO(danakj): Make validateString reject characters > 255 (or utf16 Strings) |
+ // TODO(danakj): Make validateShaderSource reject characters > 255 (or utf16 Strings) |
// so we don't need to use StringUTF8Adaptor. |
- if (!validateString("shaderSource", stringWithoutComments)) |
+ if (!validateShaderSource(stringWithoutComments)) |
return; |
shader->setSource(string); |
WTF::StringUTF8Adaptor adaptor(stringWithoutComments); |
@@ -5469,6 +5477,25 @@ bool WebGLRenderingContextBase::validateString(const char* functionName, const S |
return true; |
} |
+bool WebGLRenderingContextBase::validateShaderSource(const String& string) |
+{ |
+ for (size_t i = 0; i < string.length(); ++i) { |
+ // line-continuation character \ is supported in WebGL 2.0. |
+ if (isWebGL2OrHigher() && string[i] == '\\') { |
+ if (i + 1 >= string.length() || (string[i + 1] != '\n' && string[i + 1] != '\r')) { |
+ synthesizeGLError(GL_INVALID_VALUE, "shaderSource", "line-continuation character is not immediately preceding a new-line"); |
Zhenyao Mo
2016/06/30 16:10:39
From reading the spec, I am not sure if it's an er
Ken Russell (switch to Gerrit)
2016/07/01 00:42:30
From my reading of the spec, the continuation char
qiankun
2016/07/01 10:32:01
Comments have already been removed before doing va
Zhenyao Mo
2016/07/01 16:53:50
Is this behavior (generating INVALID_VALUE if '\\'
|
+ return false; |
+ } |
+ continue; |
+ } |
+ if (!validateCharacter(string[i])) { |
+ synthesizeGLError(GL_INVALID_VALUE, "shaderSource", "string not ASCII"); |
+ return false; |
+ } |
+ } |
+ return true; |
+} |
+ |
bool WebGLRenderingContextBase::validateTexFuncFormatAndType(const char* functionName, TexImageFunctionType functionType, GLenum internalformat, GLenum format, GLenum type, GLint level) |
{ |
if (!m_isWebGL2FormatsTypesAdded && isWebGL2OrHigher()) { |