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

Unified Diff: runtime/lib/identical.cc

Issue 312693008: Add javascript compatibility warnings for strings that are not identical, but (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/identical.cc
===================================================================
--- runtime/lib/identical.cc (revision 37011)
+++ runtime/lib/identical.cc (working copy)
@@ -4,14 +4,45 @@
#include "vm/bootstrap_natives.h"
+#include "vm/code_patcher.h"
+#include "vm/exceptions.h"
#include "vm/object.h"
+#include "vm/stack_frame.h"
namespace dart {
+DECLARE_FLAG(bool, warn_on_javascript_compatibility);
+
+static void JSWarning(const char* msg) {
+ DartFrameIterator iterator;
+ iterator.NextFrame(); // Skip native call.
+ StackFrame* caller_frame = iterator.NextFrame();
+ ASSERT(caller_frame != NULL);
+ const Code& caller_code = Code::Handle(caller_frame->LookupDartCode());
+ ASSERT(!caller_code.IsNull());
+ const uword caller_pc = caller_frame->pc();
+ // Assume an unoptimized static call. Optimization was prevented.
+ ICData& ic_data = ICData::Handle();
+ CodePatcher::GetUnoptimizedStaticCallAt(caller_pc, caller_code, &ic_data);
+ ASSERT(!ic_data.IsNull());
+ // Report warning only if not already reported at this location.
+ if (!ic_data.IssuedJSWarning()) {
+ ic_data.SetIssuedJSWarning();
+ Exceptions::JSWarning(caller_frame, "%s", msg);
+ }
+}
+
+
DEFINE_NATIVE_ENTRY(Identical_comparison, 2) {
GET_NATIVE_ARGUMENT(Instance, a, arguments->NativeArgAt(0));
GET_NATIVE_ARGUMENT(Instance, b, arguments->NativeArgAt(1));
- return Bool::Get(a.IsIdenticalTo(b)).raw();
+ const bool is_identical = a.IsIdenticalTo(b);
+ if (FLAG_warn_on_javascript_compatibility) {
+ if (!is_identical && a.IsString() && String::Cast(a).Equals(b)) {
+ JSWarning("strings that are equal are also identical");
+ }
+ }
+ return Bool::Get(is_identical).raw();
}
} // namespace dart
« no previous file with comments | « no previous file | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698