From cc025d8386e1d93b703765ccb9bfb5b3d978f2df Mon Sep 17 00:00:00 2001 From: adele Date: Wed, 28 Mar 2007 20:59:59 +0000 Subject: [PATCH] WebCore: Reviewed by Kevin M. WebCore part of fix for VitalSource Bookshelf should not pass return statements into stringByEvaluatingJavaScriptFromString * page/mac/WebCoreFrameBridge.mm: (-[WebCoreFrameBridge stringByEvaluatingJavaScriptFromString:forceUserGesture:]): Convert return value to a string. This matches the behavior in Safari 2.0. WebKit: Reviewed by Kevin M. WebKit part of fix for VitalSource Bookshelf should not pass return statements into stringByEvaluatingJavaScriptFromString Added an app specific workaround for VitalSource Bookshelf that strips "return" from the beginning of their script strings. We used to allow this but now we throw a JavaScript exception for return statements that aren't in functions. Filed this evangelism bug so we can notify VitalSource of the problem: VitalSource Bookshelf should not pass return statements into stringByEvaluatingJavaScriptFromString * WebView/WebView.mm: (-[WebView stringByEvaluatingJavaScriptFromString:]): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@20555 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- WebCore/ChangeLog | 9 +++++++++ WebCore/page/mac/WebCoreFrameBridge.mm | 4 ++-- WebKit/ChangeLog | 14 ++++++++++++++ WebKit/WebView/WebView.mm | 8 ++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog index 36899c59525..05ea7c587a6 100644 --- a/WebCore/ChangeLog +++ b/WebCore/ChangeLog @@ -1,3 +1,12 @@ +2007-03-28 Adele Peterson + + Reviewed by Kevin M. + + WebCore part of fix for VitalSource Bookshelf should not pass return statements into stringByEvaluatingJavaScriptFromString + + * page/mac/WebCoreFrameBridge.mm: (-[WebCoreFrameBridge stringByEvaluatingJavaScriptFromString:forceUserGesture:]): + Convert return value to a string. This matches the behavior in Safari 2.0. + 2007-03-28 Alexey Proskuryakov Reviewed by Darin. diff --git a/WebCore/page/mac/WebCoreFrameBridge.mm b/WebCore/page/mac/WebCoreFrameBridge.mm index 0166987e903..be5376ad39b 100644 --- a/WebCore/page/mac/WebCoreFrameBridge.mm +++ b/WebCore/page/mac/WebCoreFrameBridge.mm @@ -687,10 +687,10 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element) { m_frame->loader()->createEmptyDocument(); JSValue* result = m_frame->loader()->executeScript(0, string, forceUserGesture); - if (!result || !result->isString()) + if (!result) return 0; JSLock lock; - return String(result->getString()); + return String(result->isString() ? result->getString() : result->toString(m_frame->scriptProxy()->interpreter()->globalExec())); } - (NSAppleEventDescriptor *)aeDescByEvaluatingJavaScriptFromString:(NSString *)string diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog index 3a68c64dcf7..974193b15c8 100644 --- a/WebKit/ChangeLog +++ b/WebKit/ChangeLog @@ -1,3 +1,17 @@ +2007-03-28 Adele Peterson + + Reviewed by Kevin M. + + WebKit part of fix for VitalSource Bookshelf should not pass return statements into stringByEvaluatingJavaScriptFromString + + Added an app specific workaround for VitalSource Bookshelf that strips "return" from the beginning of their script strings. We used to allow this + but now we throw a JavaScript exception for return statements that aren't in functions. + + Filed this evangelism bug so we can notify VitalSource of the problem: + VitalSource Bookshelf should not pass return statements into stringByEvaluatingJavaScriptFromString + + * WebView/WebView.mm: (-[WebView stringByEvaluatingJavaScriptFromString:]): + 2007-03-27 John Sullivan Reviewed by Tim diff --git a/WebKit/WebView/WebView.mm b/WebKit/WebView/WebView.mm index 8875104278b..1f11e0b778f 100644 --- a/WebKit/WebView/WebView.mm +++ b/WebKit/WebView/WebView.mm @@ -2099,6 +2099,14 @@ NS_ENDHANDLER - (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script { + // FIXME: We can remove this workaround for VitalSource Bookshelf when they update + // their code so that it no longer calls stringByEvaluatingJavaScriptFromString with a return statement. + // Return statements are only valid in a function. See for the evangelism bug. + if ([[[NSBundle mainBundle] bundleIdentifier] isEqualToString:@"com.vitalsource.bookshelf"]) { + NSRange returnStringRange = [script rangeOfString:@"return "]; + if (returnStringRange.length != 0 && returnStringRange.location == 0) + script = [script substringFromIndex: returnStringRange.location + returnStringRange.length]; + } return [[[self mainFrame] _bridge] stringByEvaluatingJavaScriptFromString:script]; } -- GitLab