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

Side by Side Diff: test/cctest/test-api.cc

Issue 106763002: Get information about original function from bound function (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Code review response 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
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 17818 matching lines...) Expand 10 before | Expand all | Expand 10 after
17829 script->Run(); 17829 script->Run();
17830 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( 17830 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
17831 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo"))); 17831 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo")));
17832 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( 17832 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast(
17833 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "bar"))); 17833 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "bar")));
17834 CHECK_EQ(script->GetId(), foo->ScriptId()); 17834 CHECK_EQ(script->GetId(), foo->ScriptId());
17835 CHECK_EQ(script->GetId(), bar->ScriptId()); 17835 CHECK_EQ(script->GetId(), bar->ScriptId());
17836 } 17836 }
17837 17837
17838 17838
17839 THREADED_TEST(FunctionGetBoundFunction) {
17840 LocalContext env;
17841 v8::HandleScope scope(env->GetIsolate());
17842 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::NewFromUtf8(
17843 env->GetIsolate(), "test"));
17844 v8::Handle<v8::String> script = v8::String::NewFromUtf8(
17845 env->GetIsolate(),
17846 "var a = new Object();\n"
17847 "a.x = 1;\n"
17848 "function f () { return this.x };\n"
17849 "var g = f.bind(a);\n"
17850 "var b = g();");
17851 v8::Script::Compile(script, &origin)->Run();
17852 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
17853 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f")));
17854 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast(
17855 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "g")));
17856 CHECK(g->GetBoundFunction()->IsFunction());
17857 Local<v8::Function> original_function = Local<v8::Function>::Cast(
17858 g->GetBoundFunction());
17859 CHECK_EQ(f->GetName(), original_function->GetName());
17860 CHECK_EQ(f->GetScriptLineNumber(), original_function->GetScriptLineNumber());
17861 CHECK_EQ(f->GetScriptColumnNumber(),
17862 original_function->GetScriptColumnNumber());
17863 }
17864
17865
17839 static void GetterWhichReturns42( 17866 static void GetterWhichReturns42(
17840 Local<String> name, 17867 Local<String> name,
17841 const v8::PropertyCallbackInfo<v8::Value>& info) { 17868 const v8::PropertyCallbackInfo<v8::Value>& info) {
17842 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); 17869 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject());
17843 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); 17870 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject());
17844 info.GetReturnValue().Set(v8_num(42)); 17871 info.GetReturnValue().Set(v8_num(42));
17845 } 17872 }
17846 17873
17847 17874
17848 static void SetterWhichSetsYOnThisTo23( 17875 static void SetterWhichSetsYOnThisTo23(
(...skipping 3101 matching lines...) Expand 10 before | Expand all | Expand 10 after
20950 } 20977 }
20951 for (int i = 0; i < runs; i++) { 20978 for (int i = 0; i < runs; i++) {
20952 Local<String> expected; 20979 Local<String> expected;
20953 if (i != 0) { 20980 if (i != 0) {
20954 CHECK_EQ(v8_str("escape value"), values[i]); 20981 CHECK_EQ(v8_str("escape value"), values[i]);
20955 } else { 20982 } else {
20956 CHECK(values[i].IsEmpty()); 20983 CHECK(values[i].IsEmpty());
20957 } 20984 }
20958 } 20985 }
20959 } 20986 }
OLDNEW
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698